forked from mattkeller/mk-project
/
mk-project-anything.el
163 lines (143 loc) · 7 KB
/
mk-project-anything.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;;; mk-project-anything.el --- Anything integration for mk-project
;; Copyright (C) 2008 Andreas Raster <lazor at affenbande dot org>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; More information about this library, including the most recent
;; version and a comprehensive README, is available at
;; http://github.com/mattkeller/mk-project
;;; Code:
(require 'mk-project)
(require 'anything)
(require 'anything-config)
;; ---------------------------------------------------------------------
;; Anything Utilities
;; ---------------------------------------------------------------------
(defun* project-find-anything ()
"Find files, buffers and interesting items with 'anything'.
The behaviour of this command is modified with
`mk-proj-anything-sources'."
(interactive)
(mk-proj-assert-proj)
(unless (get-buffer mk-proj-fib-name)
(message "Please use project-index to create the index before running project-find-anything")
(return-from "project-find-anything" nil))
(anything-other-buffer mk-proj-anything-sources
"*anything mk-project*"))
(defun anything-c-mk-project-buffer-persistent-action (name)
(cl-flet ((kill (item)
(with-current-buffer item
(if (and (buffer-modified-p)
(buffer-file-name (current-buffer)))
(progn
(save-buffer)
(kill-buffer item))
(kill-buffer item))))
(goto (item)
(switch-to-buffer item)))
(if current-prefix-arg
(progn
(kill name)
(anything-delete-current-selection))
(goto name))))
;; ---------------------------------------------------------------------
;; Anything Sources
;; ---------------------------------------------------------------------
(defvar anything-c-source-mk-project-projects
'((name . "mk-project Projects")
(candidates . (lambda ()
(let ((ps '()))
(maphash (lambda (k p)
(progn
;;(print (assoc 'org-header p))
(let ((h (cadr (assoc 'org-header p))))
(if h
(setq ps (cons `(,h ,k) ps))
(setq ps (cons k ps))))
))
mk-proj-list)
ps)))
(action . (lambda (entry)
(if (listp entry)
(mk-proj-load (car entry))
(mk-proj-load entry)))))
"All configured mk-project projects.")
(defvar anything-c-source-mk-project-files
'((name . "Files")
(candidates . (lambda ()
(condition-case nil
(mapcar (lambda (s)
(replace-regexp-in-string "/\\./" "/" (concat (file-name-as-directory mk-proj-basedir) s)))
(if (mk-proj-get-config-val 'patterns-are-regex)
(mk-proj-fib-matches mk-proj-src-patterns)
(mk-proj-fib-matches nil))) (error nil))))
(match anything-c-match-on-file-name
anything-c-match-on-directory-name)
(type . file))
"All files of the currently active project.")
(defvar anything-c-source-mk-project-open-buffers
'((name . "Mk-Project buffers")
(candidates . (lambda () (mapcar 'buffer-name (condition-case nil
(remove-if (lambda (buf) (string-match "\*[^\*]\*" (buffer-name buf))) (mk-proj-buffers))
(error nil)))))
(type . buffer)
(candidate-transformer anything-c-skip-current-buffer
anything-c-highlight-buffers
anything-c-skip-boring-buffers)
(persistent-action . anything-c-mk-project-buffer-persistent-action)
(persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer"))
"All buffers of the currently active project." )
(defvar anything-c-source-mk-friendly-files
'((name . "Friendly files")
(candidates . (lambda () (condition-case nil (mk-proj-fib-friend-matches) (error nil))))
(match anything-c-match-on-file-name
anything-c-match-on-directory-name)
(type . file))
"All files of projects which are friends of this project.")
(defvar anything-c-source-mk-project-open-friendly-buffers
'((name . "Mk-Project friendly buffers")
(candidates . (lambda () (mapcar 'buffer-name (condition-case nil
(mk-proj-friendly-buffers nil)
(error nil)))))
(type . buffer)
(candidate-transformer anything-c-skip-current-buffer
anything-c-highlight-buffers
anything-c-skip-boring-buffers)
(persistent-action . anything-c-mk-project-buffer-persistent-action)
(persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer"))
"All friendly buffers of the currently active project." )
(defvar anything-c-source-mk-project-open-special-buffers
'((name . "Mk-Project special buffers")
(candidates . (lambda () (mapcar 'buffer-name (condition-case nil
(mk-proj-special-buffers)
(error nil)))))
(type . buffer)
(candidate-transformer anything-c-skip-current-buffer
anything-c-highlight-buffers)
(persistent-action . anything-c-mk-project-buffer-persistent-action)
(persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer"))
"All special buffers of the currently active project." )
(defvar mk-proj-anything-sources
'(anything-c-source-mk-project-open-buffers
anything-c-source-mk-project-open-friendly-buffers
anything-c-source-mk-project-open-special-buffers
anything-c-source-mk-project-files
anything-c-source-mk-friendly-files
anything-c-source-mk-project-projects)
"The `anything-sources' that `project-find-anything' uses.
See also: `anything-c-source-mk-project-open-buffers',
`anything-c-source-mk-project-files'")
(provide 'mk-project-anything)