forked from emacs-helm/helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelm-bmkext.el
304 lines (267 loc) · 10.7 KB
/
helm-bmkext.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
;;; helm-bmkext.el --- Sources to filter bookmark-extensions bookmarks.
;; Copyright (C) 2012 ~ 2013 Thierry Volpiatto <[email protected]>
;; 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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
;; Dependency: https://github.com/thierryvolpiatto/emacs-bmk-ext
;; If you want to enable google-maps in addressbook you will need
;; Julien Danjou google-maps-el package available here:
;; http://julien.danjou.info/google-maps-el.html
;;; Code:
(eval-when-compile (require 'cl))
(require 'helm)
(require 'helm-bookmark)
(require 'helm-adaptative)
(declare-function bookmark-get-filename "bookmark" (bookmark-name-or-record))
;;; Filter functions
;;
(defun helm-bmkext-filter-setup-alist (fn &rest args)
"Return a filtered `bookmark-alist' sorted alphabetically."
(loop
with alist = (if args
(apply #'(lambda (x) (funcall fn x)) args)
(funcall fn))
for i in alist
for b = (car i)
collect (propertize b 'location (bookmark-location b)) into sa
finally return (sort sa 'string-lessp)))
;;;###autoload
(defun helm-bmkext-run-edit ()
"Run `bmkext-edit-bookmark' from keyboard."
(interactive)
(helm-quit-and-execute-action 'bmkext-edit-bookmark))
;;; Addressbook.
;;
;;
(defvar helm-source-bmkext-addressbook
'((name . "Bookmark Addressbook")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global
(helm-bmkext-addressbook-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(persistent-action
. (lambda (candidate)
(let ((bmk (helm-bookmark-get-bookmark-from-name
candidate)))
(bookmark--jump-via bmk 'switch-to-buffer))))
(persistent-help . "Show contact - Prefix with C-u to append")
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(action . (("Show Contact(s)"
. (lambda (candidate)
(let* ((contacts (helm-marked-candidates))
(current-prefix-arg helm-current-prefix-arg))
(bookmark-jump
(helm-bookmark-get-bookmark-from-name (car contacts)))
(helm-aif (cdr contacts)
(let ((current-prefix-arg '(4)))
(loop for bmk in it do
(bookmark-jump
(helm-bookmark-get-bookmark-from-name bmk))))))))
("Send Mail"
. (lambda (candidate)
(let* ((contacts (helm-marked-candidates))
(bmk (helm-bookmark-get-bookmark-from-name
(car contacts)))
(append (message-buffers)))
(if append
(addressbook-set-mail-buffer1 bmk 'append)
(addressbook-set-mail-buffer1 bmk))
(setq contacts (cdr contacts))
(when contacts
(loop for bmk in contacts do
(addressbook-set-mail-buffer1 bmk 'append))))))
("Edit Bookmark"
. (lambda (candidate)
(let ((bmk (helm-bookmark-get-bookmark-from-name
candidate)))
(addressbook-bookmark-edit
(assoc bmk bookmark-alist)))))
("Insert Email at point"
. (lambda (candidate)
(let* ((bmk (helm-bookmark-get-bookmark-from-name
candidate))
(mlist (split-string
(assoc-default
'email (assoc bmk bookmark-alist))
", ")))
(insert
(if (> (length mlist) 1)
(helm-comp-read
"Insert Mail Address: " mlist :must-match t)
(car mlist))))))
("Show annotation"
. (lambda (candidate)
(let ((bmk (helm-bookmark-get-bookmark-from-name
candidate)))
(bookmark-show-annotation bmk))))
("Edit annotation"
. (lambda (candidate)
(let ((bmk (helm-bookmark-get-bookmark-from-name
candidate)))
(bookmark-edit-annotation bmk))))
("Show Google map"
. (lambda (candidate)
(let* ((bmk (helm-bookmark-get-bookmark-from-name
candidate))
(full-bmk (assoc bmk bookmark-alist)))
(addressbook-google-map full-bmk))))))))
(defun helm-bmkext-addressbook-setup-alist ()
"Specialized filter function for bookmarks w3m."
(helm-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
;;; W3m bookmarks from bookmark-extensions.
;;
(defvar helm-source-bookmark-w3m
'((name . "Bookmark W3m")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-w3m-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-w3m-setup-alist ()
"Specialized filter function for bookmarks w3m."
(helm-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
;;; Images
;;
(defvar helm-source-bookmark-images
'((name . "Bookmark Images")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-images-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-images-setup-alist ()
"Specialized filter function for images bookmarks."
(helm-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
;;; Woman Man
;;
(defvar helm-source-bookmark-man
'((name . "Bookmark Woman&Man")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-man-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-man-setup-alist ()
"Specialized filter function for bookmarks w3m."
(append (helm-bmkext-filter-setup-alist 'bmkext-man-alist-only)
(helm-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
;;; Gnus
;;
(defvar helm-source-bookmark-gnus
'((name . "Bookmark Gnus")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-gnus-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-gnus-setup-alist ()
"Specialized filter function for bookmarks gnus."
(helm-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
;;; Info
;;
(defvar helm-source-bookmark-info
'((name . "Bookmark Info")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-info-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-info-setup-alist ()
"Specialized filter function for bookmarks info."
(helm-bmkext-filter-setup-alist 'bmkext-info-alist-only))
;;; Files and directories
;;
(defvar helm-source-bookmark-files&dirs
'((name . "Bookmark Files&Directories")
(init . (lambda ()
(require 'bookmark-extensions)
(bookmark-maybe-load-default-file)
(helm-init-candidates-in-buffer
'global (helm-bookmark-local-files-setup-alist))))
(candidates-in-buffer)
(search helm-bookmark-search-fn)
(match-part . helm-pp-bookmark-match-fn)
(filtered-candidate-transformer
helm-adaptive-sort
helm-highlight-bookmark)
(type . bookmark)))
(defun helm-bookmark-local-files-setup-alist ()
"Specialized filter function for bookmarks locals files."
(helm-bmkext-filter-setup-alist 'bmkext-file-alist-only))
;;;###autoload
(defun helm-bookmark-ext ()
"Preconfigured `helm' for bookmark-extensions sources.
Needs bookmark-ext.el:
<http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
Contain also `helm-source-google-suggest'."
(interactive)
(helm
:sources
'(helm-source-bookmark-files&dirs
helm-source-bookmark-w3m
helm-source-google-suggest
helm-source-bmkext-addressbook
helm-source-bookmark-gnus
helm-source-bookmark-info
helm-source-bookmark-man
helm-source-bookmark-images
helm-source-bookmark-set)
:prompt "SearchBookmark: "
:buffer "*helm bmkext*"
:default (buffer-name helm-current-buffer)))
(provide 'helm-bmkext)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-bmkext.el ends here