* anything-config.el (anything-comp-read): Exit with value of :default keyword.
[anything-config.git] / anything-config.el
blob43ea472cc1cc13beb6d30d2eff30047e817a8171
1 ;;; anything-config.el --- Applications libary for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Applications libary for `anything.el'
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
17 ;; Created: 2009-02-16 21:38:23
19 ;; X-URL: http://repo.or.cz/w/anything-config.git
21 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
23 ;; Keywords: anything, anything-config
25 ;; Compatibility: GNU Emacs 22 ~ 24
27 ;; Dependencies: `anything.el'
29 ;;; This file is NOT part of GNU Emacs
31 ;;; License
33 ;; This program is free software; you can redistribute it and/or modify
34 ;; it under the terms of the GNU General Public License as published by
35 ;; the Free Software Foundation; either version 3, or (at your option)
36 ;; any later version.
38 ;; This program is distributed in the hope that it will be useful,
39 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 ;; GNU General Public License for more details.
43 ;; You should have received a copy of the GNU General Public License
44 ;; along with this program; see the file COPYING. If not, write to
45 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
46 ;; Floor, Boston, MA 02110-1301, USA.
48 ;;; !NOTICE!
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
53 ;;; Commentary:
55 ;; Predefined configurations for `anything.el'
57 ;; For quick start, try `anything-for-files' to open files.
59 ;; To configure anything you should define anything command
60 ;; with your favorite sources, like below:
62 ;; (defun my-anything ()
63 ;; (interactive)
64 ;; (anything-other-buffer
65 ;; '(anything-c-source-buffers
66 ;; anything-c-source-file-name-history
67 ;; anything-c-source-info-pages
68 ;; anything-c-source-info-elisp
69 ;; anything-c-source-man-pages
70 ;; anything-c-source-locate
71 ;; anything-c-source-emacs-commands)
72 ;; " *my-anything*"))
74 ;; Then type M-x my-anything to use sources.
76 ;; Defining own command is better than setup `anything-sources'
77 ;; directly, because you can define multiple anything commands with
78 ;; different sources. Each anything command should have own anything
79 ;; buffer, because M-x anything-resume revives anything command.
82 ;;; Autodoc documentation:
83 ;; ---------------------
85 ;; * Commands defined here are:
86 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
87 ;; `anything-configuration'
88 ;; Customize `anything'.
89 ;; `anything-c-buffer-help'
90 ;; Help command for anything buffers.
91 ;; `anything-ff-help'
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
94 ;; Not documented.
95 ;; `anything-generic-file-help'
96 ;; Not documented.
97 ;; `anything-grep-help'
98 ;; Not documented.
99 ;; `anything-pdfgrep-help'
100 ;; Not documented.
101 ;; `anything-etags-help'
102 ;; The help function for etags.
103 ;; `anything-c-ucs-help'
104 ;; Help command for `anything-ucs'.
105 ;; `anything-mini'
106 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
107 ;; `anything-for-files'
108 ;; Preconfigured `anything' for opening files.
109 ;; `anything-recentf'
110 ;; Preconfigured `anything' for `recentf'.
111 ;; `anything-info-at-point'
112 ;; Preconfigured `anything' for searching info at point.
113 ;; `anything-info-emacs'
114 ;; Preconfigured anything for Emacs manual index.
115 ;; `anything-show-kill-ring'
116 ;; Preconfigured `anything' for `kill-ring'.
117 ;; `anything-minibuffer-history'
118 ;; Preconfigured `anything' for `minibuffer-history'.
119 ;; `anything-gentoo'
120 ;; Preconfigured `anything' for gentoo linux.
121 ;; `anything-imenu'
122 ;; Preconfigured `anything' for `imenu'.
123 ;; `anything-google-suggest'
124 ;; Preconfigured `anything' for google search with google suggest.
125 ;; `anything-yahoo-suggest'
126 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
127 ;; `anything-for-buffers'
128 ;; Preconfigured `anything' for buffer.
129 ;; `anything-buffers-list'
130 ;; Enhanced preconfigured `anything' for buffer.
131 ;; `anything-bbdb'
132 ;; Preconfigured `anything' for BBDB.
133 ;; `anything-locate'
134 ;; Preconfigured `anything' for Locate.
135 ;; `anything-w3m-bookmarks'
136 ;; Preconfigured `anything' for w3m bookmark.
137 ;; `anything-firefox-bookmarks'
138 ;; Preconfigured `anything' for firefox bookmark.
139 ;; `anything-colors'
140 ;; Preconfigured `anything' for color.
141 ;; `anything-bookmarks'
142 ;; Preconfigured `anything' for bookmarks.
143 ;; `anything-c-pp-bookmarks'
144 ;; Preconfigured `anything' for bookmarks (pretty-printed).
145 ;; `anything-c-insert-latex-math'
146 ;; Preconfigured anything for latex math symbols completion.
147 ;; `anything-register'
148 ;; Preconfigured `anything' for Emacs registers.
149 ;; `anything-man-woman'
150 ;; Preconfigured `anything' for Man and Woman pages.
151 ;; `anything-org-keywords'
152 ;; Preconfigured `anything' for org keywords.
153 ;; `anything-emms'
154 ;; Preconfigured `anything' for emms sources.
155 ;; `anything-eev-anchors'
156 ;; Preconfigured `anything' for eev anchors.
157 ;; `anything-bm-list'
158 ;; Preconfigured `anything' for visible bookmarks.
159 ;; `anything-timers'
160 ;; Preconfigured `anything' for timers.
161 ;; `anything-list-emacs-process'
162 ;; Preconfigured `anything' for emacs process.
163 ;; `anything-occur'
164 ;; Preconfigured Anything for Occur source.
165 ;; `anything-browse-code'
166 ;; Preconfigured anything to browse code.
167 ;; `anything-org-headlines'
168 ;; Preconfigured anything to show org headlines.
169 ;; `anything-info-gnus'
170 ;; Preconfigured anything to browse Gnus Manual.
171 ;; `anything-regexp'
172 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
173 ;; `anything-c-copy-files-async'
174 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
175 ;; `anything-find-files'
176 ;; Preconfigured `anything' for anything implementation of `find-file'.
177 ;; `anything-write-file'
178 ;; Preconfigured `anything' providing completion for `write-file'.
179 ;; `anything-insert-file'
180 ;; Preconfigured `anything' providing completion for `insert-file'.
181 ;; `anything-dired-rename-file'
182 ;; Preconfigured `anything' to rename files from dired.
183 ;; `anything-dired-copy-file'
184 ;; Preconfigured `anything' to copy files from dired.
185 ;; `anything-dired-symlink-file'
186 ;; Preconfigured `anything' to symlink files from dired.
187 ;; `anything-dired-hardlink-file'
188 ;; Preconfigured `anything' to hardlink files from dired.
189 ;; `anything-do-grep'
190 ;; Preconfigured anything for grep.
191 ;; `anything-c-etags-select'
192 ;; Preconfigured anything for etags.
193 ;; `anything-filelist'
194 ;; Preconfigured `anything' to open files instantly.
195 ;; `anything-filelist+'
196 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
197 ;; `anything-M-x'
198 ;; Preconfigured `anything' for Emacs commands.
199 ;; `anything-manage-advice'
200 ;; Preconfigured `anything' to disable/enable function advices.
201 ;; `anything-bookmark-ext'
202 ;; Preconfigured `anything' for bookmark-extensions sources.
203 ;; `anything-simple-call-tree'
204 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
205 ;; `anything-mark-ring'
206 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
207 ;; `anything-global-mark-ring'
208 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
209 ;; `anything-all-mark-rings'
210 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
211 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
212 ;; Preconfigured `anything' to edit or view EmacsWiki page.
213 ;; `anything-yaoddmuse-emacswiki-post-library'
214 ;; Preconfigured `anything' to post library to EmacsWiki.
215 ;; `anything-eval-expression'
216 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
217 ;; `anything-eval-expression-with-eldoc'
218 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
219 ;; `anything-calcul-expression'
220 ;; Preconfigured anything for `anything-c-source-calculation-result'.
221 ;; `anything-surfraw'
222 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
223 ;; `anything-call-source'
224 ;; Preconfigured `anything' to call anything source.
225 ;; `anything-execute-anything-command'
226 ;; Preconfigured `anything' to execute preconfigured `anything'.
227 ;; `anything-create'
228 ;; Preconfigured `anything' to do many create actions from STRING.
229 ;; `anything-top'
230 ;; Preconfigured `anything' for top command.
231 ;; `anything-select-xfont'
232 ;; Preconfigured `anything' to select Xfont.
233 ;; `anything-world-time'
234 ;; Preconfigured `anything' to show world time.
235 ;; `anything-apt'
236 ;; Preconfigured `anything' : frontend of APT package manager.
237 ;; `anything-esh-pcomplete'
238 ;; Preconfigured anything to provide anything completion in eshell.
239 ;; `anything-eshell-history'
240 ;; Preconfigured anything for eshell history.
241 ;; `anything-c-run-external-command'
242 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
243 ;; `anything-ratpoison-commands'
244 ;; Preconfigured `anything' to execute ratpoison commands.
245 ;; `anything-ucs'
246 ;; Preconfigured anything for `ucs-names' math symbols.
247 ;; `anything-show-this-source-only'
248 ;; Show all candidates of this source.
249 ;; `anything-test-sources'
250 ;; List all anything sources for test.
251 ;; `anything-select-source'
252 ;; [OBSOLETE] Select source.
253 ;; `anything-mark-all'
254 ;; Mark all visible unmarked candidates in current source.
255 ;; `anything-unmark-all'
256 ;; Unmark all candidates in all sources of current anything session.
257 ;; `anything-toggle-all-marks'
258 ;; Toggle all marks.
259 ;; `anything-buffer-diff-persistent'
260 ;; Toggle diff buffer without quitting anything.
261 ;; `anything-buffer-revert-persistent'
262 ;; Revert buffer without quitting anything.
263 ;; `anything-buffer-save-persistent'
264 ;; Save buffer without quitting anything.
265 ;; `anything-buffer-run-kill-buffers'
266 ;; Run kill buffer action from `anything-c-source-buffers-list'.
267 ;; `anything-buffer-run-grep'
268 ;; Run Grep action from `anything-c-source-buffers-list'.
269 ;; `anything-buffer-run-zgrep'
270 ;; Run Grep action from `anything-c-source-buffers-list'.
271 ;; `anything-buffer-run-query-replace-regexp'
272 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
273 ;; `anything-buffer-run-query-replace'
274 ;; Run Query replace action from `anything-c-source-buffers-list'.
275 ;; `anything-buffer-switch-other-window'
276 ;; Run switch to other window action from `anything-c-source-buffers-list'.
277 ;; `anything-buffer-switch-other-frame'
278 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
279 ;; `anything-buffer-switch-to-elscreen'
280 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
281 ;; `anything-buffer-run-ediff'
282 ;; Run ediff action from `anything-c-source-buffers-list'.
283 ;; `anything-buffer-run-ediff-merge'
284 ;; Run ediff action from `anything-c-source-buffers-list'.
285 ;; `anything-ff-run-toggle-auto-update'
286 ;; Not documented.
287 ;; `anything-ff-run-switch-to-history'
288 ;; Run Switch to history action from `anything-c-source-find-files'.
289 ;; `anything-ff-run-grep'
290 ;; Run Grep action from `anything-c-source-find-files'.
291 ;; `anything-ff-run-pdfgrep'
292 ;; Run Pdfgrep action from `anything-c-source-find-files'.
293 ;; `anything-ff-run-zgrep'
294 ;; Run Grep action from `anything-c-source-find-files'.
295 ;; `anything-ff-run-copy-file'
296 ;; Run Copy file action from `anything-c-source-find-files'.
297 ;; `anything-ff-run-rename-file'
298 ;; Run Rename file action from `anything-c-source-find-files'.
299 ;; `anything-ff-run-byte-compile-file'
300 ;; Run Byte compile file action from `anything-c-source-find-files'.
301 ;; `anything-ff-run-load-file'
302 ;; Run Load file action from `anything-c-source-find-files'.
303 ;; `anything-ff-run-eshell-command-on-file'
304 ;; Run eshell command on file action from `anything-c-source-find-files'.
305 ;; `anything-ff-run-ediff-file'
306 ;; Run Ediff file action from `anything-c-source-find-files'.
307 ;; `anything-ff-run-ediff-merge-file'
308 ;; Run Ediff merge file action from `anything-c-source-find-files'.
309 ;; `anything-ff-run-symlink-file'
310 ;; Run Symlink file action from `anything-c-source-find-files'.
311 ;; `anything-ff-run-delete-file'
312 ;; Run Delete file action from `anything-c-source-find-files'.
313 ;; `anything-ff-run-complete-fn-at-point'
314 ;; Run complete file name action from `anything-c-source-find-files'.
315 ;; `anything-ff-run-switch-to-eshell'
316 ;; Run switch to eshell action from `anything-c-source-find-files'.
317 ;; `anything-ff-run-switch-other-window'
318 ;; Run switch to other window action from `anything-c-source-find-files'.
319 ;; `anything-ff-run-switch-other-frame'
320 ;; Run switch to other frame action from `anything-c-source-find-files'.
321 ;; `anything-ff-run-open-file-externally'
322 ;; Run open file externally command action from `anything-c-source-find-files'.
323 ;; `anything-ff-run-locate'
324 ;; Run locate action from `anything-c-source-find-files'.
325 ;; `anything-ff-run-gnus-attach-files'
326 ;; Run gnus attach files command action from `anything-c-source-find-files'.
327 ;; `anything-ff-run-etags'
328 ;; Run Etags command action from `anything-c-source-find-files'.
329 ;; `anything-ff-run-print-file'
330 ;; Run Print file action from `anything-c-source-find-files'.
331 ;; `anything-ff-run-toggle-basename'
332 ;; Not documented.
333 ;; `anything-find-files-down-one-level'
334 ;; Go down one level like unix command `cd ..'.
335 ;; `anything-ff-properties-persistent'
336 ;; Show properties without quitting anything.
337 ;; `anything-ff-run-kill-buffer-persistent'
338 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
339 ;; `anything-ff-rotate-left-persistent'
340 ;; Rotate image left without quitting anything.
341 ;; `anything-ff-rotate-right-persistent'
342 ;; Rotate image right without quitting anything.
343 ;; `anything-c-goto-precedent-file'
344 ;; Go to precedent file in anything grep/etags buffers.
345 ;; `anything-c-goto-next-file'
346 ;; Go to precedent file in anything grep/etags buffers.
347 ;; `anything-c-grep-run-persistent-action'
348 ;; Run grep persistent action from `anything-do-grep-1'.
349 ;; `anything-c-grep-run-default-action'
350 ;; Run grep default action from `anything-do-grep-1'.
351 ;; `anything-c-grep-run-other-window-action'
352 ;; Run grep goto other window action from `anything-do-grep-1'.
353 ;; `anything-c-grep-run-save-buffer'
354 ;; Run grep save results action from `anything-do-grep-1'.
355 ;; `anything-do-pdfgrep'
356 ;; Not documented.
357 ;; `anything-yank-text-at-point'
358 ;; Yank text at point in minibuffer.
359 ;; `anything-c-describe-attributes'
360 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
361 ;; `anything-yaoddmuse-cache-pages'
362 ;; Fetch the list of files on emacswiki and create cache file.
363 ;; `anything-eval-new-line-and-indent'
364 ;; Not documented.
365 ;; `anything-call-source-from-anything'
366 ;; Call anything source within `anything' session.
367 ;; `anything-create-from-anything'
368 ;; Run `anything-create' from `anything' as a fallback.
369 ;; `anything-c-ucs-persistent-insert'
370 ;; Not documented.
371 ;; `anything-c-ucs-persistent-forward'
372 ;; Not documented.
373 ;; `anything-c-ucs-persistent-backward'
374 ;; Not documented.
375 ;; `anything-c-ucs-persistent-delete'
376 ;; Not documented.
377 ;; `anything-lisp-completion-at-point'
378 ;; Anything lisp symbol completion at point.
379 ;; `anything-c-complete-file-name-at-point'
380 ;; Complete file name at point.
381 ;; `anything-lisp-completion-at-point-or-indent'
382 ;; First call indent and second call complete lisp symbol.
383 ;; `anything-lisp-completion-or-file-name-at-point'
384 ;; Complete lisp symbol or filename at point.
385 ;; `anything-c-set-variable'
386 ;; Set value to VAR interactively.
387 ;; `anything-c-adaptive-save-history'
388 ;; Save history information to file given by `anything-c-adaptive-history-file'.
389 ;; `anything-c-reset-adaptative-history'
390 ;; Delete all `anything-c-adaptive-history' and his file.
391 ;; `anything-c-toggle-match-plugin'
392 ;; Toggle anything-match-plugin.
394 ;; * User variables defined here:
395 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
396 ;; `anything-c-adaptive-history-file'
397 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
398 ;; `anything-c-adaptive-history-length'
399 ;; Default Value: 50
400 ;; `anything-c-google-suggest-url'
401 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
402 ;; `anything-c-google-suggest-search-url'
403 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
404 ;; `anything-google-suggest-use-curl-p'
405 ;; Default Value: nil
406 ;; `anything-c-yahoo-suggest-url'
407 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
408 ;; `anything-c-yahoo-suggest-search-url'
409 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
410 ;; `anything-c-boring-buffer-regexp'
411 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
412 ;; `anything-c-boring-file-regexp'
413 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
414 ;; `anything-kill-ring-threshold'
415 ;; Default Value: 10
416 ;; `anything-c-kill-ring-max-lines-number'
417 ;; Default Value: nil
418 ;; `anything-su-or-sudo'
419 ;; Default Value: "su"
420 ;; `anything-for-files-prefered-list'
421 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
422 ;; `anything-create--actions-private'
423 ;; Default Value: nil
424 ;; `anything-allow-skipping-current-buffer'
425 ;; Default Value: t
426 ;; `anything-c-enable-eval-defun-hack'
427 ;; Default Value: t
428 ;; `anything-tramp-verbose'
429 ;; Default Value: 0
430 ;; `anything-raise-command'
431 ;; Default Value: nil
432 ;; `anything-command-map-prefix-key'
433 ;; Default Value: "<f5> a"
434 ;; `anything-c-browse-code-regexp-lisp'
435 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
436 ;; `anything-c-browse-code-regexp-python'
437 ;; Default Value: "\\<def\\>\\|\\<class\\>"
438 ;; `anything-c-browse-code-regexp-alist'
439 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
440 ;; `anything-c-external-programs-associations'
441 ;; Default Value: nil
442 ;; `anything-ff-auto-update-initial-value'
443 ;; Default Value: t
444 ;; `anything-c-copy-async-prefered-emacs'
445 ;; Default Value: "emacs"
446 ;; `anything-ff-lynx-style-map'
447 ;; Default Value: t
448 ;; `anything-ff-history-max-length'
449 ;; Default Value: 100
450 ;; `anything-ff-smart-completion'
451 ;; Default Value: t
452 ;; `anything-ff-default-kbsize'
453 ;; Default Value: 1024.0
454 ;; `anything-ff-tramp-not-fancy'
455 ;; Default Value: t
456 ;; `anything-ff-exif-data-program'
457 ;; Default Value: "exiftran"
458 ;; `anything-ff-exif-data-program-args'
459 ;; Default Value: "-d"
460 ;; `anything-c-grep-use-ioccur-style-keys'
461 ;; Default Value: t
462 ;; `anything-c-pdfgrep-default-read-command'
463 ;; Default Value: "xpdf '%f' %p"
464 ;; `anything-c-etags-tag-file-name'
465 ;; Default Value: "TAGS"
466 ;; `anything-c-etags-tag-file-search-limit'
467 ;; Default Value: 10
468 ;; `anything-c-etags-use-regexp-search'
469 ;; Default Value: nil
470 ;; `anything-c-filelist-file-name'
471 ;; Default Value: nil
472 ;; `anything-c-eldoc-in-minibuffer-show-fn'
473 ;; Default Value: anything-c-eldoc-show-in-mode-line
474 ;; `anything-c-turn-on-show-completion'
475 ;; Default Value: t
476 ;; `anything-lisp-completion-or-indent-delay'
477 ;; Default Value: 0.6
478 ;; `anything-c-default-external-file-browser'
479 ;; Default Value: "nautilus"
480 ;; `anything-c-use-adaptative-sorting'
481 ;; Default Value: nil
482 ;; `anything-ff-newfile-prompt-p'
483 ;; Default Value: t
484 ;; `anything-ff-avfs-directory'
485 ;; Default Value: nil
486 ;; `anything-ff-file-compressed-list'
487 ;; Default Value: ("gz" "bz2" "zip" "7z")
488 ;; `anything-locate-db-file-regexp'
489 ;; Default Value: "m?locate.db$"
490 ;; `anything-c-eldoc-show-in-mode-line-delay'
491 ;; Default Value: 12
492 ;; `anything-c-copy-files-async-log-file'
493 ;; Default Value: "/tmp/dired.log"
494 ;; `anything-ff-printer-list'
495 ;; Default Value: nil
496 ;; `anything-ff-transformer-show-only-basename'
497 ;; Default Value: nil
499 ;; * Anything sources defined here:
500 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
501 ;; `anything-c-source-regexp' (Regexp Builder)
502 ;; `anything-c-source-buffers' (Buffers)
503 ;; `anything-c-source-buffer-not-found' (Create buffer)
504 ;; `anything-c-source-buffers-list' (Buffers)
505 ;; `anything-c-source-file-name-history' (File Name History)
506 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
507 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
508 ;; `anything-c-source-find-files' (Find Files)
509 ;; `anything-c-source-write-file' (Write File)
510 ;; `anything-c-source-insert-file' (Insert File)
511 ;; `anything-c-source-copy-files' (Copy Files)
512 ;; `anything-c-source-symlink-files' (Symlink Files)
513 ;; `anything-c-source-hardlink-files' (Hardlink Files)
514 ;; `anything-c-source-file-cache' (File Cache)
515 ;; `anything-c-source-locate' (Locate)
516 ;; `anything-c-source-recentf' (Recentf)
517 ;; `anything-c-source-ffap-guesser' (File at point)
518 ;; `anything-c-source-ffap-line' (File/Lineno at point)
519 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
520 ;; `anything-c-source-filelist' (FileList)
521 ;; `anything-c-source-info-pages' (Info Pages)
522 ;; `anything-c-source-info-elisp' (Info index: elisp)
523 ;; `anything-c-source-info-cl' (Info index: cl)
524 ;; `anything-c-source-info-org' (Info index: org)
525 ;; `anything-c-source-info-gnus' (Info index: Gnus)
526 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
527 ;; `anything-c-source-info-zsh' (Info index: zsh)
528 ;; `anything-c-source-info-bash' (Info index: bash)
529 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
530 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
531 ;; `anything-c-source-info-find' (Info index: find)
532 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
533 ;; `anything-c-source-info-textutils' (Info index: textutils)
534 ;; `anything-c-source-info-libc' (Info index: libc)
535 ;; `anything-c-source-info-make' (Info index: make)
536 ;; `anything-c-source-info-automake' (Info index: automake)
537 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
538 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
539 ;; `anything-c-source-info-emacs' (Info index: emacs)
540 ;; `anything-c-source-info-elib' (Info index: elib)
541 ;; `anything-c-source-info-eieio' (Info index: eieio)
542 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
543 ;; `anything-c-source-info-guile' (Info index: guile)
544 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
545 ;; `anything-c-source-info-goops' (Info index: goops)
546 ;; `anything-c-source-info-screen' (Info index: screen)
547 ;; `anything-c-source-info-latex' (Info index: latex)
548 ;; `anything-c-source-info-gawk' (Info index: gawk)
549 ;; `anything-c-source-info-sed' (Info index: sed)
550 ;; `anything-c-source-info-m4' (Info index: m4)
551 ;; `anything-c-source-info-wget' (Info index: wget)
552 ;; `anything-c-source-info-binutils' (Info index: binutils)
553 ;; `anything-c-source-info-as' (Info index: as)
554 ;; `anything-c-source-info-bfd' (Info index: bfd)
555 ;; `anything-c-source-info-gprof' (Info index: gprof)
556 ;; `anything-c-source-info-ld' (Info index: ld)
557 ;; `anything-c-source-info-diff' (Info index: diff)
558 ;; `anything-c-source-info-flex' (Info index: flex)
559 ;; `anything-c-source-info-grep' (Info index: grep)
560 ;; `anything-c-source-info-gzip' (Info index: gzip)
561 ;; `anything-c-source-info-libtool' (Info index: libtool)
562 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
563 ;; `anything-c-source-info-info' (Info index: info)
564 ;; `anything-c-source-info-gdb' (Info index: gdb)
565 ;; `anything-c-source-info-stabs' (Info index: stabs)
566 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
567 ;; `anything-c-source-info-cvs' (Info index: cvs)
568 ;; `anything-c-source-info-bison' (Info index: bison)
569 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
570 ;; `anything-c-source-info-global' (Info index: global)
571 ;; `anything-c-source-man-pages' (Manual Pages)
572 ;; `anything-c-source-complex-command-history' (Complex Command History)
573 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
574 ;; `anything-c-source-emacs-commands' (Emacs Commands)
575 ;; `anything-c-source-lacarte' (Lacarte)
576 ;; `anything-c-source-emacs-functions' (Emacs Functions)
577 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
578 ;; `anything-c-source-advice' (Function Advice)
579 ;; `anything-c-source-emacs-variables' (Emacs Variables)
580 ;; `anything-c-source-bookmarks' (Bookmarks)
581 ;; `anything-c-source-bookmark-set' (Set Bookmark)
582 ;; `anything-c-source-bm' (Visible Bookmarks)
583 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
584 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
585 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
586 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
587 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
588 ;; `anything-c-source-bookmark-images' (Bookmark Images)
589 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
590 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
591 ;; `anything-c-source-bookmark-info' (Bookmark Info)
592 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
593 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
594 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
595 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
596 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
597 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
598 ;; `anything-c-source-imenu' (Imenu)
599 ;; `anything-c-source-ctags' (Exuberant ctags)
600 ;; `anything-c-source-etags-select' (Etags)
601 ;; `anything-c-source-semantic' (Semantic Tags)
602 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
603 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
604 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
605 ;; `anything-c-source-customize-face' (Customize Face)
606 ;; `anything-c-source-colors' (Colors)
607 ;; `anything-c-source-tracker-search' (Tracker Search)
608 ;; `anything-c-source-mac-spotlight' (mdfind)
609 ;; `anything-c-source-picklist' (Picklist)
610 ;; `anything-c-source-kill-ring' (Kill Ring)
611 ;; `anything-c-source-mark-ring' (mark-ring)
612 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
613 ;; `anything-c-source-register' (Registers)
614 ;; `anything-c-source-latex-math' (Latex Math Menu)
615 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
616 ;; `anything-c-source-rd-headline' (RD HeadLine)
617 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
618 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
619 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
620 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
621 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
622 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
623 ;; `anything-c-source-eev-anchor' (Anchors)
624 ;; `anything-c-source-org-headline' (Org HeadLine)
625 ;; `anything-c-source-org-keywords' (Org Keywords)
626 ;; `anything-c-source-bbdb' (BBDB)
627 ;; `anything-c-source-evaluation-result' (Evaluation Result)
628 ;; `anything-c-source-calculation-result' (Calculation Result)
629 ;; `anything-c-source-google-suggest' (Google Suggest)
630 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
631 ;; `anything-c-source-emms-streams' (Emms Streams)
632 ;; `anything-c-source-emms-dired' (Music Directory)
633 ;; `anything-c-source-emms-files' (Emms files)
634 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
635 ;; `anything-c-source-call-source' (Call anything source)
636 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
637 ;; `anything-c-source-occur' (Occur)
638 ;; `anything-c-source-browse-code' (Browse code)
639 ;; `anything-c-source-create' (Create)
640 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
641 ;; `anything-c-source-elscreen' (Elscreen)
642 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
643 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
644 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
645 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
646 ;; `anything-c-source-xfonts' (X Fonts)
647 ;; `anything-c-source-ucs' (Ucs names)
648 ;; `anything-c-source-emacs-process' (Emacs Process)
649 ;; `anything-c-source-time-world' (Time World List)
650 ;; `anything-c-source-apt' (APT)
651 ;; `anything-c-source-gentoo' (Portage sources)
652 ;; `anything-c-source-use-flags' (Use Flags)
653 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
654 ;; `anything-c-source-esh' (Eshell completions)
655 ;; `anything-c-source-eshell-history' (Eshell history)
657 ;; *** END auto-documentation
659 ;;; For Maintainers:
661 ;; Install developer-tools/autodoc.el and
662 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
663 ;; This function generates anything-c-source-* / functions / options list.
665 ;; [EVAL IT] (autodoc-update-all)
667 ;; Please write details documentation about function, then others will
668 ;; read code more easier. -- Andy Stewart
672 ;;; Change log:
674 ;; Change log of this file is found at
675 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
677 ;; Change log of this project is found at
678 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
680 ;;; Contributors:
682 ;; Tamas Patrovics
683 ;; Tassilo Horn <tassilo@member.fsf.org>
684 ;; Vagn Johansen <gonz808@hotmail.com>
685 ;; Mathias Dahl <mathias.dahl@gmail.com>
686 ;; Bill Clementson <billclem@gmail.com>
687 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
688 ;; Drew Adams <drew.adams@oracle.com>
689 ;; Jason McBrayer <jmcbray@carcosa.net>
690 ;; Andy Stewart <lazycat.manatee@gmail.com>
691 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
692 ;; rubikitch <rubikitch@ruby-lang.org>
693 ;; Scott Vokes <vokes.s@gmail.com>
694 ;; Kenichirou Oyama <k1lowxb@gmail.com>
697 ;;; TODO
699 ;; - Fix documentation, now many functions haven't documentations.
703 ;;; Code:
705 ;;; Require
708 (require 'anything)
709 (require 'thingatpt)
710 (require 'ffap)
711 (require 'cl)
712 (require 'dired-aux)
713 (require 'dired-x)
714 (require 'tramp)
715 (require 'grep)
716 (require 'url)
717 (require 'xml)
718 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
719 (eval-when-compile (require 'semantic nil t))
720 (require 'anything-match-plugin)
724 ;;; Declare external functions
727 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
728 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
729 (declare-function image-dired-update-property "image-dired.el" (prop value))
730 (declare-function woman-file-name-all-completions "woman.el" (topic))
731 (declare-function Man-getpage-in-background "man.el" (topic))
732 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
733 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
734 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
735 (declare-function org-get-current-options "ext:org-exp.el")
736 (declare-function emms-streams "ext:emms-streams")
737 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
738 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
739 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
740 (declare-function emms-stream-quit "ext:emms-streams")
741 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
742 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
743 (declare-function emms-playlist-first "ext:emms")
744 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
745 (declare-function term-line-mode "term")
746 (declare-function term-char-mode "term")
747 (declare-function term-send-input "term")
748 (declare-function term-send-eof "term")
749 (declare-function Info-index-nodes "info" (&optional file))
750 (declare-function Info-goto-node "info" (&optional fork))
751 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
752 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
753 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
754 (declare-function elscreen-goto "ext:elscreen.el" (screen))
755 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
756 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
757 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
758 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
759 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
760 (declare-function bbdb "ext:bbdb-com")
761 (declare-function bbdb-current-record "ext:bbdb-com")
762 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
763 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
764 (declare-function bbdb-current-record "ext:bbdb-com")
765 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
766 (declare-function bbdb-records "ext:bbdb-com"
767 (&optional dont-check-disk already-in-db-buffer))
768 (declare-function eshell-read-aliases-list "em-alias")
769 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
770 (declare-function eshell-bol "esh-mode")
771 (declare-function eldoc-current-symbol "eldoc")
772 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
773 (declare-function eldoc-get-var-docstring "eldoc" (sym))
774 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
775 (declare-function find-library-name "find-func.el" (library))
776 (declare-function adoc-construct "ext:auto-document.el" (buf))
777 (declare-function adoc-first-line "ext:auto-document.el" (str))
778 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
779 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
783 ;;; compatibility
786 (unless (fboundp 'window-system)
787 (defun window-system (&optional arg)
788 window-system))
792 ;;; Customize
795 (defgroup anything-config nil
796 "Predefined configurations for `anything.el'."
797 :group 'anything)
799 (defcustom anything-c-adaptive-history-file
800 "~/.emacs.d/anything-c-adaptive-history"
801 "Path of file where history information is stored."
802 :type 'string
803 :group 'anything-config)
805 (defcustom anything-c-adaptive-history-length 50
806 "Maximum number of candidates stored for a source."
807 :type 'number
808 :group 'anything-config)
810 (defcustom anything-c-google-suggest-url
811 "http://google.com/complete/search?output=toolbar&q="
812 "URL used for looking up Google suggestions."
813 :type 'string
814 :group 'anything-config)
816 (defcustom anything-c-google-suggest-search-url
817 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
818 "URL used for Google searching."
819 :type 'string
820 :group 'anything-config)
822 (defcustom anything-google-suggest-use-curl-p nil
823 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
824 Otherwise `url-retrieve-synchronously' is used."
825 :type 'boolean
826 :group 'anything-config)
828 (defcustom anything-c-yahoo-suggest-url
829 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
830 "Url used for looking up Yahoo suggestions."
831 :type 'string
832 :group 'anything-config)
834 (defcustom anything-c-yahoo-suggest-search-url
835 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
836 "Url used for Yahoo searching."
837 :type 'string
838 :group 'anything-config)
840 (defcustom anything-c-boring-buffer-regexp
841 (rx (or
842 (group bos " ")
843 ;; anything-buffer
844 "*anything"
845 ;; echo area
846 " *Echo Area" " *Minibuf"))
847 "The regexp that match boring buffers.
848 Buffer candidates matching this regular expression will be
849 filtered from the list of candidates if the
850 `anything-c-skip-boring-buffers' candidate transformer is used, or
851 they will be displayed with face `file-name-shadow' if
852 `anything-c-shadow-boring-buffers' is used."
853 :type 'string
854 :group 'anything-config)
855 ;; (string-match anything-c-boring-buffer-regexp "buf")
856 ;; (string-match anything-c-boring-buffer-regexp " hidden")
857 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
859 (defcustom anything-c-boring-file-regexp
860 (rx (or
861 ;; Boring directories
862 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
863 ;; Boring files
864 (and line-start ".#")
865 (and (or ".class" ".la" ".o" "~") eol)))
866 "The regexp that match boring files.
867 File candidates matching this regular expression will be
868 filtered from the list of candidates if the
869 `anything-c-skip-boring-files' candidate transformer is used, or
870 they will be displayed with face `file-name-shadow' if
871 `anything-c-shadow-boring-files' is used."
872 :type 'string
873 :group 'anything-config)
875 (defcustom anything-kill-ring-threshold 10
876 "*Minimum length to be listed by `anything-c-source-kill-ring'."
877 :type 'integer
878 :group 'anything-config)
880 (defcustom anything-c-kill-ring-max-lines-number nil
881 "Max number of lines displayed per candidate in kill-ring browser.
882 If nil or zero, don't truncate candidate, show all."
883 :type 'integer
884 :group 'anything-config)
886 (defcustom anything-su-or-sudo "su"
887 "What command to use for root access."
888 :type 'string
889 :group 'anything-config)
891 (defcustom anything-for-files-prefered-list
892 '(anything-c-source-ffap-line
893 anything-c-source-ffap-guesser
894 anything-c-source-buffers-list
895 anything-c-source-recentf
896 anything-c-source-bookmarks
897 anything-c-source-file-cache
898 anything-c-source-files-in-current-dir+
899 anything-c-source-locate)
900 "Your prefered sources to find files."
901 :type 'list
902 :group 'anything-config)
904 (defcustom anything-create--actions-private nil
905 "User defined actions for `anything-create' / `anything-c-source-create'.
906 It is a list of (DISPLAY . FUNCTION) pairs like `action'
907 attribute of `anything-sources'.
909 It is prepended to predefined pairs."
910 :type 'list
911 :group 'anything-config)
913 (defcustom anything-allow-skipping-current-buffer t
914 "Show current buffer or not in anything buffer"
915 :type 'boolean
916 :group 'anything-config)
918 (defcustom anything-c-enable-eval-defun-hack t
919 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
920 This hack is invoked when pressing C-M-x in the form \
921 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
922 :type 'boolean
923 :group 'anything-config)
925 (defcustom anything-tramp-verbose 0
926 "*Just like `tramp-verbose' but specific to anything.
927 When set to 0 don't show tramp messages in anything.
928 If you want to have the default tramp messages set it to 3."
929 :type 'integer
930 :group 'anything-config)
932 (defcustom anything-raise-command nil
933 "*A shell command to jump to a window running specific program.
934 Need external program wmctrl.
935 This will be use with `format', so use something like \"wmctrl -xa %s\"."
936 :type 'string
937 :group 'anything-config)
939 (defun anything-set-anything-command-map-prefix-key (var key)
940 (declare (special anything-command-map-prefix-key))
941 (when (boundp 'anything-command-map-prefix-key)
942 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
943 (setq anything-command-map-prefix-key key)
944 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
945 'anything-command-map))
947 (defcustom anything-command-map-prefix-key "<f5> a"
948 "*The prefix key for all `anything-command-map' commands.
950 !!WARNING!!
951 This default value is very likely to be changed,
952 because it is under discussion."
953 :type 'string
954 :set 'anything-set-anything-command-map-prefix-key
955 :group 'anything-config)
957 (defcustom anything-c-browse-code-regexp-lisp
958 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
959 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
960 "*Regexp used to parse lisp buffer when browsing code."
961 :type 'string
962 :group 'anything-config)
964 (defcustom anything-c-browse-code-regexp-python
965 "\\<def\\>\\|\\<class\\>"
966 "*Regexp used to parse python buffer when browsing code."
967 :type 'string
968 :group 'anything-config)
970 (defcustom anything-c-browse-code-regexp-alist
971 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
972 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
973 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
974 (python-mode . ,anything-c-browse-code-regexp-python))
975 "*Alist to store regexps for browsing code corresponding \
976 to a specific `major-mode'."
977 :type 'list
978 :group 'anything-config)
980 (defcustom anything-c-external-programs-associations nil
981 "*Alist to store externals programs associated with file extension.
982 This variable overhide setting in .mailcap file.
983 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
984 :type 'list
985 :group 'anything-config)
987 (defcustom anything-ff-auto-update-initial-value t
988 "Auto update when only one candidate directory is matched.
989 This is the default value when starting `anything-find-files'."
990 :group 'anything-config
991 :type 'boolean)
993 (defcustom anything-c-copy-async-prefered-emacs "emacs"
994 "Path to the emacs you want to use for copying async.
995 Emacs versions < 24 fail to copy directory due to a bug not fixed
996 in `copy-directory'."
997 :group 'anything-config
998 :type 'string)
1000 (defcustom anything-ff-lynx-style-map t
1001 "Use arrow keys to navigate with `anything-find-files'.
1002 You will have to restart Emacs or reeval `anything-find-files-map'
1003 and `anything-c-read-file-map' for this take effect."
1004 :group 'anything-config
1005 :type 'boolean)
1007 (defcustom anything-ff-history-max-length 100
1008 "*Number of elements shown in `anything-find-files' history."
1009 :group 'anything-config
1010 :type 'integer)
1012 (defcustom anything-ff-smart-completion t
1013 "Try to complete filenames smarter when non--nil.
1014 See `anything-ff-transform-fname-for-completion' for more info."
1015 :group 'anything-config
1016 :type 'boolean)
1018 (defcustom anything-ff-default-kbsize 1024.0
1019 "Default Kbsize to use for showing files size.
1020 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1021 :group 'anything-config
1022 :type 'float)
1024 (defcustom anything-ff-tramp-not-fancy t
1025 "No colors when listing remote files when set to non--nil.
1026 This make listing much faster, specially on slow machines."
1027 :group 'anything-config
1028 :type 'boolean)
1030 (defcustom anything-ff-exif-data-program "exiftran"
1031 "*Program used to extract exif data of an image file."
1032 :group 'anything-config
1033 :type 'string)
1035 (defcustom anything-ff-exif-data-program-args "-d"
1036 "*Arguments used for `anything-ff-exif-data-program'."
1037 :group 'anything-config
1038 :type 'string)
1040 (defcustom anything-c-grep-use-ioccur-style-keys t
1041 "Use Arrow keys to jump to occurences."
1042 :group 'anything-config
1043 :type 'boolean)
1045 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1046 "Default command to read pdf files from pdfgrep.
1047 Where '%f' format spec is filename and '%p' is page number"
1048 :group 'anything-config
1049 :type 'string)
1051 (defcustom anything-c-etags-tag-file-name "TAGS"
1052 "Etags tag file name."
1053 :type 'string
1054 :group 'anything-config)
1056 (defcustom anything-c-etags-tag-file-search-limit 10
1057 "The limit level of directory to search tag file.
1058 Don't search tag file deeply if outside this value."
1059 :type 'number
1060 :group 'anything-config)
1062 (defcustom anything-c-etags-use-regexp-search nil
1063 "When non--nil search etags candidates by regexp.
1064 This disable anything-match-plugin when enabled.
1065 When nil search is performed literally and *match-plugin is used
1066 if available."
1067 :group 'anything-config
1068 :type 'boolean)
1070 (defcustom anything-c-filelist-file-name nil
1071 "Filename of file list.
1072 Accept a list of string for multiple files.
1074 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1075 File list is created by make-filelist.rb script.
1077 Usage:
1078 ruby make-filelist.rb > /tmp/all.filelist
1080 Then
1081 ;; Assume that /tmp is ramdisk or tmpfs
1082 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1083 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1085 :type 'string
1086 :group 'anything-config)
1088 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1089 'anything-c-eldoc-show-in-mode-line
1090 "A function to display eldoc info.
1091 Should take one arg: the string to display."
1092 :group 'anything-config
1093 :type 'symbol)
1095 (defcustom anything-c-turn-on-show-completion t
1096 "Display candidate in buffer while moving selection when non--nil."
1097 :group 'anything-config
1098 :type 'boolean)
1100 (defcustom anything-lisp-completion-or-indent-delay 0.6
1101 "After this delay `anything-lisp-completion-counter' is reset to 0.
1102 This allow to indent again without completing lisp symbol after this delay.
1103 Default is 0.6 seconds."
1104 :group 'anything-config
1105 :type 'number)
1107 (defcustom anything-c-default-external-file-browser "nautilus"
1108 "Default external file browser for your system.
1109 Directories will be opened externally with it.
1110 Set to nil if you do not have external file browser
1111 or do not want to use it."
1112 :group 'anything-config
1113 :type 'string)
1115 (defcustom anything-c-use-adaptative-sorting nil
1116 "*Wheter to use or not adaptative sorting.
1117 Even if a source use it, it will have no effect when set to nil."
1118 :type 'boolean
1119 :group 'anything-config)
1121 (defcustom anything-ff-newfile-prompt-p t
1122 "Whether Prompt or not when creating new file.
1123 This set `ffap-newfile-prompt'."
1124 :type 'boolean
1125 :group 'anything-config)
1128 (defcustom anything-ff-avfs-directory nil
1129 "*The default avfs directory, usually '.avfs'.
1130 When this is set you will be able to expand archive filenames with `C-z'
1131 inside an avfs directory mounted with mountavfs.
1132 See <http://sourceforge.net/projects/avf/>."
1133 :type 'boolean
1134 :group 'anything-config)
1136 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1137 "*Minimal list of compressed files extension."
1138 :type 'list
1139 :group 'anything-config)
1141 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1142 "Default regexp to match locate database.
1143 If nil Search in all files."
1144 :type 'string
1145 :group 'anything-config)
1147 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1148 "Eldoc will show info in mode-line during this delay if user is idle."
1149 :type 'integer
1150 :group 'anything-config)
1152 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1153 "The file used to communicate with two emacs when copying files async."
1154 :type 'string
1155 :group 'anything-config)
1157 (defcustom anything-ff-printer-list nil
1158 "A list of available printers on your system.
1159 When non--nil let you choose a printer to print file.
1160 Otherwise when nil the variable `printer-name' will be used.
1161 On Unix based systems you can use `anything-ff-find-printers' to
1162 find a list of available printers."
1163 :type 'list
1164 :group 'anything-config)
1166 (defcustom anything-ff-transformer-show-only-basename nil
1167 "Show only basename of candidates in `anything-find-files'.
1168 This can be toggled at anytime from `anything-find-files' with \
1169 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1170 :type 'boolean
1171 :group 'anything-config)
1173 (defcustom anything-completing-read-handlers-alist
1174 '((describe-function . anything-completing-read-symbols)
1175 (describe-variable . anything-completing-read-symbols)
1176 (debug-on-entry . anything-completing-read-symbols)
1177 (find-function . anything-completing-read-symbols)
1178 (trace-function . anything-completing-read-symbols)
1179 (trace-function-background . anything-completing-read-symbols)
1180 (ffap-alternate-file . nil))
1181 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1182 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1183 where key and value are symbols.
1185 Each key is an Emacs command that use originaly `completing-read'.
1187 Each value maybe an anything function that take same arguments as
1188 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1189 anything source and BUFFER the name of the buffer we will use.
1190 This function prefix name must start by \"anything\".
1192 See `anything-completing-read-symbols' for example.
1194 If the value of an entry is nil completion will fall back to
1195 emacs vanilla behavior.
1196 e.g If you want to disable anything completion for `describe-function':
1197 \(describe-function . nil\).
1199 Ido is also supported, you can use `ido-completing-read' and
1200 `ido-read-file-name' as value of an entry or just 'ido.
1201 e.g ido completion for `find-file':
1202 \(find-file . ido\)
1203 same as
1204 \(find-file . ido-read-file-name\)
1205 Note that you don't need to enable `ido-mode' for this to work."
1206 :group 'anything-config
1207 :type '(alist :key-type symbol :value-type symbol))
1211 ;;; General internal variables
1213 ;; Some internals variable that need to be loaded
1214 ;; here to avoid compiler warnings.
1215 (defvar anything-c-external-commands-list nil
1216 "A list of all external commands the user can execute. If this
1217 variable is not set by the user, it will be calculated
1218 automatically.")
1220 (defvar anything-c-show-completion-overlay nil)
1222 (defvar anything-c-locate-command
1223 (case system-type
1224 ('gnu/linux "locate -i -r %s")
1225 ('berkeley-unix "locate -i %s")
1226 ('windows-nt "es -i -r %s")
1227 (t "locate %s"))
1228 "A list of arguments for locate program.
1229 The \"-r\" option must be the last option.")
1232 ;;; Faces
1235 (defface anything-buffer-saved-out
1236 '((t (:foreground "red")))
1237 "*Face used for buffer files modified outside of emacs."
1238 :group 'anything-config)
1240 (defface anything-buffer-not-saved
1241 '((t (:foreground "Indianred2")))
1242 "*Face used for buffer files not already saved on disk."
1243 :group 'anything-config)
1245 (defface anything-ff-prefix
1246 '((t (:background "yellow" :foreground "black")))
1247 "*Face used to prefix new file or url paths in `anything-find-files'."
1248 :group 'anything-config)
1250 (defface anything-ff-executable
1251 '((t (:foreground "green")))
1252 "*Face used for executable files in `anything-find-files'."
1253 :group 'anything-config)
1255 (defface anything-ff-directory
1256 '((t (:foreground "DarkRed" :background "LightGray")))
1257 "*Face used for directories in `anything-find-files'."
1258 :group 'anything-config)
1260 (defface anything-ff-symlink
1261 '((t (:foreground "DarkOrange")))
1262 "*Face used for symlinks in `anything-find-files'."
1263 :group 'anything-config)
1265 (defface anything-ff-invalid-symlink
1266 '((t (:foreground "black" :background "red")))
1267 "*Face used for invalid symlinks in `anything-find-files'."
1268 :group 'anything-config)
1270 (defface anything-ff-file
1271 '((t (:foreground "CadetBlue" :underline t)))
1272 "*Face used for file names in `anything-find-files'."
1273 :group 'anything-config)
1275 (defface anything-grep-match
1276 '((t (:inherit match)))
1277 "Face used to highlight grep matches."
1278 :group 'anything-config)
1280 (defface anything-grep-file
1281 '((t (:foreground "BlueViolet" :underline t)))
1282 "Face used to highlight grep results filenames."
1283 :group 'anything-config)
1285 (defface anything-grep-lineno
1286 '((t (:foreground "Darkorange1")))
1287 "Face used to highlight grep number lines."
1288 :group 'anything-config)
1290 (defface anything-grep-running
1291 '((t (:foreground "Red")))
1292 "Face used in mode line when grep is running."
1293 :group 'anything-config)
1295 (defface anything-grep-finish
1296 '((t (:foreground "Green")))
1297 "Face used in mode line when grep is finish."
1298 :group 'anything-config)
1300 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1301 "*Face used in anything-M-x to show keybinding."
1302 :group 'anything)
1304 (defface anything-bmkext-info
1305 '((t (:foreground "green")))
1306 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1307 :group 'anything)
1309 (defface anything-bmkext-w3m
1310 '((t (:foreground "yellow")))
1311 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1312 :group 'anything)
1314 (defface anything-bmkext-gnus
1315 '((t (:foreground "magenta")))
1316 "*Face used for Gnus bookmarks."
1317 :group 'anything)
1319 (defface anything-bmkext-man
1320 '((t (:foreground "Orange4")))
1321 "*Face used for Woman/man bookmarks."
1322 :group 'anything)
1324 (defface anything-bmkext-no--file
1325 '((t (:foreground "grey")))
1326 "*Face used for non--file bookmarks."
1327 :group 'anything)
1329 (defface anything-bmkext-file
1330 '((t (:foreground "Deepskyblue2")))
1331 "*Face used for non--file bookmarks."
1332 :group 'anything)
1334 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1335 "Face for su/sudo bookmarks."
1336 :group 'anything)
1338 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1339 "Face for w3m bookmarks" :group 'anything)
1341 (defface anything-emms-playlist
1342 '((t (:foreground "Springgreen4" :underline t)))
1343 "*Face used for tracks in current emms playlist."
1344 :group 'anything)
1346 (defface anything-apt-installed
1347 '((t (:foreground "green")))
1348 "*Face used for apt installed candidates."
1349 :group 'anything)
1351 (defface anything-gentoo-match-face '((t (:foreground "red")))
1352 "Face for anything-gentoo installed packages."
1353 :group 'traverse-faces)
1355 (defface anything-lisp-show-completion
1356 '((t (:background "DarkSlateGray")))
1357 "*Face used for showing candidates in `anything-lisp-completion'."
1358 :group 'anything-config)
1360 (defface anything-lisp-completion-info
1361 '((t (:foreground "red")))
1362 "*Face used for showing info in `anything-lisp-completion'."
1363 :group 'anything-config)
1365 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1366 "Face for source header in the anything buffer." :group 'anything)
1368 ;;;###autoload
1369 (defun anything-configuration ()
1370 "Customize `anything'."
1371 (interactive)
1372 (customize-group "anything-config"))
1376 ;;; Anything-command-map
1379 ;;;###autoload
1380 (defvar anything-command-map)
1381 (define-prefix-command 'anything-command-map)
1384 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1385 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1386 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1387 (define-key anything-command-map (kbd "l") 'anything-locate)
1388 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1389 (define-key anything-command-map (kbd "r") 'anything-regexp)
1390 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1391 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1392 (define-key anything-command-map (kbd "#") 'anything-emms)
1393 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1394 (define-key anything-command-map (kbd "t") 'anything-top)
1395 (define-key anything-command-map (kbd "i") 'anything-imenu)
1396 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1397 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1398 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1399 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1400 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1401 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1402 (define-key anything-command-map (kbd "f") 'anything-for-files)
1403 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1404 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1405 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1406 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1407 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1408 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1409 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1410 (define-key anything-command-map (kbd "c") 'anything-colors)
1411 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1412 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1413 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1414 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1415 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1416 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1417 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1418 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1419 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1420 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1422 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1423 ;; minibuffer-local-filename-must-match-map.
1424 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1425 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1426 (dolist (map (list minibuffer-local-filename-completion-map
1427 minibuffer-local-completion-map
1428 minibuffer-local-must-match-filename-map
1429 minibuffer-local-filename-must-match-map
1430 minibuffer-local-map
1431 minibuffer-local-isearch-map
1432 minibuffer-local-must-match-map
1433 minibuffer-local-ns-map))
1434 (define-key map "\C-r" 'anything-minibuffer-history))
1438 ;;; Menu
1441 (easy-menu-define nil global-map
1442 "`anything' menu"
1443 '("Anything"
1444 ["All anything commands" anything-execute-anything-command t]
1445 ["Find any Files/Buffers" anything-for-files t]
1446 ["Anything Everywhere" ac-mode t]
1447 "----"
1448 ("Files:"
1449 ["Find files" anything-find-files t]
1450 ["Recent Files" anything-recentf t]
1451 ["Locate" anything-locate t]
1452 ["Bookmarks" anything-c-pp-bookmarks t])
1453 ("Buffers:"
1454 ["Find buffers" anything-buffers-list t])
1455 ("Commands:"
1456 ["Emacs Commands" anything-M-x t]
1457 ["Externals Commands" anything-c-run-external-command t])
1458 ("Help:"
1459 ["Anything Apropos" anything-c-apropos t])
1460 ("Info:"
1461 ["Info at point" anything-info-at-point t]
1462 ["Emacs Manual index" anything-info-emacs t]
1463 ["Gnus Manual index" anything-info-gnus t])
1464 ("Org:"
1465 ["Org keywords" anything-org-keywords t]
1466 ["Org headlines" anything-org-headlines t])
1467 ("Tools:"
1468 ["Occur" anything-occur t]
1469 ["Grep" anything-do-grep t]
1470 ["Etags" anything-c-etags-select t]
1471 ["Lisp complete at point" anything-lisp-completion-at-point t]
1472 ["Browse Kill ring" anything-show-kill-ring t]
1473 ["Browse register" anything-register t]
1474 ["Browse code" anything-browse-code t]
1475 ["Mark Ring" anything-all-mark-rings t]
1476 ["Regexp handler" anything-regexp t]
1477 ["Colors & Faces" anything-colors t]
1478 ["Show xfonts" anything-select-xfont t]
1479 ["Ucs Symbols" anything-ucs t]
1480 ["Imenu" anything-imenu t]
1481 ["Google Suggest" anything-google-suggest t]
1482 ["Eval expression" anything-eval-expression-with-eldoc t]
1483 ["Calcul expression" anything-calcul-expression t]
1484 ["Man pages" anything-man-woman t]
1485 ["Top externals process" anything-top t]
1486 ["Emacs internals process" anything-list-emacs-process t])
1487 "----"
1488 ["Prefered Options" anything-configuration t]))
1490 ;;; Anything map add ons
1493 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1494 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1495 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1498 ;;; Specialized keymaps
1501 (defvar anything-c-buffer-map
1502 (let ((map (copy-keymap anything-map)))
1503 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1504 ;; No need to have separate command for grep and zgrep
1505 ;; as we don't use recursivity for buffers.
1506 ;; So use zgrep for both as it is capable to handle non--compressed files.
1507 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1508 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1509 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1510 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1511 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1512 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1513 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1514 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1515 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1516 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1517 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1518 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1519 (define-key map (kbd "M-a") 'anything-mark-all)
1520 (when (locate-library "elscreen")
1521 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1522 (delq nil map))
1523 "Keymap for buffer sources in anything.")
1525 (defvar anything-find-files-map
1526 (let ((map (copy-keymap anything-map)))
1527 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1528 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1529 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1530 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1531 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1532 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1533 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1534 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1535 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1536 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1537 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1538 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1539 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1540 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1541 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1542 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1543 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1544 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1545 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1546 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1547 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1548 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1549 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1550 (define-key map (kbd "C-c ?") 'anything-ff-help)
1551 (define-key map (kbd "C-}") 'anything-narrow-window)
1552 (define-key map (kbd "C-{") 'anything-enlarge-window)
1553 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1554 (define-key map (kbd "M-a") 'anything-mark-all)
1555 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1556 (define-key map (kbd "M-u") 'anything-unmark-all)
1557 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1558 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1559 ;; Next 2 have no effect if candidate is not an image file.
1560 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1561 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1562 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1563 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1565 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1566 (when anything-ff-lynx-style-map
1567 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1568 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1569 (delq nil map))
1570 "Keymap for `anything-find-files'.")
1572 (defvar anything-c-read-file-map
1573 (let ((map (copy-keymap anything-map)))
1574 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1575 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1576 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1577 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1578 (when anything-ff-lynx-style-map
1579 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1580 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1581 (define-key map (kbd "<M-left>") 'anything-previous-source)
1582 (define-key map (kbd "<M-right>") 'anything-next-source))
1583 (delq nil map))
1584 "Keymap for `anything-c-read-file-name'.")
1586 (defvar anything-generic-files-map
1587 (let ((map (copy-keymap anything-map)))
1588 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1589 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1590 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1591 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1592 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1593 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1594 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1595 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1596 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1597 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1598 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1599 map)
1600 "Generic Keymap for files.")
1602 (defvar anything-c-grep-map
1603 (let ((map (copy-keymap anything-map)))
1604 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1605 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1606 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1607 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1608 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1609 (when anything-c-grep-use-ioccur-style-keys
1610 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1611 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1612 (define-key map (kbd "C-c ?") 'anything-grep-help)
1613 (delq nil map))
1614 "Keymap used in Grep sources.")
1616 (defvar anything-c-pdfgrep-map
1617 (let ((map (copy-keymap anything-map)))
1618 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1619 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1620 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1621 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1622 map)
1623 "Keymap used in pdfgrep.")
1625 (defvar anything-c-etags-map
1626 (let ((map (copy-keymap anything-map)))
1627 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1628 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1629 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1630 (define-key map (kbd "C-c ?") 'anything-etags-help)
1631 map)
1632 "Keymap used in Etags.")
1634 (defvar anything-eval-expression-map
1635 (let ((map (copy-keymap anything-map)))
1636 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1637 (define-key map (kbd "<tab>") 'lisp-indent-line)
1638 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1639 (define-key map (kbd "C-p") 'previous-line)
1640 (define-key map (kbd "C-n") 'next-line)
1641 (define-key map (kbd "<up>") 'previous-line)
1642 (define-key map (kbd "<down>") 'next-line)
1643 (define-key map (kbd "<right>") 'forward-char)
1644 (define-key map (kbd "<left>") 'backward-char)
1645 map))
1647 (defvar anything-c-ucs-map
1648 (let ((map (copy-keymap anything-map)))
1649 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1650 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1651 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1652 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1653 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1654 map)
1655 "Keymap for `anything-ucs'.")
1659 ;;; Embeded documentation.
1662 (defun anything-c-list-preconfigured-anything ()
1663 "Collect preconfigured anything functions in this file."
1664 (loop with doc
1665 with sym
1666 for entry in (cdr (assoc
1667 (file-truename (locate-library "anything-config"))
1668 load-history))
1669 if (and (consp entry)
1670 (eq (car entry) 'defun)
1671 (string-match "^Preconfigured.+$"
1672 (setq doc (or (documentation (setq sym (cdr entry)))
1673 ""))))
1674 collect (cons sym (match-string 0 doc))))
1676 (defun anything-c-format-preconfigured-anything ()
1677 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1678 (anything-c-list-preconfigured-anything)))
1680 ;;; Global help message - Used by `anything-help'
1683 (setq anything-help-message
1684 (lambda ()
1685 (concat
1686 "\\<anything-map>"
1687 "`anything' is QuickSilver-like candidate-selection framework.
1689 Narrow the list by typing some pattern,
1690 Multiple patterns are allowed by splitting by space.
1691 Select with natural Emacs operations, choose with RET.
1693 If you have any problems, press C-c C-x C-b!!
1694 Feel free to send bug reports. I'll fix them.
1695 The steps are described in the beginning of anything.el file.
1697 == Basic Operations ==
1698 C-p, Up: Previous Line
1699 C-n, Down : Next Line
1700 M-v, PageUp : Previous Page
1701 C-v, PageDown : Next Page
1702 Enter : Execute first (default) action / Select
1703 M-< : First Line
1704 M-> : Last Line
1705 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1706 M-PageDown, C-M-v : Next Page (other-window)
1708 Tab, C-i : Show action list
1709 Left : Previous Source
1710 Right, C-o : Next Source
1711 C-k : Delete pattern
1712 C-z : Persistent Action (Execute action with anything session kept)
1713 C-c C-x C-b: Send a bug report
1715 == Shortcuts For 2nd/3rd Action ==
1716 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1717 \\[anything-select-3rd-action] : Execute 3rd Action
1719 == Visible Marks ==
1720 Visible marks store candidate. Some actions uses marked candidates.
1722 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1723 \\[anything-prev-visible-mark] : Previous Mark
1724 \\[anything-next-visible-mark] : Next Mark
1726 == Miscellaneous Commands ==
1727 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1728 \\[anything-quit-and-find-file] : Drop into `find-file'
1729 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1730 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1731 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1732 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1733 \\[anything-force-update] : Recalculate And Redisplay Candidates
1735 == Global Commands ==
1736 \\<global-map>\\[anything-resume] revives last `anything' session.
1737 It is very useful, so you should bind any key.
1739 Single source is executed by \\[anything-call-source].
1741 == Preconfigured `anything' ==
1742 Preconfigured `anything' is commands that uses `anything' interface.
1743 You can use them without configuration.
1746 (apply 'concat (anything-c-format-preconfigured-anything))
1748 Enjoy!")))
1750 ;;; `anything-buffer-list' help
1753 ;;;###autoload
1754 (defun anything-c-buffer-help ()
1755 "Help command for anything buffers."
1756 (interactive)
1757 (let ((anything-help-message "== Anything Buffer ==
1758 \nTips:
1759 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1760 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1761 \nSpecific commands for `anything-buffers-list':
1762 \\<anything-c-buffer-map>
1763 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1764 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1765 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1766 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1767 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1768 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1769 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1770 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1771 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1772 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1773 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1774 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1775 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1776 \\[anything-mark-all]\t\t->Mark all.
1777 \\[anything-c-buffer-help]\t\t->Display this help.
1778 \n== Anything Map ==
1779 \\{anything-map}
1781 (anything-help)))
1784 ;;; Find files help (`anything-find-files')
1787 ;;;###autoload
1788 (defun anything-ff-help ()
1789 "Help command for `anything-find-files'."
1790 (interactive)
1791 (let ((anything-help-message "== Anything Find Files ==
1792 \nTips:
1793 \n- Enter `~/' at end of pattern to quickly reach home directory.
1794 - Enter `/' at end of pattern to quickly reach root of your file system.
1795 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1796 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1797 - Use `C-u C-z' to watch an image.
1798 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1799 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1801 \nSpecific commands for `anything-find-files':
1802 \\<anything-find-files-map>
1803 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1804 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1805 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1806 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1807 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1808 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1809 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1810 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1811 \\[anything-ff-run-load-file]\t\t->Load File.
1812 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1813 \\[anything-ff-run-delete-file]\t\t->Delete File.
1814 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1815 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1816 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1817 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1818 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1819 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1820 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1821 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1822 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1823 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1824 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1825 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1826 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1827 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1828 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1829 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1830 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1831 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1832 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1833 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1834 \\[anything-narrow-window]\t\t->Narrow anything window.
1835 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1836 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1837 \\[anything-ff-help]\t\t->Display this help info.
1838 \n== Anything Map ==
1839 \\{anything-map}
1841 (anything-help)))
1843 ;;; Help for `anything-c-read-file-name'
1846 ;;;###autoload
1847 (defun anything-read-file-name-help ()
1848 (interactive)
1849 (let ((anything-help-message "== Anything read file name Map ==\
1850 \nSpecific commands for anything-c-read-file-name:
1851 \\<anything-c-read-file-map>
1852 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1853 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1854 \\[anything-next-source]\t\t->Goto next source.
1855 \\[anything-previous-source]\t->Goto previous source.
1856 \\[anything-read-file-name-help]\t\t->Display this help info.
1857 \n== Anything Map ==
1858 \\{anything-map}
1860 (anything-help)))
1862 ;;; Generic file help - Used by locate.
1865 ;;;###autoload
1866 (defun anything-generic-file-help ()
1867 (interactive)
1868 (let ((anything-help-message "== Anything Generic files Map ==\
1869 \nSpecific commands for anything locate and others files sources:
1870 \\<anything-generic-files-map>
1871 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1872 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1873 \\[anything-ff-run-delete-file]\t\t->Delete file.
1874 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1875 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1876 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1877 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1878 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1879 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1880 \nLocate tips:
1881 You can add after writing search pattern any of the locate command line options.
1882 e.g -b, -e, -n <number>...etc.
1883 See Man locate for more infos.
1884 \n== Anything Map ==
1885 \\{anything-map}"))
1886 (anything-help)))
1889 ;;; Grep help
1892 ;;;###autoload
1893 (defun anything-grep-help ()
1894 (interactive)
1895 (let ((anything-help-message "== Anything Grep Map ==\
1896 \nSpecific commands for Grep and Etags:
1897 \\<anything-c-grep-map>
1898 \\[anything-c-goto-next-file]\t->Next File.
1899 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1900 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1901 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1902 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1903 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1904 \\[anything-grep-help]\t\t->Show this help.
1905 \n== Anything Map ==
1906 \\{anything-map}"))
1907 (anything-help)))
1909 ;;; Pdf grep help
1912 ;;;###autoload
1913 (defun anything-pdfgrep-help ()
1914 (interactive)
1915 (let ((anything-help-message "== Anything PdfGrep Map ==\
1916 \nSpecific commands for Pdf Grep:
1917 \\<anything-c-pdfgrep-map>
1918 \\[anything-c-goto-next-file]\t->Next File.
1919 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1920 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1921 \\[anything-pdfgrep-help]\t\t->Show this help.
1922 \n== Anything Map ==
1923 \\{anything-map}"))
1924 (anything-help)))
1926 ;;; Etags help
1929 ;;;###autoload
1930 (defun anything-etags-help ()
1931 "The help function for etags."
1932 (interactive)
1933 (let ((anything-help-message "== Anything Etags Map ==\
1934 \nSpecific commands for Etags:
1935 \\<anything-c-etags-map>
1936 \\[anything-c-goto-next-file]\t->Next File.
1937 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1938 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1939 \\[anything-etags-help]\t\t->Show this help.
1940 \n== Anything Map ==
1941 \\{anything-map}"))
1942 (anything-help)))
1944 ;;; Ucs help
1947 (defun anything-c-ucs-help ()
1948 "Help command for `anything-ucs'."
1949 (interactive)
1950 (let ((anything-help-message "== Anything Ucs ==
1951 \nSpecific commands for `anything-ucs':
1952 \\<anything-c-ucs-map>
1953 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1954 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1955 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1956 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1957 \\[anything-c-ucs-help]\t\t->Show this help.
1959 \n== Anything Map ==
1960 \\{anything-map}
1962 (anything-help)))
1966 ;;; Mode line strings
1969 (defvar anything-buffer-mode-line-string
1970 '("Buffer(s)"
1971 "\\<anything-c-buffer-map>\
1972 \\[anything-c-buffer-help]:Help, \
1973 \\<anything-map>\
1974 \\[anything-select-action]:Acts,\
1975 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1976 \\[anything-select-3rd-action]:NthAct,\
1977 \\[anything-send-bug-report-from-anything]:BugReport."
1978 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1980 (defvar anything-ff-mode-line-string
1981 "\\<anything-find-files-map>\
1982 \\[anything-ff-help]:Help, \
1983 \\[anything-send-bug-report-from-anything]:BugReport, \
1984 \\<anything-map>\
1985 \\[anything-select-action]:Acts, \
1986 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1987 \\[anything-select-3rd-action]:NthAct"
1988 "String displayed in mode-line in `anything-c-source-find-files'")
1990 (defvar anything-read-file-name-mode-line-string
1991 "\\<anything-c-read-file-map>\
1992 \\[anything-read-file-name-help]:Help, \
1993 \\<anything-map>\
1994 \\[anything-select-action]:Acts,\
1995 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1996 \\[anything-select-3rd-action]:NthAct"
1997 "String displayed in mode-line in `anything-c-source-find-files'")
1999 (defvar anything-generic-file-mode-line-string
2000 "\\<anything-generic-files-map>\
2001 \\[anything-generic-file-help]:Help, \
2002 \\<anything-map>\
2003 \\[anything-select-action]:Acts,\
2004 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2005 \\[anything-select-3rd-action]:NthAct,\
2006 \\[anything-send-bug-report-from-anything]:BugReport."
2007 "String displayed in mode-line in Locate.")
2009 (defvar anything-grep-mode-line-string
2010 "\\<anything-c-grep-map>\
2011 \\[anything-grep-help]:Help,\
2012 \\<anything-map>\
2013 \\[anything-select-action]:Acts,\
2014 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2015 \\[anything-select-3rd-action]:NthAct,\
2016 \\[anything-send-bug-report-from-anything]:BugReport."
2017 "String displayed in mode-line in `anything-do-grep'.")
2019 (defvar anything-pdfgrep-mode-line-string
2020 "\\<anything-c-pdfgrep-map>\
2021 \\[anything-pdfgrep-help]:Help,\
2022 \\<anything-map>\
2023 \\[anything-select-action]:Acts,\
2024 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2025 \\[anything-select-3rd-action]:NthAct,\
2026 \\[anything-send-bug-report-from-anything]:BugReport."
2027 "String displayed in mode-line in `anything-do-pdfgrep'.")
2029 (defvar anything-etags-mode-line-string
2030 "\\<anything-c-etags-map>\
2031 \\[anything-etags-help]:Help,\
2032 \\<anything-map>\
2033 \\[anything-select-action]:Acts,\
2034 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2035 \\[anything-select-3rd-action]:NthAct,\
2036 \\[anything-send-bug-report-from-anything]:BugReport."
2037 "String displayed in mode-line in `anything-c-etags-select'.")
2040 (defvar anything-c-ucs-mode-line-string
2041 "\\<anything-c-ucs-map>\
2042 \\[anything-c-ucs-help]:Help, \
2043 \\<anything-map>\
2044 \\[anything-select-action]:Acts,\
2045 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2046 \\[anything-select-3rd-action]:NthAct."
2047 "String displayed in mode-line in `anything-ucs'.")
2051 ;;; Utilities Functions
2054 (defun anything-ff-find-printers ()
2055 "Return a list of available printers on Unix systems."
2056 (let ((printer-list (with-temp-buffer
2057 (call-process "lpstat" nil t nil "-a")
2058 (split-string (buffer-string) "\n"))))
2059 (loop for p in printer-list
2060 for printer = (car (split-string p))
2061 when printer
2062 collect printer)))
2064 ;; Shut up byte compiler in emacs24*.
2065 (defun anything-c-switch-to-buffer (buffer-or-name)
2066 "Same as `switch-to-buffer' whithout warnings at compile time."
2067 (with-no-warnings
2068 (switch-to-buffer buffer-or-name)))
2070 (defsubst* anything-c-position (item seq &key (test 'eq))
2071 "A simple and faster replacement of CL `position'."
2072 (loop for i in seq for index from 0
2073 when (funcall test i item) return index))
2075 (defun anything-c-get-pid-from-process-name (process-name)
2076 "Get pid from running process PROCESS-NAME."
2077 (loop with process-list = (list-system-processes)
2078 for pid in process-list
2079 for process = (assoc-default 'comm (process-attributes pid))
2080 when (and process (string-match process-name process))
2081 return pid))
2083 (defun* anything-current-buffer-narrowed-p (&optional
2084 (buffer anything-current-buffer))
2085 "Check if BUFFER is narrowed.
2086 Default is `anything-current-buffer'."
2087 (with-current-buffer buffer
2088 (let ((beg (point-min))
2089 (end (point-max))
2090 (total (buffer-size)))
2091 (or (/= beg 1) (/= end (1+ total))))))
2093 (defun anything-region-active-p ()
2094 (and transient-mark-mode mark-active (/= (mark) (point))))
2096 (defun anything-goto-line (lineno)
2097 "Goto LINENO opening only outline headline if needed."
2098 (goto-char (point-min)) (forward-line (1- lineno))
2099 (when (or (eq major-mode 'org-mode)
2100 (and (boundp 'outline-minor-mode)
2101 outline-minor-mode))
2102 (require 'org) ; On some old Emacs versions org may not be loaded.
2103 (org-reveal))
2104 (anything-match-line-color-current-line) (sit-for 0.3)
2105 (anything-match-line-cleanup))
2107 (defun anything-show-this-source-only ()
2108 "Show all candidates of this source."
2109 (interactive)
2110 (setq anything-candidate-number-limit nil)
2111 (anything-set-source-filter
2112 (list (assoc-default 'name (anything-get-current-source)))))
2114 ;;;###autoload
2115 (defun anything-test-sources ()
2116 "List all anything sources for test.
2117 The output is sexps which are evaluated by \\[eval-last-sexp]."
2118 (interactive)
2119 (with-output-to-temp-buffer "*Anything Test Sources*"
2120 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2121 (apropos-internal "^anything-c-source" #'boundp))
2122 (pop-to-buffer standard-output)))
2124 (defun anything-nest (&rest same-as-anything)
2125 "Nested `anything'. If you use `anything' within `anything', use it."
2126 (with-selected-window (anything-window)
2127 (let (anything-current-position
2128 anything-current-buffer
2129 (orig-anything-buffer anything-buffer)
2130 anything-pattern
2131 anything-buffer
2132 anything-sources
2133 anything-compiled-sources
2134 anything-buffer-chars-modified-tick
2135 (anything-samewindow t)
2136 (enable-recursive-minibuffers t))
2137 (unwind-protect
2138 (apply #'anything same-as-anything)
2139 (anything-initialize-overlays orig-anything-buffer)
2140 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2142 (defun anything-displaying-source-names ()
2143 "Display sources name."
2144 (with-current-buffer anything-buffer
2145 (goto-char (point-min))
2146 (loop with pos
2147 while (setq pos (next-single-property-change (point) 'anything-header))
2148 do (goto-char pos)
2149 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2150 do (forward-line 1))))
2152 ;; [Obsolete]
2153 (defun anything-select-source ()
2154 "[OBSOLETE] Select source."
2155 (interactive)
2156 (let ((default (assoc-default 'name (anything-get-current-source)))
2157 (source-names (anything-displaying-source-names))
2158 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2159 (anything-get-sources))))
2160 (setq anything-candidate-number-limit 9999)
2161 (anything-aif
2162 (let (anything-source-filter)
2163 (anything-nest '(((name . "Anything Source")
2164 (candidates . source-names)
2165 (action . identity))
2166 ((name . "Anything Source (ALL)")
2167 (candidates . all-source-names)
2168 (action . identity)))
2169 nil "Source: " nil
2170 default "*anything select source*"))
2171 (anything-set-source-filter (list it))
2172 (anything-set-source-filter nil))))
2174 (defun anything-c-match-on-file-name (candidate)
2175 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2176 (string-match anything-pattern (file-name-nondirectory candidate)))
2178 (defun anything-c-match-on-directory-name (candidate)
2179 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2180 (anything-aif (file-name-directory candidate)
2181 (string-match anything-pattern it)))
2183 (defun anything-c-match-on-basename (candidate)
2184 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2185 (string-match anything-pattern (anything-c-basename candidate)))
2187 (defun anything-c-string-match (candidate)
2188 "Return non-nil if `anything-pattern' match CANDIDATE.
2189 The match is done with `string-match'."
2190 (string-match anything-pattern candidate))
2192 (defun anything-c-skip-entries (list regexp)
2193 "Remove entries which matches REGEXP from LIST."
2194 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2195 list))
2197 (defun anything-c-shadow-entries (list regexp)
2198 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2199 (mapcar (lambda (file)
2200 ;; Add shadow face property to boring files.
2201 (let ((face (if (facep 'file-name-shadow)
2202 'file-name-shadow
2203 ;; fall back to default on XEmacs
2204 'default)))
2205 (if (string-match regexp file)
2206 (setq file (propertize file 'face face))))
2207 file)
2208 list))
2210 (defsubst anything-c-stringify (str-or-sym)
2211 "Get string of STR-OR-SYM."
2212 (if (stringp str-or-sym)
2213 str-or-sym
2214 (symbol-name str-or-sym)))
2216 (defsubst anything-c-symbolify (str-or-sym)
2217 "Get symbol of STR-OR-SYM."
2218 (if (symbolp str-or-sym)
2219 str-or-sym
2220 (intern str-or-sym)))
2222 (defun anything-c-describe-function (func)
2223 "FUNC is symbol or string."
2224 (describe-function (anything-c-symbolify func)))
2226 (defun anything-c-describe-variable (var)
2227 "VAR is symbol or string."
2228 (describe-variable (anything-c-symbolify var)))
2230 (defun anything-c-find-function (func)
2231 "FUNC is symbol or string."
2232 (find-function (anything-c-symbolify func)))
2234 (defun anything-c-find-variable (var)
2235 "VAR is symbol or string."
2236 (find-variable (anything-c-symbolify var)))
2238 (defun anything-c-kill-new (candidate &optional replace)
2239 "CANDIDATE is symbol or string.
2240 See `kill-new' for argument REPLACE."
2241 (kill-new (anything-c-stringify candidate) replace))
2243 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2244 "Remove duplicates elements in list SEQ.
2245 This is same as `remove-duplicates' but with memoisation.
2246 It is much faster, especially in large lists.
2247 A test function can be provided with TEST argument key.
2248 Default is `eq'."
2249 (let ((cont (make-hash-table :test test)))
2250 (loop for elm in seq
2251 unless (gethash elm cont)
2252 do (puthash elm elm cont)
2253 finally return
2254 (loop for i being the hash-values in cont collect i))))
2256 (defadvice eval-defun (after anything-source-hack activate)
2257 "Allow immediate execution of anything source when evaling it.
2258 See `anything-c-enable-eval-defun-hack'."
2259 (when anything-c-enable-eval-defun-hack
2260 (let ((varsym (save-excursion
2261 (beginning-of-defun)
2262 (forward-char 1)
2263 (when (memq (read (current-buffer)) '(defvar setq))
2264 (read (current-buffer))))))
2265 (when (string-match "^anything-c-source-" (symbol-name varsym))
2266 (anything varsym)))))
2267 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2270 ;; Move this function from anything.el and redefine here
2271 ;; to avoid an unneeded defadvice.
2272 (defun anything-quit-and-find-file ()
2273 "Drop into `anything-find-files' from `anything'.
2274 If current selection is a buffer or a file, `anything-find-files'
2275 from its directory."
2276 (interactive)
2277 (anything-run-after-quit
2278 (lambda (f)
2279 (if (file-exists-p f)
2280 (anything-find-files-1 (file-name-directory f)
2281 (if anything-ff-transformer-show-only-basename
2282 (anything-c-basename f) f))
2283 (anything-find-files-1 f)))
2284 (anything-aif (get-buffer (anything-get-selection))
2285 (or (buffer-file-name it)
2286 (car (rassoc it dired-buffers))
2287 (and (with-current-buffer it
2288 (eq major-mode 'org-agenda-mode))
2289 org-directory
2290 (expand-file-name org-directory))
2291 default-directory)
2292 (let ((sel (anything-get-selection)))
2293 (if (file-exists-p sel)
2294 (expand-file-name sel)
2295 default-directory)))))
2298 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2299 "Walk through DIRECTORY tree.
2300 PATH can be one of basename, relative, or full.
2301 DIRECTORIES when non--nil (default) return also directories names, otherwise
2302 skip directories names.
2303 MATCH match only filenames matching regexp MATCH."
2304 `(let (result
2305 (fn (case ,path
2306 (basename 'file-name-nondirectory)
2307 (relative 'file-relative-name)
2308 (full 'identity)
2309 (t 'file-name-nondirectory))))
2310 (labels ((ls-R (dir)
2311 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2312 for f in ls
2313 if (file-directory-p f)
2314 do (progn (when ,directories
2315 (push (funcall fn f) result))
2316 ;; Don't recurse in directory symlink.
2317 (unless (file-symlink-p f)
2318 (ls-R f)))
2319 else do
2320 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2321 (push (funcall fn f) result)))))
2322 (ls-R ,directory)
2323 (nreverse result))))
2325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2327 ;;; Anything regexp.
2330 (defun anything-c-query-replace-regexp (candidate)
2331 "Query replace regexp from `anything-regexp'.
2332 With a prefix arg replace only matches surrounded by word boundaries,
2333 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2334 (let ((regexp (funcall (anything-attr 'regexp))))
2335 (apply 'query-replace-regexp
2336 (anything-c-query-replace-args regexp))))
2338 (defun anything-c-kill-regexp-as-sexp (candidate)
2339 "Kill regexp in a format usable in lisp code."
2340 (anything-c-regexp-kill-new
2341 (prin1-to-string (funcall (anything-attr 'regexp)))))
2343 (defun anything-c-kill-regexp (candidate)
2344 "Kill regexp as it is in `anything-pattern'."
2345 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2347 (defun anything-c-query-replace-args (regexp)
2348 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2349 (let ((region-only (anything-region-active-p)))
2350 (list
2351 regexp
2352 (query-replace-read-to regexp
2353 (format "Query replace %sregexp %s"
2354 (if anything-current-prefix-arg "word " "")
2355 (if region-only "in region " ""))
2357 anything-current-prefix-arg
2358 (when region-only (region-beginning))
2359 (when region-only (region-end)))))
2361 (defvar anything-c-source-regexp
2362 '((name . "Regexp Builder")
2363 (init . (lambda ()
2364 (anything-candidate-buffer anything-current-buffer)))
2365 (candidates-in-buffer)
2366 (get-line . anything-c-regexp-get-line)
2367 (persistent-action . anything-c-regexp-persistent-action)
2368 (persistent-help . "Show this line")
2369 (multiline)
2370 (delayed)
2371 (requires-pattern . 2)
2372 (mode-line . "Press TAB to select action.")
2373 (regexp . (lambda () anything-input))
2374 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2375 ("Query Replace Regexp (C-u Not inside word.)"
2376 . anything-c-query-replace-regexp)
2377 ("Kill Regexp" . anything-c-kill-regexp)))))
2379 (defun anything-c-regexp-get-line (s e)
2380 (propertize
2381 (apply 'concat
2382 ;; Line contents
2383 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2384 ;; subexps
2385 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2386 collect (format "\n %s'%s'"
2387 (if (zerop i) "Group 0: " (format "Group %d: " i))
2388 (match-string i))))
2389 ;; match beginning
2390 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2391 ;; It is implementation problem of candidates-in-buffer.
2392 'anything-realvalue
2393 (1- s)))
2395 (defun anything-c-regexp-persistent-action (pt)
2396 (goto-char pt)
2397 (anything-persistent-highlight-point))
2399 (defun anything-c-regexp-kill-new (input)
2400 (kill-new input)
2401 (message "Killed: %s" input))
2405 ;;; Toggle all marks.
2408 ;;;###autoload
2409 (defun anything-mark-all ()
2410 "Mark all visible unmarked candidates in current source."
2411 (interactive)
2412 (with-anything-window
2413 (save-excursion
2414 (goto-char (anything-get-previous-header-pos))
2415 (anything-next-line)
2416 (let* ((next-head (anything-get-next-header-pos))
2417 (end (and next-head
2418 (save-excursion
2419 (goto-char next-head)
2420 (forward-line -1)
2421 (point))))
2422 (maxpoint (or end (point-max))))
2423 (while (< (point) maxpoint)
2424 (anything-mark-current-line)
2425 (let ((prefix (get-text-property (point-at-bol) 'display))
2426 (bn (anything-c-basename (anything-get-selection)))
2427 (src (assoc-default 'name (anything-get-current-source))))
2428 (when (and (not (anything-this-visible-mark))
2429 (not (or (string= prefix "[?]")
2430 (string= prefix "[@]"))))
2431 ;; Don't mark possibles directories ending with . or ..
2432 ;; and also autosave files/links.
2433 (unless
2434 (and (or (anything-file-completion-source-p)
2435 (equal src "Files from Current Directory"))
2436 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2437 (anything-make-visible-mark))))
2438 (forward-line 1) (end-of-line))))
2439 (anything-mark-current-line)
2440 (message "%s candidates marked" (length anything-marked-candidates))))
2442 ;;;###autoload
2443 (defun anything-unmark-all ()
2444 "Unmark all candidates in all sources of current anything session."
2445 (interactive)
2446 (with-anything-window
2447 (let ((len (length anything-marked-candidates)))
2448 (save-excursion
2449 (anything-clear-visible-mark))
2450 (setq anything-marked-candidates nil)
2451 (anything-mark-current-line)
2452 (message "%s candidates unmarked" len))))
2454 ;;;###autoload
2455 (defun anything-toggle-all-marks ()
2456 "Toggle all marks.
2457 Mark all visible candidates of current source or unmark all candidates
2458 visible or invisible in all sources of current anything session"
2459 (interactive)
2460 (let ((marked (anything-marked-candidates)))
2461 (if (and (>= (length marked) 1)
2462 (with-anything-window anything-visible-mark-overlays))
2463 (anything-unmark-all)
2464 (anything-mark-all))))
2468 ;;; Buffers
2471 (defun anything-c-buffer-list ()
2472 "Return the list of names of buffers with boring buffers filtered out.
2473 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2474 The first buffer in the list will be the last recently used
2475 buffer that is not the current buffer."
2476 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2477 (append (cdr buffers) (list (car buffers)))))
2479 (defvar anything-c-source-buffers
2480 '((name . "Buffers")
2481 (candidates . anything-c-buffer-list)
2482 (type . buffer)))
2483 ;; (anything 'anything-c-source-buffers)
2485 (defvar anything-c-source-buffer-not-found
2486 '((name . "Create buffer")
2487 (dummy)
2488 (filtered-candidate-transformer (lambda (cands source)
2489 (list anything-pattern)))
2490 (action . (lambda (candidate)
2491 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2492 ;; (anything 'anything-c-source-buffer-not-found)
2494 ;;; Buffers-list (was buffers+)
2497 (eval-when-compile (require 'dired))
2499 (defun anything-c-highlight-buffers (buffers)
2500 (loop for i in buffers
2501 for buf = (get-buffer i)
2502 for bfname = (buffer-file-name buf)
2503 collect
2504 (cond (;; A dired buffer.
2505 (rassoc buf dired-buffers)
2506 (propertize i 'face 'anything-ff-directory
2507 'help-echo (car (rassoc buf dired-buffers))))
2508 ;; A buffer file modified somewhere outside of emacs.
2509 ((and bfname (not (file-remote-p bfname))
2510 (file-exists-p bfname)
2511 (not (verify-visited-file-modtime buf)))
2512 (propertize i 'face 'anything-buffer-saved-out
2513 'help-echo bfname))
2514 ;; A new buffer file not already saved on disk.
2515 ((and bfname (not (file-remote-p bfname))
2516 (not (verify-visited-file-modtime buf)))
2517 (propertize i 'face 'anything-buffer-not-saved
2518 'help-echo bfname))
2519 ;; A Remote buffer file modified and not saved on disk.
2520 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2521 (let ((prefix (propertize
2522 " " 'display
2523 (propertize "@ " 'face 'anything-ff-prefix))))
2524 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2525 'help-echo bfname)) i)))
2526 ;; A buffer file modified and not saved on disk.
2527 ((and bfname (buffer-modified-p buf))
2528 (propertize i 'face 'anything-ff-symlink
2529 'help-echo bfname))
2530 ;; A remote buffer file not modified and saved on disk.
2531 ((and bfname (file-remote-p bfname))
2532 (let ((prefix (propertize
2533 " " 'display
2534 (propertize "@ " 'face 'anything-ff-prefix))))
2535 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2536 'help-echo bfname)) i)))
2537 ;; A buffer file not modified and saved on disk.
2538 (bfname
2539 (propertize i 'face 'font-lock-type-face
2540 'help-echo bfname))
2541 ;; Any non--file buffer.
2542 (t (propertize i 'face 'italic)))))
2545 (defvar anything-c-source-buffers-list
2546 '((name . "Buffers")
2547 (candidates . anything-c-buffer-list)
2548 (type . buffer)
2549 (match anything-c-buffer-match-major-mode)
2550 (diff-action . anything-buffer-toggle-diff)
2551 (revert-action . anything-buffer-revert-and-update)
2552 (save-action . anything-buffer-save-and-update)
2553 (candidate-transformer anything-c-skip-current-buffer
2554 anything-c-skip-boring-buffers
2555 anything-c-highlight-buffers)
2556 (persistent-action . anything-c-buffers-list-persistent-action)
2557 (volatile)
2558 (mode-line . anything-buffer-mode-line-string)
2559 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2560 ;; (anything 'anything-c-source-buffers-list)
2562 (defun anything-c-buffer-match-major-mode (candidate)
2563 "Match maybe buffer by major-mode.
2564 If you give a major-mode or partial major-mode,
2565 it will list all buffers of this major-mode and/or buffers with name
2566 matching this major-mode.
2567 If you add a space after major-mode and then a space,
2568 it will match all buffers of the major-mode
2569 before space matching pattern after space.
2570 If you give a pattern which doesn't match a major-mode, it will search buffer
2571 with name matching pattern."
2572 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2573 (buf (get-buffer cand)))
2574 (when buf
2575 (with-current-buffer buf
2576 (let ((mjm (symbol-name major-mode))
2577 (split (split-string anything-pattern)))
2578 (cond ((string-match "\\s-$" anything-pattern)
2579 (string-match (car split) mjm))
2580 ((string-match "\\s-" anything-pattern)
2581 (and (string-match (car split) mjm)
2582 (string-match (cadr split) cand)))
2583 (t (or (string-match anything-pattern mjm)
2584 (string-match anything-pattern cand)))))))))
2586 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2587 "Query replace in marked buffers.
2588 If REGEXP-FLAG is given use `query-replace-regexp'."
2589 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2590 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2591 (bufs (anything-marked-candidates)))
2592 (loop
2593 with replace = (query-replace-read-from prompt regexp-flag)
2594 with tostring = (unless (consp replace)
2595 (query-replace-read-to
2596 replace prompt regexp-flag))
2597 for buf in bufs
2599 (save-window-excursion
2600 (anything-c-switch-to-buffer buf)
2601 (save-excursion
2602 (let ((case-fold-search t))
2603 (goto-char (point-min))
2604 (if (consp replace)
2605 (apply fn (list (car replace) (cdr replace)))
2606 (apply fn (list replace tostring)))))))))
2608 (defun anything-c-buffer-query-replace-regexp (candidate)
2609 (anything-c-buffer-query-replace-1 'regexp))
2611 (defun anything-c-buffer-query-replace (candidate)
2612 (anything-c-buffer-query-replace-1))
2614 (defun anything-buffer-toggle-diff (candidate)
2615 "Toggle diff buffer CANDIDATE with it's file."
2616 (if (get-buffer-window "*Diff*")
2617 (kill-buffer "*Diff*")
2618 (diff-buffer-with-file (get-buffer candidate))))
2620 ;;;###autoload
2621 (defun anything-buffer-diff-persistent ()
2622 "Toggle diff buffer without quitting anything."
2623 (interactive)
2624 (anything-execute-persistent-action 'diff-action))
2626 (defun anything-buffer-revert-and-update (candidate)
2627 (let ((marked (anything-marked-candidates)))
2628 (loop for buf in marked do (anything-revert-buffer buf))
2629 (anything-force-update candidate)))
2631 ;;;###autoload
2632 (defun anything-buffer-revert-persistent ()
2633 "Revert buffer without quitting anything."
2634 (interactive)
2635 (anything-execute-persistent-action 'revert-action 'onewindow))
2637 (defun anything-buffer-save-and-update (candidate)
2638 (let ((marked (anything-marked-candidates))
2639 (enable-recursive-minibuffers t))
2640 (loop for buf in marked do
2641 (with-current-buffer (get-buffer buf)
2642 (save-buffer)))
2643 (anything-force-update candidate)))
2645 ;;;###autoload
2646 (defun anything-buffer-save-persistent ()
2647 "Save buffer without quitting anything."
2648 (interactive)
2649 (anything-execute-persistent-action 'save-action 'onewindow))
2651 ;;;###autoload
2652 (defun anything-buffer-run-kill-buffers ()
2653 "Run kill buffer action from `anything-c-source-buffers-list'."
2654 (interactive)
2655 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2657 ;;;###autoload
2658 (defun anything-buffer-run-grep ()
2659 "Run Grep action from `anything-c-source-buffers-list'."
2660 (interactive)
2661 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2663 ;;;###autoload
2664 (defun anything-buffer-run-zgrep ()
2665 "Run Grep action from `anything-c-source-buffers-list'."
2666 (interactive)
2667 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2669 ;;;###autoload
2670 (defun anything-buffer-run-query-replace-regexp ()
2671 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2672 (interactive)
2673 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2675 ;;;###autoload
2676 (defun anything-buffer-run-query-replace ()
2677 "Run Query replace action from `anything-c-source-buffers-list'."
2678 (interactive)
2679 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2681 ;;;###autoload
2682 (defun anything-buffer-switch-other-window ()
2683 "Run switch to other window action from `anything-c-source-buffers-list'."
2684 (interactive)
2685 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2687 ;;;###autoload
2688 (defun anything-buffer-switch-other-frame ()
2689 "Run switch to other frame action from `anything-c-source-buffers-list'."
2690 (interactive)
2691 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2693 ;;;###autoload
2694 (defun anything-buffer-switch-to-elscreen ()
2695 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2696 (interactive)
2697 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2699 ;;;###autoload
2700 (defun anything-buffer-run-ediff ()
2701 "Run ediff action from `anything-c-source-buffers-list'."
2702 (interactive)
2703 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2705 (defun anything-buffer-run-ediff-merge ()
2706 "Run ediff action from `anything-c-source-buffers-list'."
2707 (interactive)
2708 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2710 (defun anything-c-buffers-persistent-kill (buffer)
2711 "Persistent action to kill buffer."
2712 (with-current-buffer (get-buffer buffer)
2713 (if (and (buffer-modified-p)
2714 (buffer-file-name (current-buffer)))
2715 (progn
2716 (save-buffer)
2717 (kill-buffer buffer))
2718 (kill-buffer buffer)))
2719 (anything-delete-current-selection))
2721 (defun anything-c-recenter-window ()
2722 "Make visible current selection by recentering anything window."
2723 (with-anything-window (recenter)))
2725 (defun anything-c-buffers-list-persistent-action (candidate)
2726 (if current-prefix-arg
2727 (anything-c-buffers-persistent-kill candidate)
2728 (anything-c-switch-to-buffer candidate)))
2731 ;;;; <File>
2734 ;;; File name history
2735 (defvar anything-c-source-file-name-history
2736 '((name . "File Name History")
2737 (candidates . file-name-history)
2738 (match anything-c-match-on-basename)
2739 (type . file)))
2740 ;; (anything 'anything-c-source-file-name-history)
2742 ;;; Files in current dir
2745 (defvar anything-c-source-files-in-current-dir
2746 '((name . "Files from Current Directory")
2747 (candidates . (lambda ()
2748 (with-anything-current-buffer
2749 (directory-files (anything-c-current-directory)))))
2750 ;; volatile is not needed, I think.
2751 (type . file)))
2752 ;; (anything 'anything-c-source-files-in-current-dir)
2754 (defun anything-c-highlight-files (files)
2755 (loop for i in files
2756 if (file-directory-p i)
2757 collect (propertize (file-name-nondirectory i)
2758 'face 'anything-ff-directory
2759 'help-echo (expand-file-name i))
2760 else
2761 collect (propertize (file-name-nondirectory i)
2762 'face 'anything-ff-file
2763 'help-echo (expand-file-name i))))
2765 (defvar anything-c-source-files-in-current-dir+
2766 '((name . "Files from Current Directory")
2767 (candidates . (lambda ()
2768 (with-anything-current-buffer
2769 (directory-files (anything-c-current-directory) t))))
2770 (candidate-transformer anything-c-highlight-files)
2771 ;; volatile is not needed, I think.
2772 (type . file)))
2773 ;; (anything 'anything-c-source-files-in-current-dir+)
2777 ;;; Anything-find-files - The anything files browser.
2780 ;; Internal.
2781 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2782 "*The doc that is inserted in the Name header of a find-files or dired source.")
2783 (defvar anything-ff-auto-update-flag nil
2784 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2785 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2786 (defvar anything-ff-last-expanded nil
2787 "Store last expanded directory or file.")
2788 (defvar anything-ff-default-directory nil)
2789 (defvar anything-ff-history nil)
2790 (defvar anything-ff-cand-to-mark nil)
2793 (defvar anything-c-source-find-files
2794 `((name . "Find Files")
2795 (header-name . (lambda (name)
2796 (concat name anything-c-find-files-doc-header)))
2797 ;; It is needed for filenames with capital letters
2798 (disable-shortcuts)
2799 (init . (lambda ()
2800 (setq anything-ff-auto-update-flag
2801 anything-ff-auto-update-initial-value)))
2802 (candidates . anything-find-files-get-candidates)
2803 (filtered-candidate-transformer anything-c-find-files-transformer)
2804 (image-action1 . anything-ff-rotate-image-left)
2805 (image-action2 . anything-ff-rotate-image-right)
2806 (toggle-basename . anything-ff-toggle-basename)
2807 (properties-action . anything-ff-properties)
2808 (toggle-auto-update . anything-ff-toggle-auto-update)
2809 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2810 (persistent-action . anything-find-files-persistent-action)
2811 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2812 (mode-line . anything-ff-mode-line-string)
2813 (volatile)
2814 (candidate-number-limit . 9999)
2815 (action-transformer . anything-find-files-action-transformer)
2816 (action
2817 . ,(delq
2819 `(("Find File" . anything-c-find-file-or-marked)
2820 ("Find file in Dired" . anything-c-point-file-in-dired)
2821 ,(and (locate-library "elscreen")
2822 '("Find file in Elscreen" . anything-elscreen-find-file))
2823 ,(and (locate-library "popwin")
2824 '("Find file in popup window" . popwin:find-file))
2825 ("Checksum File" . anything-ff-checksum)
2826 ("Complete at point `M-tab'"
2827 . anything-c-insert-file-name-completion-at-point)
2828 ("Open file externally `C-c C-x, C-u to choose'"
2829 . anything-c-open-file-externally)
2830 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2831 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2832 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2833 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2834 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2835 . anything-find-files-eshell-command-on-file)
2836 ("Find file as root" . anything-find-file-as-root)
2837 ("Find file in hex dump" . hexl-find-file)
2838 ("Ediff File `C-='" . anything-find-files-ediff-files)
2839 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2840 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2841 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2842 ("Copy file(s) Async" . anything-ff-copy-async)
2843 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2844 ("Serial rename files" . anything-ff-serial-rename)
2845 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2846 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2847 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2848 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2849 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2850 ("Find file other window `C-o'" . find-file-other-window)
2851 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2852 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2853 ("Print File `C-c p'" . anything-ff-print)
2854 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2855 ;; (anything 'anything-c-source-find-files)
2857 (defun anything-find-files-set-prompt-for-action (action files)
2858 "Set prompt for action ACTION for FILES."
2859 (let ((len (length files)))
2860 (format "%s *%s File(s)\n%s to: "
2861 action len
2862 (mapconcat (lambda (f)
2863 (format "- %s\n" f)) files ""))))
2865 (defun anything-dwim-target-directory ()
2866 "Return value of `default-directory' of buffer in other window.
2867 If there is only one window return the value ot `default-directory'
2868 for current buffer."
2869 (with-anything-current-buffer
2870 (let ((num-windows (length (window-list))))
2871 (if (> num-windows 1)
2872 (save-window-excursion
2873 (other-window 1)
2874 default-directory)
2875 (car anything-ff-history)))))
2877 (defun anything-find-files-do-action (action)
2878 "Generic function for creating action from `anything-c-source-find-files'.
2879 ACTION must be an action supported by `anything-dired-action'."
2880 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2881 (anything-marked-candidates)))
2882 (cand (anything-get-selection)) ; Target
2883 (prompt (anything-find-files-set-prompt-for-action
2884 (capitalize (symbol-name action)) ifiles))
2885 (parg anything-current-prefix-arg)
2886 (dest (anything-c-read-file-name
2887 prompt
2888 :preselect (if anything-ff-transformer-show-only-basename
2889 (anything-c-basename cand) cand)
2890 :initial-input (anything-dwim-target-directory)
2891 :history (anything-find-files-history :comp-read nil))))
2892 (anything-dired-action
2893 dest :files ifiles :action action :follow parg)))
2895 (defun anything-find-files-copy (candidate)
2896 "Copy files from `anything-find-files'."
2897 (anything-find-files-do-action 'copy))
2899 (defun anything-find-files-rename (candidate)
2900 "Rename files from `anything-find-files'."
2901 (anything-find-files-do-action 'rename))
2903 (defun anything-find-files-symlink (candidate)
2904 "Symlink files from `anything-find-files'."
2905 (anything-find-files-do-action 'symlink))
2907 (defun anything-find-files-relsymlink (candidate)
2908 "Relsymlink files from `anything-find-files'."
2909 (anything-find-files-do-action 'relsymlink))
2911 (defun anything-find-files-hardlink (candidate)
2912 "Hardlink files from `anything-find-files'."
2913 (anything-find-files-do-action 'hardlink))
2915 (defun anything-find-files-byte-compile (candidate)
2916 "Byte compile elisp files from `anything-find-files'."
2917 (let ((files (anything-marked-candidates))
2918 (parg anything-current-prefix-arg))
2919 (loop for fname in files
2920 do (byte-compile-file fname parg))))
2922 (defun anything-find-files-load-files (candidate)
2923 "Load elisp files from `anything-find-files'."
2924 (let ((files (anything-marked-candidates)))
2925 (loop for fname in files
2926 do (load fname))))
2928 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2929 "Generic function to ediff/merge files in `anything-find-files'."
2930 (let ((bname (anything-c-basename candidate))
2931 (prompt (if merge "Ediff Merge `%s' With File: "
2932 "Ediff `%s' With File: "))
2933 (fun (if merge 'ediff-merge-files 'ediff-files)))
2934 (funcall fun
2935 candidate
2936 (condition-case quit
2937 (anything-c-read-file-name
2938 (format prompt bname))
2939 (quit ;; Hit C-g ask user to fallback to locate.
2940 (if (y-or-n-p "Search file for ediff with locate? ")
2941 (anything-c-locate-read-file-name
2942 (format prompt bname)
2943 ;; Check if -b option is available.
2944 (if (and (eq system-type 'windows-nt)
2945 (string-match "^es" anything-c-locate-command))
2946 bname
2947 (concat bname " -b")))
2948 (error "Error: Ediff Operation aborted")))))))
2950 (defun anything-find-files-ediff-files (candidate)
2951 (anything-find-files-ediff-files-1 candidate))
2953 (defun anything-find-files-ediff-merge-files (candidate)
2954 (anything-find-files-ediff-files-1 candidate 'merge))
2956 (defun anything-find-files-grep (candidate)
2957 "Default action to grep files from `anything-find-files'."
2958 (anything-do-grep-1 (anything-marked-candidates)
2959 anything-current-prefix-arg))
2961 (defun anything-ff-zgrep (candidate)
2962 "Default action to zgrep files from `anything-find-files'."
2963 (let ((prefarg anything-current-prefix-arg)
2964 (ls (anything-marked-candidates)))
2965 (anything-ff-zgrep-1 ls prefarg)))
2967 (defun anything-ff-pdfgrep (candidate)
2968 "Default action to pdfgrep files from `anything-find-files'."
2969 (let ((cands (loop for file in (anything-marked-candidates)
2970 if (or (string= (file-name-extension file) "pdf")
2971 (string= (file-name-extension file) "PDF"))
2972 collect file))
2973 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2974 (when cands
2975 (anything-do-pdfgrep-1 cands))))
2977 (defun anything-ff-etags-select (candidate)
2978 "Default action to jump to etags from `anything-find-files'."
2979 (when (get-buffer anything-action-buffer)
2980 (kill-buffer anything-action-buffer))
2981 (let ((default-directory anything-ff-default-directory))
2982 (anything-c-etags-select anything-current-prefix-arg)))
2984 (defun anything-find-files-switch-to-hist (candidate)
2985 "Switch to anything-find-files history."
2986 (anything-find-files t))
2988 ;;; Asynchronous copy of files.
2991 (defun anything-c-copy-files-async-1 (flist dest)
2992 "Copy a list of Files FLIST to DEST asynchronously.
2993 It use another emacs process to do the job.
2994 Communication with background emacs is done with temp file
2995 `anything-c-copy-files-async-log-file'."
2996 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2997 "-Q" "--batch" "--eval"
2998 (format "(progn
2999 (require 'dired) (require 'cl)
3000 (let ((dired-recursive-copies 'always)
3001 failures success
3002 (ovw-count 0)
3003 (cpf-count 0))
3004 (dolist (f '%S)
3005 (condition-case err
3006 (let ((file-exists (file-exists-p
3007 (expand-file-name
3008 (file-name-nondirectory (directory-file-name f))
3009 (file-name-directory
3010 (file-name-as-directory \"%s\"))))))
3011 (dired-copy-file f \"%s\" t)
3012 (if file-exists
3013 (progn (push (cons \"Overwriting\" f) success)
3014 (incf ovw-count))
3015 (push (cons \"Copying\" f) success)
3016 (incf cpf-count)))
3017 (file-error
3018 (push (dired-make-relative
3019 (expand-file-name
3020 (file-name-nondirectory (directory-file-name f))
3021 (file-name-directory \"%s\")))
3022 failures))))
3023 (with-current-buffer (find-file-noselect \"%s\")
3024 (erase-buffer)
3025 (when failures
3026 (dolist (fail (reverse failures))
3027 (insert (concat \"Failed to copy \" fail \"\n\"))))
3028 (when success
3029 (loop for (a . s) in (reverse success) do
3030 (insert (concat a \" \" s \" to %s done\n\"))))
3031 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3032 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3033 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3034 (save-buffer))))"
3035 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3037 (defun anything-c-copy-async-with-log (flist dest)
3038 "Copy file list FLIST to DEST showing log.
3039 Log is send to `anything-c-copy-files-async-log-file'.
3040 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3041 (declare (special auto-revert-interval))
3042 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3043 (set (make-local-variable 'auto-revert-interval) 1)
3044 (erase-buffer)
3045 (insert "Wait copying files...\n")
3046 (sit-for 0.5) (save-buffer)
3047 (goto-char (point-max))
3048 (auto-revert-mode 1)
3049 (anything-c-copy-files-async-1 flist dest))
3051 (defun anything-ff-copy-async (candidate)
3052 "Anything find files action to copy files async.
3053 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3054 (let* ((flist (anything-marked-candidates))
3055 (dest (anything-c-read-file-name
3056 (anything-find-files-set-prompt-for-action
3057 "Copy Async" flist)
3058 :preselect candidate
3059 :initial-input (car anything-ff-history)
3060 :history (anything-find-files-history :comp-read nil))))
3061 (anything-c-copy-async-with-log flist dest)))
3063 (defvar eshell-command-aliases-list nil)
3064 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3065 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3067 Basename of CANDIDATE can be a wild-card.
3068 If MAP is given run `eshell-command' on all marked files at once,
3069 Otherwise, run `eshell-command' on each marked files.
3071 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3072 `eshell-command-aliases-list' will not be loaded first time you use this."
3073 (when (or eshell-command-aliases-list
3074 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3075 (and eshell-command-aliases-list (eshell-read-aliases-list))
3076 (let* ((cand-list (anything-marked-candidates))
3077 (default-directory (or anything-ff-default-directory
3078 ;; If candidate is an url *-ff-default-directory is nil
3079 ;; so keep value of default-directory.
3080 default-directory))
3081 (command (anything-comp-read
3082 "Command: "
3083 (loop for (a . c) in eshell-command-aliases-list
3084 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3085 collect (propertize a 'help-echo (car c)) into ls
3086 finally return (sort ls 'string<))))
3087 (com-value (car (assoc-default command eshell-command-aliases-list))))
3088 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3089 (> (length cand-list) 1))
3090 ;; Run eshell-command with ALL marked files as arguments.
3091 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3092 (eshell-command (format "%s %s" command mapfiles)))
3093 ;; Run eshell-command on EACH marked files.
3094 (loop
3095 for i in cand-list
3096 for bn = (anything-c-basename i)
3097 for files = (if (and bn (string-match "^\*" bn))
3098 ;; Assume if fname is a wildcard
3099 ;; cand-list have a length of 1.
3100 (mapconcat
3101 'shell-quote-argument
3102 (file-expand-wildcards i t) " ")
3103 (format "'%s'" i))
3104 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3105 ;; This allow to enter other args AFTER filename
3106 ;; i.e <command %s some_more_args>
3107 (format command files)
3108 (format "%s %s" command files))
3109 do (eshell-command com))))))
3111 (defun anything-find-files-eshell-command-on-file (candidate)
3112 "Run `eshell-command' on CANDIDATE or marked candidates.
3113 See `anything-find-files-eshell-command-on-file-1' for more info."
3114 (anything-find-files-eshell-command-on-file-1
3115 candidate anything-current-prefix-arg))
3117 (defun anything-ff-switch-to-eshell (candidate)
3118 "Switch to eshell and cd to `anything-ff-default-directory'."
3119 (flet ((cd-eshell ()
3120 (goto-char (point-max))
3121 (insert
3122 (format "cd '%s'" anything-ff-default-directory))
3123 (eshell-send-input)))
3124 (if (get-buffer "*eshell*")
3125 (progn
3126 (anything-c-switch-to-buffer "*eshell*")
3127 (cd-eshell))
3128 (call-interactively 'eshell)
3129 (cd-eshell))))
3131 (defun anything-ff-serial-rename-action (method)
3132 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3133 See `anything-ff-serial-rename-1'."
3134 (let* ((cands (anything-marked-candidates))
3135 (name (read-string "NewName: "))
3136 (start (read-number "StartAtNumber: "))
3137 (extension (read-string "Extension: " (file-name-extension (car cands))))
3138 (dir (expand-file-name
3139 (anything-c-read-file-name
3140 "Serial Rename to directory: " :initial-input
3141 (expand-file-name anything-ff-default-directory)))))
3142 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3143 (length cands) dir name))
3144 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3145 (anything-find-files-1 dir))))
3147 (defun anything-ff-member-directory-p (file directory)
3148 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3149 (cur-dir (expand-file-name (file-name-as-directory directory))))
3150 (string= dir-file cur-dir)))
3152 (defun* anything-ff-serial-rename-1
3153 (directory collection new-name start-at-num extension &key (method 'rename))
3154 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3155 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3156 EXTENSION is the file extension to use, in empty prompt,
3157 reuse the original extension of file.
3158 METHOD can be one of rename, copy or symlink.
3159 Files will be renamed if they are files of current directory, otherwise they
3160 will be treated with METHOD.
3161 Default METHOD is rename."
3162 ;; Maybe remove directories selected by error in collection.
3163 (setq collection (remove-if 'file-directory-p collection))
3164 (flet ((symlink-file (file dest)
3165 (let ((flist (list file)))
3166 (anything-dired-action
3167 dest :action 'symlink :files flist))))
3169 (let* ((tmp-dir (file-name-as-directory
3170 (concat (file-name-as-directory directory)
3171 (symbol-name (gensym "tmp")))))
3172 (fn (case method
3173 (copy 'copy-file)
3174 (symlink 'symlink-file)
3175 (rename 'rename-file)
3176 (t (error "Error: Unknow method %s" method)))))
3177 (make-directory tmp-dir)
3178 (loop for i in collection
3179 for count from start-at-num
3180 for fnum = (if (< count 10) "0%s" "%s")
3181 for nname = (concat tmp-dir new-name (format fnum count)
3182 (if (not (string= extension ""))
3183 (format ".%s" (replace-regexp-in-string
3184 "[.]" "" extension))
3185 (file-name-extension i 'dot)))
3186 do (if (anything-ff-member-directory-p i directory)
3187 (rename-file i nname)
3188 (funcall fn i nname)))
3189 (loop with dirlist = (directory-files
3190 tmp-dir t directory-files-no-dot-files-regexp)
3191 for f in dirlist do
3192 (if (file-symlink-p f)
3193 (symlink-file (file-truename f)
3194 (concat (file-name-as-directory directory)
3195 (anything-c-basename f)))
3196 (rename-file f directory)))
3197 (delete-directory tmp-dir t))))
3199 (defun anything-ff-serial-rename (candidate)
3200 "Serial rename all marked files to `anything-ff-default-directory'.
3201 Rename only file of current directory, and symlink files coming from
3202 other directories.
3203 See `anything-ff-serial-rename-1'."
3204 (anything-ff-serial-rename-action 'rename))
3206 (defun anything-ff-serial-rename-by-symlink (candidate)
3207 "Serial rename all marked files to `anything-ff-default-directory'.
3208 Rename only file of current directory, and symlink files coming from
3209 other directories.
3210 See `anything-ff-serial-rename-1'."
3211 (anything-ff-serial-rename-action 'symlink))
3213 (defun anything-ff-serial-rename-by-copying (candidate)
3214 "Serial rename all marked files to `anything-ff-default-directory'.
3215 Rename only file of current directory, and copy files coming from
3216 other directories.
3217 See `anything-ff-serial-rename-1'."
3218 (anything-ff-serial-rename-action 'copy))
3220 (defun anything-c-quit-and-execute-action (action)
3221 "Quit current anything session and execute ACTION."
3222 (setq anything-saved-action action)
3223 (anything-exit-minibuffer))
3225 (defun anything-ff-toggle-auto-update (candidate)
3226 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3227 (message "[Auto expansion %s]"
3228 (if anything-ff-auto-update-flag "enabled" "disabled")))
3230 ;;;###autoload
3231 (defun anything-ff-run-toggle-auto-update ()
3232 (interactive)
3233 (anything-execute-persistent-action 'toggle-auto-update))
3235 ;;;###autoload
3236 (defun anything-ff-run-switch-to-history ()
3237 "Run Switch to history action from `anything-c-source-find-files'."
3238 (interactive)
3239 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3241 ;;;###autoload
3242 (defun anything-ff-run-grep ()
3243 "Run Grep action from `anything-c-source-find-files'."
3244 (interactive)
3245 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3247 ;;;###autoload
3248 (defun anything-ff-run-pdfgrep ()
3249 "Run Pdfgrep action from `anything-c-source-find-files'."
3250 (interactive)
3251 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3253 ;;;###autoload
3254 (defun anything-ff-run-zgrep ()
3255 "Run Grep action from `anything-c-source-find-files'."
3256 (interactive)
3257 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3259 ;;;###autoload
3260 (defun anything-ff-run-copy-file ()
3261 "Run Copy file action from `anything-c-source-find-files'."
3262 (interactive)
3263 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3265 ;;;###autoload
3266 (defun anything-ff-run-rename-file ()
3267 "Run Rename file action from `anything-c-source-find-files'."
3268 (interactive)
3269 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3271 ;;;###autoload
3272 (defun anything-ff-run-byte-compile-file ()
3273 "Run Byte compile file action from `anything-c-source-find-files'."
3274 (interactive)
3275 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3277 ;;;###autoload
3278 (defun anything-ff-run-load-file ()
3279 "Run Load file action from `anything-c-source-find-files'."
3280 (interactive)
3281 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3283 ;;;###autoload
3284 (defun anything-ff-run-eshell-command-on-file ()
3285 "Run eshell command on file action from `anything-c-source-find-files'."
3286 (interactive)
3287 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3289 ;;;###autoload
3290 (defun anything-ff-run-ediff-file ()
3291 "Run Ediff file action from `anything-c-source-find-files'."
3292 (interactive)
3293 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3295 ;;;###autoload
3296 (defun anything-ff-run-ediff-merge-file ()
3297 "Run Ediff merge file action from `anything-c-source-find-files'."
3298 (interactive)
3299 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3301 ;;;###autoload
3302 (defun anything-ff-run-symlink-file ()
3303 "Run Symlink file action from `anything-c-source-find-files'."
3304 (interactive)
3305 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3307 ;;;###autoload
3308 (defun anything-ff-run-delete-file ()
3309 "Run Delete file action from `anything-c-source-find-files'."
3310 (interactive)
3311 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3313 ;;;###autoload
3314 (defun anything-ff-run-complete-fn-at-point ()
3315 "Run complete file name action from `anything-c-source-find-files'."
3316 (interactive)
3317 (anything-c-quit-and-execute-action
3318 'anything-c-insert-file-name-completion-at-point))
3320 ;;;###autoload
3321 (defun anything-ff-run-switch-to-eshell ()
3322 "Run switch to eshell action from `anything-c-source-find-files'."
3323 (interactive)
3324 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3326 ;;;###autoload
3327 (defun anything-ff-run-switch-other-window ()
3328 "Run switch to other window action from `anything-c-source-find-files'."
3329 (interactive)
3330 (anything-c-quit-and-execute-action 'find-file-other-window))
3332 ;;;###autoload
3333 (defun anything-ff-run-switch-other-frame ()
3334 "Run switch to other frame action from `anything-c-source-find-files'."
3335 (interactive)
3336 (anything-c-quit-and-execute-action 'find-file-other-frame))
3338 ;;;###autoload
3339 (defun anything-ff-run-open-file-externally ()
3340 "Run open file externally command action from `anything-c-source-find-files'."
3341 (interactive)
3342 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3344 (defun anything-ff-locate (candidate)
3345 "Locate action function for `anything-find-files'."
3346 (let ((input (concat (anything-c-basename
3347 (expand-file-name
3348 candidate
3349 anything-ff-default-directory))
3350 ;; The locate '-b' option doesn't exists
3351 ;; in everything.
3352 (unless (and (eq system-type 'windows-nt)
3353 (string-match "^es" anything-c-locate-command))
3354 " -b")))
3355 (anything-mp-highlight-delay 0.7))
3356 (anything-locate-1 anything-current-prefix-arg input)))
3358 ;;;###autoload
3359 (defun anything-ff-run-locate ()
3360 "Run locate action from `anything-c-source-find-files'."
3361 (interactive)
3362 (anything-c-quit-and-execute-action 'anything-ff-locate))
3364 ;;;###autoload
3365 (defun anything-ff-run-gnus-attach-files ()
3366 "Run gnus attach files command action from `anything-c-source-find-files'."
3367 (interactive)
3368 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3370 ;;;###autoload
3371 (defun anything-ff-run-etags ()
3372 "Run Etags command action from `anything-c-source-find-files'."
3373 (interactive)
3374 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3377 (defun anything-ff-print (candidate)
3378 "Print marked files.
3379 You have to set in order
3380 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3382 e.g:
3383 \(setq lpr-command \"gtklp\"\)
3384 \(setq lpr-switches '(\"-P\")\)
3385 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3387 Same as `dired-do-print' but for anything."
3388 (let* ((file-list (anything-marked-candidates))
3389 (len (length file-list))
3390 (printer-name (if anything-ff-printer-list
3391 (anything-comp-read
3392 "Printer: " anything-ff-printer-list)
3393 printer-name))
3394 (command (read-string
3395 (format "Print *%s File(s):\n%s with: "
3397 (mapconcat
3398 (lambda (f) (format "- %s\n" f))
3399 file-list ""))
3400 (when (and lpr-command
3401 (or lpr-switches
3402 printer-name))
3403 (mapconcat 'identity
3404 (cons lpr-command
3405 (append (if (stringp lpr-switches)
3406 (list lpr-switches)
3407 lpr-switches)
3408 (list printer-name)))
3409 " "))))
3410 (file-args (mapconcat #'(lambda (x)
3411 (format "'%s'" x))
3412 file-list " "))
3413 (cmd-line (concat command " " file-args)))
3414 (if command
3415 (start-process-shell-command "anything-print" nil cmd-line)
3416 (error "Error: Please verify your printer settings in Emacs."))))
3418 ;;;###autoload
3419 (defun anything-ff-run-print-file ()
3420 "Run Print file action from `anything-c-source-find-files'."
3421 (interactive)
3422 (anything-c-quit-and-execute-action 'anything-ff-print))
3424 (defun anything-ff-checksum (file)
3425 "Calculate the checksum of FILE.
3426 Provide completion on different algorithms to use on Emacs24.
3427 On Emacs23 only 'sha1' is available.
3428 The checksum is copied to kill-ring."
3429 (let ((algo-list (and (fboundp 'secure-hash)
3430 '(md5 sha1 sha224 sha256 sha384 sha512))))
3431 (kill-new
3432 (if algo-list
3433 (secure-hash (intern
3434 (anything-comp-read
3435 "Algorithm: " algo-list))
3436 file)
3437 (sha1 (with-temp-buffer
3438 (insert-file-contents file)
3439 (buffer-string)))))
3440 (message "Checksum copied to kill-ring.")))
3442 (defun anything-ff-toggle-basename (candidate)
3443 (setq anything-ff-transformer-show-only-basename
3444 (not anything-ff-transformer-show-only-basename))
3445 (let ((target (if anything-ff-transformer-show-only-basename
3446 (anything-c-basename candidate) candidate)))
3447 (anything-force-update target)))
3449 (defun anything-ff-run-toggle-basename ()
3450 (interactive)
3451 (anything-execute-persistent-action 'toggle-basename))
3453 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3454 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3455 If LEVEL is positive reduce from end else from beginning.
3456 If UNIX-CLOSE is non--nil close filename with /.
3457 If EXPAND is non--nil expand-file-name."
3458 (let* ((exp-fname (expand-file-name fname))
3459 (fname-list (split-string (if (or (string= fname "~/") expand)
3460 exp-fname fname) "/" t))
3461 (len (length fname-list))
3462 (pop-list (if (< level 0)
3463 (subseq fname-list (* level -1))
3464 (subseq fname-list 0 (- len level))))
3465 (result (mapconcat 'identity pop-list "/"))
3466 (empty (string= result "")))
3467 (when unix-close (setq result (concat result "/")))
3468 (if (string-match "^~" result)
3469 (if (string= result "~/") "~/" result)
3470 (if (< level 0)
3471 (if empty "../" (concat "../" result))
3472 (cond ((eq system-type 'windows-nt)
3473 (if empty "c:/" result))
3474 (empty "/")
3476 (concat "/" result)))))))
3478 ;; Internal
3479 (defvar anything-file-completion-sources
3480 '("Find Files" "find-file" "Copy Files"
3481 "dired-do-copy" "dired-do-rename"
3482 "dired-do-symlink" "dired-do-hardlink"
3483 "write-file" "insert-file" "dired"
3484 "find-alternate-file" "find-alternate-file-other-window"
3485 "find-file-read-only" "list-directory"
3486 "Read File Name History" "mml-attach-file"
3487 "Rename Files" "Symlink Files"
3488 "Hardlink Files" "Write File"
3489 "Insert File" "Read File Name")
3490 "Sources that use the *find-files mechanism can be added here.
3491 You should not modify this yourself and know what you do if you do so.")
3493 (defun anything-file-completion-source-p ()
3494 "Test if current source is a dired or find-files source."
3495 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3496 (loop for i in anything-file-completion-sources
3497 thereis (string= cur-source i))))
3499 (defun anything-find-files-down-one-level (arg)
3500 "Go down one level like unix command `cd ..'.
3501 If prefix numeric arg is given go ARG level down."
3502 (interactive "p")
3503 (when (and (anything-file-completion-source-p)
3504 (not (anything-ff-invalid-tramp-name-p)))
3505 (with-anything-window
3506 (setq anything-follow-mode nil))
3507 ;; When going to precedent level we want to be at the line
3508 ;; corresponding to actual directory, so store this info
3509 ;; in `anything-ff-last-expanded'.
3510 (if (and (not (file-directory-p anything-pattern))
3511 (file-exists-p anything-pattern))
3512 (setq anything-ff-last-expanded anything-pattern)
3513 (setq anything-ff-last-expanded anything-ff-default-directory))
3514 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3515 :unix-close t :expand t)))
3516 (anything-set-pattern new-pattern))))
3518 (defun anything-ff-retrieve-last-expanded ()
3519 "Move overlay to last visited directory `anything-ff-last-expanded'.
3520 This happen after using `anything-find-files-down-one-level',
3521 or hitting C-z on \"..\"."
3522 (when (and anything-ff-last-expanded
3523 (anything-file-completion-source-p))
3524 (let ((dirname (if anything-ff-transformer-show-only-basename
3525 (anything-c-basename
3526 (directory-file-name anything-ff-last-expanded))
3527 (directory-file-name anything-ff-last-expanded))))
3528 (with-anything-window
3529 (when (or (re-search-forward (concat dirname "$") nil t)
3530 (re-search-forward
3531 (concat anything-ff-last-expanded "$") nil t))
3532 (forward-line 0)
3533 (anything-mark-current-line)))
3534 (setq anything-ff-last-expanded nil))))
3535 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3537 ;; Auto-update - anything-find-files auto expansion of directories.
3539 (defun anything-ff-update-when-only-one-matched ()
3540 "Expand to directory when sole completion.
3541 When only one candidate is remaining and it is a directory,
3542 expand to this directory."
3543 (when (and anything-ff-auto-update-flag
3544 (anything-file-completion-source-p)
3545 (not (anything-ff-invalid-tramp-name-p)))
3546 (let* ((history-p (string= (assoc-default
3547 'name (anything-get-current-source))
3548 "Read File Name History"))
3549 (pat (if (string-match tramp-file-name-regexp
3550 anything-pattern)
3551 (anything-create-tramp-name anything-pattern)
3552 anything-pattern))
3553 (completed-p (string= (file-name-as-directory pat)
3554 anything-ff-default-directory)))
3555 (when (and (or
3556 ;; Only one candidate remaining
3557 ;; and at least 2 char in basename.
3558 (and (<= (anything-approximate-candidate-number) 2)
3559 (>= (length (anything-c-basename anything-pattern)) 2))
3560 ;; Already completed.
3561 completed-p)
3562 (not history-p)) ; Don't try to auto complete in history.
3563 (with-anything-window
3564 (let ((cur-cand (prog2
3565 (unless completed-p
3566 ;; Only one non--existing candidate
3567 ;; and one directory candidate, move to it.
3568 (anything-next-line))
3569 (anything-get-selection))))
3570 (when (file-directory-p cur-cand)
3571 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3572 ;; Maybe we are here because completed-p is true
3573 ;; but check this again to be sure. (Windows fix)
3574 (<= (anything-approximate-candidate-number) 2)) ; [2]
3575 ;; If after going to next line the candidate
3576 ;; is not one of "." or ".." [1]
3577 ;; and only one candidate is remaining [2],
3578 ;; assume candidate is a new directory to expand, and do it.
3579 (anything-set-pattern (file-name-as-directory cur-cand))
3580 ;; The candidate is one of "." or ".."
3581 ;; that mean we have entered the last letter of the directory name
3582 ;; in prompt, so expansion is already done, just add the "/" at end
3583 ;; of name unless anything-pattern ends with "."
3584 ;; (i.e we are writing something starting with ".")
3585 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3586 (anything-set-pattern
3587 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3588 (expand-file-name (file-name-as-directory anything-pattern)))))
3589 (anything-check-minibuffer-input-1))))))))
3590 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3592 ;; Allow expanding to home directory or root
3593 ;; when entering respectively "~/" or "//" at end of pattern.
3594 ;; e.g /home/thierry/labo/anything-config-qp/~/
3595 ;; will expand to "~/"
3596 ;; and /home/thierry/labo/anything-config-qp//
3597 ;; will expand to "/"
3598 (defun anything-ff-auto-expand-to-home-or-root ()
3599 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3600 This happen only in function using sources that are
3601 `anything-file-completion-source-p' compliant."
3602 (when (and (anything-file-completion-source-p)
3603 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3604 anything-pattern))
3605 (let ((match (match-string 1 anything-pattern)))
3606 (cond ((string= match "//")
3607 (if (eq system-type 'windows-nt)
3608 (setq anything-pattern "c:/")
3609 (setq anything-pattern "/")))
3610 ((string= match "/~/")
3611 (if (eq system-type 'windows-nt)
3612 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3613 (setq anything-pattern "~/")))
3614 ((string= match "/./")
3615 (setq anything-pattern
3616 (with-anything-current-buffer
3617 (expand-file-name default-directory))))))
3618 (setq anything-ff-default-directory anything-pattern)
3619 ;; For some reasons, i must use here with-current-buffer => mini buffer
3620 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3621 (with-current-buffer (window-buffer (minibuffer-window))
3622 (delete-minibuffer-contents)
3623 (insert anything-pattern))))
3625 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3627 (defun anything-c-point-file-in-dired (file)
3628 "Put point on filename FILE in dired buffer."
3629 (dired (file-name-directory file))
3630 (dired-goto-file file))
3632 (defun anything-create-tramp-name (fname)
3633 "Build filename for `anything-pattern' like /su:: or /sudo::."
3634 (apply #'tramp-make-tramp-file-name
3635 (loop with v = (tramp-dissect-file-name fname)
3636 for i across v collect i)))
3638 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3639 "Get a list of hosts for tramp method found in `anything-pattern'.
3640 Argument PATTERN default to `anything-pattern', it is here only for debugging
3641 purpose."
3642 (when (string-match tramp-file-name-regexp pattern)
3643 (let ((method (match-string 1 pattern))
3644 (tn (match-string 0 pattern))
3645 (all-methods (mapcar 'car tramp-methods)))
3646 (remove-duplicates
3647 (loop for (f . h) in (tramp-get-completion-function method)
3648 append (loop for e in (funcall f (car h))
3649 for host = (and (consp e) (cadr e))
3650 when (and host (not (member host all-methods)))
3651 collect (concat tn host)))
3652 :test 'equal))))
3654 (defun anything-ff-before-action-hook-fn ()
3655 "Exit anything when user try to execute action on an invalid tramp fname."
3656 (let ((cand (anything-get-selection)))
3657 (when (and (anything-file-completion-source-p)
3658 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3659 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3660 (error "Error: Unknow file or directory `%s'" cand))))
3661 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3663 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3664 "Return non--nil when PATTERN is an invalid tramp filename."
3665 (string= (anything-ff-set-pattern pattern)
3666 "Invalid tramp file name"))
3668 (defun anything-ff-set-pattern (pattern)
3669 "Handle tramp filenames in `anything-pattern'."
3670 (let ((methods (mapcar 'car tramp-methods))
3671 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3672 cur-method tramp-name)
3673 (cond ((string= pattern "") "")
3674 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3675 (with-anything-current-buffer
3676 (expand-file-name default-directory)))
3677 ((string-match ".*\\(~//\\|//\\)$" pattern)
3678 (if (eq system-type 'windows-nt) "c:/" "/"))
3679 ((string-match "^~\\|.*/~/$" pattern)
3680 (let* ((home (expand-file-name (getenv "HOME"))))
3681 (replace-match home nil t pattern)))
3682 ;; Match "/method:maybe_hostname:"
3683 ((and (string-match reg pattern)
3684 (setq cur-method (match-string 1 pattern))
3685 (member cur-method methods))
3686 (setq tramp-name (anything-create-tramp-name
3687 (match-string 0 pattern)))
3688 (replace-match tramp-name nil t pattern))
3689 ;; Match "/hostname:"
3690 ((and (string-match tramp-file-name-regexp pattern)
3691 (setq cur-method (match-string 1 pattern))
3692 (and cur-method (not (member cur-method methods))))
3693 (setq tramp-name (anything-create-tramp-name
3694 (match-string 0 pattern)))
3695 (replace-match tramp-name nil t pattern))
3696 ;; Match "/method:" in this case don't try to connect.
3697 ((and (not (string-match reg pattern))
3698 (string-match tramp-file-name-regexp pattern)
3699 (member (match-string 1 pattern) methods))
3700 "Invalid tramp file name") ; Write in anything-buffer.
3701 ;; PATTERN is a directory, end it with "/".
3702 ;; This will make PATTERN not ending yet with "/"
3703 ;; candidate for `anything-ff-default-directory',
3704 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3705 ;; when descending level.
3706 ((file-directory-p pattern)
3707 (file-name-as-directory pattern))
3708 ;; Return PATTERN unchanged.
3709 (t pattern))))
3711 (defun anything-find-files-get-candidates ()
3712 "Create candidate list for `anything-c-source-find-files'."
3713 (let* ((path (anything-ff-set-pattern anything-pattern))
3714 (path-name-dir (if (file-directory-p path)
3715 (file-name-as-directory path)
3716 (file-name-directory path)))
3717 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3718 (set-text-properties 0 (length path) nil path)
3719 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3720 ;; like that the actual value (e.g /ssh:) is passed to
3721 ;; `anything-ff-tramp-hostnames'.
3722 (unless (string= path "Invalid tramp file name")
3723 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3724 (setq anything-ff-default-directory
3725 (if (string= anything-pattern "")
3726 (if (eq system-type 'windows-nt) "c:/" "/")
3727 (unless (string-match ffap-url-regexp path)
3728 ;; If path is an url *default-directory have to be nil.
3729 path-name-dir)))
3730 (cond ((string= path "Invalid tramp file name")
3731 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3732 (prog2
3733 ;; `anything-pattern' have not been modified yet.
3734 ;; Set it here to the value of `path' that should be now
3735 ;; "Invalid tramp file name" and set the candidates list
3736 ;; to ("Invalid tramp file name") to make `anything-pattern'
3737 ;; match single candidate "Invalid tramp file name".
3738 (setq anything-pattern path)
3739 ;; "Invalid tramp file name" is now printed
3740 ;; in `anything-buffer'.
3741 (list path))))
3742 ((or (file-regular-p path)
3743 (and (not (file-exists-p path)) (string-match "/$" path))
3744 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3745 (list path))
3746 ((string= path "") (directory-files "/" t))
3747 ((and (file-directory-p path) (not (file-readable-p path)))
3748 (list (format "Opening directory: access denied, `%s'" path)))
3749 ((file-directory-p path) (directory-files path t))
3751 (append (list path) (directory-files path-name-dir t))))))
3753 (defun anything-ff-transform-fname-for-completion (fname)
3754 "Return FNAME with it's basename modified as a regexp.
3755 e.g foo => f.*o.*o .
3756 If basename contain one or more space or FNAME is a valid directory name
3757 return FNAME unchanged."
3758 (let ((bn (anything-c-basename fname)))
3759 (if (or (not anything-ff-smart-completion)
3760 (string-match "\\s-" bn)
3761 (string-match "/$" fname) ; Allow mkdir.
3762 (file-directory-p fname))
3763 fname ; Fall back to match-plugin.
3764 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3765 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3766 (concat (file-name-directory fname) bn))))
3768 (defun anything-ff-save-history ()
3769 "Store the last value of `anything-ff-default-directory' \
3770 in `anything-ff-history'."
3771 (when (and anything-ff-default-directory
3772 (anything-file-completion-source-p))
3773 (push anything-ff-default-directory anything-ff-history)))
3774 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3776 (defun anything-ff-valid-symlink-p (file)
3777 (file-exists-p (file-truename file)))
3779 (defun anything-ff-properties (candidate)
3780 "Show file properties of CANDIDATE in a tooltip or message."
3781 (let ((type (anything-ff-attributes candidate :type t))
3782 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3783 (if (window-system)
3784 (tooltip-show
3785 (concat
3786 (anything-c-basename candidate) ": \n"
3787 "Type: " type "\n"
3788 (when (string= type "symlink")
3789 (format "True name: '%s'\n"
3790 (cond ((string-match "^\.#" (anything-c-basename candidate))
3791 "Autosave symlink")
3792 ((anything-ff-valid-symlink-p candidate)
3793 (file-truename candidate))
3794 (t "Invalid Symlink"))))
3795 dired-line))
3796 (message dired-line) (sit-for 5))))
3798 ;;;###autoload
3799 (defun anything-ff-properties-persistent ()
3800 "Show properties without quitting anything."
3801 (interactive)
3802 (anything-execute-persistent-action 'properties-action))
3804 (defun anything-ff-kill-buffer-fname (candidate)
3805 (let* ((buf (get-file-buffer candidate))
3806 (buf-name (buffer-name buf)))
3807 (if buf
3808 (progn
3809 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3810 (message "No buffer to kill"))))
3812 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3813 "Find file CANDIDATE or kill it's buffer if it is visible.
3814 Never kill `anything-current-buffer'.
3815 Never kill buffer modified.
3816 This is called normally on third hit of \
3817 \\<anything-map>\\[anything-execute-persistent-action]
3818 in `anything-find-files-persistent-action'."
3819 (let* ((buf (get-file-buffer candidate))
3820 (buf-name (buffer-name buf)))
3821 (if (and buf (get-buffer-window buf)
3822 (not (eq buf (get-buffer anything-current-buffer)))
3823 (not (buffer-modified-p buf)))
3824 (progn
3825 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3826 (find-file candidate))))
3828 ;;;###autoload
3829 (defun anything-ff-run-kill-buffer-persistent ()
3830 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3831 (interactive)
3832 (anything-execute-persistent-action 'kill-buffer-fname))
3834 (defun anything-ff-human-size (size)
3835 "Return a string showing SIZE of a file in human readable form.
3836 SIZE can be an integer or a float depending it's value.
3837 `file-attributes' will take care of that to avoid overflow error.
3838 KBSIZE if a floating point number, default value is 1024.0."
3839 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3840 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3841 (K (cons "K" (/ size anything-ff-default-kbsize)))
3842 (B (cons "B" size)))
3843 (loop with result = B
3844 for (a . b) in
3845 (loop for (x . y) in (list M G K B)
3846 unless (< y 1) collect (cons x y))
3847 when (< b (cdr result)) do (setq result (cons a b))
3848 finally return (if (string= (car result) "B")
3849 (format "%s" size)
3850 (format "%.1f%s" (cdr result) (car result))))))
3852 (defun* anything-ff-attributes
3853 (file &key type links uid gid access-time modif-time
3854 status size mode gid-change inode device-num dired human-size)
3855 "Easy interface for `file-attributes'."
3856 (let ((all (destructuring-bind
3857 (type links uid gid access-time modif-time
3858 status size mode gid-change inode device-num)
3859 (file-attributes file 'string)
3860 (list :type type
3861 :links links
3862 :uid uid
3863 :gid gid
3864 :access-time access-time
3865 :modif-time modif-time
3866 :status status
3867 :size size
3868 :mode mode
3869 :gid-change gid-change
3870 :inode inode
3871 :device-num device-num))))
3872 (cond (type
3873 (let ((result (getf all :type)))
3874 (cond ((stringp result)
3875 "symlink")
3876 (result "directory")
3877 (t "file"))))
3878 (links (getf all :links))
3879 (uid (getf all :uid))
3880 (gid (getf all :gid))
3881 (access-time
3882 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3883 (modif-time
3884 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3885 (status
3886 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3887 (size (if human-size (anything-ff-human-size (getf all :size))
3888 (getf all :size)))
3889 (mode (getf all :mode))
3890 (gid-change (getf all :gid-change))
3891 (inode (getf all :inode))
3892 (device-num (getf all :device-num))
3893 (dired
3894 (concat
3895 (getf all :mode) " "
3896 (number-to-string (getf all :links)) " "
3897 (getf all :uid) ":"
3898 (getf all :gid) " "
3899 (if human-size (anything-ff-human-size (getf all :size))
3900 (int-to-string (getf all :size))) " "
3901 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3902 (t all))))
3904 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3905 "Return filename FNAME maybe prefixed with [?] or [@].
3906 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3907 existing filename or valid symlink and there is no need to test it.
3908 NEW-FILE when non--nil mean FNAME is a non existing file and
3909 return FNAME prefixed with [?]."
3910 (let* ((prefix-new (propertize
3911 " " 'display
3912 (propertize "[?]" 'face 'anything-ff-prefix)))
3913 (prefix-url (propertize
3914 " " 'display
3915 (propertize "[@]" 'face 'anything-ff-prefix))))
3916 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3917 ((string-match ffap-url-regexp fname)
3918 (concat prefix-url " " fname))
3919 ((or new-file (not (file-exists-p fname)))
3920 (concat prefix-new " " fname)))))
3922 (defun anything-c-find-files-transformer (files sources)
3923 "Transformer for `anything-c-source-find-files'.
3924 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3925 is non--nil."
3926 (if (and (string-match tramp-file-name-regexp anything-pattern)
3927 anything-ff-tramp-not-fancy)
3928 (if anything-ff-transformer-show-only-basename
3929 (loop for i in files collect
3930 (if (string-match "[.]\\{1,2\\}$" i)
3931 i (cons (anything-c-basename i) i)))
3932 files)
3933 (anything-ff-highlight-files files sources)))
3935 (defun anything-ff-highlight-files (files sources)
3936 "Candidate transformer for `anything-c-source-find-files' without icons."
3937 (loop for i in files
3938 for disp = (if (and anything-ff-transformer-show-only-basename
3939 (not (string-match "[.]\\{1,2\\}$" i))
3940 (not (string-match ffap-url-regexp i)))
3941 (anything-c-basename i) i)
3942 collect
3943 (cond ((and (stringp (car (file-attributes i)))
3944 (not (anything-ff-valid-symlink-p i))
3945 (not (string-match "^\.#" (anything-c-basename i))))
3946 (cons (anything-ff-prefix-filename
3947 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3949 ((stringp (car (file-attributes i)))
3950 (cons (anything-ff-prefix-filename
3951 (propertize disp 'face 'anything-ff-symlink) t)
3953 ((eq t (car (file-attributes i)))
3954 (cons (anything-ff-prefix-filename
3955 (propertize disp 'face 'anything-ff-directory) t)
3957 ((file-executable-p i)
3958 (cons (anything-ff-prefix-filename
3959 (propertize disp 'face 'anything-ff-executable) t)
3961 ((file-exists-p i)
3962 (cons (anything-ff-prefix-filename
3963 (propertize disp 'face 'anything-ff-file) t)
3966 (cons (anything-ff-prefix-filename
3967 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3968 i)))))
3970 (defun anything-find-files-action-transformer (actions candidate)
3971 "Action transformer for `anything-c-source-find-files'."
3972 (cond ((with-anything-current-buffer
3973 (eq major-mode 'message-mode))
3974 (append (subseq actions 0 4)
3975 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3976 (subseq actions 4)))
3977 ((string-match (image-file-name-regexp) candidate)
3978 (append (subseq actions 0 4)
3979 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3980 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3981 (subseq actions 4)))
3982 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3983 (car it) candidate))
3984 (append (subseq actions 0 4)
3985 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3986 . anything-find-files-byte-compile)
3987 ("Load File(s) `M-L'" . anything-find-files-load-files))
3988 (subseq actions 4)))
3989 ((and (string-match "\.html?$" candidate)
3990 (file-exists-p candidate))
3991 (append (subseq actions 0 4)
3992 '(("Browse url file" . browse-url-of-file))
3993 (subseq actions 5)))
3994 ((or (string= (file-name-extension candidate) "pdf")
3995 (string= (file-name-extension candidate) "PDF"))
3996 (append (subseq actions 0 4)
3997 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3998 (subseq actions 5)))
3999 (t actions)))
4001 (defun anything-ff-gnus-attach-files (candidate)
4002 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4003 (let ((flist (anything-marked-candidates)))
4004 (gnus-dired-attach flist)))
4006 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4007 "Rotate current image at NUM-ARG degrees.
4008 This is a destructive operation on FILE made by external tool mogrify."
4009 (declare (special image-dired-display-image-buffer))
4010 (setq file (file-truename file)) ; For symlinked images.
4011 ;; When FILE is not an image-file, do nothing.
4012 (when (string-match (image-file-name-regexp) file)
4013 (if (executable-find "mogrify")
4014 (progn
4015 (shell-command (format "mogrify -rotate %s %s"
4016 (or num-arg 90)
4017 (shell-quote-argument file)))
4018 (when (buffer-live-p image-dired-display-image-buffer)
4019 (kill-buffer image-dired-display-image-buffer))
4020 (image-dired-display-image file)
4021 (message nil)
4022 (display-buffer (get-buffer image-dired-display-image-buffer)))
4023 (error "mogrify not found"))))
4025 (defun anything-ff-rotate-image-left (candidate)
4026 "Rotate image file CANDIDATE left.
4027 This affect directly file CANDIDATE."
4028 (anything-ff-rotate-current-image-1 candidate -90))
4030 (defun anything-ff-rotate-image-right (candidate)
4031 "Rotate image file CANDIDATE right.
4032 This affect directly file CANDIDATE."
4033 (anything-ff-rotate-current-image-1 candidate))
4035 (defun anything-ff-rotate-left-persistent ()
4036 "Rotate image left without quitting anything."
4037 (interactive)
4038 (anything-execute-persistent-action 'image-action1))
4040 (defun anything-ff-rotate-right-persistent ()
4041 "Rotate image right without quitting anything."
4042 (interactive)
4043 (anything-execute-persistent-action 'image-action2))
4045 (defun anything-ff-exif-data (candidate)
4046 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4047 (if (and anything-ff-exif-data-program
4048 (executable-find anything-ff-exif-data-program))
4049 (shell-command-to-string (format "%s %s %s"
4050 anything-ff-exif-data-program
4051 anything-ff-exif-data-program-args
4052 candidate))
4053 (format "No program %s found to extract exif"
4054 anything-ff-exif-data-program)))
4056 (defun anything-find-files-persistent-action (candidate)
4057 "Open subtree CANDIDATE without quitting anything.
4058 If CANDIDATE is not a directory expand CANDIDATE filename.
4059 If CANDIDATE is alone, open file CANDIDATE filename.
4060 That's mean:
4061 First hit on C-z expand CANDIDATE second hit open file.
4062 If a prefix arg is given or `anything-follow-mode' is on open file."
4063 (let ((follow (buffer-local-value
4064 'anything-follow-mode
4065 (get-buffer-create anything-buffer)))
4066 (new-pattern (anything-get-selection))
4067 (num-lines-buf (with-current-buffer anything-buffer
4068 (count-lines (point-min) (point-max)))))
4069 (flet ((insert-in-minibuffer (fname)
4070 (with-selected-window (minibuffer-window)
4071 (unless follow
4072 (delete-minibuffer-contents)
4073 (set-text-properties 0 (length fname) nil fname)
4074 (insert fname)))))
4075 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4076 "Invalid tramp file name")
4077 (string-match tramp-file-name-regexp candidate))
4078 ;; First hit insert hostname and
4079 ;; second hit insert ":" and expand.
4080 (if (string= candidate anything-pattern)
4081 (insert-in-minibuffer (concat candidate ":"))
4082 (insert-in-minibuffer candidate)))
4083 (;; A symlink directory, expand it's truename.
4084 (and (file-directory-p candidate) (file-symlink-p candidate))
4085 (insert-in-minibuffer (file-name-as-directory
4086 (file-truename
4087 (expand-file-name candidate)))))
4088 ;; A directory, open it.
4089 ((file-directory-p candidate)
4090 (when (string= (anything-c-basename candidate) "..")
4091 (setq anything-ff-last-expanded anything-ff-default-directory))
4092 (insert-in-minibuffer (file-name-as-directory
4093 (expand-file-name candidate))))
4094 ;; A symlink file, expand to it's true name. (first hit)
4095 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4096 (insert-in-minibuffer (file-truename candidate)))
4097 ;; A regular file, expand it, (first hit)
4098 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4099 (insert-in-minibuffer new-pattern))
4100 ;; An image file and it is the second hit on C-z,
4101 ;; show the file in `image-dired'.
4102 ((string-match (image-file-name-regexp) candidate)
4103 (when (buffer-live-p image-dired-display-image-buffer)
4104 (kill-buffer image-dired-display-image-buffer))
4105 (image-dired-display-image candidate)
4106 (message nil)
4107 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4108 (with-current-buffer image-dired-display-image-buffer
4109 (let ((exif-data (anything-ff-exif-data candidate)))
4110 (image-dired-update-property 'help-echo exif-data))))
4111 ;; Allow browsing archive on avfs fs.
4112 ;; Assume volume is already mounted with mountavfs.
4113 ((and anything-ff-avfs-directory
4114 (string-match
4115 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4116 (file-name-directory candidate))
4117 (anything-ff-file-compressed-p candidate))
4118 (insert-in-minibuffer (concat candidate "#")))
4119 ;; On second hit we open file.
4120 ;; On Third hit we kill it's buffer maybe.
4122 (anything-ff-kill-or-find-buffer-fname candidate))))))
4124 (defun anything-ff-file-compressed-p (candidate)
4125 "Whether CANDIDATE is a compressed file or not."
4126 (member (file-name-extension candidate)
4127 anything-ff-file-compressed-list))
4129 (defun anything-c-insert-file-name-completion-at-point (candidate)
4130 "Insert file name completion at point."
4131 (with-anything-current-buffer
4132 (if buffer-read-only
4133 (error "Error: Buffer `%s' is read-only" (buffer-name))
4134 (let* ((end (point))
4135 (guess (substring-no-properties (thing-at-point 'filename)))
4136 (beg (- (point) (length guess)))
4137 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4138 (string-match-p "^[^\~]" guess))))
4139 (set-text-properties 0 (length candidate) nil candidate)
4140 (if (and guess (not (string= guess ""))
4141 (string-match-p "^~\\|/.*" guess))
4142 (progn
4143 (delete-region beg end)
4144 (insert (if full-path-p
4145 (expand-file-name candidate)
4146 (abbreviate-file-name candidate))))
4147 (error "Aborting completion: No valid file name at point"))))))
4149 (defun* anything-find-files-history (&key (comp-read t))
4150 "The `anything-find-files' history.
4151 Show the first `anything-ff-history-max-length' elements of
4152 `anything-ff-history' in an `anything-comp-read'."
4153 (let ((history (when anything-ff-history
4154 (anything-fast-remove-dups anything-ff-history
4155 :test 'equal))))
4156 (when history
4157 (setq anything-ff-history
4158 (if (>= (length history) anything-ff-history-max-length)
4159 (subseq history 0 anything-ff-history-max-length)
4160 history))
4161 (if comp-read
4162 (anything-comp-read
4163 "Switch to Directory: "
4164 anything-ff-history
4165 :name "Anything Find Files History"
4166 :must-match t)
4167 anything-ff-history))))
4169 (defun anything-find-files-1 (fname &optional preselect)
4170 "Find FNAME with `anything' completion.
4171 Like `find-file' but with `anything' support.
4172 Use it for non--interactive calls of `anything-find-files'."
4173 (when (get-buffer anything-action-buffer)
4174 (kill-buffer anything-action-buffer))
4175 (let ((anything-mp-highlight-delay nil)
4176 ;; Be sure we don't erase the precedent minibuffer if some.
4177 (anything-ff-auto-update-initial-value
4178 (not (minibuffer-window-active-p (minibuffer-window))))
4179 anything-samewindow)
4180 (anything :sources 'anything-c-source-find-files
4181 :input fname
4182 :preselect preselect
4183 :keymap anything-find-files-map
4184 :prompt "Find Files or Url: "
4185 :buffer "*Anything Find Files*")))
4188 (defun anything-find-files-initial-input (&optional input)
4189 "Return INPUT if present, otherwise try to guess it."
4190 (or (and input (expand-file-name input))
4191 (anything-find-files-input
4192 (ffap-guesser)
4193 (thing-at-point 'filename))))
4195 (defun anything-find-files-input (fap tap)
4196 "Default input of `anything-find-files'."
4197 (let* ((def-dir (anything-c-current-directory))
4198 (lib (anything-find-library-at-point))
4199 (url (anything-ff-find-url-at-point))
4200 (file-p (and fap (not (string= fap ""))
4201 (file-exists-p fap)
4202 tap (not (string= tap ""))
4203 (file-exists-p
4204 (file-name-directory (expand-file-name tap def-dir))))))
4205 (cond (lib) ; e.g we are inside a require sexp.
4206 (url) ; String at point is an hyperlink.
4207 (file-p (expand-file-name tap def-dir))
4208 (t (and (not (string= fap "")) fap)))))
4210 (defun anything-c-current-directory ()
4211 "Return current-directory name at point.
4212 Useful in dired buffers when there is inserted subdirs."
4213 (if (eq major-mode 'dired-mode)
4214 (dired-current-directory)
4215 default-directory))
4217 (defun anything-ff-find-url-at-point ()
4218 "Try to find link to an url in text-property at point."
4219 (let* ((he (get-text-property (point) 'help-echo))
4220 (ov (overlays-at (point)))
4221 (ov-he (and ov (overlay-get
4222 (car (overlays-at (point))) 'help-echo)))
4223 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4224 (nt-prop (get-text-property (point) 'nt-link)))
4225 ;; Org link.
4226 (when (and (stringp he) (string-match "^LINK: " he))
4227 (setq he (replace-match "" t t he)))
4228 (loop for i in (list he ov-he w3m-l nt-prop)
4229 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4231 (defun anything-find-library-at-point ()
4232 "Try to find library path at point.
4233 Find inside `require' and `declare-function' sexp."
4234 (require 'find-func)
4235 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4236 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4237 (sexp (and beg-sexp end-sexp
4238 (buffer-substring-no-properties
4239 (1+ beg-sexp) (1- end-sexp)))))
4240 (ignore-errors
4241 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4242 (find-library-name
4243 (replace-regexp-in-string
4244 "'\\|\)\\|\(" ""
4245 ;; If require use third arg, ignore it,
4246 ;; always use library path found in `load-path'.
4247 (second (split-string (match-string 0 sexp))))))
4248 ((and sexp (string-match-p "^declare-function" sexp))
4249 (find-library-name
4250 (replace-regexp-in-string
4251 "\"\\|ext:" ""
4252 (third (split-string sexp)))))
4253 (t nil)))))
4255 ;;; Anything completion for `write-file'.==> C-x C-w
4256 (defvar anything-c-source-write-file
4257 `((name . "Write File")
4258 (header-name . (lambda (name)
4259 (concat name anything-c-find-files-doc-header)))
4260 ;; It is needed for filenames with capital letters
4261 (disable-shortcuts)
4262 (candidates . anything-find-files-get-candidates)
4263 (filtered-candidate-transformer anything-c-find-files-transformer)
4264 (persistent-action . anything-find-files-persistent-action)
4265 (persistent-help . "Expand Candidate")
4266 (volatile)
4267 (action .
4268 (("Write File" . (lambda (candidate)
4269 (write-file candidate 'confirm)))))))
4271 ;;; Anything completion for `insert-file'.==> C-x i
4272 (defvar anything-c-source-insert-file
4273 `((name . "Insert File")
4274 (header-name . (lambda (name)
4275 (concat name anything-c-find-files-doc-header)))
4276 ;; It is needed for filenames with capital letters
4277 (disable-shortcuts)
4278 (candidates . anything-find-files-get-candidates)
4279 (filtered-candidate-transformer anything-c-find-files-transformer)
4280 (persistent-action . anything-find-files-persistent-action)
4281 (persistent-help . "Expand Candidate")
4282 (volatile)
4283 (action .
4284 (("Insert File" . (lambda (candidate)
4285 (when (y-or-n-p (format "Really insert %s in %s "
4286 candidate anything-current-buffer))
4287 (insert-file-contents candidate))))))))
4289 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4290 (defvar anything-c-source-copy-files
4291 `((name . "Copy Files")
4292 (header-name . (lambda (name)
4293 (concat name anything-c-find-files-doc-header)))
4294 ;; It is needed for filenames with capital letters
4295 (disable-shortcuts)
4296 (candidates . anything-find-files-get-candidates)
4297 (filtered-candidate-transformer anything-c-find-files-transformer)
4298 (persistent-action . anything-find-files-persistent-action)
4299 (persistent-help . "Expand Candidate")
4300 (volatile)
4301 (action .
4302 (("Copy File"
4303 . (lambda (candidate)
4304 (anything-dired-action candidate :action 'copy)))
4305 ("Copy and Follow"
4306 . (lambda (candidate)
4307 (anything-dired-action candidate :action 'copy :follow t)))))))
4310 (defvar anything-c-source-rename-files
4311 `((name . "Rename Files")
4312 (header-name . (lambda (name)
4313 (concat name anything-c-find-files-doc-header)))
4314 ;; It is needed for filenames with capital letters
4315 (disable-shortcuts)
4316 (candidates . anything-find-files-get-candidates)
4317 (filtered-candidate-transformer anything-c-find-files-transformer)
4318 (persistent-action . anything-find-files-persistent-action)
4319 (persistent-help . "Expand Candidate")
4320 (volatile)
4321 (action .
4322 (("Rename File"
4323 . (lambda (candidate)
4324 (anything-dired-action candidate :action 'rename)))
4325 ("Rename and Follow"
4326 . (lambda (candidate)
4327 (anything-dired-action candidate :action 'rename :follow t)))))))
4329 (defvar anything-c-source-symlink-files
4330 `((name . "Symlink Files")
4331 (header-name . (lambda (name)
4332 (concat name anything-c-find-files-doc-header)))
4333 ;; It is needed for filenames with capital letters
4334 (disable-shortcuts)
4335 (candidates . anything-find-files-get-candidates)
4336 (filtered-candidate-transformer anything-c-find-files-transformer)
4337 (persistent-action . anything-find-files-persistent-action)
4338 (persistent-help . "Expand Candidate")
4339 (volatile)
4340 (action
4341 . (("Symlink File"
4342 . (lambda (candidate)
4343 (anything-dired-action candidate :action 'symlink)))
4344 ("RelSymlink File"
4345 . (lambda (candidate)
4346 (anything-dired-action candidate :action 'relsymlink)))))))
4349 (defvar anything-c-source-hardlink-files
4350 `((name . "Hardlink Files")
4351 (header-name . (lambda (name)
4352 (concat name anything-c-find-files-doc-header)))
4353 ;; It is needed for filenames with capital letters
4354 (disable-shortcuts)
4355 (candidates . anything-find-files-get-candidates)
4356 (filtered-candidate-transformer anything-c-find-files-transformer)
4357 (persistent-action . anything-find-files-persistent-action)
4358 (persistent-help . "Expand Candidate")
4359 (volatile)
4360 (action
4361 . (("Hardlink File"
4362 . (lambda (candidate)
4363 (anything-dired-action candidate :action 'hardlink)))))))
4365 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4366 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4367 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4368 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4369 (let ((fn (case action
4370 ('copy 'dired-copy-file)
4371 ('rename 'dired-rename-file)
4372 ('symlink 'make-symbolic-link)
4373 ('relsymlink 'dired-make-relative-symlink)
4374 ('hardlink 'dired-hardlink)))
4375 (marker (case action
4376 ((copy rename) dired-keep-marker-copy)
4377 ('symlink dired-keep-marker-symlink)
4378 ('relsymlink dired-keep-marker-relsymlink)
4379 ('hardlink dired-keep-marker-hardlink)))
4380 (dirflag (and (= (length files) 1)
4381 (file-directory-p (car files))
4382 (not (file-directory-p candidate)))))
4383 (dired-create-files
4384 fn (symbol-name action) files
4385 ;; CANDIDATE is the destination.
4386 (if (file-directory-p candidate)
4387 ;; When CANDIDATE is a directory, build file-name in this directory.
4388 ;; Else we use CANDIDATE.
4389 #'(lambda (from)
4390 (expand-file-name (file-name-nondirectory from) candidate))
4391 #'(lambda (from) candidate))
4392 marker)
4393 (when (and follow (not (get-buffer dired-log-buffer)))
4394 (let ((target (directory-file-name candidate)))
4395 (unwind-protect
4396 (progn
4397 (setq anything-ff-cand-to-mark
4398 (anything-get-dest-fnames-from-list files candidate dirflag))
4399 (if (and dirflag (eq action 'rename))
4400 (anything-find-files-1 (file-name-directory target)
4401 (if anything-ff-transformer-show-only-basename
4402 (anything-c-basename target) target))
4403 (anything-find-files-1 (expand-file-name candidate))))
4404 (setq anything-ff-cand-to-mark nil))))))
4407 (defun anything-c-basename (fname)
4408 "Resolve basename of file or directory named FNAME."
4409 (file-name-nondirectory (directory-file-name fname)))
4411 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4412 "Transform filenames of FLIST to abs of DEST-CAND.
4413 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4414 members of FLIST."
4415 ;; At this point files have been renamed/copied at destination.
4416 ;; That's mean DEST-CAND exists.
4417 (loop
4418 with dest = (expand-file-name dest-cand)
4419 for src in flist
4420 for basename-src = (anything-c-basename src)
4421 for fname = (cond (rename-dir-flag (directory-file-name dest))
4422 ((file-directory-p dest)
4423 (concat (file-name-as-directory dest) basename-src))
4424 (t dest))
4425 when (file-exists-p fname)
4426 collect fname into tmp-list
4427 finally return (sort tmp-list 'string<)))
4429 (defun anything-ff-maybe-mark-candidates ()
4430 "Mark all candidates of list `anything-ff-cand-to-mark'."
4431 (when (and (string= (assoc-default 'name (anything-get-current-source))
4432 (assoc-default 'name anything-c-source-find-files))
4433 anything-ff-cand-to-mark)
4434 (with-anything-window
4435 (while anything-ff-cand-to-mark
4436 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4437 (progn
4438 (anything-make-visible-mark)
4439 (anything-next-line)
4440 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4441 (anything-next-line)))
4442 (unless (anything-this-visible-mark)
4443 (anything-prev-visible-mark)))))
4445 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4447 (defun* anything-dired-do-action-on-file (&key action)
4448 (let* ((files (dired-get-marked-files))
4449 (len (length files))
4450 (fname (if (> len 1)
4451 (format "* %d Files" len)
4452 (car files)))
4453 (source (case action
4454 ('copy 'anything-c-source-copy-files)
4455 ('rename 'anything-c-source-rename-files)
4456 ('symlink 'anything-c-source-symlink-files)
4457 ('hardlink 'anything-c-source-hardlink-files)))
4458 (prompt-fm (case action
4459 ('copy "Copy %s to: ")
4460 ('rename "Rename %s to: ")
4461 ('symlink "Symlink %s to: ")
4462 ('hardlink "Hardlink %s to: ")))
4463 (buffer (case action
4464 ('copy "*Anything Copy Files*")
4465 ('rename "*Anything Rename Files*")
4466 ('symlink "*Anything Symlink Files*")
4467 ('hardlink "*Anything Hardlink Files*")))
4468 (anything-mp-highlight-delay nil))
4469 (anything :sources source
4470 :input (or (dired-dwim-target-directory)
4471 (expand-file-name (anything-c-current-directory)))
4472 :preselect (dired-get-filename)
4473 :prompt (format prompt-fm fname)
4474 :keymap anything-c-read-file-map
4475 :buffer buffer)))
4477 ;;;###autoload
4478 (define-minor-mode anything-dired-mode ()
4479 "Enable anything completion in Dired functions.
4480 Bindings affected are C, R, S, H.
4481 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4482 :group 'anything-config
4483 :global t
4484 (if anything-dired-mode
4485 (progn
4486 (substitute-key-definition
4487 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4488 (substitute-key-definition
4489 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4490 (substitute-key-definition
4491 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4492 (substitute-key-definition
4493 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4494 (substitute-key-definition
4495 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4496 (substitute-key-definition
4497 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4498 (substitute-key-definition
4499 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4500 (substitute-key-definition
4501 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4503 (defalias 'anything-dired-bindings 'anything-dired-mode)
4505 (defun* anything-c-read-file-name (prompt
4506 &key
4507 (name "Read File Name")
4508 (initial-input (expand-file-name default-directory))
4509 (buffer "*Anything Completions*")
4510 test
4511 (preselect nil)
4512 (history nil)
4513 (marked-candidates nil)
4514 (alistp t)
4515 (persistent-action 'anything-find-files-persistent-action)
4516 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4517 "Anything `read-file-name' emulation.
4518 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4519 (when (get-buffer anything-action-buffer)
4520 (kill-buffer anything-action-buffer))
4521 (let ((anything-mp-highlight-delay nil)
4522 ;; Be sure we don't erase the underlying minibuffer if some.
4523 (anything-ff-auto-update-initial-value
4524 (not (minibuffer-window-active-p (minibuffer-window))))
4525 anything-same-window)
4526 (flet ((action-fn (candidate)
4527 (if marked-candidates
4528 (anything-marked-candidates)
4529 (identity candidate))))
4530 (or (anything
4531 :sources
4532 `(((name . ,(format "%s History" name))
4533 (header-name . (lambda (name)
4534 (concat name anything-c-find-files-doc-header)))
4535 (disable-shortcuts)
4536 (mode-line . anything-read-file-name-mode-line-string)
4537 (candidates . (lambda ()
4538 (anything-comp-read-get-candidates history nil nil alistp)))
4539 (persistent-action . ,persistent-action)
4540 (persistent-help . ,persistent-help)
4541 (action . ,'action-fn))
4542 ((name . ,name)
4543 (header-name . (lambda (name)
4544 (concat name anything-c-find-files-doc-header)))
4545 ;; It is needed for filenames with capital letters
4546 (disable-shortcuts)
4547 (mode-line . anything-read-file-name-mode-line-string)
4548 (candidates . (lambda ()
4549 (let ((seq (anything-find-files-get-candidates)))
4550 (if test
4551 (loop for fname in seq
4552 when (funcall test fname) collect fname)
4553 seq))))
4554 (filtered-candidate-transformer anything-c-find-files-transformer)
4555 (persistent-action . ,persistent-action)
4556 (candidate-number-limit . 9999)
4557 (toggle-auto-update . anything-ff-toggle-auto-update)
4558 (persistent-help . ,persistent-help)
4559 (volatile)
4560 (action . ,'action-fn)))
4561 :input initial-input
4562 :prompt prompt
4563 :keymap anything-c-read-file-map
4564 :resume 'noresume
4565 :buffer buffer
4566 :preselect preselect)
4567 (keyboard-quit)))))
4570 ;;; File Cache
4571 (defvar anything-c-file-cache-initialized-p nil)
4573 (defvar anything-c-file-cache-files nil)
4575 (defvar anything-c-source-file-cache
4576 '((name . "File Cache")
4577 (init
4578 . (lambda ()
4579 (require 'filecache nil t)
4580 (unless anything-c-file-cache-initialized-p
4581 (setq anything-c-file-cache-files
4582 (loop for item in file-cache-alist append
4583 (destructuring-bind (base &rest dirs) item
4584 (loop for dir in dirs collect
4585 (concat dir base)))))
4586 (defadvice file-cache-add-file (after file-cache-list activate)
4587 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4588 (setq anything-c-file-cache-initialized-p t))))
4589 (candidates . anything-c-file-cache-files)
4590 (match anything-c-match-on-basename)
4591 (type . file)))
4592 ;; (anything 'anything-c-source-file-cache)
4595 ;;; Locate
4598 ;; NOTE for WINDOZE users:
4599 ;; You have to install Everything with his command line interface here:
4600 ;; http://www.voidtools.com/download.php
4602 (defun anything-locate-1 (&optional localdb init)
4603 "Generic function to run Locate.
4604 if LOCALDB is non--nil search and use a local locate db file.
4605 INIT is a string to use as initial input in prompt.
4606 See `anything-locate-with-db' and `anything-locate'."
4607 (anything-locate-with-db
4608 (and localdb
4609 (anything-c-read-file-name
4610 "LocateDBFiles: "
4611 :marked-candidates t
4612 :preselect anything-locate-db-file-regexp
4613 :test #'(lambda (x)
4614 (if anything-locate-db-file-regexp
4615 ;; Select only locate db files and directories
4616 ;; to allow navigation.
4617 (or (string-match
4618 anything-locate-db-file-regexp x)
4619 (file-directory-p x))
4620 x))))
4621 init))
4622 ;; (anything-locate-1 t)
4624 (defun anything-locate-with-db (&optional db initial-input)
4625 "Run locate -d DB.
4626 If DB is not given or nil use locate without -d option.
4627 Argument DB can be given as a string or list of db files.
4628 Argument INITIAL-INPUT is a string to use as initial-input.
4629 See also `anything-locate'."
4630 (when (and db (stringp db)) (setq db (list db)))
4631 (let ((anything-c-locate-command
4632 (if db
4633 (replace-regexp-in-string
4634 "locate"
4635 (format "locate -d %s"
4636 (mapconcat 'identity
4637 ;; Remove eventually
4638 ;; marked directories by error.
4639 (loop for i in db
4640 unless (file-directory-p i)
4641 collect i) ":"))
4642 anything-c-locate-command)
4643 anything-c-locate-command)))
4644 (anything :sources 'anything-c-source-locate
4645 :buffer "*anything locate*"
4646 :input initial-input
4647 :keymap anything-generic-files-map)))
4648 ;; (anything-locate-with-db "~/locate.db")
4650 (defun anything-c-locate-init ()
4651 "Initialize async locate process for `anything-c-source-locate'."
4652 (setq mode-line-format
4653 '(" " mode-line-buffer-identification " "
4654 (line-number-mode "%l") " "
4655 (:eval (propertize "(Locate Process Running) "
4656 'face '((:foreground "red"))))))
4657 (prog1
4658 (start-process-shell-command "locate-process" nil
4659 (format anything-c-locate-command
4660 anything-pattern))
4661 (set-process-sentinel (get-process "locate-process")
4662 #'(lambda (process event)
4663 (when (string= event "finished\n")
4664 (with-anything-window
4665 (force-mode-line-update nil)
4666 (anything-update-move-first-line)))))))
4668 (defvar anything-c-source-locate
4669 '((name . "Locate")
4670 (candidates . anything-c-locate-init)
4671 (type . file)
4672 (properties-action . anything-ff-properties)
4673 (requires-pattern . 3)
4674 (candidate-number-limit . 9999)
4675 (mode-line . anything-generic-file-mode-line-string)
4676 (delayed))
4677 "Find files matching the current input pattern with locate.")
4678 ;; (anything 'anything-c-source-locate)
4680 (defun anything-c-locate-read-file-name (prompt &optional init)
4681 "Search a file with locate and return it's filename.
4682 Use argument PROMPT and INIT for `anything' arguments
4683 prompt and input."
4684 (anything :sources
4685 '((name . "Locate")
4686 (candidates . anything-c-locate-init)
4687 (action . identity)
4688 (properties-action . anything-ff-properties)
4689 (requires-pattern . 3)
4690 (candidate-number-limit . 9999)
4691 (mode-line . anything-generic-file-mode-line-string)
4692 (delayed))
4693 :prompt prompt
4694 :input init
4695 :buffer "*anything locate rfn*"))
4699 ;;; Anything Incremental Grep.
4702 ;; Allow to grep incrementally with anything interface.
4703 ;; It allow also to Grep files recursively without using 'find' shell command.
4704 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4705 (defvar anything-c-grep-default-command
4706 "grep -d skip %e -niH -e %p %f"
4707 "Default grep format command for `anything-do-grep-1'.
4708 Where:
4709 '%e' format spec is for --exclude or --include grep options.
4710 '%p' format spec is for pattern.
4711 '%f' format spec is for filenames.")
4713 (defvar anything-c-grep-default-recurse-command
4714 "grep -d recurse %e -niH -e %p %f"
4715 "Default recursive grep format command for `anything-do-grep-1'.
4716 See `anything-c-grep-default-command' for format specs.")
4718 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4720 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4722 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4724 (defvar anything-c-grep-debug-command-line nil
4725 "Turn on anything grep command-line debugging when non--nil.")
4727 (defvar anything-c-zgrep-recurse-flag nil)
4729 (defvar anything-c-grep-history nil)
4731 (defvar anything-c-grep-max-length-history 100
4732 "*Max number of elements to save in `anything-c-grep-history'.")
4734 (defun anything-c-grep-prepare-candidates (candidates)
4735 "Prepare filenames and directories CANDIDATES for grep command line."
4736 ;; If one or more candidate is a directory, search in all files
4737 ;; of this candidate (e.g /home/user/directory/*).
4738 ;; If r option is enabled search also in subdidrectories.
4739 ;; We need here to expand wildcards to support crap windows filenames
4740 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4741 (if anything-c-zgrep-recurse-flag
4742 (mapconcat 'shell-quote-argument candidates " ")
4743 (loop for i in candidates append
4744 (cond ( ;; Candidate is a directory and we use recursion.
4745 (and (file-directory-p i)
4746 (anything-c-grep-recurse-p))
4747 (list (expand-file-name i)))
4748 ;; Candidate is a directory, search in all files.
4749 ((file-directory-p i)
4750 (file-expand-wildcards
4751 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4752 ;; Candidate is a file or wildcard and we use recursion, use the
4753 ;; current directory instead of candidate.
4754 ((and (or (file-exists-p i) (string-match "\*" i))
4755 (anything-c-grep-recurse-p))
4756 (list (expand-file-name
4757 (directory-file-name ; Needed for windoze.
4758 (file-name-directory (directory-file-name i))))))
4759 ;; Candidate use wildcard.
4760 ((string-match "^\*" (anything-c-basename i))
4761 (file-expand-wildcards i t))
4762 ;; Else should be one or more file.
4763 (t (list i))) into all-files
4764 finally return
4765 (mapconcat 'shell-quote-argument all-files " "))))
4767 (defun anything-c-grep-recurse-p ()
4768 "Check if `anything-do-grep-1' have switched to recursive."
4769 (let ((args (replace-regexp-in-string
4770 "grep" "" anything-c-grep-default-command)))
4771 (string-match-p "r\\|recurse" args)))
4773 (defun anything-c-grep-init (only-files &optional include zgrep)
4774 "Start an asynchronous grep process in ONLY-FILES list."
4775 (let* ((fnargs (anything-c-grep-prepare-candidates
4776 (if (file-remote-p anything-ff-default-directory)
4777 (mapcar #'(lambda (x)
4778 (file-remote-p x 'localname))
4779 only-files)
4780 only-files)))
4781 (ignored-files (mapconcat
4782 #'(lambda (x)
4783 (concat "--exclude=" (shell-quote-argument x)))
4784 grep-find-ignored-files " "))
4785 (ignored-dirs (mapconcat
4786 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4787 #'(lambda (x)
4788 (concat "--exclude-dir=" (shell-quote-argument x)))
4789 grep-find-ignored-directories " "))
4790 (exclude (if (anything-c-grep-recurse-p)
4791 (concat (or include ignored-files) " " ignored-dirs)
4792 ignored-files))
4793 (cmd-line (format-spec
4794 anything-c-grep-default-command
4795 (delq nil
4796 (list (unless zgrep (cons ?e exclude))
4797 (cons ?p (shell-quote-argument anything-pattern))
4798 (cons ?f fnargs))))))
4799 (when anything-c-grep-debug-command-line
4800 (with-current-buffer (get-buffer-create "*any grep debug*")
4801 (goto-char (point-max))
4802 (insert (concat ">>> " cmd-line "\n\n"))))
4803 (setq mode-line-format
4804 '(" " mode-line-buffer-identification " "
4805 (line-number-mode "%l") " "
4806 (:eval (when (get-process "grep-process")
4807 (propertize "[Grep Process Running] "
4808 'face 'anything-grep-running)))))
4809 (force-mode-line-update nil)
4810 (prog1
4811 (let ((default-directory anything-ff-default-directory))
4812 (start-file-process-shell-command "grep-process" nil cmd-line))
4813 (message nil)
4814 (set-process-sentinel
4815 (get-process "grep-process")
4816 #'(lambda (process event)
4817 (when (string= event "finished\n")
4818 (with-anything-window
4819 (anything-update-move-first-line)
4820 (setq mode-line-format
4821 '(" " mode-line-buffer-identification " "
4822 (line-number-mode "%l") " "
4823 (:eval (propertize
4824 (format "[Grep Process Finished - (%s results)] "
4825 (let ((nlines (1- (count-lines
4826 (point-min)
4827 (point-max)))))
4828 (if (> nlines 0) nlines 0)))
4829 'face 'anything-grep-finish))))
4830 (force-mode-line-update nil))))))))
4832 (defun anything-c-grep-action (candidate &optional where mark)
4833 "Define a default action for `anything-do-grep' on CANDIDATE.
4834 WHERE can be one of other-window, elscreen, other-frame."
4835 (let* ((split (anything-c-grep-split-line candidate))
4836 (lineno (string-to-number (nth 1 split)))
4837 (loc-fname (car split))
4838 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4839 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4840 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4841 (fname (if tramp-host
4842 (concat tramp-prefix loc-fname) loc-fname)))
4843 (case where
4844 (other-window (find-file-other-window fname))
4845 (elscreen (anything-elscreen-find-file fname))
4846 (other-frame (find-file-other-frame fname))
4847 (t (find-file fname)))
4848 (anything-goto-line lineno)
4849 (when mark
4850 (set-marker (mark-marker) (point))
4851 (push-mark (point) 'nomsg))
4852 ;; Save history
4853 (unless (or anything-in-persistent-action
4854 (string= anything-pattern ""))
4855 (setq anything-c-grep-history
4856 (cons anything-pattern
4857 (delete anything-pattern anything-c-grep-history)))
4858 (when (> (length anything-c-grep-history)
4859 anything-c-grep-max-length-history)
4860 (setq anything-c-grep-history
4861 (delete (car (last anything-c-grep-history))
4862 anything-c-grep-history))))))
4864 (defun anything-c-grep-other-window (candidate)
4865 "Jump to result in other window from anything grep."
4866 (anything-c-grep-action candidate 'other-window))
4868 (defun anything-c-grep-other-frame (candidate)
4869 "Jump to result in other frame from anything grep."
4870 (anything-c-grep-action candidate 'other-frame))
4872 (defun anything-c-grep-jump-elscreen (candidate)
4873 "Jump to result in elscreen from anything grep."
4874 (anything-c-grep-action candidate 'elscreen))
4876 (defun anything-c-grep-save-results (candidate)
4877 "Save anything grep result in a `grep-mode' buffer."
4878 (let ((buf "*grep*")
4879 new-buf)
4880 (when (get-buffer buf)
4881 (setq new-buf (read-string "GrepBufferName: " buf))
4882 (loop for b in (anything-c-buffer-list)
4883 when (and (string= new-buf b)
4884 (not (y-or-n-p
4885 (format "Buffer `%s' already exists overwrite? "
4886 new-buf))))
4887 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4888 (setq buf new-buf))
4889 (with-current-buffer (get-buffer-create buf)
4890 (let ((inhibit-read-only t))
4891 (erase-buffer)
4892 (insert "-*- mode: grep -*-\n\n"
4893 (format "Grep Results for `%s':\n\n" anything-pattern))
4894 (save-excursion
4895 (insert (with-current-buffer anything-buffer
4896 (forward-line 1)
4897 (buffer-substring (point) (point-max))))
4898 (grep-mode))))
4899 (message "Anything Grep Results saved in `%s' buffer" buf)))
4901 (defun anything-c-grep-persistent-action (candidate)
4902 "Persistent action for `anything-do-grep'.
4903 With a prefix arg record CANDIDATE in `mark-ring'."
4904 (if current-prefix-arg
4905 (anything-c-grep-action candidate nil 'mark)
4906 (anything-c-grep-action candidate))
4907 (anything-match-line-color-current-line))
4909 (defun anything-c-grep-guess-extensions (files)
4910 "Try to guess file extensions in FILES list when using grep recurse.
4911 These extensions will be added to command line with --include arg of grep."
4912 (loop
4913 with glob-list = nil
4914 with lst = (if (file-directory-p (car files))
4915 (directory-files
4916 (car files) nil
4917 directory-files-no-dot-files-regexp)
4918 files)
4919 for i in lst
4920 for ext = (file-name-extension i t)
4921 for glob = (and ext (not (string= ext ""))
4922 (concat "*" ext))
4923 unless (or (not glob)
4924 (member glob glob-list)
4925 (member glob grep-find-ignored-files))
4926 collect glob into glob-list
4927 finally return glob-list))
4929 (defun anything-do-grep-1 (only &optional recurse zgrep)
4930 "Launch grep with a list of ONLY files.
4931 When RECURSE is given use -r option of grep and prompt user
4932 to set the --include args of grep.
4933 You can give more than one arg separated by space.
4934 e.g *.el *.py *.tex.
4935 If it's empty --exclude `grep-find-ignored-files' is used instead."
4936 (let* ((anything-compile-source-functions
4937 ;; rule out anything-match-plugin because the input is one regexp.
4938 (delq 'anything-compile-source--match-plugin
4939 (copy-sequence anything-compile-source-functions)))
4940 (exts (anything-c-grep-guess-extensions only))
4941 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4942 (include-files (and recurse (not zgrep)
4943 (read-string "OnlyExt(*.[ext]): "
4944 globs)))
4945 ;; Set `minibuffer-history' AFTER includes-files
4946 ;; to avoid storing wild-cards here.
4947 (minibuffer-history anything-c-grep-history)
4948 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4949 (recurse anything-c-grep-default-recurse-command)
4950 (zgrep anything-c-default-zgrep-command)
4951 (t anything-c-grep-default-command)))
4952 ;; Disable match-plugin and use here own highlighting.
4953 (anything-mp-highlight-delay nil))
4954 (when include-files
4955 (setq include-files
4956 (and (not (string= include-files ""))
4957 (mapconcat #'(lambda (x)
4958 (concat "--include=" (shell-quote-argument x)))
4959 (split-string include-files) " "))))
4960 ;; When called as action from an other source e.g *-find-files
4961 ;; we have to kill action buffer.
4962 (when (get-buffer anything-action-buffer)
4963 (kill-buffer anything-action-buffer))
4964 ;; `anything-find-files' haven't already started,
4965 ;; give a default value to `anything-ff-default-directory'.
4966 (setq anything-ff-default-directory (or anything-ff-default-directory
4967 default-directory))
4968 (anything
4969 :sources
4970 `(((name . "Grep (C-c ? Help)")
4971 (candidates
4972 . (lambda ()
4973 (funcall anything-c-grep-default-function only include-files zgrep)))
4974 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4975 (candidate-number-limit . 9999)
4976 (mode-line . anything-grep-mode-line-string)
4977 (jump-persistent . anything-c-grep-persistent-action)
4978 (action . ,(delq
4980 `(("Find File" . anything-c-grep-action)
4981 ("Find file other frame" . anything-c-grep-other-frame)
4982 ,(and (locate-library "elscreen")
4983 '("Find file in Elscreen"
4984 . anything-c-grep-jump-elscreen))
4985 ("Save results in grep buffer" . anything-c-grep-save-results)
4986 ("Find file other window" . anything-c-grep-other-window))))
4987 (persistent-action . anything-c-grep-persistent-action)
4988 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4989 (requires-pattern . 3)
4990 (delayed)))
4991 :keymap anything-c-grep-map
4992 :buffer "*anything grep*")))
4994 (defun anything-ff-zgrep-1 (flist recursive)
4995 (unwind-protect
4996 (let* ((def-dir (or anything-ff-default-directory
4997 default-directory))
4998 (only (if recursive
4999 (or (gethash def-dir anything-c-rzgrep-cache)
5000 (puthash
5001 def-dir
5002 (anything-c-walk-directory
5003 def-dir
5004 :directories nil
5005 :path 'full
5006 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5007 anything-c-rzgrep-cache))
5008 flist)))
5009 (when recursive (setq anything-c-zgrep-recurse-flag t))
5010 (anything-do-grep-1 only recursive 'zgrep))
5011 (setq anything-c-zgrep-recurse-flag nil)))
5013 (defun anything-c-grep-split-line (line)
5014 "Split a grep output line."
5015 (let (beg fname lineno str)
5016 ;; Don't print until grep line is valid.
5017 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5018 (with-temp-buffer
5019 (insert line)
5020 (goto-char (point-min))
5021 (setq beg (point))
5022 (forward-char 2)
5023 (re-search-forward ":" nil t)
5024 (setq fname (buffer-substring-no-properties beg (1- (point))))
5025 (setq beg (point))
5026 (re-search-forward ":" nil t)
5027 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5028 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5029 (list fname lineno str))))
5031 (defun anything-c-grep-cand-transformer (candidates sources)
5032 "Filtered candidate transformer function for `anything-do-grep'."
5033 (loop for i in candidates
5034 for split = (and i (anything-c-grep-split-line i))
5035 for fname = (car split)
5036 for lineno = (nth 1 split)
5037 for str = (nth 2 split)
5038 when (and fname lineno str)
5039 collect
5040 (cons (concat (propertize (file-name-nondirectory fname)
5041 'face 'anything-grep-file
5042 'help-echo fname) ":"
5043 (propertize lineno 'face 'anything-grep-lineno) ":"
5044 (anything-c-grep-highlight-match str))
5045 i)))
5047 (defun anything-c-grep-highlight-match (str)
5048 "Highlight in string STR all occurences matching `anything-pattern'."
5049 (condition-case nil
5050 (with-temp-buffer
5051 (insert str)
5052 (goto-char (point-min))
5053 (while (and (re-search-forward anything-pattern nil t)
5054 (> (- (match-end 0) (match-beginning 0)) 0))
5055 (add-text-properties
5056 (match-beginning 0) (match-end 0)
5057 '(face anything-grep-match)))
5058 (buffer-string))
5059 (error nil)))
5061 ;; Go to next or precedent file (common to etags and grep).
5062 (defun anything-c-goto-next-or-prec-file (n)
5063 "Go to next or precedent candidate file in anything grep/etags buffers.
5064 If N is positive go forward otherwise go backward."
5065 (with-anything-window
5066 (let* ((current-line-list (split-string
5067 (buffer-substring
5068 (point-at-bol)
5069 (point-at-eol)) ":"))
5070 (current-fname (nth 0 current-line-list))
5071 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5072 (catch 'break
5073 (while (not (funcall fn-b-o-f))
5074 (forward-line n) ; Go forward or backward depending of n value.
5075 (unless (search-forward current-fname (point-at-eol) t)
5076 (anything-mark-current-line)
5077 (throw 'break nil))))
5078 (cond ((and (eq n 1) (eobp))
5079 (re-search-backward ".")
5080 (forward-line 0)
5081 (anything-mark-current-line))
5082 ((and (< n 1) (bobp))
5083 (forward-line 1)
5084 (anything-mark-current-line))))))
5086 ;;;###autoload
5087 (defun anything-c-goto-precedent-file ()
5088 "Go to precedent file in anything grep/etags buffers."
5089 (interactive)
5090 (anything-c-goto-next-or-prec-file -1))
5092 ;;;###autoload
5093 (defun anything-c-goto-next-file ()
5094 "Go to precedent file in anything grep/etags buffers."
5095 (interactive)
5096 (anything-c-goto-next-or-prec-file 1))
5098 ;;;###autoload
5099 (defun anything-c-grep-run-persistent-action ()
5100 "Run grep persistent action from `anything-do-grep-1'."
5101 (interactive)
5102 (anything-execute-persistent-action 'jump-persistent))
5104 ;;;###autoload
5105 (defun anything-c-grep-run-default-action ()
5106 "Run grep default action from `anything-do-grep-1'."
5107 (interactive)
5108 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5110 ;;;###autoload
5111 (defun anything-c-grep-run-other-window-action ()
5112 "Run grep goto other window action from `anything-do-grep-1'."
5113 (interactive)
5114 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5116 ;;;###autoload
5117 (defun anything-c-grep-run-save-buffer ()
5118 "Run grep save results action from `anything-do-grep-1'."
5119 (interactive)
5120 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5122 ;; Grep buffers
5123 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5124 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5125 If one of selected buffers is not a file--buffer,
5126 it is ignored and grep will run on all others file--buffers.
5127 If only one candidate is selected and it is not a file--buffer,
5128 switch to this buffer and run `anything-occur'.
5129 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5130 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5131 (cands (if prefarg
5132 (buffer-list)
5133 (anything-marked-candidates)))
5134 (win-conf (current-window-configuration))
5135 ;; Non--fname buffers are ignored.
5136 (bufs (loop for buf in cands
5137 for fname = (buffer-file-name (get-buffer buf))
5138 when fname
5139 collect (expand-file-name fname))))
5140 (if bufs
5141 (if zgrep
5142 (anything-do-grep-1 bufs nil 'zgrep)
5143 (anything-do-grep-1 bufs))
5144 ;; bufs is empty, thats mean we have only CANDIDATE
5145 ;; and it is not a buffer-filename, fallback to occur.
5146 (anything-c-switch-to-buffer candidate)
5147 (when (get-buffer anything-action-buffer)
5148 (kill-buffer anything-action-buffer))
5149 (anything-occur)
5150 (when (eq anything-exit-status 1)
5151 (set-window-configuration win-conf)))))
5153 (defun anything-c-grep-buffers (candidate)
5154 "Action to grep buffers."
5155 (anything-c-grep-buffers-1 candidate))
5157 (defun anything-c-zgrep-buffers (candidate)
5158 "Action to zgrep buffers."
5159 (anything-c-grep-buffers-1 candidate 'zgrep))
5162 ;;; Anything interface for pdfgrep
5163 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5164 ;; and a pdf-reader (e.g xpdf) are needed.
5166 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5167 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5168 (defvar anything-c-pdfgrep-debug-command-line nil)
5170 (defun anything-c-pdfgrep-init (only-files)
5171 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5172 (let* ((fnargs (anything-c-grep-prepare-candidates
5173 (if (file-remote-p anything-ff-default-directory)
5174 (mapcar #'(lambda (x)
5175 (file-remote-p x 'localname))
5176 only-files)
5177 only-files)))
5178 (cmd-line (format anything-c-pdfgrep-default-command
5179 anything-pattern
5180 fnargs)))
5181 (when anything-c-pdfgrep-debug-command-line
5182 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5183 (goto-char (point-max))
5184 (insert (concat ">>> " cmd-line "\n\n"))))
5185 (setq mode-line-format
5186 '(" " mode-line-buffer-identification " "
5187 (line-number-mode "%l") " "
5188 (:eval (propertize "(Pdfgrep Process Running) "
5189 'face '((:foreground "red"))))))
5190 (prog1
5191 (let ((default-directory anything-ff-default-directory))
5192 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5193 (message nil)
5194 (set-process-sentinel
5195 (get-process "pdfgrep-process")
5196 #'(lambda (process event)
5197 (when (string= event "finished\n")
5198 (with-anything-window
5199 (anything-update-move-first-line))
5200 (force-mode-line-update nil)))))))
5203 (defun anything-do-pdfgrep-1 (only)
5204 "Launch pdfgrep with a list of ONLY files."
5205 (unless (executable-find "pdfgrep")
5206 (error "Error: No such program `pdfgrep'."))
5207 (let* ((anything-compile-source-functions
5208 ;; rule out anything-match-plugin because the input is one regexp.
5209 (delq 'anything-compile-source--match-plugin
5210 (copy-sequence anything-compile-source-functions)))
5211 ;; Disable match-plugin and use here own highlighting.
5212 (anything-mp-highlight-delay nil))
5213 ;; When called as action from an other source e.g *-find-files
5214 ;; we have to kill action buffer.
5215 (when (get-buffer anything-action-buffer)
5216 (kill-buffer anything-action-buffer))
5217 ;; If `anything-find-files' haven't already started,
5218 ;; give a default value to `anything-ff-default-directory'.
5219 (setq anything-ff-default-directory (or anything-ff-default-directory
5220 default-directory))
5221 (anything
5222 :sources
5223 `(((name . "PdfGrep")
5224 (candidates
5225 . (lambda ()
5226 (funcall anything-c-pdfgrep-default-function only)))
5227 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5228 (candidate-number-limit . 9999)
5229 (mode-line . anything-pdfgrep-mode-line-string)
5230 (action . anything-c-pdfgrep-action)
5231 (persistent-help . "Jump to PDF Page")
5232 (requires-pattern . 3)
5233 (delayed)))
5234 :keymap anything-c-pdfgrep-map
5235 :buffer "*anything grep*")))
5238 (defun anything-c-pdfgrep-action (candidate)
5239 (let* ((split (anything-c-grep-split-line candidate))
5240 (pageno (nth 1 split))
5241 (fname (car split)))
5242 (start-file-process-shell-command
5243 "pdf-reader" nil
5244 (format-spec anything-c-pdfgrep-default-read-command
5245 (list (cons ?f fname) (cons ?p pageno))))))
5247 (defun anything-do-pdfgrep ()
5248 (interactive)
5249 (let ((only (anything-c-read-file-name
5250 "Search in file(s): "
5251 :marked-candidates t
5252 :test #'(lambda (file)
5253 (or (string= (file-name-extension file) "pdf")
5254 (string= (file-name-extension file) "PDF")
5255 (file-directory-p file)))
5256 :preselect (or (dired-get-filename nil t)
5257 (buffer-file-name (current-buffer)))))
5258 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5259 (anything-do-pdfgrep-1 only)))
5262 ;; Yank text at point.
5265 ;; Internal
5266 (defvar anything-yank-point nil)
5268 ;;;###autoload
5269 (defun anything-yank-text-at-point ()
5270 "Yank text at point in minibuffer."
5271 (interactive)
5272 (let (input)
5273 (flet ((insert-in-minibuffer (word)
5274 (with-selected-window (minibuffer-window)
5275 (let ((str anything-pattern))
5276 (delete-minibuffer-contents)
5277 (set-text-properties 0 (length word) nil word)
5278 (insert (concat str word))))))
5279 (with-anything-current-buffer
5280 ;; Start to initial point if C-w have never been hit.
5281 (unless anything-yank-point (setq anything-yank-point (point)))
5282 (and anything-yank-point (goto-char anything-yank-point))
5283 (forward-word 1)
5284 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5285 (setq anything-yank-point (point))) ; End of last forward-word
5286 (insert-in-minibuffer input))))
5288 (defun anything-reset-yank-point ()
5289 (setq anything-yank-point nil))
5291 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5292 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5295 ;;; Recentf files
5298 (defvar anything-c-source-recentf
5299 '((name . "Recentf")
5300 (init . (lambda ()
5301 (require 'recentf)
5302 (or recentf-mode (recentf-mode 1))))
5303 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5304 (candidates . recentf-list)
5305 (match anything-c-match-on-basename)
5306 (type . file))
5307 "See (info \"(emacs)File Conveniences\").
5308 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5309 ;; (anything 'anything-c-source-recentf)
5311 ;;; ffap
5312 (eval-when-compile (require 'ffap))
5313 (defvar anything-c-source-ffap-guesser
5314 '((name . "File at point")
5315 (init . (lambda () (require 'ffap)))
5316 (candidates . (lambda ()
5317 (anything-aif
5318 (with-anything-current-buffer
5319 (ffap-guesser))
5320 (list it))))
5321 (type . file)))
5322 ;; (anything 'anything-c-source-ffap-guesser)
5324 ;;; ffap with line number
5325 (defun anything-c-ffap-file-line-at-point ()
5326 "Get (FILENAME . LINENO) at point."
5327 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5328 (save-excursion
5329 (beginning-of-line)
5330 (when (and (search-forward it nil t)
5331 (looking-at ":\\([0-9]+\\)"))
5332 (cons it (string-to-number (match-string 1)))))))
5334 (defvar anything-c-ffap-line-location nil
5335 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5336 It is cleared after jumping line.")
5338 (defun anything-c-ffap-line-candidates ()
5339 (with-anything-current-buffer
5340 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5341 (when anything-c-ffap-line-location
5342 (destructuring-bind (file . line) anything-c-ffap-line-location
5343 (list (cons (format "%s (line %d)" file line) file)))))
5345 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5346 (defun anything-c-ffap-line-goto-line ()
5347 (when (car anything-c-ffap-line-location)
5348 (unwind-protect
5349 (ignore-errors
5350 (with-selected-window
5351 (get-buffer-window
5352 (get-file-buffer (car anything-c-ffap-line-location)))
5353 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5354 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5355 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5357 (defvar anything-c-source-ffap-line
5358 '((name . "File/Lineno at point")
5359 (init . (lambda () (require 'ffap)))
5360 (candidates . anything-c-ffap-line-candidates)
5361 (type . file)))
5362 ;; (anything 'anything-c-source-ffap-line)
5364 ;;; list of files gleaned from every dired buffer
5365 (defun anything-c-files-in-all-dired-candidates ()
5366 (save-excursion
5367 (mapcan
5368 (lambda (dir)
5369 (cond ((listp dir) ;filelist
5370 dir)
5371 ((equal "" (file-name-nondirectory dir)) ;dir
5372 (directory-files dir t))
5373 (t ;wildcard
5374 (file-expand-wildcards dir t))))
5375 (delq nil
5376 (mapcar (lambda (buf)
5377 (set-buffer buf)
5378 (when (eq major-mode 'dired-mode)
5379 (if (consp dired-directory)
5380 (cdr dired-directory) ;filelist
5381 dired-directory))) ;dir or wildcard
5382 (buffer-list))))))
5383 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5385 (defvar anything-c-source-files-in-all-dired
5386 '((name . "Files in all dired buffer.")
5387 (candidates . anything-c-files-in-all-dired-candidates)
5388 (type . file)))
5389 ;; (anything 'anything-c-source-files-in-all-dired)
5391 (defvar anything-c-source-filelist
5392 '((name . "FileList")
5393 (grep-candidates . anything-c-filelist-file-name)
5394 (candidate-number-limit . 200)
5395 (requires-pattern . 4)
5396 (type . file))
5397 "Source to find files instantly.
5398 See `anything-c-filelist-file-name' docstring for usage.")
5401 ;;;; <info>
5402 ;;; Info pages
5403 (defvar anything-c-info-pages nil
5404 "All info pages on system.
5405 Will be calculated the first time you invoke anything with this
5406 source.")
5408 (defun anything-c-info-pages-init ()
5409 "Collect candidates for initial Info node Top."
5410 (if anything-c-info-pages
5411 anything-c-info-pages
5412 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5413 topics)
5414 (require 'info)
5415 (with-temp-buffer
5416 (Info-find-node "dir" "top")
5417 (goto-char (point-min))
5418 (while (re-search-forward info-topic-regexp nil t)
5419 (push (match-string-no-properties 1) topics))
5420 (kill-buffer))
5421 (setq anything-c-info-pages topics))))
5423 (defvar anything-c-source-info-pages
5424 `((name . "Info Pages")
5425 (init . anything-c-info-pages-init)
5426 (candidates . anything-c-info-pages)
5427 (action . (("Show with Info" .(lambda (node-str)
5428 (info (replace-regexp-in-string
5429 "^[^:]+: " "" node-str))))))
5430 (requires-pattern . 2)))
5431 ;; (anything 'anything-c-source-info-pages)
5434 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5435 (defun anything-c-describe-attributes (anything-attribute)
5436 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5437 Same as `anything-describe-anything-attribute' but with anything completion."
5438 (interactive (list (intern
5439 (anything-comp-read
5440 "Describe anything attribute: "
5441 (mapcar 'symbol-name anything-additional-attributes)
5442 :must-match t
5443 :persistent-action
5444 #'(lambda (candidate)
5445 (with-output-to-temp-buffer "*Help*"
5446 (princ (get (intern candidate) 'anything-attrdoc))))))))
5447 (with-output-to-temp-buffer "*Help*"
5448 (princ (get anything-attribute 'anything-attrdoc))))
5451 ;;; Use info-index plug-in.
5454 ;; Note that `name' attribute is not needed since
5455 ;; `anything-c-insert-summary' have been removed.
5456 ;; Info Elisp
5457 (defvar anything-c-source-info-elisp
5458 '((name . "Info index: elisp")
5459 (info-index . "elisp")))
5460 ;; (anything 'anything-c-source-info-elisp)
5462 ;; Info-Common-Lisp
5463 (defvar anything-c-source-info-cl
5464 '((name . "Info index: cl")
5465 (info-index . "cl")))
5466 ;; (anything 'anything-c-source-info-cl)
5468 ;; Info Index org
5469 (defvar anything-c-source-info-org
5470 '((name . "Info index: org")
5471 (info-index . "org")))
5472 ;; (anything 'anything-c-source-info-org)
5474 ;; Info Index gnus
5475 (defvar anything-c-source-info-gnus
5476 '((name . "Info index: Gnus")
5477 (info-index . "gnus")))
5479 ;; Info Index ratpoison
5480 (defvar anything-c-source-info-ratpoison
5481 '((name . "Info index: ratpoison")
5482 (info-index . "ratpoison")))
5483 ;; (anything 'anything-c-source-info-ratpoison)
5485 ;; Info Index zsh
5486 (defvar anything-c-source-info-zsh
5487 '((name . "Info index: zsh")
5488 (info-index . "zsh")))
5489 ;; (anything 'anything-c-source-info-zsh)
5491 ;; Info Index bash
5492 (defvar anything-c-source-info-bash
5493 '((name . "Info index: bash")
5494 (info-index . "bash")))
5495 ;; (anything 'anything-c-source-info-bash)
5497 ;; Info Index coreutils
5498 (defvar anything-c-source-info-coreutils
5499 '((name . "Info index: coreutils")
5500 (info-index . "coreutils")))
5501 ;; (anything 'anything-c-source-info-coreutils)
5503 ;; Info Index fileutils
5504 (defvar anything-c-source-info-fileutils
5505 '((name . "Info index: fileutils")
5506 (info-index . "fileutils")))
5507 ;; (anything 'anything-c-source-info-fileutils)
5509 ;; Info Index find
5510 (defvar anything-c-source-info-find
5511 '((name . "Info index: find")
5512 (info-index . "find")))
5513 ;; (anything 'anything-c-source-info-find)
5515 ;; Info Index sh-utils
5516 (defvar anything-c-source-info-sh-utils
5517 '((name . "Info index: sh-utils")
5518 (info-index . "sh-utils")))
5519 ;; (anything 'anything-c-source-info-sh-utils)
5521 ;; Info Index textutils
5522 (defvar anything-c-source-info-textutils
5523 '((name . "Info index: textutils")
5524 (info-index . "textutils")))
5525 ;; (anything 'anything-c-source-info-textutils)
5527 ;; Info Index libc
5528 (defvar anything-c-source-info-libc
5529 '((name . "Info index: libc")
5530 (info-index . "libc")))
5531 ;; (anything 'anything-c-source-info-libc)
5533 ;; Info Index make
5534 (defvar anything-c-source-info-make
5535 '((name . "Info index: make")
5536 (info-index . "make")))
5537 ;; (anything 'anything-c-source-info-make)
5539 ;; Info Index automake
5540 (defvar anything-c-source-info-automake
5541 '((name . "Info index: automake")
5542 (info-index . "automake")))
5543 ;; (anything 'anything-c-source-info-automake)
5545 ;; Info Index autoconf
5546 (defvar anything-c-source-info-autoconf
5547 '((name . "Info index: autoconf")
5548 (info-index . "autoconf")))
5549 ;; (anything 'anything-c-source-info-autoconf)
5551 ;; Info Index emacs-lisp-intro
5552 (defvar anything-c-source-info-emacs-lisp-intro
5553 '((name . "Info index: emacs-lisp-intro")
5554 (info-index . "emacs-lisp-intro")))
5555 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5557 ;; Info Index emacs
5558 (defvar anything-c-source-info-emacs
5559 '((name . "Info index: emacs")
5560 (info-index . "emacs")))
5561 ;; (anything 'anything-c-source-info-emacs)
5563 ;; Info Index elib
5564 (defvar anything-c-source-info-elib
5565 '((name . "Info index: elib")
5566 (info-index . "elib")))
5567 ;; (anything 'anything-c-source-info-elib)
5569 ;; Info Index eieio
5570 (defvar anything-c-source-info-eieio
5571 '((name . "Info index: eieio")
5572 (info-index . "eieio")))
5573 ;; (anything 'anything-c-source-info-eieio)
5575 ;; Info Index gauche-refe
5576 (defvar anything-c-source-info-gauche-refe
5577 '((name . "Info index: gauche")
5578 (info-index . "gauche-refe")))
5579 ;; (anything 'anything-c-source-info-gauche-refe)
5581 ;; Info Index guile
5582 (defvar anything-c-source-info-guile
5583 '((name . "Info index: guile")
5584 (info-index . "guile")))
5585 ;; (anything 'anything-c-source-info-guile)
5587 ;; Info Index guile-tut
5588 (defvar anything-c-source-info-guile-tut
5589 '((name . "Info index: guile-tut")
5590 (info-index . "guile-tut")))
5591 ;; (anything 'anything-c-source-info-guile-tut)
5593 ;; Info Index goops
5594 (defvar anything-c-source-info-goops
5595 '((name . "Info index: goops")
5596 (info-index . "goops")))
5597 ;; (anything 'anything-c-source-info-goops)
5599 ;; Info Index screen
5600 (defvar anything-c-source-info-screen
5601 '((name . "Info index: screen")
5602 (info-index . "screen")
5603 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5604 ;; (anything 'anything-c-source-info-screen)
5606 ;; Info Index latex
5607 (defvar anything-c-source-info-latex
5608 '((name . "Info index: latex")
5609 (info-index . "latex")))
5610 ;; (anything 'anything-c-source-info-latex)
5612 ;; Info Index gawk
5613 (defvar anything-c-source-info-gawk
5614 '((name . "Info index: gawk")
5615 (info-index . "gawk")))
5616 ;; (anything 'anything-c-source-info-gawk)
5618 ;; Info Index sed
5619 (defvar anything-c-source-info-sed
5620 '((name . "Info index: sed")
5621 (info-index . "sed")))
5622 ;; (anything 'anything-c-source-info-sed)
5624 ;; Info Index m4
5625 (defvar anything-c-source-info-m4
5626 '((name . "Info index: m4")
5627 (info-index . "m4")))
5628 ;; (anything 'anything-c-source-info-m4)
5630 ;; Info Index wget
5631 (defvar anything-c-source-info-wget
5632 '((name . "Info index: wget")
5633 (info-index . "wget")))
5634 ;; (anything 'anything-c-source-info-wget)
5636 ;; Info Index binutils
5637 (defvar anything-c-source-info-binutils
5638 '((name . "Info index: binutils")
5639 (info-index . "binutils")))
5640 ;; (anything 'anything-c-source-info-binutils)
5642 ;; Info Index as
5643 (defvar anything-c-source-info-as
5644 '((name . "Info index: as")
5645 (info-index . "as")))
5646 ;; (anything 'anything-c-source-info-as)
5648 ;; Info Index bfd
5649 (defvar anything-c-source-info-bfd
5650 '((name . "Info index: bfd")
5651 (info-index . "bfd")))
5652 ;; (anything 'anything-c-source-info-bfd)
5654 ;; Info Index gprof
5655 (defvar anything-c-source-info-gprof
5656 '((name . "Info index: gprof")
5657 (info-index . "gprof")))
5658 ;; (anything 'anything-c-source-info-gprof)
5660 ;; Info Index ld
5661 (defvar anything-c-source-info-ld
5662 '((name . "Info index: ld")
5663 (info-index . "ld")))
5664 ;; (anything 'anything-c-source-info-ld)
5666 ;; Info Index diff
5667 (defvar anything-c-source-info-diff
5668 '((name . "Info index: diff")
5669 (info-index . "diff")))
5670 ;; (anything 'anything-c-source-info-diff)
5672 ;; Info Index flex
5673 (defvar anything-c-source-info-flex
5674 '((name . "Info index: flex")
5675 (info-index . "flex")))
5676 ;; (anything 'anything-c-source-info-flex)
5678 ;; Info Index grep
5679 (defvar anything-c-source-info-grep
5680 '((name . "Info index: grep")
5681 (info-index . "grep")))
5682 ;; (anything 'anything-c-source-info-grep)
5684 ;; Info Index gzip
5685 (defvar anything-c-source-info-gzip
5686 '((name . "Info index: gzip")
5687 (info-index . "gzip")))
5688 ;; (anything 'anything-c-source-info-gzip)
5690 ;; Info Index libtool
5691 (defvar anything-c-source-info-libtool
5692 '((name . "Info index: libtool")
5693 (info-index . "libtool")))
5694 ;; (anything 'anything-c-source-info-libtool)
5696 ;; Info Index texinfo
5697 (defvar anything-c-source-info-texinfo
5698 '((name . "Info index: texinfo")
5699 (info-index . "texinfo")))
5700 ;; (anything 'anything-c-source-info-texinfo)
5702 ;; Info Index info
5703 (defvar anything-c-source-info-info
5704 '((name . "Info index: info")
5705 (info-index . "info")))
5706 ;; (anything 'anything-c-source-info-info)
5708 ;; Info Index gdb
5709 (defvar anything-c-source-info-gdb
5710 '((name . "Info index: gdb")
5711 (info-index . "gdb")))
5712 ;; (anything 'anything-c-source-info-gdb)
5714 ;; Info Index stabs
5715 (defvar anything-c-source-info-stabs
5716 '((name . "Info index: stabs")
5717 (info-index . "stabs")))
5718 ;; (anything 'anything-c-source-info-stabs)
5720 ;; Info Index cvsbook
5721 (defvar anything-c-source-info-cvsbook
5722 '((name . "Info index: cvsbook")
5723 (info-index . "cvsbook")))
5724 ;; (anything 'anything-c-source-info-cvsbook)
5726 ;; Info Index cvs
5727 (defvar anything-c-source-info-cvs
5728 '((name . "Info index: cvs")
5729 (info-index . "cvs")))
5730 ;; (anything 'anything-c-source-info-cvs)
5732 ;; Info Index bison
5733 (defvar anything-c-source-info-bison
5734 '((name . "Info index: bison")
5735 (info-index . "bison")))
5736 ;; (anything 'anything-c-source-info-bison)
5738 ;; Info Index id-utils
5739 (defvar anything-c-source-info-id-utils
5740 '((name . "Info index: id-utils")
5741 (info-index . "id-utils")))
5742 ;; (anything 'anything-c-source-info-id-utils)
5744 ;; Info Index global
5745 (defvar anything-c-source-info-global
5746 '((name . "Info index: global")
5747 (info-index . "global")))
5748 ;; (anything 'anything-c-source-info-global)
5751 ;;; Man and woman UI
5754 (defvar anything-c-man-pages nil
5755 "All man pages on system.
5756 Will be calculated the first time you invoke anything with this
5757 source.")
5759 (defun anything-c-man-default-action (candidate)
5760 "Default action for jumping to a woman or man page from anything."
5761 (let ((wfiles (woman-file-name-all-completions candidate)))
5762 (condition-case err
5763 (if (> (length wfiles) 1)
5764 (woman-find-file
5765 (anything-comp-read
5766 "ManFile: " wfiles :must-match t))
5767 (woman candidate))
5768 ;; If woman is unable to format correctly
5769 ;; use man instead.
5770 (error (kill-buffer) ; Kill woman buffer.
5771 (let ((Man-notify-method 'meek))
5772 (Man-getpage-in-background candidate))))))
5774 (defvar anything-c-source-man-pages
5775 `((name . "Manual Pages")
5776 (candidates . (lambda ()
5777 (if anything-c-man-pages
5778 anything-c-man-pages
5779 ;; XEmacs doesn't have a woman :)
5780 (setq anything-c-man-pages
5781 (ignore-errors
5782 (require 'woman)
5783 (woman-file-name "")
5784 (sort (mapcar 'car woman-topic-all-completions)
5785 'string-lessp))))))
5786 (action ("Show with Woman" . anything-c-man-default-action))
5787 ;; Woman does not work OS X
5788 ;; http://xahlee.org/emacs/modernization_man_page.html
5789 (action-transformer . (lambda (actions candidate)
5790 (if (eq system-type 'darwin)
5791 '(("Show with Man" . man))
5792 actions)))
5793 (requires-pattern . 2)))
5794 ;; (anything 'anything-c-source-man-pages)
5797 ;;;; <Command>
5798 ;;; Anything M-x - Enhanced M-x UI
5801 ;; Another replacement of `M-x' that act exactly like the
5802 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5803 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5804 ;; anything invocation.
5805 ;; Documentation of commands available without quitting,
5806 ;; Show keybindings of commands.
5807 ;; Show history.
5808 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5809 "Return alist of MODE-MAP."
5810 (loop for key being the key-seqs of mode-map using (key-bindings com)
5811 for str-key = (key-description key)
5812 for ismenu = (string-match "<menu-bar>" str-key)
5813 unless ismenu collect (cons str-key com)))
5815 (defun anything-get-mode-map-from-mode (mode)
5816 "Guess the mode-map name according to MODE.
5817 Some modes don't use conventional mode-map name
5818 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5819 Return nil if no mode-map found."
5820 (loop
5821 ;; Start with a conventional mode-map name.
5822 with mode-map = (intern-soft (format "%s-map" mode))
5823 with mode-string = (symbol-name mode)
5824 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5825 while (not mode-map)
5826 for count downfrom (length mode-name)
5827 ;; Return when no result after parsing entire string.
5828 when (eq count 0) return nil
5829 for sub-name = (substring mode-name 0 count)
5830 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5831 finally return mode-map))
5833 (defun anything-M-x-current-mode-map-alist ()
5834 "Return mode-map alist of current `major-mode'."
5835 (let ((map (anything-get-mode-map-from-mode major-mode)))
5836 (when (and map (boundp map))
5837 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5840 (defun anything-M-x-transformer (candidates sources)
5841 "filtered-candidate-transformer to show bindings in emacs commands.
5842 Show global bindings and local bindings according to current `major-mode'."
5843 (with-anything-current-buffer
5844 (loop
5845 with local-map = (anything-M-x-current-mode-map-alist)
5846 for cand in candidates
5847 for local-key = (car (rassq cand local-map))
5848 for key = (substitute-command-keys (format "\\[%s]" cand))
5849 collect
5850 (cons (cond ((and (string-match "^M-x" key) local-key)
5851 (format "%s (%s)"
5852 cand (propertize
5853 local-key
5854 'face 'anything-M-x-key-face)))
5855 ((string-match "^M-x" key) cand)
5856 (t (format "%s (%s)"
5857 cand (propertize
5859 'face 'anything-M-x-key-face))))
5860 cand) into ls
5861 finally return
5862 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5865 ;;; Complex command history
5868 (defvar anything-c-source-complex-command-history
5869 '((name . "Complex Command History")
5870 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5871 (type . sexp)))
5872 ;; (anything 'anything-c-source-complex-command-history)
5874 ;;; M-x history (not related to `anything-M-x')
5877 (defvar anything-c-source-extended-command-history
5878 '((name . "Emacs Commands History")
5879 (candidates . extended-command-history)
5880 (type . command)))
5881 ;; (anything 'anything-c-source-extended-command-history)
5883 ;;; Emacs commands (Basic source for emacs commands)
5886 (defvar anything-c-source-emacs-commands
5887 '((name . "Emacs Commands")
5888 (candidates . (lambda ()
5889 (let (commands)
5890 (mapatoms (lambda (a)
5891 (if (commandp a)
5892 (push (symbol-name a)
5893 commands))))
5894 (sort commands 'string-lessp))))
5895 (type . command)
5896 (requires-pattern . 2))
5897 "Source for completing and invoking Emacs commands.
5898 A command is a function with interactive spec that can
5899 be invoked with `M-x'.
5901 To get non-interactive functions listed, use
5902 `anything-c-source-emacs-functions'.")
5903 ;; (anything 'anything-c-source-emacs-commands)
5906 ;;;; <Function>
5907 ;;; Emacs functions
5910 (defvar anything-c-source-emacs-functions
5911 '((name . "Emacs Functions")
5912 (candidates . (lambda ()
5913 (let (commands)
5914 (mapatoms (lambda (a)
5915 (if (functionp a)
5916 (push (symbol-name a) commands))))
5917 (sort commands 'string-lessp))))
5918 (type . function)
5919 (requires-pattern . 2))
5920 "Source for completing Emacs functions.")
5921 ;; (anything 'anything-c-source-emacs-functions)
5923 ;;; With abbrev expansion
5924 ;;; Similar to my exec-abbrev-cmd.el
5925 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5926 (defvar anything-c-function-abbrev-regexp nil
5927 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5928 Regexp built from the current `anything-pattern' interpreting it
5929 as abbreviation.
5930 Only for internal use.")
5932 (defun anything-c-match-function-by-abbrev (candidate)
5933 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5935 Abbreviations are made by taking the first character from each
5936 word in the function's name, e.g. \"bb\" is an abbrev for
5937 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5938 (string-match anything-c-function-abbrev-regexp candidate))
5940 (defvar anything-c-source-emacs-functions-with-abbrevs
5941 (append anything-c-source-emacs-functions
5942 '((match anything-c-match-function-by-abbrev
5943 anything-c-string-match))
5944 '((init
5945 . (lambda ()
5946 (defadvice anything-update
5947 (before anything-c-update-function-abbrev-regexp activate)
5948 (let ((char-list (append anything-pattern nil))
5949 (str "^"))
5950 (dolist (c char-list)
5951 (setq str (concat str (list c) "[^-]*-")))
5952 (setq str (concat (substring str 0 (1- (length str))) "$"))
5953 (setq anything-c-function-abbrev-regexp str))))))))
5954 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5956 (defvar anything-c-source-advice
5957 '((name . "Function Advice")
5958 (candidates . anything-c-advice-candidates)
5959 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5960 ;; (real-to-display . anything-c-advice-real-to-display)
5961 (persistent-action . anything-c-advice-persistent-action)
5962 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5963 ;; (anything 'anything-c-source-advice)
5964 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5965 ;; (testadvice)
5967 (defun anything-c-advice-candidates ()
5968 (require 'advice)
5969 (loop for (fname) in ad-advised-functions
5970 for function = (intern fname)
5971 append
5972 (loop for class in ad-advice-classes append
5973 (loop for advice in (ad-get-advice-info-field function class)
5974 for enabled = (ad-advice-enabled advice)
5975 collect
5976 (cons (format
5977 "%s %s %s"
5978 (if enabled "Enabled " "Disabled")
5979 (propertize fname 'face 'font-lock-function-name-face)
5980 (ad-make-single-advice-docstring advice class nil))
5981 (list function class advice))))))
5983 (defun anything-c-advice-persistent-action (func-class-advice)
5984 (if current-prefix-arg
5985 (anything-c-advice-toggle func-class-advice)
5986 (describe-function (car func-class-advice))))
5988 (defun anything-c-advice-toggle (func-class-advice)
5989 (destructuring-bind (function class advice) func-class-advice
5990 (cond ((ad-advice-enabled advice)
5991 (ad-advice-set-enabled advice nil)
5992 (message "Disabled"))
5993 (t ;disabled
5994 (ad-advice-set-enabled advice t)
5995 (message "Enabled")))
5996 (ad-activate function)
5997 (and anything-in-persistent-action
5998 (anything-c-advice-update-current-display-string))))
6000 (defun anything-c-advice-update-current-display-string ()
6001 (anything-edit-current-selection
6002 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6003 ((looking-at "Enabled") "Disabled")))
6004 realvalue)
6005 (when newword
6006 (delete-region (point) (progn (forward-word 1) (point)))
6007 (insert newword)))))
6010 ;;;; <Variable>
6011 ;;; Emacs variables
6014 (defvar anything-c-source-emacs-variables
6015 '((name . "Emacs Variables")
6016 (candidates . (lambda ()
6017 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6018 (type . variable)
6019 (requires-pattern . 2))
6020 "Source for completing Emacs variables.")
6021 ;; (anything 'anything-c-source-emacs-variables)
6024 ;;; LaCarte
6025 (defvar anything-c-source-lacarte
6026 '((name . "Lacarte")
6027 (init . (lambda () (require 'lacarte )))
6028 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6029 (candidate-number-limit . 9999)
6030 (action . anything-c-call-interactively))
6031 "Needs lacarte.el.
6033 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6034 ;; (anything 'anything-c-source-lacarte)
6037 ;;; Bookmarks
6040 ;; Bind some faces for bookmarks.
6041 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6042 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6043 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6045 (eval-when-compile (require 'bookmark))
6046 (defvar anything-c-source-bookmarks
6047 '((name . "Bookmarks")
6048 (init . (lambda ()
6049 (require 'bookmark)))
6050 (candidates . bookmark-all-names)
6051 (type . bookmark))
6052 "See (info \"(emacs)Bookmarks\").")
6053 ;; (anything 'anything-c-source-bookmarks)
6055 ;;; bookmark-set
6056 (defvar anything-c-source-bookmark-set
6057 '((name . "Set Bookmark")
6058 (dummy)
6059 (action . bookmark-set))
6060 "See (info \"(emacs)Bookmarks\").")
6061 ;; (anything 'anything-c-source-bookmark-set)
6063 ;;; Visible Bookmarks
6064 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6067 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6068 (defvar anything-c-source-bm
6069 '((name . "Visible Bookmarks")
6070 (init . anything-c-bm-init)
6071 (candidates-in-buffer)
6072 (type . line))
6073 "Needs bm.el.
6075 http://www.nongnu.org/bm/")
6077 (defun anything-c-bm-init ()
6078 "Init function for `anything-c-source-bm'."
6079 (when (require 'bm nil t)
6080 (with-no-warnings
6081 (let ((bookmarks (bm-lists))
6082 (buf (anything-candidate-buffer 'global)))
6083 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6084 '< :key 'overlay-start))
6085 (let ((start (overlay-start bm))
6086 (end (overlay-end bm))
6087 (annotation (or (overlay-get bm 'annotation) "")))
6088 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6089 (let ((str (format "%5d: [%s]: %s\n"
6090 (line-number-at-pos start)
6091 annotation
6092 (buffer-substring start (1- end)))))
6093 (with-current-buffer buf (insert str))))))))))
6095 ;;; Special bookmarks
6096 (defvar anything-c-source-bookmarks-ssh
6097 '((name . "Bookmarks-ssh")
6098 (init . (lambda ()
6099 (require 'bookmark)))
6100 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6101 (type . bookmark))
6102 "See (info \"(emacs)Bookmarks\").")
6103 ;; (anything 'anything-c-source-bookmarks-ssh)
6105 (defvar anything-c-source-bookmarks-su
6106 '((name . "Bookmarks-root")
6107 (init . (lambda ()
6108 (require 'bookmark)))
6109 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6110 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6112 (type . bookmark))
6113 "See (info \"(emacs)Bookmarks\").")
6114 ;; (anything 'anything-c-source-bookmarks-su)
6116 (defvar anything-c-source-bookmarks-local
6117 '((name . "Bookmarks-Local")
6118 (init . (lambda ()
6119 (require 'bookmark)))
6120 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6121 (filtered-candidate-transformer
6122 anything-c-adaptive-sort
6123 anything-c-highlight-bookmark)
6124 (type . bookmark))
6125 "See (info \"(emacs)Bookmarks\").")
6126 ;; (anything 'anything-c-source-bookmarks-local)
6128 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6129 (let* ((lis-all (bookmark-all-names))
6130 (lis-loc (cond (local (loop for i in lis-all
6131 unless (string-match "^(ssh)\\|^(su)" i)
6132 collect i))
6133 (su (loop for i in lis-all
6134 when (string-match "^(su)" i)
6135 collect i))
6136 (sudo (loop for i in lis-all
6137 when (string-match "^(sudo)" i)
6138 collect i))
6139 (ssh (loop for i in lis-all
6140 when (string-match "^(ssh)" i)
6141 collect i)))))
6142 (sort lis-loc 'string-lessp)))
6144 (defun anything-c-bookmark-root-logged-p ()
6145 (catch 'break
6146 (dolist (i (mapcar #'buffer-name (buffer-list)))
6147 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6148 (throw 'break t)))))
6150 (defun anything-c-highlight-bookmark-su (files source)
6151 (if (anything-c-bookmark-root-logged-p)
6152 (anything-c-highlight-bookmark files source)
6153 (anything-c-highlight-not-logged files source)))
6155 (defun anything-c-highlight-not-logged (files source)
6156 (loop for i in files
6157 collect (propertize i 'face anything-c-bookmarks-face3)))
6159 (defun anything-c-highlight-bookmark (bookmarks source)
6160 "Used as `candidate-transformer' to colorize bookmarks.
6161 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6162 (loop for i in bookmarks
6163 for isfile = (bookmark-get-filename i)
6164 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6165 (bmkext-get-buffer-name i))
6166 for handlerp = (and (fboundp 'bookmark-get-handler)
6167 (bookmark-get-handler i))
6168 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6169 (bmkext-w3m-bookmark-p i))
6170 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6171 (bmkext-gnus-bookmark-p i))
6172 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6173 (bmkext-man-bookmark-p i))
6174 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6175 (bmkext-woman-bookmark-p i))
6176 for handlerp = (bookmark-get-handler i)
6177 for isannotation = (bookmark-get-annotation i)
6178 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6179 for isinfo = (eq handlerp 'Info-bookmark-jump)
6180 ;; Add a * if bookmark have annotation
6181 if (and isannotation (not (string-equal isannotation "")))
6182 do (setq i (concat "*" i))
6183 collect (cond (;; info buffers
6184 isinfo
6185 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6186 (;; w3m buffers
6187 isw3m
6188 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6189 (;; gnus buffers
6190 isgnus
6191 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6192 (;; Man Woman
6193 (or iswoman isman)
6194 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6195 (;; Addressbook
6196 isabook
6197 (propertize i 'face '((:foreground "Tomato"))))
6198 (;; directories
6199 (and isfile (file-directory-p isfile))
6200 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6201 (;; regular files
6203 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6207 ;;; Sources to filter bookmark-extensions bookmarks.
6210 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6211 ;; If you want to enable google-maps in addressbook you will need
6212 ;; Julien Danjou google-maps-el package available here:
6213 ;; http://julien.danjou.info/google-maps-el.html
6215 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6216 "Return a filtered `bookmark-alist' sorted alphabetically."
6217 (loop
6218 with alist = (if args
6219 (apply #'(lambda (x) (funcall fn x)) args)
6220 (funcall fn))
6221 for i in alist
6222 for b = (car i)
6223 collect b into sa
6224 finally return (sort sa 'string-lessp)))
6226 ;;; Addressbook.
6229 (defvar anything-c-source-bmkext-addressbook
6230 '((name . "Bookmark Addressbook")
6231 (init . (lambda ()
6232 (require 'bookmark-extensions)
6233 (bookmark-maybe-load-default-file)))
6234 (candidates . anything-c-bmkext-addressbook-setup-alist)
6235 (persistent-action
6236 . (lambda (candidate)
6237 (let ((bmk (anything-bookmark-get-bookmark-from-name
6238 candidate)))
6239 (bookmark--jump-via bmk 'pop-to-buffer))))
6240 (persistent-help . "Show contact - Prefix with C-u to append")
6241 (filtered-candidate-transformer
6242 anything-c-adaptive-sort
6243 anything-c-highlight-bookmark)
6244 (action . (("Show Contact(s)"
6245 . (lambda (candidate)
6246 (let* ((contacts (anything-marked-candidates))
6247 (current-prefix-arg (or anything-current-prefix-arg
6248 (> (length contacts) 1))))
6249 (bookmark-jump
6250 (anything-bookmark-get-bookmark-from-name (car contacts)))
6251 (anything-aif (cdr contacts)
6252 (loop for bmk in it do
6253 (bookmark-jump
6254 (anything-bookmark-get-bookmark-from-name bmk)))))))
6255 ("Send Mail"
6256 . (lambda (candidate)
6257 (let* ((contacts (anything-marked-candidates))
6258 (bmk (anything-bookmark-get-bookmark-from-name
6259 (car contacts)))
6260 (append (message-buffers)))
6261 (if append
6262 (addressbook-set-mail-buffer1 bmk 'append)
6263 (addressbook-set-mail-buffer1 bmk))
6264 (setq contacts (cdr contacts))
6265 (when contacts
6266 (loop for bmk in contacts do
6267 (addressbook-set-mail-buffer1 bmk 'append))))))
6268 ("Edit Bookmark"
6269 . (lambda (candidate)
6270 (let ((bmk (anything-bookmark-get-bookmark-from-name
6271 candidate)))
6272 (addressbook-bookmark-edit
6273 (assoc bmk bookmark-alist)))))
6274 ("Insert Email at point"
6275 . (lambda (candidate)
6276 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6277 candidate))
6278 (mlist (split-string
6279 (assoc-default
6280 'email (assoc bmk bookmark-alist))
6281 ", ")))
6282 (insert
6283 (if (> (length mlist) 1)
6284 (anything-comp-read
6285 "Insert Mail Address: " mlist :must-match t)
6286 (car mlist))))))
6287 ("Show annotation"
6288 . (lambda (candidate)
6289 (let ((bmk (anything-bookmark-get-bookmark-from-name
6290 candidate)))
6291 (bookmark-show-annotation bmk))))
6292 ("Edit annotation"
6293 . (lambda (candidate)
6294 (let ((bmk (anything-bookmark-get-bookmark-from-name
6295 candidate)))
6296 (bookmark-edit-annotation bmk))))
6297 ("Show Google map"
6298 . (lambda (candidate)
6299 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6300 candidate))
6301 (full-bmk (assoc bmk bookmark-alist)))
6302 (addressbook-google-map full-bmk))))))))
6305 (defun anything-c-bmkext-addressbook-setup-alist ()
6306 "Specialized filter function for bookmarks w3m."
6307 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6309 ;; W3m bookmarks from bookmark-extensions.
6310 (defvar anything-c-source-bookmark-w3m
6311 '((name . "Bookmark W3m")
6312 (init . (lambda ()
6313 (require 'bookmark-extensions)
6314 (bookmark-maybe-load-default-file)))
6315 (candidates . anything-c-bookmark-w3m-setup-alist)
6316 (filtered-candidate-transformer
6317 anything-c-adaptive-sort
6318 anything-c-highlight-bookmark)
6319 (type . bookmark)))
6320 ;; (anything 'anything-c-source-bookmark-w3m)
6322 (defun anything-c-bookmark-w3m-setup-alist ()
6323 "Specialized filter function for bookmarks w3m."
6324 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6326 ;; Images
6327 (defvar anything-c-source-bookmark-images
6328 '((name . "Bookmark Images")
6329 (init . (lambda ()
6330 (require 'bookmark-extensions)
6331 (bookmark-maybe-load-default-file)))
6332 (candidates . anything-c-bookmark-images-setup-alist)
6333 (filtered-candidate-transformer
6334 anything-c-adaptive-sort
6335 anything-c-highlight-bookmark)
6336 (type . bookmark)))
6337 ;; (anything 'anything-c-source-bookmark-images)
6339 (defun anything-c-bookmark-images-setup-alist ()
6340 "Specialized filter function for images bookmarks."
6341 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6343 ;; Woman Man
6344 (defvar anything-c-source-bookmark-man
6345 '((name . "Bookmark Woman&Man")
6346 (init . (lambda ()
6347 (require 'bookmark-extensions)
6348 (bookmark-maybe-load-default-file)))
6349 (candidates . anything-c-bookmark-man-setup-alist)
6350 (filtered-candidate-transformer
6351 anything-c-adaptive-sort
6352 anything-c-highlight-bookmark)
6353 (type . bookmark)))
6354 ;; (anything 'anything-c-source-bookmark-man)
6356 (defun anything-c-bookmark-man-setup-alist ()
6357 "Specialized filter function for bookmarks w3m."
6358 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6359 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6361 ;; Gnus
6362 (defvar anything-c-source-bookmark-gnus
6363 '((name . "Bookmark Gnus")
6364 (init . (lambda ()
6365 (require 'bookmark-extensions)
6366 (bookmark-maybe-load-default-file)))
6367 (candidates . anything-c-bookmark-gnus-setup-alist)
6368 (filtered-candidate-transformer
6369 anything-c-adaptive-sort
6370 anything-c-highlight-bookmark)
6371 (type . bookmark)))
6372 ;; (anything 'anything-c-source-bookmark-gnus)
6374 (defun anything-c-bookmark-gnus-setup-alist ()
6375 "Specialized filter function for bookmarks gnus."
6376 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6378 ;; Info
6379 (defvar anything-c-source-bookmark-info
6380 '((name . "Bookmark Info")
6381 (init . (lambda ()
6382 (require 'bookmark-extensions)
6383 (bookmark-maybe-load-default-file)))
6384 (candidates . anything-c-bookmark-info-setup-alist)
6385 (filtered-candidate-transformer
6386 anything-c-adaptive-sort
6387 anything-c-highlight-bookmark)
6388 (type . bookmark)))
6389 ;; (anything 'anything-c-source-bookmark-info)
6391 (defun anything-c-bookmark-info-setup-alist ()
6392 "Specialized filter function for bookmarks info."
6393 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6395 ;; Local Files&directories
6396 (defvar anything-c-source-bookmark-files&dirs
6397 '((name . "Bookmark Files&Directories")
6398 (init . (lambda ()
6399 (require 'bookmark-extensions)
6400 (bookmark-maybe-load-default-file)))
6401 (candidates . anything-c-bookmark-local-files-setup-alist)
6402 (filtered-candidate-transformer
6403 anything-c-adaptive-sort
6404 anything-c-highlight-bookmark)
6405 (type . bookmark)))
6406 ;; (anything 'anything-c-source-bookmark-files&dirs)
6408 (defun anything-c-bookmark-local-files-setup-alist ()
6409 "Specialized filter function for bookmarks locals files."
6410 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6412 ;; Su Files&directories
6413 (defvar anything-c-source-bookmark-su-files&dirs
6414 '((name . "Bookmark Root-Files&Directories")
6415 (init . (lambda ()
6416 (require 'bookmark-extensions)
6417 (bookmark-maybe-load-default-file)))
6418 (candidates . anything-c-bookmark-su-files-setup-alist)
6419 (filtered-candidate-transformer
6420 anything-c-adaptive-sort
6421 anything-c-highlight-bookmark-su)
6422 (type . bookmark)))
6423 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6425 (defun anything-c-bookmark-su-files-setup-alist ()
6426 "Specialized filter function for bookmarks su/sudo files."
6427 (declare (special bmkext-su-or-sudo-regexp))
6428 (loop
6429 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6430 for i in l
6431 for isfile = (bookmark-get-filename i)
6432 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6433 (save-match-data
6434 (string-match tramp-file-name-regexp isfile)))
6435 for issu = (and istramp
6436 (string-match bmkext-su-or-sudo-regexp isfile))
6437 if issu
6438 collect i))
6440 ;; Ssh Files&directories
6441 (defvar anything-c-source-bookmark-ssh-files&dirs
6442 '((name . "Bookmark Ssh-Files&Directories")
6443 (init . (lambda ()
6444 (require 'bookmark-extensions)
6445 (bookmark-maybe-load-default-file)))
6446 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6447 (filtered-candidate-transformer . anything-c-adaptive-sort)
6448 (type . bookmark)))
6449 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6451 (defun anything-c-bookmark-ssh-files-setup-alist ()
6452 "Specialized filter function for bookmarks ssh files."
6453 (loop
6454 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6455 for i in l
6456 for isfile = (bookmark-get-filename i)
6457 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6458 (save-match-data
6459 (string-match tramp-file-name-regexp isfile)))
6460 for isssh = (and istramp
6461 (string-match "/ssh:" isfile))
6462 if isssh
6463 collect i))
6467 ;;; Firefox bookmarks
6470 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6471 ;; (only for firefox versions >=3)
6472 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6473 ;; to true:
6474 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6475 ;; You should have now:
6476 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6478 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6479 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6481 (defun anything-get-firefox-user-init-dir ()
6482 "Guess the default Firefox user directory name."
6483 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6484 (moz-user-dir
6485 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6486 (goto-char (point-min))
6487 (prog1
6488 (when (search-forward "Path=" nil t)
6489 (buffer-substring-no-properties (point) (point-at-eol)))
6490 (kill-buffer)))))
6491 (file-name-as-directory (concat moz-dir moz-user-dir))))
6493 (defun anything-guess-firefox-bookmark-file ()
6494 "Return the path of the Firefox bookmarks file."
6495 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6497 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6498 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6499 (let (bookmarks-alist url title)
6500 (with-temp-buffer
6501 (insert-file-contents file)
6502 (goto-char (point-min))
6503 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6504 (forward-line 0)
6505 (when (re-search-forward url-regexp nil t)
6506 (setq url (match-string 0)))
6507 (when (re-search-forward bmk-regexp nil t)
6508 (setq title (match-string 1)))
6509 (push (cons title url) bookmarks-alist)
6510 (forward-line)))
6511 (nreverse bookmarks-alist)))
6513 (defvar anything-c-firefox-bookmarks-alist nil)
6514 (defvar anything-c-source-firefox-bookmarks
6515 '((name . "Firefox Bookmarks")
6516 (init . (lambda ()
6517 (setq anything-c-firefox-bookmarks-alist
6518 (anything-html-bookmarks-to-alist
6519 (anything-guess-firefox-bookmark-file)
6520 anything-firefox-bookmark-url-regexp
6521 anything-firefox-bookmarks-regexp))))
6522 (candidates . (lambda ()
6523 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6524 (filtered-candidate-transformer
6525 anything-c-adaptive-sort
6526 anything-c-highlight-firefox-bookmarks)
6527 (action . (("Browse Url Firefox"
6528 . (lambda (candidate)
6529 (browse-url-firefox
6530 (anything-c-firefox-bookmarks-get-value candidate))))
6531 ("Browse Url w3m"
6532 . (lambda (candidate)
6533 (w3m-browse-url
6534 (anything-c-firefox-bookmarks-get-value candidate))))
6535 ("Copy Url"
6536 . (lambda (elm)
6537 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6539 ;; (anything 'anything-c-source-firefox-bookmarks)
6541 (defun anything-c-firefox-bookmarks-get-value (elm)
6542 (assoc-default elm anything-c-firefox-bookmarks-alist))
6544 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6545 (loop for i in bookmarks
6546 collect (propertize
6547 i 'face '((:foreground "YellowGreen"))
6548 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6552 ;;; W3m bookmark - anything interface.
6555 ;; Some users have the emacs-w3m library in load-path
6556 ;; without having the w3m executable :-;
6557 ;; So check if w3m program is present before trying to load
6558 ;; emacs-w3m.
6559 (eval-when-compile
6560 (when (executable-find "w3m")
6561 (require 'w3m-bookmark nil t)))
6563 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6564 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6565 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6566 (defvar anything-c-w3m-bookmarks-alist nil)
6567 (defvar anything-c-source-w3m-bookmarks
6568 '((name . "W3m Bookmarks")
6569 (init . (lambda ()
6570 (setq anything-c-w3m-bookmarks-alist
6571 (anything-html-bookmarks-to-alist
6572 w3m-bookmark-file
6573 anything-w3m-bookmark-url-regexp
6574 anything-w3m-bookmarks-regexp))))
6575 (candidates . (lambda ()
6576 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6577 (filtered-candidate-transformer
6578 anything-c-adaptive-sort
6579 anything-c-highlight-w3m-bookmarks)
6580 (action . (("Browse Url"
6581 . (lambda (candidate)
6582 (anything-c-w3m-browse-bookmark candidate)))
6583 ("Copy Url"
6584 . (lambda (elm)
6585 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6586 ("Browse Url Firefox"
6587 . (lambda (candidate)
6588 (anything-c-w3m-browse-bookmark candidate t)))
6589 ("Delete Bookmark"
6590 . (lambda (candidate)
6591 (anything-c-w3m-delete-bookmark candidate)))
6592 ("Rename Bookmark"
6593 . (lambda (candidate)
6594 (anything-c-w3m-rename-bookmark candidate)))))
6595 (persistent-action . (lambda (candidate)
6596 (if current-prefix-arg
6597 (anything-c-w3m-browse-bookmark candidate t)
6598 (anything-c-w3m-browse-bookmark candidate nil t))))
6599 (persistent-help . "Open URL with emacs-w3m in new tab / \
6600 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6601 "Needs w3m and emacs-w3m.
6603 http://w3m.sourceforge.net/
6604 http://emacs-w3m.namazu.org/")
6606 ;; (anything 'anything-c-source-w3m-bookmarks)
6608 (defun anything-c-w3m-bookmarks-get-value (elm)
6609 (replace-regexp-in-string
6610 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6612 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6613 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6614 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6615 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6617 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6618 (loop for i in bookmarks
6619 collect (propertize
6620 i 'face 'anything-w3m-bookmarks-face
6621 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6624 (defun anything-c-w3m-delete-bookmark (elm)
6625 "Delete w3m bookmark from `w3m-bookmark-file'."
6626 (with-current-buffer
6627 (find-file-literally w3m-bookmark-file)
6628 (goto-char (point-min))
6629 (when (re-search-forward elm nil t)
6630 (beginning-of-line)
6631 (delete-region (point)
6632 (line-end-position))
6633 (delete-blank-lines))
6634 (save-buffer)
6635 (kill-buffer)))
6637 (defun anything-c-w3m-rename-bookmark (elm)
6638 "Rename w3m bookmark in `w3m-bookmark-file'."
6639 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6640 (new-title (read-string "NewTitle: " old-title)))
6641 (with-current-buffer
6642 (find-file-literally w3m-bookmark-file)
6643 (goto-char (point-min))
6644 (when (re-search-forward (concat elm "<") nil t)
6645 (goto-char (1- (point)))
6646 (delete-char (- (length old-title)))
6647 (insert new-title))
6648 (save-buffer)
6649 (kill-buffer))))
6652 ;;;; <Library>
6653 ;;; Elisp library scan
6656 (defvar anything-c-source-elisp-library-scan
6657 '((name . "Elisp libraries (Scan)")
6658 (init . (anything-c-elisp-library-scan-init))
6659 (candidates-in-buffer)
6660 (action ("Find library"
6661 . (lambda (candidate) (find-file (find-library-name candidate))))
6662 ("Find library other window"
6663 . (lambda (candidate)
6664 (find-file-other-window (find-library-name candidate))))
6665 ("Load library"
6666 . (lambda (candidate) (load-library candidate))))))
6667 ;; (anything 'anything-c-source-elisp-library-scan)
6669 (defun anything-c-elisp-library-scan-init ()
6670 "Init anything buffer status."
6671 (let ((anything-buffer (anything-candidate-buffer 'global))
6672 (library-list (anything-c-elisp-library-scan-list)))
6673 (with-current-buffer anything-buffer
6674 (dolist (library library-list)
6675 (insert (format "%s\n" library))))))
6677 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6678 "Do completion for file names passed to `locate-file'.
6679 DIRS is directory to search path.
6680 STRING is string to match."
6681 ;; Use `load-path' as path when ignore `dirs'.
6682 (or dirs (setq dirs load-path))
6683 ;; Init with blank when ignore `string'.
6684 (or string (setq string ""))
6685 ;; Get library list.
6686 (let ((string-dir (file-name-directory string))
6687 ;; File regexp that suffix match `load-file-rep-suffixes'.
6688 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6689 name
6690 names)
6691 (dolist (dir dirs)
6692 (unless dir
6693 (setq dir default-directory))
6694 (if string-dir
6695 (setq dir (expand-file-name string-dir dir)))
6696 (when (file-directory-p dir)
6697 (dolist (file (file-name-all-completions
6698 (file-name-nondirectory string) dir))
6699 ;; Suffixes match `load-file-rep-suffixes'.
6700 (setq name (if string-dir (concat string-dir file) file))
6701 (if (string-match match-regexp name)
6702 (add-to-list 'names name)))))
6703 names))
6706 ;;;; <Programming>
6710 ;;; Imenu
6713 (defvar anything-c-imenu-delimiter " / ")
6715 (defvar anything-c-imenu-index-filter nil)
6716 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6718 (defvar anything-c-cached-imenu-alist nil)
6719 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6721 (defvar anything-c-cached-imenu-candidates nil)
6722 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6724 (defvar anything-c-cached-imenu-tick nil)
6725 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6727 (eval-when-compile (require 'imenu))
6728 (setq imenu-auto-rescan t)
6730 (defun anything-imenu-create-candidates (entry)
6731 "Create candidates with ENTRY."
6732 (if (listp (cdr entry))
6733 (mapcan
6734 (lambda (sub)
6735 (if (consp (cdr sub))
6736 (mapcar
6737 (lambda (subentry)
6738 (concat (car entry) anything-c-imenu-delimiter subentry))
6739 (anything-imenu-create-candidates sub))
6740 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6741 (cdr entry))
6742 (list entry)))
6744 (defvar anything-c-source-imenu
6745 '((name . "Imenu")
6746 (init . (lambda () (require 'imenu)))
6747 (candidates . anything-c-imenu-candidates)
6748 (persistent-action . (lambda (elm)
6749 (anything-c-imenu-default-action elm)
6750 (unless (fboundp 'semantic-imenu-tag-overlay)
6751 (anything-match-line-color-current-line))))
6752 (persistent-help . "Show this entry")
6753 (action . anything-c-imenu-default-action))
6754 "See (info \"(emacs)Imenu\")")
6756 ;; (anything 'anything-c-source-imenu)
6758 (defun anything-c-imenu-candidates ()
6759 (with-anything-current-buffer
6760 (let ((tick (buffer-modified-tick)))
6761 (if (eq anything-c-cached-imenu-tick tick)
6762 anything-c-cached-imenu-candidates
6763 (setq imenu--index-alist nil)
6764 (setq anything-c-cached-imenu-tick tick
6765 anything-c-cached-imenu-candidates
6766 (ignore-errors
6767 (mapcan
6768 'anything-imenu-create-candidates
6769 (setq anything-c-cached-imenu-alist
6770 (let ((index (imenu--make-index-alist)))
6771 (if anything-c-imenu-index-filter
6772 (funcall anything-c-imenu-index-filter index)
6773 index))))))
6774 (setq anything-c-cached-imenu-candidates
6775 (mapcar #'(lambda (x)
6776 (if (stringp x)
6778 (car x)))
6779 anything-c-cached-imenu-candidates))))))
6781 (setq imenu-default-goto-function 'imenu-default-goto-function)
6782 (defun anything-c-imenu-default-action (elm)
6783 "The default action for `anything-c-source-imenu'."
6784 (let ((path (split-string elm anything-c-imenu-delimiter))
6785 (alist anything-c-cached-imenu-alist))
6786 (dolist (elm path)
6787 (setq alist (assoc elm alist)))
6788 (imenu alist)))
6792 ;;; Ctags
6795 (defvar anything-c-ctags-modes
6796 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6797 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6798 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6800 (defun anything-c-source-ctags-init ()
6801 (when (and buffer-file-name
6802 (memq major-mode anything-c-ctags-modes)
6803 (anything-current-buffer-is-modified))
6804 (with-current-buffer (anything-candidate-buffer 'local)
6805 (call-process-shell-command
6806 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6807 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6808 anything-buffer-file-name)
6809 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6810 nil (current-buffer))
6811 (goto-char (point-min))
6812 (forward-line 2)
6813 (delete-region (point-min) (point))
6814 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6815 for lineno-start = (point)
6816 for lineno = (buffer-substring
6817 lineno-start
6818 (1- (search-forward "," (point-at-eol) t)))
6820 (beginning-of-line)
6821 (insert (format "%5s:" lineno))
6822 (search-forward "\177" (point-at-eol) t)
6823 (delete-region (1- (point)) (point-at-eol))
6824 (forward-line 1)))))
6826 (defvar anything-c-source-ctags
6827 '((name . "Exuberant ctags")
6828 (init . anything-c-source-ctags-init)
6829 (candidates-in-buffer)
6830 (adjust)
6831 (type . line))
6832 "Needs Exuberant Ctags.
6834 http://ctags.sourceforge.net/")
6835 ;; (anything 'anything-c-source-ctags)
6838 ;;; Etags
6841 ;; anything-etags.el is deprecated, if this file is found,
6842 ;; warn user at compile time.
6843 (eval-when-compile
6844 (when (locate-library "anything-etags.el")
6845 (display-warning
6846 '(anything-config)
6847 "You are using obsolete library `anything-etags.el' and should remove it."
6848 :warning)))
6850 (defvar anything-c-etags-tag-file-dir nil
6851 "Etags file directory.")
6852 (defvar anything-c-etags-mtime-alist nil
6853 "Store the last modification time of etags files here.")
6854 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6855 "Cache content of etags files used here for faster access.")
6857 (defun anything-c-etags-get-tag-file (&optional directory)
6858 "Return the path of etags file if found."
6859 ;; Get tag file from `default-directory' or upper directory.
6860 (let ((current-dir (anything-c-etags-find-tag-file-directory
6861 (or directory default-directory))))
6862 ;; Return nil if not find tag file.
6863 (when current-dir
6864 ;; Set tag file directory.
6865 (setq anything-c-etags-tag-file-dir current-dir)
6866 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6868 (defun anything-c-etags-find-tag-file-directory (current-dir)
6869 "Try to find the directory containing tag file.
6870 If not found in CURRENT-DIR search in upper directory."
6871 (flet ((file-exists? (dir)
6872 (let ((tag-path (expand-file-name
6873 anything-c-etags-tag-file-name dir)))
6874 (and (stringp tag-path)
6875 (file-exists-p tag-path)
6876 (file-readable-p tag-path)))))
6877 (loop with count = 0
6878 until (file-exists? current-dir)
6879 ;; Return nil if outside the value of
6880 ;; `anything-c-etags-tag-file-search-limit'.
6881 if (= count anything-c-etags-tag-file-search-limit)
6882 do (return nil)
6883 ;; Or search upper directories.
6884 else
6885 do (incf count)
6886 (setq current-dir (expand-file-name (concat current-dir "../")))
6887 finally return current-dir)))
6889 (defun anything-c-source-etags-header-name (x)
6890 "Create header name for this anything etags session."
6891 (concat "Etags in "
6892 (with-anything-current-buffer
6893 (anything-c-etags-get-tag-file))))
6895 (defmacro anything-c-etags-create-buffer (file)
6896 "Create the `anything-buffer' based on contents of etags tag FILE."
6897 `(let* ((tag-fname ,file)
6899 (split (with-current-buffer (find-file-noselect tag-fname)
6900 (prog1
6901 (split-string (buffer-string) "\n" 'omit-nulls)
6902 (setq max (line-number-at-pos (point-max)))
6903 (kill-buffer))))
6904 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6905 (loop
6906 with fname
6907 with cand
6908 for i in split for count from 0
6909 for elm = (unless (string-match "^\x0c" i)
6910 (anything-aif (string-match "\177" i)
6911 (substring i 0 it)
6913 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6914 (setq fname (match-string 1 elm)))
6915 (elm (setq cand (concat fname ": " elm)))
6916 (t (setq cand nil)))
6917 when cand do (progn
6918 (insert (concat cand "\n"))
6919 (progress-reporter-update progress-reporter count)))))
6921 (defun anything-c-etags-init ()
6922 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6923 If no entry in cache, create one."
6924 (let ((tagfile (anything-c-etags-get-tag-file)))
6925 (when tagfile
6926 (with-current-buffer (anything-candidate-buffer 'global)
6927 (anything-aif (gethash tagfile anything-c-etags-cache)
6928 ;; An entry is present in cache, insert it.
6929 (insert it)
6930 ;; No entry, create a new buffer using content of tag file (slower).
6931 (anything-c-etags-create-buffer tagfile)
6932 ;; Store content of buffer in cache.
6933 (puthash tagfile (buffer-string) anything-c-etags-cache)
6934 ;; Store or set the last modification of tag file.
6935 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6936 ;; If an entry exists modify it.
6937 (setcdr it (anything-c-etags-mtime tagfile))
6938 ;; No entry create a new one.
6939 (add-to-list 'anything-c-etags-mtime-alist
6940 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6942 (defvar anything-c-source-etags-select
6943 '((name . "Etags")
6944 (header-name . anything-c-source-etags-header-name)
6945 (init . anything-c-etags-init)
6946 (candidates-in-buffer)
6947 (search . (anything-c-etags-search-fn))
6948 (mode-line . anything-etags-mode-line-string)
6949 (action . anything-c-etags-default-action)
6950 (persistent-action . (lambda (candidate)
6951 (anything-c-etags-default-action candidate)
6952 (anything-match-line-color-current-line))))
6953 "Anything source for Etags.")
6955 (defun anything-c-etags-search-fn (pattern bound noerror)
6956 "Search function for `anything-c-source-etags-select'."
6957 (re-search-forward
6958 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6959 bound noerror))
6961 (defun anything-c-etags-default-action (candidate)
6962 "Anything default action to jump to an etags entry."
6963 (let* ((split (split-string candidate ": "))
6964 (fname (expand-file-name
6965 (car split) anything-c-etags-tag-file-dir))
6966 (elm (cadr split)))
6967 (find-file fname)
6968 (goto-char (point-min))
6969 (search-forward elm nil t)
6970 (goto-char (match-beginning 0))))
6972 (defun anything-c-etags-mtime (file)
6973 "Last modification time of etags tag FILE."
6974 (cadr (nth 5 (file-attributes file))))
6976 (defun anything-c-etags-file-modified-p (file)
6977 "Check if tag FILE have been modified in this session.
6978 If FILE is nil return nil."
6979 (let ((last-modif (and file
6980 (assoc-default file anything-c-etags-mtime-alist))))
6981 (and last-modif
6982 (/= last-modif (anything-c-etags-mtime file)))))
6986 ;;; Semantic
6989 (defvar anything-semantic-candidates nil)
6991 (defun anything-semantic-construct-candidates (tags depth)
6992 (when (require 'semantic nil t)
6993 (apply
6994 'append
6995 (mapcar
6996 (lambda (tag)
6997 (if (listp tag)
6998 (let ((type (semantic-tag-type tag))
6999 (class (semantic-tag-class tag)))
7000 (if (or (and (stringp type)
7001 (or (string= type "class")
7002 (string= type "namespace")))
7003 (eq class 'function)
7004 (eq class 'variable))
7005 (cons (cons (concat (make-string (* depth 2) ?\s)
7006 (semantic-format-tag-summarize tag nil t))
7007 tag)
7008 (anything-semantic-construct-candidates
7009 (semantic-tag-components tag) (1+ depth)))))))
7010 tags))))
7012 (defun anything-semantic-default-action (candidate)
7013 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7014 (semantic-go-to-tag tag)))
7016 (defvar anything-c-source-semantic
7017 '((name . "Semantic Tags")
7018 (init . (lambda ()
7019 (setq anything-semantic-candidates
7020 (ignore-errors (anything-semantic-construct-candidates
7021 (semantic-fetch-tags) 0)))))
7022 (candidates . (lambda ()
7023 (if anything-semantic-candidates
7024 (mapcar 'car anything-semantic-candidates))))
7025 (persistent-action . (lambda (elm)
7026 (anything-semantic-default-action elm)
7027 (anything-match-line-color-current-line)))
7028 (persistent-help . "Show this entry")
7029 (action . anything-semantic-default-action)
7030 "Needs semantic in CEDET.
7032 http://cedet.sourceforge.net/semantic.shtml
7033 http://cedet.sourceforge.net/"))
7035 ;; (anything 'anything-c-source-semantic)
7038 ;;; Anything interface of `simple-call-tree.el'.
7040 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7042 ;; Function is called by
7043 (defvar anything-c-source-simple-call-tree-functions-callers
7044 '((name . "Function is called by")
7045 (init . anything-c-simple-call-tree-functions-callers-init)
7046 (multiline)
7047 (candidates . anything-c-simple-call-tree-candidates)
7048 (persistent-action . anything-c-simple-call-tree-persistent-action)
7049 (persistent-help . "Show function definitions by rotation")
7050 (action ("Find definition selected by persistent-action" .
7051 anything-c-simple-call-tree-find-definition)))
7052 "Needs simple-call-tree.el.
7053 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7055 (defvar anything-c-simple-call-tree-tick nil)
7056 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7057 (defun anything-c-simple-call-tree-analyze-maybe ()
7058 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7059 (simple-call-tree-analyze)
7060 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7062 (defun anything-c-simple-call-tree-init-base (function message)
7063 (require 'simple-call-tree)
7064 (with-no-warnings
7065 (when (anything-current-buffer-is-modified)
7066 (anything-c-simple-call-tree-analyze-maybe)
7067 (let ((list (funcall function simple-call-tree-alist)))
7068 (with-current-buffer (anything-candidate-buffer 'local)
7069 (dolist (entry list)
7070 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7071 (insert (car entry) message
7072 (if (string= funcs " ")
7073 " no functions."
7074 funcs)
7075 "\n\n"))))))))
7077 (defun anything-c-simple-call-tree-functions-callers-init ()
7078 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7079 " is called by\n"))
7081 (defun anything-c-simple-call-tree-candidates ()
7082 (with-current-buffer (anything-candidate-buffer)
7083 (split-string (buffer-string) "\n\n")))
7085 (defvar anything-c-simple-call-tree-related-functions nil)
7086 (defvar anything-c-simple-call-tree-function-index 0)
7087 (defun anything-c-simple-call-tree-persistent-action (candidate)
7088 (unless (eq last-command 'anything-execute-persistent-action)
7089 (setq anything-c-simple-call-tree-related-functions
7090 (delete "no functions."
7091 (split-string
7092 (replace-regexp-in-string " \\| is called by\\| calls "
7093 "" candidate)
7094 "\n")))
7095 (setq anything-c-simple-call-tree-function-index -1))
7096 (incf anything-c-simple-call-tree-function-index)
7097 (anything-c-simple-call-tree-find-definition candidate))
7099 (defun anything-c-simple-call-tree-find-definition (candidate)
7100 (find-function
7101 (intern
7102 (nth (mod anything-c-simple-call-tree-function-index
7103 (length anything-c-simple-call-tree-related-functions))
7104 anything-c-simple-call-tree-related-functions))))
7106 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7108 ;;; Function calls
7109 (defvar anything-c-source-simple-call-tree-callers-functions
7110 '((name . "Function calls")
7111 (init . anything-c-simple-call-tree-callers-functions-init)
7112 (multiline)
7113 (candidates . anything-c-simple-call-tree-candidates)
7114 (persistent-action . anything-c-simple-call-tree-persistent-action)
7115 (persistent-help . "Show function definitions by rotation")
7116 (action ("Find definition selected by persistent-action" .
7117 anything-c-simple-call-tree-find-definition)))
7118 "Needs simple-call-tree.el.
7119 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7121 (defun anything-c-simple-call-tree-callers-functions-init ()
7122 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7124 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7128 ;;; Anything UI of auto-document.el
7130 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7132 ;; Commands/Options with doc
7133 (defvar anything-c-auto-document-data nil)
7134 (make-variable-buffer-local 'anything-c-auto-document-data)
7135 (defvar anything-c-source-commands-and-options-in-file
7136 '((name . "Commands/Options in file")
7137 (header-name
7138 . (lambda (x) (format "Commands/Options in %s"
7139 (buffer-local-value 'buffer-file-name
7140 anything-current-buffer))))
7141 (candidates . anything-command-and-options-candidates)
7142 (multiline)
7143 (action . imenu))
7144 "List Commands and Options with doc. It needs auto-document.el .
7146 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7148 (eval-when-compile (require 'auto-document nil t))
7149 (defun anything-command-and-options-candidates ()
7150 (with-anything-current-buffer
7151 (when (and (require 'auto-document nil t)
7152 (eq major-mode 'emacs-lisp-mode)
7153 (or (anything-current-buffer-is-modified)
7154 (not anything-c-auto-document-data)))
7155 (or imenu--index-alist (imenu--make-index-alist t))
7156 (setq anything-c-auto-document-data
7157 (destructuring-bind (commands options)
7158 (adoc-construct anything-current-buffer)
7159 (append
7160 (loop for (command . doc) in commands
7161 for cmdname = (symbol-name command)
7162 collect
7163 (cons
7164 (format "Command: %s\n %s"
7165 (propertize cmdname 'face font-lock-function-name-face)
7166 (adoc-first-line doc))
7167 (assoc cmdname imenu--index-alist)))
7168 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7169 for (option doc default) in options
7170 for optname = (symbol-name option)
7171 collect
7172 (cons
7173 (format "Option: %s\n %s\n default = %s"
7174 (propertize optname 'face font-lock-variable-name-face)
7175 (adoc-first-line doc)
7176 (adoc-prin1-to-string default))
7177 (assoc optname
7178 var-alist)))))))
7179 anything-c-auto-document-data))
7181 ;; (anything 'anything-c-source-commands-and-options-in-file)
7184 ;;;; <Color and Face>
7187 ;;; Customize Face
7190 (defvar anything-c-source-customize-face
7191 '((name . "Customize Face")
7192 (init . (lambda ()
7193 (unless (anything-candidate-buffer)
7194 (save-window-excursion (list-faces-display))
7195 (anything-candidate-buffer (get-buffer "*Faces*")))))
7196 (candidates-in-buffer)
7197 (get-line . buffer-substring)
7198 (action . (lambda (line)
7199 (customize-face (intern (car (split-string line))))))
7200 (requires-pattern . 3))
7201 "See (info \"(emacs)Faces\")")
7202 ;; (anything 'anything-c-source-customize-face)
7204 ;;; Colors browser
7207 (defvar anything-c-source-colors
7208 '((name . "Colors")
7209 (init . (lambda () (unless (anything-candidate-buffer)
7210 (save-window-excursion (list-colors-display))
7211 (anything-candidate-buffer (get-buffer "*Colors*")))))
7212 (candidates-in-buffer)
7213 (get-line . buffer-substring)
7214 (action
7215 ("Copy Name" . (lambda (candidate)
7216 (kill-new (anything-c-colors-get-name candidate))))
7217 ("Copy RGB" . (lambda (candidate)
7218 (kill-new (anything-c-colors-get-rgb candidate))))
7219 ("Insert Name" . (lambda (candidate)
7220 (with-anything-current-buffer
7221 (insert (anything-c-colors-get-name candidate)))))
7222 ("Insert RGB" . (lambda (candidate)
7223 (with-anything-current-buffer
7224 (insert (anything-c-colors-get-rgb candidate))))))))
7225 ;; (anything 'anything-c-source-colors)
7227 (defun anything-c-colors-get-name (candidate)
7228 "Get color name."
7229 (replace-regexp-in-string
7230 " " ""
7231 (with-temp-buffer
7232 (insert (capitalize candidate))
7233 (goto-char (point-min))
7234 (search-forward-regexp "\\s-\\{2,\\}")
7235 (delete-region (point) (point-max))
7236 (buffer-string))))
7238 (defun anything-c-colors-get-rgb (candidate)
7239 "Get color RGB."
7240 (replace-regexp-in-string
7241 " " ""
7242 (with-temp-buffer
7243 (insert (capitalize candidate))
7244 (goto-char (point-max))
7245 (search-backward-regexp "\\s-\\{2,\\}")
7246 (delete-region (point) (point-min))
7247 (buffer-string))))
7250 ;;;; <Search Engine>
7251 ;;; Tracker desktop search
7252 (defvar anything-c-source-tracker-search
7253 '((name . "Tracker Search")
7254 (candidates . (lambda ()
7255 (start-process "tracker-search-process" nil
7256 "tracker-search"
7257 anything-pattern)))
7258 (type . file)
7259 (requires-pattern . 3)
7260 (delayed))
7261 "Source for retrieving files matching the current input pattern
7262 with the tracker desktop search.")
7263 ;; (anything 'anything-c-source-tracker-search)
7265 ;;; Spotlight (MacOS X desktop search)
7266 (defvar anything-c-source-mac-spotlight
7267 '((name . "mdfind")
7268 (candidates
7269 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7270 (type . file)
7271 (requires-pattern . 3)
7272 (delayed))
7273 "Source for retrieving files via Spotlight's command line
7274 utility mdfind.")
7275 ;; (anything 'anything-c-source-mac-spotlight)
7277 ;;; Picklist
7278 (defvar anything-c-source-picklist
7279 '((name . "Picklist")
7280 (candidates . (lambda () (mapcar 'car picklist-list)))
7281 (type . file)))
7282 ;; (anything 'anything-c-source-picklist)
7286 ;;; Kill ring
7289 (defvar anything-c-source-kill-ring
7290 '((name . "Kill Ring")
7291 (init . (lambda () (anything-attrset 'last-command last-command)))
7292 (candidates . anything-c-kill-ring-candidates)
7293 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7294 (action . anything-c-kill-ring-action)
7295 (last-command)
7296 (migemo)
7297 (multiline))
7298 "Source for browse and insert contents of kill-ring.")
7300 (defun anything-c-kill-ring-candidates ()
7301 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7302 unless (or (< (length kill) anything-kill-ring-threshold)
7303 (string-match "^[\\s\\t]+$" kill))
7304 collect kill))
7306 (defun anything-c-kill-ring-transformer (candidates source)
7307 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7308 (loop for i in candidates
7309 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7310 if (and anything-c-kill-ring-max-lines-number
7311 (> nlines anything-c-kill-ring-max-lines-number))
7312 collect (cons
7313 (with-temp-buffer
7314 (insert i)
7315 (goto-char (point-min))
7316 (concat
7317 (buffer-substring
7318 (point-min)
7319 (save-excursion
7320 (forward-line anything-c-kill-ring-max-lines-number)
7321 (point)))
7322 "[...]")) i)
7323 else collect i))
7325 (defun anything-c-kill-ring-action (str)
7326 "Insert STR in `kill-ring' and set STR to the head.
7327 If this action is executed just after `yank',
7328 replace with STR as yanked string."
7329 (setq kill-ring (delete str kill-ring))
7330 (if (not (eq (anything-attr 'last-command) 'yank))
7331 (insert-for-yank str)
7332 ;; from `yank-pop'
7333 (let ((inhibit-read-only t)
7334 (before (< (point) (mark t))))
7335 (if before
7336 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7337 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7338 (setq yank-undo-function nil)
7339 (set-marker (mark-marker) (point) (current-buffer))
7340 (insert-for-yank str)
7341 ;; Set the window start back where it was in the yank command,
7342 ;; if possible.
7343 (set-window-start (selected-window) yank-window-start t)
7344 (if before
7345 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7346 ;; It is cleaner to avoid activation, even though the command
7347 ;; loop would deactivate the mark because we inserted text.
7348 (goto-char (prog1 (mark t)
7349 (set-marker (mark-marker) (point) (current-buffer)))))))
7350 (kill-new str))
7352 ;; (anything 'anything-c-source-kill-ring)
7355 ;;;; <Mark ring>
7356 ;; DO NOT include these sources in `anything-sources' use
7357 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7358 ;; `anything-all-mark-rings' instead.
7360 (defun anything-c-source-mark-ring-candidates ()
7361 (flet ((get-marks (pos)
7362 (save-excursion
7363 (goto-char pos)
7364 (beginning-of-line)
7365 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7366 (when (string= "" line)
7367 (setq line "<EMPTY LINE>"))
7368 (format "%7d: %s" (line-number-at-pos) line)))))
7369 (with-anything-current-buffer
7370 (loop
7371 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7372 with recip = nil
7373 for i in marks
7374 for m = (get-marks i)
7375 unless (member m recip)
7376 collect m into recip
7377 finally return recip))))
7379 (defvar anything-mark-ring-cache nil)
7380 (defvar anything-c-source-mark-ring
7381 '((name . "mark-ring")
7382 (init . (lambda ()
7383 (setq anything-mark-ring-cache
7384 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7385 (candidates . (lambda ()
7386 (anything-aif anything-mark-ring-cache
7387 it)))
7388 (action . (("Goto line"
7389 . (lambda (candidate)
7390 (anything-goto-line (string-to-number candidate))))))
7391 (persistent-action . (lambda (candidate)
7392 (anything-goto-line (string-to-number candidate))
7393 (anything-match-line-color-current-line)))
7394 (persistent-help . "Show this line")))
7396 ;; (anything 'anything-c-source-mark-ring)
7398 ;;; Global-mark-ring
7399 (defvar anything-c-source-global-mark-ring
7400 '((name . "global-mark-ring")
7401 (candidates . anything-c-source-global-mark-ring-candidates)
7402 (action . (("Goto line"
7403 . (lambda (candidate)
7404 (let ((items (split-string candidate ":")))
7405 (anything-c-switch-to-buffer (second items))
7406 (anything-goto-line (string-to-number (car items))))))))
7407 (persistent-action . (lambda (candidate)
7408 (let ((items (split-string candidate ":")))
7409 (anything-c-switch-to-buffer (second items))
7410 (anything-goto-line (string-to-number (car items)))
7411 (anything-match-line-color-current-line))))
7412 (persistent-help . "Show this line")))
7414 (defun anything-c-source-global-mark-ring-candidates ()
7415 (flet ((buf-fn (m)
7416 (with-current-buffer (marker-buffer m)
7417 (goto-char m)
7418 (beginning-of-line)
7419 (let (line)
7420 (if (string= "" line)
7421 (setq line "<EMPTY LINE>")
7422 (setq line (car (split-string (thing-at-point 'line)
7423 "[\n\r]"))))
7424 (format "%7d:%s: %s"
7425 (line-number-at-pos) (marker-buffer m) line)))))
7426 (loop
7427 with marks = global-mark-ring
7428 with recip = nil
7429 for i in marks
7430 for gm = (unless (or (string-match
7431 "^ " (format "%s" (marker-buffer i)))
7432 (null (marker-buffer i)))
7433 (buf-fn i))
7434 when (and gm (not (member gm recip)))
7435 collect gm into recip
7436 finally return recip)))
7438 ;; (anything 'anything-c-source-global-mark-ring)
7441 ;;;; <Register>
7442 ;;; Insert from register
7443 (defvar anything-c-source-register
7444 '((name . "Registers")
7445 (candidates . anything-c-register-candidates)
7446 (action-transformer . anything-c-register-action-transformer)
7447 (multiline)
7448 (action))
7449 "See (info \"(emacs)Registers\")")
7451 (defun anything-c-register-candidates ()
7452 "Collecting register contents and appropriate commands."
7453 (loop for (char . val) in register-alist
7454 for key = (single-key-description char)
7455 for string-actions =
7456 (cond
7457 ((numberp val)
7458 (list (int-to-string val)
7459 'insert-register
7460 'increment-register))
7461 ((markerp val)
7462 (let ((buf (marker-buffer val)))
7463 (if (null buf)
7464 (list "a marker in no buffer")
7465 (list (concat
7466 "a buffer position:"
7467 (buffer-name buf)
7468 ", position "
7469 (int-to-string (marker-position val)))
7470 'jump-to-register
7471 'insert-register))))
7472 ((and (consp val) (window-configuration-p (car val)))
7473 (list "window configuration."
7474 'jump-to-register))
7475 ((and (consp val) (frame-configuration-p (car val)))
7476 (list "frame configuration."
7477 'jump-to-register))
7478 ((and (consp val) (eq (car val) 'file))
7479 (list (concat "file:"
7480 (prin1-to-string (cdr val))
7481 ".")
7482 'jump-to-register))
7483 ((and (consp val) (eq (car val) 'file-query))
7484 (list (concat "file:a file-query reference: file "
7485 (car (cdr val))
7486 ", position "
7487 (int-to-string (car (cdr (cdr val))))
7488 ".")
7489 'jump-to-register))
7490 ((consp val)
7491 (let ((lines (format "%4d" (length val))))
7492 (list (format "%s: %s\n" lines
7493 (truncate-string-to-width
7494 (mapconcat 'identity (list (car val))
7495 ;; (mapconcat (lambda (y) y) val
7496 "^J") (- (window-width) 15)))
7497 'insert-register)))
7498 ((stringp val)
7499 (list ;; without properties
7500 (substring-no-properties val)
7501 'insert-register
7502 'append-to-register
7503 'prepend-to-register))
7505 "GARBAGE!"))
7506 collect (cons (format "register %3s: %s" key (car string-actions))
7507 (cons char (cdr string-actions)))))
7509 (defun anything-c-register-action-transformer (actions register-and-functions)
7510 "Decide actions by the contents of register."
7511 (loop with func-actions =
7512 '((insert-register
7513 "Insert Register" .
7514 (lambda (c) (insert-register (car c))))
7515 (jump-to-register
7516 "Jump to Register" .
7517 (lambda (c) (jump-to-register (car c))))
7518 (append-to-register
7519 "Append Region to Register" .
7520 (lambda (c) (append-to-register
7521 (car c) (region-beginning) (region-end))))
7522 (prepend-to-register
7523 "Prepend Region to Register" .
7524 (lambda (c) (prepend-to-register
7525 (car c) (region-beginning) (region-end))))
7526 (increment-register
7527 "Increment Prefix Arg to Register" .
7528 (lambda (c) (increment-register
7529 anything-current-prefix-arg (car c)))))
7530 for func in (cdr register-and-functions)
7531 for cell = (assq func func-actions)
7532 when cell
7533 collect (cdr cell)))
7535 ;; (anything 'anything-c-source-register)
7538 ;;; Latex completion
7539 (defun anything-c-latex-math-candidates ()
7540 "Collect candidates for latex math completion."
7541 (declare (special LaTeX-math-menu))
7542 (loop for i in (cddr LaTeX-math-menu)
7543 for elm = (loop for s in i when (vectorp s)
7544 collect (cons (aref s 0) (aref s 1)))
7545 append elm))
7547 (defvar anything-c-source-latex-math
7548 '((name . "Latex Math Menu")
7549 (init . (lambda ()
7550 (with-anything-current-buffer
7551 (LaTeX-math-mode 1))))
7552 (candidate-number-limit . 9999)
7553 (candidates . anything-c-latex-math-candidates)
7554 (action . (lambda (candidate)
7555 (call-interactively candidate)))))
7558 ;;;; <Headline Extraction>
7559 (defvar anything-c-source-fixme
7560 '((name . "TODO/FIXME/DRY comments")
7561 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7562 (adjust)
7563 (recenter))
7564 "Show TODO/FIXME/DRY comments in current file.")
7565 ;; (anything 'anything-c-source-fixme)
7567 (defvar anything-c-source-rd-headline
7568 '((name . "RD HeadLine")
7569 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7570 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7571 (migemo)
7572 (subexp . 1))
7573 "Show RD headlines.
7575 RD is Ruby's POD.
7576 http://en.wikipedia.org/wiki/Ruby_Document_format")
7577 ;; (anything 'anything-c-source-rd-headline)
7579 (defvar anything-c-source-oddmuse-headline
7580 '((name . "Oddmuse HeadLine")
7581 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7582 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7583 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7584 (migemo)
7585 (subexp . 1))
7586 "Show Oddmuse headlines, such as EmacsWiki.")
7587 ;; (anything 'anything-c-source-oddmuse-headline)
7589 (defvar anything-c-source-emacs-source-defun
7590 '((name . "Emacs Source DEFUN")
7591 (headline . "DEFUN\\|DEFVAR")
7592 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7593 (or buffer-file-name ""))))
7594 "Show DEFUN/DEFVAR in Emacs C source file.")
7595 ;; (anything 'anything-c-source-emacs-source-defun)
7597 (defvar anything-c-source-emacs-lisp-expectations
7598 '((name . "Emacs Lisp Expectations")
7599 (headline . "(desc[ ]\\|(expectations")
7600 (condition . (eq major-mode 'emacs-lisp-mode)))
7601 "Show descriptions (desc) in Emacs Lisp Expectations.
7603 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7604 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7606 (defvar anything-c-source-emacs-lisp-toplevels
7607 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7608 (headline . "^(\\|(@\\*\\|^;;;;")
7609 (get-line . buffer-substring)
7610 (condition . (eq major-mode 'emacs-lisp-mode))
7611 (adjust))
7612 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7613 linkd.el is optional because linkd stars are extracted by regexp.
7614 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7615 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7618 ;;; Anything yaoddmuse
7620 ;; Be sure to have yaoddmuse.el installed
7621 ;; install-elisp may be required if you want to install elisp file from here.
7622 (defvar anything-yaoddmuse-use-cache-file nil)
7623 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7624 (defvar anything-c-yaoddmuse-ew-cache nil)
7626 (defun anything-yaoddmuse-get-candidates ()
7627 (declare (special yaoddmuse-pages-hash))
7628 (if anything-yaoddmuse-use-cache-file
7629 (ignore-errors
7630 (unless anything-c-yaoddmuse-ew-cache
7631 (load anything-c-yaoddmuse-cache-file)
7632 (setq anything-c-yaoddmuse-ew-cache
7633 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7634 anything-c-yaoddmuse-ew-cache)
7635 (yaoddmuse-update-pagename t)
7636 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7638 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7639 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7640 (candidates . anything-yaoddmuse-get-candidates)
7641 (action . (("Edit page" . (lambda (candidate)
7642 (yaoddmuse-edit "EmacsWiki" candidate)))
7643 ("Browse page"
7644 . (lambda (candidate)
7645 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7646 ("Browse page other window"
7647 . (lambda (candidate)
7648 (if (one-window-p)
7649 (split-window-vertically))
7650 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7651 ("Browse diff"
7652 . (lambda (candidate)
7653 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7654 ("Copy URL"
7655 . (lambda (candidate)
7656 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7657 (message "Have copy page %s's URL to yank." candidate)))
7658 ("Create page"
7659 . (lambda (candidate)
7660 (yaoddmuse-edit "EmacsWiki" anything-input)))
7661 ("Update cache"
7662 . (lambda (candidate)
7663 (if anything-yaoddmuse-use-cache-file
7664 (progn
7665 (anything-yaoddmuse-cache-pages t)
7666 (setq anything-c-yaoddmuse-ew-cache
7667 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7668 (yaoddmuse-update-pagename))))))
7669 (action-transformer anything-c-yaoddmuse-action-transformer))
7670 "Needs yaoddmuse.el.
7672 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7674 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7676 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7677 '((name . "Yaoddmuse Post library (EmacsWiki)")
7678 (init . (anything-yaoddmuse-init))
7679 (candidates-in-buffer)
7680 (action . (("Post library and Browse"
7681 . (lambda (candidate)
7682 (yaoddmuse-post-file
7683 (find-library-name candidate)
7684 "EmacsWiki"
7685 (file-name-nondirectory (find-library-name candidate))
7686 nil t)))
7687 ("Post library"
7688 . (lambda (candidate)
7689 (yaoddmuse-post-file
7690 (find-library-name candidate)
7691 "EmacsWiki"
7692 (file-name-nondirectory
7693 (find-library-name candidate))))))))
7694 "Needs yaoddmuse.el.
7696 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7698 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7700 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7701 "Allow the use of `install-elisp' only on elisp files."
7702 (if (string-match "\.el$" candidate)
7703 (append actions '(("Install Elisp"
7704 . (lambda (elm)
7705 (install-elisp-from-emacswiki elm)))))
7706 actions))
7708 ;;;###autoload
7709 (defun anything-yaoddmuse-cache-pages (&optional load)
7710 "Fetch the list of files on emacswiki and create cache file.
7711 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7712 (interactive)
7713 (declare (special yaoddmuse-pages-hash))
7714 (yaoddmuse-update-pagename)
7715 (save-excursion
7716 (find-file anything-c-yaoddmuse-cache-file)
7717 (erase-buffer)
7718 (insert "(puthash \"EmacsWiki\" '(")
7719 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7721 (insert (concat "(\"" (car i) "\") ")))
7722 (insert ") yaoddmuse-pages-hash)\n")
7723 (save-buffer)
7724 (kill-buffer (current-buffer))
7725 (when (or current-prefix-arg
7726 load)
7727 (load anything-c-yaoddmuse-cache-file))))
7729 (defun anything-yaoddmuse-init ()
7730 "Init anything buffer status."
7731 (let ((anything-buffer (anything-candidate-buffer 'global))
7732 (library-list (yaoddmuse-get-library-list)))
7733 (with-current-buffer anything-buffer
7734 ;; Insert library name.
7735 (dolist (library library-list)
7736 (insert (format "%s\n" library)))
7737 ;; Sort lines.
7738 (sort-lines nil (point-min) (point-max)))))
7741 ;;; Eev anchors
7742 (defvar anything-c-source-eev-anchor
7743 '((name . "Anchors")
7744 (candidates
7745 . (lambda ()
7746 (ignore-errors
7747 (with-anything-current-buffer
7748 (loop initially (goto-char (point-min))
7749 while (re-search-forward
7750 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7751 for anchor = (match-string-no-properties 1)
7752 collect (cons (format "%5d:%s"
7753 (line-number-at-pos (match-beginning 0))
7754 (format ee-anchor-format anchor))
7755 anchor))))))
7756 (persistent-action . (lambda (item)
7757 (ee-to item)
7758 (anything-match-line-color-current-line)))
7759 (persistent-help . "Show this entry")
7760 (action . (("Goto link" . ee-to)))))
7761 ;; (anything 'anything-c-source-eev-anchor)
7764 ;;; Org headlines
7767 (defvar anything-c-source-org-headline
7768 `((name . "Org HeadLine")
7769 (headline
7770 ,@(mapcar
7771 (lambda (num)
7772 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7773 num))
7774 (number-sequence 1 8)))
7775 (condition . (eq major-mode 'org-mode))
7776 (migemo)
7777 (subexp . 1)
7778 (persistent-action . (lambda (elm)
7779 (anything-c-action-line-goto elm)
7780 (org-cycle)))
7781 (action-transformer
7782 . (lambda (actions candidate)
7783 '(("Go to Line" . anything-c-action-line-goto)
7784 ("Refile to this Headline" . anything-c-org-headline-refile)
7785 ("Insert Link to This Headline"
7786 . anything-c-org-headline-insert-link-to-headline)))))
7787 "Show Org headlines.
7788 org-mode is very very much extended text-mode/outline-mode.
7790 See (find-library \"org.el\")
7791 See http://orgmode.org for the latest version.")
7792 ;; (anything 'anything-c-source-org-headline)
7794 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7795 (insert
7796 (save-excursion
7797 (anything-goto-line (car lineno-and-content))
7798 (and (looking-at org-complex-heading-regexp)
7799 (org-make-link-string (concat "*" (match-string 4)))))))
7801 (defun anything-c-org-headline-refile (lineno-and-content)
7802 "Refile current org entry to LINENO-AND-CONTENT."
7803 (with-anything-current-buffer
7804 (org-cut-subtree)
7805 (anything-goto-line (car lineno-and-content))
7806 (org-end-of-subtree t t)
7807 (let ((org-yank-adjusted-subtrees t))
7808 (org-yank))))
7811 ;;; Org keywords
7814 (defvar anything-c-source-org-keywords
7815 '((name . "Org Keywords")
7816 (init . anything-c-org-keywords-init)
7817 (candidates . anything-c-org-keywords-candidates)
7818 (action . anything-c-org-keywords-insert)
7819 (persistent-action . anything-c-org-keywords-show-help)
7820 (persistent-help . "Show an example and info page to describe this keyword.")
7821 (keywords-examples)
7822 (keywords)))
7823 ;; (anything 'anything-c-source-org-keywords)
7825 (defvar anything-c-org-keywords-info-location
7826 '(("#+TITLE:" . "(org)Export options")
7827 ("#+AUTHOR:" . "(org)Export options")
7828 ("#+DATE:" . "(org)Export options")
7829 ("#+EMAIL:" . "(org)Export options")
7830 ("#+DESCRIPTION:" . "(org)Export options")
7831 ("#+KEYWORDS:" . "(org)Export options")
7832 ("#+LANGUAGE:" . "(org)Export options")
7833 ("#+TEXT:" . "(org)Export options")
7834 ("#+TEXT:" . "(org)Export options")
7835 ("#+OPTIONS:" . "(org)Export options")
7836 ("#+BIND:" . "(org)Export options")
7837 ("#+LINK_UP:" . "(org)Export options")
7838 ("#+LINK_HOME:" . "(org)Export options")
7839 ("#+LATEX_HEADER:" . "(org)Export options")
7840 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7841 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7842 ("#+INFOJS_OPT" . "(org)Javascript support")
7843 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7844 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7845 ("#+ORGTBL" . "(org)Radio tables")
7846 ("#+HTML:" . "(org)Quoting HTML tags")
7847 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7848 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7849 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7850 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7851 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7852 ("#+BEGIN_SRC" . "(org)Literal examples")
7853 ("#+CAPTION" . "(org)Tables in HTML export")
7854 ("#+LABEL" . "(org)Tables in LaTeX export")
7855 ("#+ATTR_HTML" . "(org)Links")
7856 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7858 (defun anything-c-org-keywords-init ()
7859 (unless (anything-attr 'keywords-examples)
7860 (require 'org)
7861 (anything-attrset 'keywords-examples
7862 (append
7863 (mapcar
7864 (lambda (x)
7865 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7866 (cons (match-string 2 x) (match-string 1 x)))
7867 (org-split-string (org-get-current-options) "\n"))
7868 (mapcar 'list org-additional-option-like-keywords)))
7869 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7871 (defun anything-c-org-keywords-candidates ()
7872 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7873 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7874 (anything-attr 'keywords)))
7876 (defun anything-c-org-keywords-insert (keyword)
7877 (cond ((and (string-match "BEGIN" keyword)
7878 (anything-region-active-p))
7879 (let ((beg (region-beginning))
7880 (end (region-end)))
7881 (goto-char end)
7882 (insert "\n#+" (replace-regexp-in-string
7883 "BEGIN" "END" keyword) "\n")
7884 (goto-char beg)
7885 (insert "#+" keyword " ")
7886 (save-excursion (insert "\n"))))
7887 ((string-match "BEGIN" keyword)
7888 (insert "#+" keyword " ")
7889 (save-excursion
7890 (insert "\n#+" (replace-regexp-in-string
7891 "BEGIN" "END" keyword) "\n")))
7892 (t (insert "#+" keyword " "))))
7894 (defun anything-c-org-keywords-show-help (keyword)
7895 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7896 "(org)In-buffer settings"))
7897 (search-forward (concat "#+" keyword) nil t)
7898 (anything-persistent-highlight-point)
7899 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7903 ;;; bbdb
7906 (defvar bbdb-records)
7907 (defvar bbdb-buffer-name)
7909 (defun anything-c-bbdb-candidates ()
7910 "Return a list of all names in the bbdb database. The format
7911 is \"Firstname Lastname\"."
7912 (mapcar (lambda (bbdb-record)
7913 (replace-regexp-in-string
7914 "\\s-+$" ""
7915 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7916 (bbdb-records)))
7918 (defun anything-c-bbdb-create-contact (actions candidate)
7919 "Action transformer that returns only an entry to add the
7920 current `anything-pattern' as new contact. All other actions are
7921 removed."
7922 (if (string= candidate "*Add to contacts*")
7923 '(("Add to contacts" . (lambda (actions)
7924 (bbdb-create-internal
7925 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7926 (read-from-minibuffer "Company: ")
7927 (read-from-minibuffer "Email: ")
7930 (read-from-minibuffer "Note: ")))))
7931 actions))
7933 (defun anything-c-bbdb-get-record (candidate)
7934 "Return record that match CANDIDATE."
7935 (bbdb candidate nil)
7936 (set-buffer "*BBDB*")
7937 (bbdb-current-record))
7939 (defvar anything-c-bbdb-name nil
7940 "Only for internal use.")
7942 (defvar anything-c-source-bbdb
7943 '((name . "BBDB")
7944 (candidates . anything-c-bbdb-candidates)
7945 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7946 ("View person's data" . anything-c-bbdb-view-person-action))
7947 (filtered-candidate-transformer . (lambda (candidates source)
7948 (setq anything-c-bbdb-name anything-pattern)
7949 (if (not candidates)
7950 (list "*Add to contacts*")
7951 candidates)))
7952 (action-transformer . (lambda (actions candidate)
7953 (anything-c-bbdb-create-contact actions candidate))))
7954 "Needs BBDB.
7956 http://bbdb.sourceforge.net/")
7957 ;; (anything 'anything-c-source-bbdb)
7959 (defun anything-c-bbdb-view-person-action (candidate)
7960 "View BBDB data of single CANDIDATE or marked candidates."
7961 (anything-aif (anything-marked-candidates)
7962 (let ((bbdb-append-records (length it)))
7963 (dolist (i it)
7964 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7965 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7967 (defun anything-c-bbdb-collect-mail-addresses ()
7968 "Return a list of all mail addresses of records in bbdb buffer."
7969 (with-current-buffer bbdb-buffer-name
7970 (loop for i in bbdb-records
7971 if (bbdb-record-net (car i))
7972 collect (bbdb-dwim-net-address (car i)))))
7974 (defun anything-c-bbdb-compose-mail (candidate)
7975 "Compose a mail with all records of bbdb buffer."
7976 (anything-c-bbdb-view-person-action candidate)
7977 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7978 (address-str (mapconcat 'identity address-list ",\n ")))
7979 (compose-mail address-str)))
7982 ;;; Evaluation Result
7985 ;; Internal
7986 (defvar anything-eldoc-active-minibuffers-list nil)
7988 (defvar anything-c-source-evaluation-result
7989 '((name . "Evaluation Result")
7990 (disable-shortcuts)
7991 (dummy)
7992 (multiline)
7993 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7994 (filtered-candidate-transformer . (lambda (candidates source)
7995 (list
7996 (condition-case nil
7997 (with-anything-current-buffer
7998 (pp-to-string
7999 (eval (read anything-pattern))))
8000 (error "Error")))))
8001 (action . (("Copy result to kill-ring" . (lambda (candidate)
8002 (with-current-buffer anything-buffer
8003 (let ((end (save-excursion
8004 (goto-char (point-max))
8005 (search-backward "\n")
8006 (point))))
8007 (kill-region (point) end)))))
8008 ("copy sexp to kill-ring" . (lambda (candidate)
8009 (kill-new anything-input)))))))
8010 ;; (anything 'anything-c-source-evaluation-result)
8012 (defun anything-eval-new-line-and-indent ()
8013 (interactive)
8014 (newline) (lisp-indent-line))
8016 (defun anything-eldoc-store-minibuffer ()
8017 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8018 (with-selected-window (minibuffer-window)
8019 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8021 (defun anything-eldoc-show-in-eval ()
8022 "Return eldoc in mode-line for current minibuffer input."
8023 (let ((buf (with-selected-window (minibuffer-window)
8024 (buffer-name))))
8025 (when (member buf anything-eldoc-active-minibuffers-list)
8026 (let* ((str-all (with-current-buffer buf
8027 (minibuffer-completion-contents)))
8028 (sym (when str-all
8029 (with-temp-buffer
8030 (insert str-all)
8031 (goto-char (point-max))
8032 (unless (looking-back ")\\|\"") (forward-char -1))
8033 (eldoc-current-symbol))))
8034 (info-fn (eldoc-fnsym-in-current-sexp))
8035 (doc (or (eldoc-get-var-docstring sym)
8036 (eldoc-get-fnsym-args-string
8037 (car info-fn) (cadr info-fn)))))
8038 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8040 (defun anything-c-eldoc-show-in-mode-line (str)
8041 "Show string STR in mode-line."
8042 (save-window-excursion
8043 (with-current-buffer anything-buffer
8044 (let ((mode-line-format (concat " " str)))
8045 (force-mode-line-update)
8046 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8047 (force-mode-line-update))))
8049 ;;; Calculation Result
8052 (defvar anything-c-source-calculation-result
8053 '((name . "Calculation Result")
8054 (dummy)
8055 (filtered-candidate-transformer . (lambda (candidates source)
8056 (list
8057 (condition-case nil
8058 (calc-eval anything-pattern)
8059 (error "error")))))
8060 (action ("Copy result to kill-ring" . kill-new))))
8061 ;; (anything 'anything-c-source-calculation-result)
8064 ;;; Google Suggestions
8067 ;; Internal
8068 (defvar anything-ggs-max-length-real-flag 0)
8069 (defvar anything-ggs-max-length-num-flag 0)
8071 (defun anything-c-google-suggest-fetch (input)
8072 "Fetch suggestions for INPUT from XML buffer.
8073 Return an alist with elements like (data . number_results)."
8074 (setq anything-ggs-max-length-real-flag 0
8075 anything-ggs-max-length-num-flag 0)
8076 (let ((request (concat anything-c-google-suggest-url
8077 (url-hexify-string input))))
8078 (flet ((fetch ()
8079 (loop
8080 with result-alist = (xml-get-children
8081 (car (xml-parse-region
8082 (point-min) (point-max)))
8083 'CompleteSuggestion)
8084 for i in result-alist
8085 for data = (cdr (caadr (assoc 'suggestion i)))
8086 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8087 for lqueries = (length (anything-c-ggs-set-number-result
8088 nqueries))
8089 for ldata = (length data)
8091 (progn
8092 (when (> ldata anything-ggs-max-length-real-flag)
8093 (setq anything-ggs-max-length-real-flag ldata))
8094 (when (> lqueries anything-ggs-max-length-num-flag)
8095 (setq anything-ggs-max-length-num-flag lqueries)))
8096 collect (cons data nqueries) into cont
8097 finally return cont)))
8098 (if anything-google-suggest-use-curl-p
8099 (with-temp-buffer
8100 (call-process "curl" nil t nil request)
8101 (fetch))
8102 (with-current-buffer
8103 (url-retrieve-synchronously request)
8104 (fetch))))))
8106 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8107 "Set candidates with result and number of google results found."
8108 (let ((suggestions
8109 (loop with suggested-results = (anything-c-google-suggest-fetch
8110 (or (and request-prefix
8111 (concat request-prefix " " anything-pattern))
8112 anything-pattern))
8113 for (real . numresult) in suggested-results
8114 ;; Prepare number of results with ","
8115 for fnumresult = (anything-c-ggs-set-number-result numresult)
8116 ;; Calculate number of spaces to add before fnumresult
8117 ;; if it is smaller than longest result
8118 ;; `anything-ggs-max-length-num-flag'.
8119 ;; e.g 1,234,567
8120 ;; 345,678
8121 ;; To be sure it is aligned properly.
8122 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8123 (- anything-ggs-max-length-num-flag (length fnumresult))
8125 ;; Add now the spaces before fnumresult.
8126 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8127 for interval = (- anything-ggs-max-length-real-flag (length real))
8128 for spaces = (make-string (+ 2 interval) ? )
8129 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8130 collect (cons display real))))
8131 (if (loop for (disp . dat) in suggestions
8132 thereis (equal dat anything-pattern))
8133 suggestions
8134 ;; if there is no suggestion exactly matching the input then
8135 ;; prepend a Search on Google item to the list
8136 (append
8137 suggestions
8138 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8139 anything-input))))))
8141 (defun anything-c-ggs-set-number-result (num)
8142 (if num
8143 (progn
8144 (and (numberp num) (setq num (number-to-string num)))
8145 (loop for i in (reverse (split-string num "" t))
8146 for count from 1
8147 append (list i) into C
8148 when (= count 3)
8149 append (list ",") into C
8150 and do (setq count 0)
8151 finally return
8152 (replace-regexp-in-string
8153 "^," "" (mapconcat 'identity (reverse C) ""))))
8154 "?"))
8156 (defvar anything-c-google-suggest-default-browser-function nil
8157 "*The browse url function you prefer to use with google suggest.
8158 When nil, use the first browser function available
8159 See `anything-browse-url-default-browser-alist'.")
8161 (defun anything-c-google-suggest-action (candidate)
8162 "Default action to jump to a google suggested candidate."
8163 (let ((arg (concat anything-c-google-suggest-search-url
8164 (url-hexify-string candidate))))
8165 (anything-aif anything-c-google-suggest-default-browser-function
8166 (funcall it arg)
8167 (anything-c-browse-url arg))))
8169 (defvar anything-c-google-suggest-default-function
8170 'anything-c-google-suggest-set-candidates
8171 "Default function to use in anything google suggest.")
8173 (defvar anything-c-source-google-suggest
8174 '((name . "Google Suggest")
8175 (candidates . (lambda ()
8176 (funcall anything-c-google-suggest-default-function)))
8177 (action . (("Google Search" . anything-c-google-suggest-action)))
8178 (volatile)
8179 (requires-pattern . 3)
8180 (delayed)))
8182 (defun anything-c-google-suggest-emacs-lisp ()
8183 "Try to emacs lisp complete with google suggestions."
8184 (anything-c-google-suggest-set-candidates "emacs lisp"))
8186 ;; (anything 'anything-c-source-google-suggest)
8188 ;;; Yahoo suggestions
8191 (defun anything-c-yahoo-suggest-fetch (input)
8192 "Fetch Yahoo suggestions for INPUT from XML buffer.
8193 Return an alist with elements like (data . number_results)."
8194 (let ((request (concat anything-c-yahoo-suggest-url
8195 (url-hexify-string input))))
8196 (flet ((fetch ()
8197 (loop
8198 with result-alist = (xml-get-children
8199 (car (xml-parse-region (point-min) (point-max)))
8200 'Result)
8201 for i in result-alist
8202 collect (caddr i))))
8203 (with-current-buffer
8204 (url-retrieve-synchronously request)
8205 (fetch)))))
8207 (defun anything-c-yahoo-suggest-set-candidates ()
8208 "Set candidates with Yahoo results found."
8209 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8210 (or suggestions
8211 (append
8212 suggestions
8213 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8214 anything-input))))))
8216 (defun anything-c-yahoo-suggest-action (candidate)
8217 "Default action to jump to a Yahoo suggested candidate."
8218 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8219 (url-hexify-string candidate))))
8221 (defvar anything-c-source-yahoo-suggest
8222 '((name . "Yahoo Suggest")
8223 (candidates . anything-c-yahoo-suggest-set-candidates)
8224 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8225 (volatile)
8226 (requires-pattern . 3)
8227 (delayed)))
8229 ;; (anything 'anything-c-source-yahoo-suggest)
8232 ;;; Web browser functions.
8235 (require 'browse-url)
8236 ;; If default setting of `w3m-command' is not
8237 ;; what you want you and you modify it, you will have to reeval
8238 ;; also `anything-browse-url-default-browser-alist'.
8239 (defvar w3m-command "/usr/bin/w3m")
8240 (defvar anything-c-home-url "http://www.google.fr"
8241 "*Default url to use as home url.")
8243 (defvar ac-browse-url-chromium-program "chromium-browser")
8244 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8245 (defvar anything-browse-url-default-browser-alist
8246 `((,w3m-command . w3m-browse-url)
8247 (,browse-url-firefox-program . browse-url-firefox)
8248 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8249 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8250 (,browse-url-kde-program . browse-url-kde)
8251 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8252 (,browse-url-mozilla-program . browse-url-mozilla)
8253 (,browse-url-galeon-program . browse-url-galeon)
8254 (,browse-url-netscape-program . browse-url-netscape)
8255 (,browse-url-mosaic-program . browse-url-mosaic)
8256 (,browse-url-xterm-program . browse-url-text-xterm))
8257 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8259 (defun* anything-c-generic-browser (url name &rest args)
8260 "Browse URL with NAME browser."
8261 (let ((proc (concat name " " url)))
8262 (message "Starting %s..." name)
8263 (apply 'start-process proc nil name
8264 (append args (list url)))
8265 (set-process-sentinel
8266 (get-process proc)
8267 #'(lambda (process event)
8268 (when (string= event "finished\n")
8269 (message "%s process %s" process event))))))
8271 (defun ac-browse-url-chromium (url)
8272 "Browse URL with google chrome browser."
8273 (interactive "sURL: ")
8274 (anything-c-generic-browser
8275 url ac-browse-url-chromium-program))
8277 (defun ac-browse-url-uzbl (url &optional ignore)
8278 "Browse URL with uzbl browser."
8279 (interactive "sURL: ")
8280 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8282 (defun anything-browse-url-default-browser (url &rest args)
8283 "Find the first available browser and ask it to load URL."
8284 (let ((default-browser-fn
8285 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8286 thereis (and exe (executable-find exe) fn))))
8287 (if default-browser-fn
8288 (apply default-browser-fn url args)
8289 (error "No usable browser found"))))
8291 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8292 "Default command to browse URL."
8293 (if browse-url-browser-function
8294 (browse-url url)
8295 (anything-browse-url-default-browser url)))
8298 ;;; Surfraw
8300 ;; Need external program surfraw.
8301 ;; <http://surfraw.alioth.debian.org/>
8303 (defvar anything-surfraw-default-browser-function nil
8304 "*The browse url function you prefer to use with surfraw.
8305 When nil, fallback to `browse-url-browser-function'.")
8307 ;; Internal
8308 (defvar anything-surfraw-engines-history nil)
8310 (defun anything-c-build-elvi-list ()
8311 "Return list of all engines and descriptions handled by surfraw."
8312 (cdr
8313 (with-temp-buffer
8314 (call-process "surfraw" nil t nil
8315 "-elvi")
8316 (split-string (buffer-string) "\n"))))
8319 ;;; Emms
8322 (defun anything-emms-stream-edit-bookmark (elm)
8323 "Change the information of current emms-stream bookmark from anything."
8324 (declare (special emms-stream-list))
8325 (let* ((cur-buf anything-current-buffer)
8326 (bookmark (assoc elm emms-stream-list))
8327 (name (read-from-minibuffer "Description: "
8328 (nth 0 bookmark)))
8329 (url (read-from-minibuffer "URL: "
8330 (nth 1 bookmark)))
8331 (fd (read-from-minibuffer "Feed Descriptor: "
8332 (int-to-string (nth 2 bookmark))))
8333 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8334 (format "%s" (car (last bookmark))))))
8335 (save-excursion
8336 (emms-streams)
8337 (when (re-search-forward (concat "^" name) nil t)
8338 (beginning-of-line)
8339 (emms-stream-delete-bookmark)
8340 (emms-stream-add-bookmark name url (string-to-number fd) type)
8341 (emms-stream-save-bookmarks-file)
8342 (emms-stream-quit)
8343 (anything-c-switch-to-buffer cur-buf)))))
8345 (defun anything-emms-stream-delete-bookmark (elm)
8346 "Delete an emms-stream bookmark from anything."
8347 (let* ((cur-buf anything-current-buffer)
8348 (bookmark (assoc elm emms-stream-list))
8349 (name (nth 0 bookmark)))
8350 (save-excursion
8351 (emms-streams)
8352 (when (re-search-forward (concat "^" name) nil t)
8353 (beginning-of-line)
8354 (emms-stream-delete-bookmark)
8355 (emms-stream-save-bookmarks-file)
8356 (emms-stream-quit)
8357 (anything-c-switch-to-buffer cur-buf)))))
8359 (defvar anything-c-source-emms-streams
8360 '((name . "Emms Streams")
8361 (init . (lambda ()
8362 (emms-stream-init)))
8363 (candidates . (lambda ()
8364 (declare (special emms-stream-list))
8365 (mapcar 'car emms-stream-list)))
8366 (action . (("Play" . (lambda (elm)
8367 (declare (special emms-stream-list))
8368 (let* ((stream (assoc elm emms-stream-list))
8369 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8370 (url (second stream)))
8371 (funcall fn url))))
8372 ("Delete" . anything-emms-stream-delete-bookmark)
8373 ("Edit" . anything-emms-stream-edit-bookmark)))
8374 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8375 ;; (anything 'anything-c-source-emms-streams)
8377 ;; Don't forget to set `emms-source-file-default-directory'
8378 (defvar anything-c-source-emms-dired
8379 '((name . "Music Directory")
8380 (candidates . (lambda ()
8381 (cddr (directory-files emms-source-file-default-directory))))
8382 (action .
8383 (("Play Directory" . (lambda (item)
8384 (emms-play-directory
8385 (expand-file-name
8386 item
8387 emms-source-file-default-directory))))
8388 ("Open dired in file's directory" . (lambda (item)
8389 (anything-c-open-dired
8390 (expand-file-name
8391 item
8392 emms-source-file-default-directory))))))
8393 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8394 ;; (anything 'anything-c-source-emms-dired)
8397 (defun anything-c-emms-files-modifier (candidates source)
8398 (let ((current-playlist (with-current-emms-playlist
8399 (loop
8400 with cur-list = (emms-playlist-tracks-in-region
8401 (point-min) (point-max))
8402 for i in cur-list
8403 collect (assoc-default 'name i)))))
8404 (loop for i in candidates
8405 if (member (cdr i) current-playlist)
8406 collect (cons (propertize (car i)
8407 'face 'anything-emms-playlist)
8408 (cdr i)) into lis
8409 else collect i into lis
8410 finally return lis)))
8412 (defun anything-c-emms-play-current-playlist ()
8413 "Play current playlist."
8414 (with-current-emms-playlist
8415 (emms-playlist-first)
8416 (emms-playlist-mode-play-smart)))
8418 (defvar anything-c-source-emms-files
8419 '((name . "Emms files")
8420 (candidates . (lambda ()
8421 (loop for v being the hash-values in emms-cache-db
8422 for name = (assoc-default 'name v)
8423 for artist = (or (assoc-default 'info-artist v) "unknown")
8424 for genre = (or (assoc-default 'info-genre v) "unknown")
8425 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8426 for song = (or (assoc-default 'info-title v) "unknown")
8427 for info = (concat artist " - " genre " - " tracknum ": " song)
8428 unless (string-match "^http:" name) collect (cons info name))))
8429 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8430 (action . (("Play file" . emms-play-file)
8431 ("Add to Playlist and play (C-u clear current)"
8432 . (lambda (candidate)
8433 (when anything-current-prefix-arg
8434 (emms-playlist-current-clear))
8435 (emms-playlist-new)
8436 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8437 (unless emms-player-playing-p
8438 (anything-c-emms-play-current-playlist))))))))
8440 ;; (anything 'anything-c-source-emms-files)
8443 ;;; Jabber Contacts (jabber.el)
8444 (defun anything-c-jabber-online-contacts ()
8445 "List online Jabber contacts."
8446 (with-no-warnings
8447 (let (jids)
8448 (dolist (item (jabber-concat-rosters) jids)
8449 (when (get item 'connected)
8450 (push (if (get item 'name)
8451 (cons (get item 'name) item)
8452 (cons (symbol-name item) item)) jids))))))
8454 (defvar anything-c-source-jabber-contacts
8455 '((name . "Jabber Contacts")
8456 (init . (lambda () (require 'jabber)))
8457 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8458 (action . (lambda (x)
8459 (jabber-chat-with
8460 (jabber-read-account)
8461 (symbol-name
8462 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8463 ;; (anything 'anything-c-source-jabber-contacts)
8467 ;;; Call source.
8468 (defvar anything-source-select-buffer "*anything source select*")
8469 (defvar anything-c-source-call-source
8470 `((name . "Call anything source")
8471 (candidate-number-limit)
8472 (candidates
8473 . (lambda ()
8474 (loop for vname in (all-completions "anything-c-source-" obarray)
8475 for var = (intern vname)
8476 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8477 if name collect
8478 (cons (format "%s `%s'"
8479 name (propertize vname 'face 'font-lock-variable-name-face))
8480 var))))
8481 (action
8482 . (("Invoke anything with selected source"
8484 (lambda (candidate)
8485 (setq anything-candidate-number-limit 9999)
8486 (anything candidate nil nil nil nil
8487 anything-source-select-buffer)))
8488 ("Describe variable" . describe-variable)
8489 ("Find variable" . find-variable)))
8490 (persistent-action . describe-variable)
8491 (persistent-help . "Show description of this source")))
8492 ;; (anything 'anything-c-source-call-source)
8494 (defun anything-call-source-from-anything ()
8495 "Call anything source within `anything' session."
8496 (interactive)
8497 (setq anything-input-idle-delay 0)
8498 (anything-set-sources '(anything-c-source-call-source)))
8500 ;;; Execute Preconfigured anything.
8501 (defvar anything-c-source-anything-commands
8502 '((name . "Preconfigured Anything")
8503 (candidates . anything-c-anything-commands-candidates)
8504 (type . command)
8505 (candidate-number-limit)))
8506 ;; (anything 'anything-c-source-anything-commands)
8508 (defun anything-c-anything-commands-candidates ()
8509 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8510 collect (cons (if (where-is-internal cmd nil t)
8511 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8512 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8513 cmd)))
8516 ;;; Occur
8519 (defun anything-c-occur-init ()
8520 "Create the initial anything occur buffer.
8521 If region is active use region as buffer contents
8522 instead of whole buffer."
8523 (with-current-buffer (anything-candidate-buffer 'global)
8524 (erase-buffer)
8525 (let ((buf-contents
8526 (with-anything-current-buffer
8527 (if (anything-region-active-p)
8528 (buffer-substring (region-beginning) (region-end))
8529 (buffer-substring (point-min) (point-max))))))
8530 (insert buf-contents))))
8532 (defun anything-c-occur-get-line (s e)
8533 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8535 (defun anything-c-occur-query-replace-regexp (candidate)
8536 "Query replace regexp starting from CANDIDATE.
8537 If region is active ignore CANDIDATE and replace only in region.
8538 With a prefix arg replace only matches surrounded by word boundaries,
8539 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8540 (let ((regexp anything-input))
8541 (unless (anything-region-active-p)
8542 (anything-c-action-line-goto candidate))
8543 (apply 'query-replace-regexp
8544 (anything-c-query-replace-args regexp))))
8546 (defvar anything-c-source-occur
8547 '((name . "Occur")
8548 (init . anything-c-occur-init)
8549 (candidates-in-buffer)
8550 (migemo)
8551 (get-line . anything-c-occur-get-line)
8552 (display-to-real . anything-c-display-to-real-line)
8553 (action . (("Go to Line" . anything-c-action-line-goto)
8554 ("Query replace regexp (C-u Not inside word.)"
8555 . anything-c-occur-query-replace-regexp)))
8556 (recenter)
8557 (requires-pattern . 1)
8558 (delayed)
8559 (volatile)))
8560 ;; (anything 'anything-c-source-occur)
8563 ;;; Anything browse code.
8564 (defun anything-c-browse-code-get-line (beg end)
8565 "Select line if it match the regexp corresponding to current `major-mode'.
8566 Line is parsed for BEG position to END position."
8567 (let ((str-line (buffer-substring beg end))
8568 (regexp (assoc-default major-mode
8569 anything-c-browse-code-regexp-alist))
8570 (num-line (if (string= anything-pattern "") beg (1- beg))))
8571 (when (and regexp (string-match regexp str-line))
8572 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8575 (defvar anything-c-source-browse-code
8576 '((name . "Browse code")
8577 (init . (lambda ()
8578 (anything-candidate-buffer anything-current-buffer)
8579 (with-anything-current-buffer
8580 (jit-lock-fontify-now))))
8581 (candidate-number-limit . 9999)
8582 (candidates-in-buffer)
8583 (get-line . anything-c-browse-code-get-line)
8584 (type . line)
8585 (recenter)))
8588 ;; Do many actions for input
8589 (defvar anything-c-source-create
8590 '((name . "Create")
8591 (dummy)
8592 (action)
8593 (action-transformer . anything-create--actions))
8594 "Do many create actions from `anything-pattern'.
8595 See also `anything-create--actions'.")
8596 ;; (anything 'anything-c-source-create)
8598 (defun anything-create-from-anything ()
8599 "Run `anything-create' from `anything' as a fallback."
8600 (interactive)
8601 (anything-run-after-quit 'anything-create nil anything-pattern))
8603 (defun anything-create--actions (&rest ignored)
8604 "Default actions for `anything-create' / `anything-c-source-create'."
8605 (remove-if-not
8606 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8607 (append anything-create--actions-private
8608 '(("find-file" . find-file)
8609 ("find-file other window" . find-file-other-window)
8610 ("New buffer" . anything-c-switch-to-buffer)
8611 ("New buffer other window" . switch-to-buffer-other-window)
8612 ("Bookmark Set" . bookmark-set)
8613 ("Set Register" .
8614 (lambda (x) (set-register (read-char "Register: ") x)))
8615 ("Insert Linkd star" . linkd-insert-star)
8616 ("Insert Linkd Tag" . linkd-insert-tag)
8617 ("Insert Linkd Link" . linkd-insert-link)
8618 ("Insert Linkd Lisp" . linkd-insert-lisp)
8619 ("Insert Linkd Wiki" . linkd-insert-wiki)
8620 ("Google Search" . google)))))
8623 ;; Minibuffer History
8626 (defvar anything-c-source-minibuffer-history
8627 '((name . "Minibuffer History")
8628 (header-name . (lambda (name)
8629 (format "%s (%s)" name minibuffer-history-variable)))
8630 (candidates
8631 . (lambda ()
8632 (let ((history (loop
8633 for i in (symbol-value minibuffer-history-variable)
8634 unless (string= "" i) collect i)))
8635 (if (consp (car history))
8636 (mapcar 'prin1-to-string history)
8637 history))))
8638 (migemo)
8639 (action . insert)))
8640 ;; (anything 'anything-c-source-minibuffer-history)
8643 ;;; Elscreen
8646 (defvar anything-c-source-elscreen
8647 '((name . "Elscreen")
8648 (candidates . (lambda ()
8649 (if (cdr (elscreen-get-screen-to-name-alist))
8650 (sort
8651 (loop for sname in (elscreen-get-screen-to-name-alist)
8652 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8653 finally (return lst))
8654 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8655 (action . (("Change Screen".
8656 (lambda (candidate)
8657 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8658 ("Kill Screen(s)".
8659 (lambda (candidate)
8660 (dolist (i (anything-marked-candidates))
8661 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8662 (elscreen-kill))))
8663 ("Only Screen".
8664 (lambda (candidate)
8665 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8666 (elscreen-kill-others)))))))
8667 ;; (anything 'anything-c-source-elscreen)
8670 ;;;; <System>
8672 ;;; Top (process)
8673 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8674 "Top command (batch mode). %s is replaced with `frame-width'.")
8675 (defvar anything-c-source-top
8676 '((name . "Top (Press C-c C-u to refresh)")
8677 (init . anything-c-top-init)
8678 (candidates-in-buffer)
8679 (display-to-real . anything-c-top-display-to-real)
8680 (update . anything-c-top-update)
8681 (persistent-action . anything-c-top-sh-persistent-action)
8682 (persistent-help . "SIGTERM")
8683 (action
8684 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8685 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8686 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8687 ;; (anything 'anything-c-source-top)
8689 (defun anything-c-top-sh (cmd)
8690 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8692 (defun anything-c-top-sh-persistent-action (pid)
8693 (delete-other-windows)
8694 (anything-c-top-sh (format "kill -TERM %s" pid))
8695 (anything-force-update))
8697 (defun anything-c-top-init ()
8698 (with-current-buffer (anything-candidate-buffer 'global)
8699 (call-process-shell-command
8700 (format anything-c-top-command
8701 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8702 nil (current-buffer))))
8704 (defun anything-c-top-display-to-real (line)
8705 (car (split-string line)))
8707 (defun anything-c-top-update ()
8708 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8709 (anything-c-top-init)))
8711 ;;; Timers
8712 (defvar anything-c-source-absolute-time-timers
8713 '((name . "Absolute Time Timers")
8714 (candidates . timer-list)
8715 (type . timer)))
8716 ;; (anything 'anything-c-source-absolute-time-timers)
8718 (defvar anything-c-source-idle-time-timers
8719 '((name . "Idle Time Timers")
8720 (candidates . timer-idle-list)
8721 (type . timer)))
8722 ;; (anything 'anything-c-source-idle-time-timers)
8724 (defun anything-c-timer-real-to-display (timer)
8725 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8726 (append timer nil) ;use `append' to convert vector->list
8727 (format "%s repeat=%5S %s(%s)"
8728 (let ((time (list t1 t2 t3)))
8729 (if idle-delay
8730 (format-time-string "idle-for=%5s" time)
8731 (format-time-string "%m/%d %T" time)))
8732 repeat-delay
8733 func
8734 (mapconcat 'prin1-to-string args " "))))
8736 ;;; X RandR resolution change
8737 ;;; FIXME I do not care multi-display.
8738 (defvar anything-c-xrandr-output "VGA")
8739 (defvar anything-c-xrandr-screen "0")
8740 (defvar anything-c-source-xrandr-change-resolution
8741 '((name . "Change Resolution")
8742 (candidates
8743 . (lambda ()
8744 (with-temp-buffer
8745 (call-process "xrandr" nil (current-buffer) nil
8746 "--screen" anything-c-xrandr-screen "-q")
8747 (goto-char 1)
8748 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8749 collect (match-string 1)))))
8750 (action
8751 ("Change Resolution" . (lambda (mode)
8752 (call-process "xrandr" nil nil nil
8753 "--screen" anything-c-xrandr-screen
8754 "--output" anything-c-xrandr-output
8755 "--mode" mode))))))
8756 ;; (anything 'anything-c-source-xrandr-change-resolution)
8758 ;;; Xfont selection
8761 (defun anything-c-persistent-xfont-action (elm)
8762 "Show current font temporarily"
8763 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8764 (default-font elm))
8765 (unwind-protect
8766 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8767 (set-frame-font current-font))))
8769 (defvar anything-c-xfonts-cache nil)
8770 (defvar anything-c-source-xfonts
8771 '((name . "X Fonts")
8772 (init . (lambda ()
8773 (unless anything-c-xfonts-cache
8774 (setq anything-c-xfonts-cache
8775 (x-list-fonts "*")))))
8776 (candidates . anything-c-xfonts-cache)
8777 (action . (("Copy to kill ring" . (lambda (elm)
8778 (kill-new elm)))
8779 ("Set Font" . (lambda (elm)
8780 (kill-new elm)
8781 (set-frame-font elm 'keep-size)
8782 (message "New font have been copied to kill ring")))))
8783 (persistent-action . anything-c-persistent-xfont-action)
8784 (persistent-help . "Switch to this font temporarily")))
8785 ;; (anything 'anything-c-source-xfonts)
8787 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8790 (defvar anything-c-ucs-max-len 0)
8791 (defun anything-c-calculate-ucs-max-len ()
8792 "Calculate the length of longest `ucs-names' candidate."
8793 (loop with count = 0
8794 for (n . v) in (ucs-names)
8795 for len = (length n)
8796 if (> len count)
8797 do (setq count len)
8798 finally return count))
8800 (defun anything-c-ucs-init ()
8801 "Initialize an anything buffer with ucs symbols.
8802 Only math* symbols are collected."
8803 (unless (> anything-c-ucs-max-len 0)
8804 (setq anything-c-ucs-max-len
8805 (anything-c-calculate-ucs-max-len)))
8806 (with-current-buffer (anything-candidate-buffer
8807 (get-buffer-create "*anything ucs*"))
8808 ;; `ucs-names' fn will not run again, data is cached in
8809 ;; var `ucs-names'.
8810 (loop for (n . v) in (ucs-names)
8811 for len = (length n)
8812 for diff = (+ (- anything-c-ucs-max-len len) 2)
8813 unless (string= "" n)
8814 do (progn (insert (concat
8815 n ":"
8816 (make-string
8817 diff ? )))
8818 (ucs-insert v)
8819 (insert "\n")))))
8821 (defun anything-c-ucs-forward-char (candidate)
8822 (with-anything-current-buffer
8823 (forward-char 1)))
8825 (defun anything-c-ucs-backward-char (candidate)
8826 (with-anything-current-buffer
8827 (forward-char -1)))
8829 (defun anything-c-ucs-delete-backward (candidate)
8830 (with-anything-current-buffer
8831 (delete-char -1)))
8833 (defun anything-c-ucs-insert-char (candidate)
8834 (with-anything-current-buffer
8835 (insert
8836 (replace-regexp-in-string
8837 " " ""
8838 (cadr (split-string candidate ":"))))))
8840 (defun anything-c-ucs-persistent-insert ()
8841 (interactive)
8842 (anything-execute-persistent-action 'action-insert))
8844 (defun anything-c-ucs-persistent-forward ()
8845 (interactive)
8846 (anything-execute-persistent-action 'action-forward))
8848 (defun anything-c-ucs-persistent-backward ()
8849 (interactive)
8850 (anything-execute-persistent-action 'action-back))
8852 (defun anything-c-ucs-persistent-delete ()
8853 (interactive)
8854 (anything-execute-persistent-action 'action-delete))
8856 (defvar anything-c-source-ucs
8857 '((name . "Ucs names")
8858 (init . anything-c-ucs-init)
8859 (candidate-number-limit . 9999)
8860 (candidates-in-buffer)
8861 (mode-line . anything-c-ucs-mode-line-string)
8862 (action-insert . anything-c-ucs-insert-char)
8863 (action-forward . anything-c-ucs-forward-char)
8864 (action-back . anything-c-ucs-backward-char)
8865 (action-delete . anything-c-ucs-delete-backward)
8866 (action . (("Insert" . anything-c-ucs-insert-char)
8867 ("Forward char" . anything-c-ucs-forward-char)
8868 ("Backward char" . anything-c-ucs-backward-char)
8869 ("Delete char backward" . anything-c-ucs-delete-backward))))
8870 "Source for collecting `ucs-names' math symbols.")
8873 ;;; Emacs process
8876 (defvar anything-c-source-emacs-process
8877 '((name . "Emacs Process")
8878 (candidates . (lambda () (mapcar #'process-name (process-list))))
8879 (persistent-action . (lambda (elm)
8880 (delete-process (get-process elm))
8881 (anything-delete-current-selection)))
8882 (persistent-help . "Kill Process")
8883 (action ("Kill Process" . (lambda (elm)
8884 (delete-process (get-process elm)))))))
8885 ;; (anything 'anything-c-source-emacs-process)
8887 ;;; World time
8890 (defvar anything-c-source-time-world
8891 '((name . "Time World List")
8892 (init . (lambda ()
8893 (let ((anything-buffer (anything-candidate-buffer 'global)))
8894 (with-current-buffer anything-buffer
8895 (display-time-world-display display-time-world-list)))))
8896 (candidates-in-buffer)))
8900 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8903 (defvar anything-c-source-apt
8904 '((name . "APT")
8905 (init . anything-c-apt-init)
8906 (candidates-in-buffer)
8907 (candidate-transformer anything-c-apt-candidate-transformer)
8908 (display-to-real . anything-c-apt-display-to-real)
8909 (requires-pattern . 2)
8910 (update . anything-c-apt-refresh)
8911 (action
8912 ("Show package description" . anything-c-apt-cache-show)
8913 ("Install package" . anything-c-apt-install)
8914 ("Remove package" . anything-c-apt-uninstall)
8915 ("Purge package" . anything-c-apt-purge))
8916 (persistent-action . anything-c-apt-persistent-action)
8917 (persistent-help . "Show package description")))
8918 ;; (anything 'anything-c-source-apt)
8920 (defvar anything-c-apt-query "emacs")
8921 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8922 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8923 (defvar anything-c-apt-installed-packages nil)
8924 (defvar anything-c-apt-all-packages nil)
8927 (defun anything-c-apt-refresh ()
8928 "Refresh installed candidates list."
8929 (setq anything-c-apt-installed-packages nil)
8930 (setq anything-c-apt-all-packages nil))
8932 (defun anything-c-apt-persistent-action (candidate)
8933 "Persistent action for APT source."
8934 (anything-c-apt-cache-show candidate))
8936 (defun anything-c-apt-candidate-transformer (candidates)
8937 "Show installed candidates in a different color."
8938 (loop
8939 with all
8940 for cand in candidates
8941 for name = (anything-c-apt-display-to-real cand)
8942 if (member name anything-c-apt-installed-packages)
8943 collect (propertize cand 'face 'anything-apt-installed) into all
8944 else collect cand into all finally return all))
8946 (defun anything-c-apt-init ()
8947 "Initialize list of debian packages."
8948 (let ((query ""))
8949 (unless (and anything-c-apt-installed-packages
8950 anything-c-apt-all-packages)
8951 (message "Loading package list...")
8952 (setq anything-c-apt-installed-packages
8953 (with-temp-buffer
8954 (call-process-shell-command "dpkg --get-selections"
8955 nil (current-buffer))
8956 (loop for i in (split-string (buffer-string) "\n" t)
8957 collect (car (split-string i)))))
8958 (setq anything-c-apt-all-packages
8959 (with-current-buffer
8960 (anything-candidate-buffer
8961 (get-buffer-create (format "*anything-apt*")))
8962 (erase-buffer)
8963 (call-process-shell-command
8964 (format anything-c-apt-search-command query)
8965 nil (current-buffer))))
8966 (message "Loading package list done")
8967 (sit-for 0.5))))
8969 (defun anything-c-apt-display-to-real (line)
8970 "Return only name of a debian package.
8971 LINE is displayed like:
8972 package name - description."
8973 (car (split-string line " - ")))
8975 (defun anything-c-shell-command-if-needed (command)
8976 "Run shell command COMMAND to describe package.
8977 If a buffer named COMMAND already exists, just switch to it."
8978 (let ((buf (get-buffer command)))
8979 (anything-c-switch-to-buffer (get-buffer-create command))
8980 (unless buf (insert (shell-command-to-string command)))))
8982 (defun anything-c-apt-cache-show (package)
8983 "Show information on apt package PACKAGE."
8984 (anything-c-shell-command-if-needed
8985 (format anything-c-apt-show-command package)))
8987 (defun anything-c-apt-install (package)
8988 "Run 'apt-get install' shell command on PACKAGE."
8989 (anything-c-apt-generic-action :action 'install))
8991 (defun anything-c-apt-uninstall (package)
8992 "Run 'apt-get remove' shell command on PACKAGE."
8993 (anything-c-apt-generic-action :action 'uninstall))
8995 (defun anything-c-apt-purge (package)
8996 "Run 'apt-get purge' shell command on PACKAGE."
8997 (anything-c-apt-generic-action :action 'purge))
8999 (defun* anything-c-apt-generic-action (&key action)
9000 "Run 'apt-get ACTION'.
9001 Support install, remove and purge actions."
9002 (ansi-term (getenv "SHELL") "anything apt")
9003 (term-line-mode)
9004 (let ((command (case action
9005 ('install "sudo apt-get install ")
9006 ('uninstall "sudo apt-get remove ")
9007 ('purge "sudo apt-get purge ")
9008 (t (error "Unknow action"))))
9009 (beg (point))
9011 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9012 (anything-marked-candidates) " ")))
9013 (goto-char (point-max))
9014 (insert (concat command cand-list))
9015 (setq end (point))
9016 (if (y-or-n-p (format "%s package" (symbol-name action)))
9017 (progn
9018 (setq anything-c-external-commands-list nil)
9019 (setq anything-c-apt-installed-packages nil)
9020 (term-char-mode) (term-send-input))
9021 (delete-region beg end) (term-send-eof) (kill-buffer))))
9023 ;; (anything-c-apt-install "jed")
9026 ;;; Anything UI for gentoo portage.
9029 (defvar anything-c-gentoo-use-flags nil)
9030 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9031 (defvar anything-c-cache-gentoo nil)
9032 (defvar anything-c-cache-world nil)
9033 (defvar anything-c-source-gentoo
9034 '((name . "Portage sources")
9035 (init . (lambda ()
9036 (get-buffer-create anything-c-gentoo-buffer)
9037 (unless anything-c-cache-gentoo
9038 (anything-c-gentoo-setup-cache))
9039 (unless anything-c-cache-world
9040 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9041 (anything-c-gentoo-init-list)))
9042 (candidates-in-buffer)
9043 (match . identity)
9044 (candidate-transformer anything-c-highlight-world)
9045 (action . (("Show package" . (lambda (elm)
9046 (anything-c-gentoo-eshell-action elm "eix")))
9047 ("Show history" . (lambda (elm)
9048 (if (member elm anything-c-cache-world)
9049 (anything-c-gentoo-eshell-action elm "genlop -qe")
9050 (message "No infos on packages not yet installed"))))
9051 ("Copy in kill-ring" . kill-new)
9052 ("insert at point" . insert)
9053 ("Browse HomePage" . (lambda (elm)
9054 (let ((urls (anything-c-gentoo-get-url elm)))
9055 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9056 ("Show extra infos" . (lambda (elm)
9057 (if (member elm anything-c-cache-world)
9058 (anything-c-gentoo-eshell-action elm "genlop -qi")
9059 (message "No infos on packages not yet installed"))))
9060 ("Show use flags" . (lambda (elm)
9061 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9062 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9063 (font-lock-mode 1)))
9064 ("Run emerge pretend" . (lambda (elm)
9065 (anything-c-gentoo-eshell-action elm "emerge -p")))
9066 ("Emerge" . (lambda (elm)
9067 (anything-gentoo-install elm :action 'install)))
9068 ("Unmerge" . (lambda (elm)
9069 (anything-gentoo-install elm :action 'uninstall)))
9070 ("Show dependencies" . (lambda (elm)
9071 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9072 ("Show related files" . (lambda (elm)
9073 (anything-c-gentoo-default-action elm "equery" "files")))
9074 ("Refresh" . (lambda (elm)
9075 (anything-c-gentoo-setup-cache)
9076 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9078 ;; (anything 'anything-c-source-gentoo)
9080 (defun* anything-gentoo-install (candidate &key action)
9081 (setq anything-c-external-commands-list nil)
9082 (ansi-term (getenv "SHELL") "Gentoo emerge")
9083 (term-line-mode)
9084 (let ((command (case action
9085 ('install "sudo emerge -av ")
9086 ('uninstall "sudo emerge -avC ")
9087 (t (error "Unknow action"))))
9088 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9089 (beg (point)) end)
9090 (goto-char (point-max))
9091 (insert (concat command elms))
9092 (setq end (point))
9093 (term-char-mode) (term-send-input)))
9095 (defun anything-c-gentoo-default-action (elm command &rest args)
9096 "Gentoo default action that use `anything-c-gentoo-buffer'."
9097 (if (member elm anything-c-cache-world)
9098 (progn
9099 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9100 (erase-buffer)
9101 (let ((com-list (append args (list elm))))
9102 (apply #'call-process command nil t nil
9103 com-list)))
9104 (message "No infos on packages not yet installed")))
9106 (defvar anything-c-source-use-flags
9107 '((name . "Use Flags")
9108 (init . (lambda ()
9109 (unless anything-c-gentoo-use-flags
9110 (anything-c-gentoo-setup-use-flags-cache))
9111 (anything-c-gentoo-get-use)))
9112 (candidates-in-buffer)
9113 (match . identity)
9114 (candidate-transformer anything-c-highlight-local-use)
9115 (action . (("Description"
9116 . (lambda (elm)
9117 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9118 (erase-buffer)
9119 (apply #'call-process "euse" nil t nil
9120 `("-i"
9121 ,elm))
9122 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9123 (font-lock-mode 1)))
9124 ("Enable"
9125 . (lambda (elm)
9126 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9127 ("Disable"
9128 . (lambda (elm)
9129 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9130 ("Remove"
9131 . (lambda (elm)
9132 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9133 ("Show which dep use this flag"
9134 . (lambda (elm)
9135 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9136 (erase-buffer)
9137 (apply #'call-process "equery" nil t nil
9138 `("-C"
9140 ,elm))))))))
9143 ;; (anything 'anything-c-source-use-flags)
9145 (defun anything-c-gentoo-init-list ()
9146 "Initialize buffer with all packages in Portage."
9147 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9148 (buf (anything-candidate-buffer 'portage-buf)))
9149 (with-current-buffer buf
9150 (dolist (i anything-c-cache-gentoo)
9151 (insert (concat i "\n"))))))
9153 (defun anything-c-gentoo-setup-cache ()
9154 "Set up `anything-c-cache-gentoo'"
9155 (setq anything-c-cache-gentoo
9156 (split-string (with-temp-buffer
9157 (call-process "eix" nil t nil
9158 "--only-names")
9159 (buffer-string)))))
9161 (defun anything-c-gentoo-eshell-action (elm command)
9162 (when (get-buffer "*EShell Command Output*")
9163 (kill-buffer "*EShell Command Output*"))
9164 (message "Wait searching...")
9165 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9166 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9167 (progn
9168 (save-window-excursion
9169 (pop-to-buffer "*scratch*")
9170 (eshell-command (format "%s %s" command elm)))
9171 (pop-to-buffer "*EShell Command Output*"))
9172 (eshell-command (format "%s %s" command elm)))))
9174 (defun anything-c-gentoo-get-use ()
9175 "Initialize buffer with all use flags."
9176 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9177 (buf (anything-candidate-buffer 'use-buf)))
9178 (with-current-buffer buf
9179 (dolist (i anything-c-gentoo-use-flags)
9180 (insert (concat i "\n"))))))
9183 (defun anything-c-gentoo-setup-use-flags-cache ()
9184 "Setup `anything-c-gentoo-use-flags'"
9185 (setq anything-c-gentoo-use-flags
9186 (split-string (with-temp-buffer
9187 (call-process "eix" nil t nil
9188 "--print-all-useflags")
9189 (buffer-string)))))
9191 (defun anything-c-gentoo-get-url (elm)
9192 "Return a list of urls from eix output."
9193 (loop
9194 with url-list = (split-string
9195 (with-temp-buffer
9196 (call-process "eix" nil t nil
9197 elm "--format" "<homepage>\n")
9198 (buffer-string)))
9199 with all
9200 for i in url-list
9201 when (and (string-match "^http://.*" i)
9202 (not (member i all)))
9203 collect i into all
9204 finally return all))
9206 (defun anything-c-gentoo-get-world ()
9207 "Return list of all installed package on your system."
9208 (split-string (with-temp-buffer
9209 (call-process "qlist" nil t nil
9210 "-I")
9211 (buffer-string))))
9213 (defun anything-c-gentoo-get-local-use ()
9214 (split-string (with-temp-buffer
9215 (call-process "portageq" nil t nil
9216 "envvar"
9217 "USE")
9218 (buffer-string))))
9221 (defun anything-c-highlight-world (eix)
9222 "Highlight all installed package."
9223 (loop for i in eix
9224 if (member i anything-c-cache-world)
9225 collect (propertize i 'face 'anything-gentoo-match-face)
9226 else
9227 collect i))
9229 (defun anything-c-highlight-local-use (use-flags)
9230 (let ((local-uses (anything-c-gentoo-get-local-use)))
9231 (loop for i in use-flags
9232 if (member i local-uses)
9233 collect (propertize i 'face 'anything-gentoo-match-face)
9234 else
9235 collect i)))
9239 ;;; Anything ratpoison UI
9242 (defvar anything-c-source-ratpoison-commands
9243 '((name . "Ratpoison Commands")
9244 (init . anything-c-ratpoison-commands-init)
9245 (candidates-in-buffer)
9246 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9247 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9248 (candidate-number-limit)))
9249 ;; (anything 'anything-c-source-ratpoison-commands)
9251 (defun anything-c-ratpoison-commands-init ()
9252 (unless (anything-candidate-buffer)
9253 (with-current-buffer (anything-candidate-buffer 'global)
9254 ;; with ratpoison prefix key
9255 (save-excursion
9256 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9257 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9258 (replace-match "<ratpoison> \\1: \\2"))
9259 (goto-char (point-max))
9260 ;; direct binding
9261 (save-excursion
9262 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9263 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9264 (replace-match "\\1: \\2")))))
9266 (defun anything-c-ratpoison-commands-display-to-real (display)
9267 (and (string-match ": " display)
9268 (substring display (match-end 0))))
9270 (defun anything-c-ratpoison-commands-execute (candidate)
9271 (call-process "ratpoison" nil nil nil "-ic" candidate))
9275 ;;; Anything `completing-read' replacement
9278 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9279 "Convert COLLECTION to list removing elements that don't match TEST.
9280 See `anything-comp-read' about supported COLLECTION arguments.
9282 SORT-FN is a predicate to sort COLLECTION.
9284 ALISTP when non--nil will not use `all-completions' to collect
9285 candidates because it doesn't handle alists correctly for anything.
9286 i.e In `all-completions' the keys \(cars of elements\)
9287 are the possible completions. In anything we want to use the cdr instead
9288 like \(display . real\).
9289 See docstring of `all-completions' for more info.
9291 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9292 (let ((cands
9293 (cond ((and (eq collection obarray) test)
9294 (all-completions "" collection test))
9295 ((and (vectorp collection) test)
9296 (loop for i across collection when (funcall test i) collect i))
9297 ((vectorp collection)
9298 (loop for i across collection collect i))
9299 ((and alistp test)
9300 (loop for i in collection when (funcall test i) collect i))
9301 (alistp collection)
9302 ((and collection test)
9303 (all-completions "" collection test))
9304 (t (all-completions "" collection)))))
9305 (if sort-fn (sort cands sort-fn) cands)))
9307 (defun anything-cr-default-transformer (candidates source)
9308 "Default filter candidate function for `anything-comp-read'.
9309 Do nothing, just return candidate list unmodified."
9310 candidates)
9312 (defun* anything-comp-read (prompt collection
9313 &key
9314 test
9315 initial-input
9316 default
9317 preselect
9318 (buffer "*Anything Completions*")
9319 must-match
9320 (requires-pattern 0)
9321 (history nil)
9322 (persistent-action nil)
9323 (persistent-help "DoNothing")
9324 (name "Anything Completions")
9325 (volatile t)
9326 sort
9327 (fc-transformer 'anything-cr-default-transformer)
9328 (marked-candidates nil)
9329 (alistp t))
9330 "Anything `completing-read' emulation.
9331 PROMPT is the prompt name to use.
9332 COLLECTION can be a list, vector, obarray or hash-table.
9333 It can be also a function that receives three arguments:
9334 the values string, predicate and t. See `all-completions' for more details.
9336 Keys description:
9338 TEST: A predicate called with one arg i.e candidate.
9339 INITIAL-INPUT: Same as initial-input arg in `anything'.
9340 PRESELECT: See preselect arg of `anything'.
9341 DEFAULT: This option is used only for compatibility with regular
9342 Emacs `completing-read'.
9343 BUFFER: Name of anything-buffer.
9344 MUST-MATCH: Candidate selected must be one of COLLECTION.
9345 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9346 HISTORY: A list containing specific history, default is nil.
9347 When it is non--nil, all elements of HISTORY are displayed in
9348 a special source before COLLECTION.
9349 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9350 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9351 NAME: The name related to this local source.
9352 VOLATILE: Use volatile attribute \(enabled by default\).
9353 SORT: A predicate to give to `sort' e.g `string-lessp'.
9354 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9355 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9356 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9358 Any prefix args passed during `anything-comp-read' invocation will be recorded
9359 in `anything-current-prefix-arg', otherwise if prefix args where given before
9360 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9361 That's mean you can pass prefix args before or after calling a command
9362 that use `anything-comp-read' See `anything-M-x' for example."
9363 (when (get-buffer anything-action-buffer)
9364 (kill-buffer anything-action-buffer))
9365 (flet ((action-fn (candidate)
9366 (if marked-candidates
9367 (anything-marked-candidates)
9368 (identity candidate))))
9369 (let ((hist `((name . ,(format "%s History" name))
9370 (candidates
9371 . (lambda ()
9372 (let ((all (anything-comp-read-get-candidates
9373 history nil nil ,alistp)))
9374 (anything-fast-remove-dups
9375 (if (and default (not (string= default "")))
9376 (delq nil (cons default (delete default all)))
9377 all)
9378 :test 'equal))))
9379 (filtered-candidate-transformer
9380 . (lambda (candidates sources)
9381 (loop for i in candidates
9382 do (set-text-properties 0 (length i) nil i)
9383 collect i)))
9384 (persistent-action . ,persistent-action)
9385 (persistent-help . ,persistent-help)
9386 (action . ,'action-fn)))
9387 (src `((name . ,name)
9388 (candidates
9389 . (lambda ()
9390 (let ((cands (anything-comp-read-get-candidates
9391 collection test sort alistp)))
9392 (unless (or must-match (string= anything-pattern ""))
9393 (setq cands (append (list anything-pattern) cands)))
9394 (if (and default (not (string= default "")))
9395 (delq nil (cons default (delete default cands)))
9396 cands))))
9397 (filtered-candidate-transformer ,fc-transformer)
9398 (requires-pattern . ,requires-pattern)
9399 (persistent-action . ,persistent-action)
9400 (persistent-help . ,persistent-help)
9401 (action . ,'action-fn))))
9402 (when volatile (setq src (append src '((volatile)))))
9403 (or (anything
9404 :sources `(,hist ,src)
9405 :input initial-input
9406 :default default
9407 :preselect preselect
9408 :prompt prompt
9409 :resume 'noresume
9410 :buffer buffer)
9411 (unless must-match default)
9412 (keyboard-quit)))))
9414 ;; Generic completing-read
9416 ;; Support also function as collection.
9417 ;; e.g M-x man is supported.
9418 ;; Support hash-table and vectors as collection.
9419 ;; NOTE:
9420 ;; Some crap emacs functions may not be supported
9421 ;; like ffap-alternate-file (bad use of completing-read)
9422 ;; and maybe others.
9423 ;; Provide a mode `anything-completion-mode' which turn on
9424 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9426 (defvar anything-completion-mode-string " AC")
9428 (defvar anything-completion-mode-quit-message
9429 "Anything completion disabled")
9431 (defvar anything-completion-mode-start-message
9432 "Anything completion enabled")
9434 ;;; Specialized handlers
9437 (defun anything-completing-read-symbols
9438 (prompt collection test require-match init
9439 hist default inherit-input-method name buffer)
9440 "Specialized function for fast symbols completion in `ac-mode'."
9442 (anything
9443 :sources `((name . ,name)
9444 (init . (lambda ()
9445 (with-current-buffer (anything-candidate-buffer 'global)
9446 (goto-char (point-min))
9447 (when (and default (stringp default)
9448 ;; Some defaults args result as
9449 ;; (symbol-name nil) == "nil".
9450 ;; e.g debug-on-entry.
9451 (not (string= default "nil")))
9452 (insert (concat default "\n")))
9453 (loop with all = (all-completions "" collection test)
9454 for sym in all
9455 unless (and default (eq sym default))
9456 do (insert (concat sym "\n"))))))
9457 (persistent-action . anything-lisp-completion-persistent-action)
9458 (persistent-help . "Show brief doc in mode-line")
9459 (candidates-in-buffer)
9460 (action . identity))
9461 :prompt prompt
9462 :buffer buffer
9463 :input init
9464 :resume 'noresume
9465 :default (or default ""))
9466 (keyboard-quit)))
9469 ;;; Generic completing read
9472 (defun anything-completing-read-default-1
9473 (prompt collection test require-match
9474 init hist default inherit-input-method
9475 name buffer)
9476 (anything-comp-read
9477 prompt collection
9478 :test test
9479 :fc-transformer #'(lambda (candidates source)
9480 ;; In regular `completing-read'
9481 ;; when a candidate is a cons cell
9482 ;; the car is used. Anything use
9483 ;; normally the cdr, so modify that
9484 ;; to fit `completing-read'.
9485 (loop for i in candidates
9486 for cand = (if (consp i) (car i) i)
9487 do (set-text-properties 0 (length cand) nil cand)
9488 collect cand))
9489 :history (eval (or (car-safe hist) hist))
9490 :must-match require-match
9491 :alistp nil
9492 :name name
9493 :buffer buffer
9494 ;; If DEF is not provided, fallback to empty string
9495 ;; to avoid `thing-at-point' to be appended on top of list
9496 :default (or default "")
9497 :initial-input init))
9499 (defun* anything-completing-read-default
9500 (prompt collection &optional
9501 predicate require-match
9502 initial-input hist def
9503 inherit-input-method)
9504 "An anything replacement of `completing-read'.
9505 This function should be used only as a `completing-read-function'.
9507 Don't use it directly, use instead `anything-comp-read' in your programs \
9508 which is more powerful.
9510 See documentation of `completing-read' and `all-completions' for details."
9511 (declare (special anything-completion-mode))
9512 (let* ((current-command this-command)
9513 (str-command (symbol-name current-command))
9514 (buf-name (format "*ac-mode-%s*" str-command))
9515 (entry (assq current-command
9516 anything-completing-read-handlers-alist))
9517 (def-com (cdr-safe entry))
9518 (str-defcom (and def-com (symbol-name def-com)))
9519 (def-args (list prompt collection predicate require-match
9520 initial-input hist def inherit-input-method))
9521 ;; Append the two extra args needed to set the buffer and source name
9522 ;; in anything specialized functions.
9523 (any-args (append def-args (list str-command buf-name)))
9524 anything-completion-mode-start-message ; Be quiet
9525 anything-completion-mode-quit-message)
9526 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9527 (unless (or (not entry) def-com)
9528 ;; An entry in *read-handlers-alist exists but have
9529 ;; a nil value, so we exit from here, disable `ac-mode'
9530 ;; and run the command again with it original behavior.
9531 ;; `ac-mode' will be restored on exit.
9532 (return-from anything-completing-read-default
9533 (unwind-protect
9534 (progn
9535 (ac-mode -1)
9536 (call-interactively current-command))
9537 (ac-mode 1))))
9538 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9539 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9540 (when (or (eq def-com 'completing-read)
9541 ;; All specialized functions are prefixed by "anything"
9542 (and (stringp str-defcom)
9543 (not (string-match "^anything" str-defcom))))
9544 (ac-mode -1))
9545 (unwind-protect
9546 (cond (;; An anything specialized function exists, run it.
9547 (and def-com anything-completion-mode)
9548 (apply def-com any-args))
9549 (;; Try to handle `ido-completing-read' everywhere.
9550 (and def-com (eq def-com 'ido-completing-read))
9551 (setcar (memq collection def-args)
9552 (all-completions "" collection predicate))
9553 (apply def-com def-args))
9554 (;; User set explicitely `completing-read' or something similar
9555 ;; in *read-handlers-alist, use this with exactly the same
9556 ;; args as in `completing-read'.
9557 ;; If we are here `anything-completion-mode' is now disabled.
9558 def-com
9559 (apply def-com def-args))
9560 (t ; Fall back to classic `anything-comp-read'.
9561 (anything-completing-read-default-1
9562 prompt collection predicate require-match
9563 initial-input hist def inherit-input-method
9564 str-command buf-name)))
9565 (ac-mode 1)
9566 ;; When exiting minibuffer, `this-command' is set to
9567 ;; `anything-exit-minibuffer', which is unwanted when starting
9568 ;; on another `completing-read', so restore `this-command' to
9569 ;; initial value when exiting.
9570 (setq this-command current-command))))
9572 (defun* anything-generic-read-file-name
9573 (prompt &optional dir default-filename mustmatch initial predicate)
9574 "An anything replacement of `read-file-name'."
9575 (declare (special anything-completion-mode))
9576 (let* ((default (and default-filename
9577 (if (listp default-filename)
9578 (car default-filename)
9579 default-filename)))
9580 (init (or default initial dir default-directory))
9581 (ini-input (and init (expand-file-name init)))
9582 (current-command this-command)
9583 (str-command (symbol-name current-command))
9584 (buf-name (format "*ac-mode-%s*" str-command))
9585 (entry (assq current-command
9586 anything-completing-read-handlers-alist))
9587 (def-com (cdr-safe entry))
9588 (str-defcom (symbol-name def-com))
9589 (def-args (list prompt dir default-filename mustmatch initial predicate))
9590 ;; Append the two extra args needed to set the buffer and source name
9591 ;; in anything specialized functions.
9592 (any-args (append def-args (list str-command buf-name)))
9593 (ido-state ido-mode)
9594 anything-completion-mode-start-message ; Be quiet
9595 anything-completion-mode-quit-message ; Same here
9596 fname)
9597 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9598 (unless (or (not entry) def-com)
9599 (return-from anything-completing-read-default
9600 (unwind-protect
9601 (progn
9602 (ac-mode -1)
9603 (call-interactively current-command))
9604 (ac-mode 1))))
9605 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9606 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9607 (when (or (eq def-com 'read-file-name)
9608 (eq def-com 'ido-read-file-name)
9609 (and (stringp str-defcom)
9610 (not (string-match "^anything" str-defcom))))
9611 (ac-mode -1))
9612 (unwind-protect
9613 (setq fname
9614 (cond (;; A specialized function exists, run it
9615 ;; with the two extra args specific to anything..
9616 (and def-com anything-completion-mode
9617 (not (eq def-com 'ido-read-file-name)))
9618 (apply def-com any-args))
9619 (;; Def-com value is `ido-read-file-name'
9620 ;; run it with default args.
9621 (and def-com (eq def-com 'ido-read-file-name))
9622 (ido-mode 1)
9623 (apply def-com def-args))
9624 (;; Def-com value is `read-file-name'
9625 ;; run it with default args.
9626 def-com
9627 (apply def-com def-args))
9628 (t ; Fall back to classic `anything-c-read-file-name'.
9629 (anything-c-read-file-name
9630 prompt
9631 :name str-command
9632 :buffer buf-name
9633 :initial-input (expand-file-name init dir)
9634 :alistp nil
9635 :test predicate))))
9636 (ac-mode 1)
9637 (ido-mode (if ido-state 1 -1))
9638 ;; Same comment as in `anything-completing-read-default'.
9639 (setq this-command current-command))
9640 (if (and mustmatch (not (file-exists-p fname)))
9641 (if (y-or-n-p "File does not exists, create buffer?")
9642 fname (error "Abort file does not exists"))
9643 fname)))
9645 ;;;###autoload
9646 (define-minor-mode anything-completion-mode
9647 "Toggle generic anything completion.
9649 All functions in Emacs that use `completing-read'
9650 or `read-file-name' and friends will use anything interface
9651 when this mode is turned on.
9652 However you can modify this behavior for functions of your choice
9653 with `anything-completing-read-handlers-alist'.
9655 Called with a positive arg, turn on inconditionnaly, with a
9656 negative arg turn off.
9657 You can turn it on with `ac-mode'.
9659 Some crap emacs functions may not be supported,
9660 e.g `ffap-alternate-file' and maybe others
9661 You can add such functions to `anything-completing-read-handlers-alist'
9662 with a nil value.
9664 Note: This mode will work only partially on Emacs23."
9665 :group 'anything
9666 :global t
9667 :lighter anything-completion-mode-string
9668 (declare (special completing-read-function))
9669 (if anything-completion-mode
9670 (progn
9671 (setq completing-read-function 'anything-completing-read-default
9672 read-file-name-function 'anything-generic-read-file-name)
9673 (message anything-completion-mode-start-message))
9674 (setq completing-read-function (and (fboundp 'completing-read-default)
9675 'completing-read-default)
9676 read-file-name-function (and (fboundp 'read-file-name-default)
9677 'read-file-name-default))
9678 (message anything-completion-mode-quit-message)))
9680 (defalias 'ac-mode 'anything-completion-mode)
9684 ;;; Eshell completion.
9686 ;; Enable like this in .emacs:
9688 ;; (add-hook 'eshell-mode-hook
9689 ;; #'(lambda ()
9690 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9692 (defvar anything-c-source-esh
9693 '((name . "Eshell completions")
9694 (init . (lambda ()
9695 (setq pcomplete-current-completions nil
9696 pcomplete-last-completion-raw nil)
9697 ;; Eshell-command add this hook in all minibuffers
9698 ;; Remove it for the anything one. (Fixed in Emacs24)
9699 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9700 (candidates . anything-esh-get-candidates)
9701 (action . anything-ec-insert))
9702 "Anything source for Eshell completion.")
9704 ;; Internal.
9705 (defvar anything-ec-target "")
9706 (defun anything-ec-insert (candidate)
9707 "Insert CANDIDATE at point.
9708 This is the same as `ac-insert', just inlined here for compatibility."
9709 (let ((pt (point)))
9710 (when (and anything-ec-target
9711 (search-backward anything-ec-target nil t)
9712 (string= (buffer-substring (point) pt) anything-ec-target))
9713 (delete-region (point) pt)))
9714 (insert candidate))
9716 (defun anything-esh-get-candidates ()
9717 "Get candidates for eshell completion using `pcomplete'."
9718 (catch 'pcompleted
9719 (let* ((pcomplete-stub)
9720 pcomplete-seen pcomplete-norm-func
9721 pcomplete-args pcomplete-last pcomplete-index
9722 (pcomplete-autolist pcomplete-autolist)
9723 (pcomplete-suffix-list pcomplete-suffix-list))
9724 (with-anything-current-buffer
9725 (loop
9726 with table = (pcomplete-completions)
9727 with entry = (condition-case nil
9728 ;; For Emacs24
9729 (try-completion anything-pattern (pcomplete-entries))
9730 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9731 (error
9733 (let ((fc (car (last (pcomplete-parse-arguments)))))
9734 ;; Check if last arg require fname completion.
9735 (and (file-name-directory fc) fc))))
9736 for i in (if (listp table) table ; Emacs23 or commands.
9737 (all-completions pcomplete-stub table)) ; Emacs24
9738 for file-cand = (and entry
9739 (if (file-remote-p i) i
9740 (expand-file-name i (file-name-directory entry))))
9741 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9742 collect file-cand into ls
9743 else collect i into ls
9744 finally return
9745 (if (and entry (not (string= entry "")) (file-exists-p entry))
9746 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9748 ;;; Eshell history.
9751 (defvar anything-c-source-eshell-history
9752 '((name . "Eshell history")
9753 (init . (lambda ()
9754 (let (eshell-hist-ignoredups)
9755 ;; Dump the content's of hist file
9756 ;; to `eshell-history-ring'.
9757 (eshell-read-history eshell-history-file-name)
9758 ;; And now write the content's of ring to file.
9759 (eshell-write-history eshell-history-file-name t)
9760 (with-current-buffer (anything-candidate-buffer 'global)
9761 (insert-file-contents eshell-history-file-name)))
9762 ;; Same comment as in `anything-c-source-esh'
9763 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9764 (candidates-in-buffer)
9765 (filtered-candidate-transformer . (lambda (candidates sources)
9766 (reverse candidates)))
9767 (candidate-number-limit . 9999)
9768 (action . (lambda (candidate)
9769 (eshell-kill-input)
9770 (insert candidate))))
9771 "Anything source for Eshell history.")
9774 ;;; Show completion - an alternative of anything-show-completion.el.
9776 ;; Provide show completion with macro `with-anything-show-completion'.
9779 ;; Called each time cursor move in anything-buffer.
9780 (defun anything-c-show-completion ()
9781 (with-anything-current-buffer
9782 (overlay-put anything-c-show-completion-overlay
9783 'display (anything-get-selection))))
9785 (defun anything-c-show-completion-init-overlay (beg end)
9786 (and anything-c-turn-on-show-completion
9787 (setq anything-c-show-completion-overlay (make-overlay beg end))
9788 (overlay-put anything-c-show-completion-overlay
9789 'face 'anything-lisp-show-completion)))
9791 (defmacro with-anything-show-completion (beg end &rest body)
9792 "Show anything candidate in an overlay at point.
9793 BEG and END are the beginning and end position of the current completion
9794 in `anything-current-buffer'.
9795 BODY is an anything call where we want to enable show completion.
9796 If `anything-c-turn-on-show-completion' is nil just do nothing."
9797 (declare (indent 2) (debug t))
9798 `(let ((anything-move-selection-after-hook
9799 (and anything-c-turn-on-show-completion
9800 (append (list 'anything-c-show-completion)
9801 anything-move-selection-after-hook))))
9802 (unwind-protect
9803 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9804 ,@body)
9805 (and anything-c-turn-on-show-completion
9806 (delete-overlay anything-c-show-completion-overlay)))))
9809 ;;; Lisp symbol completion.
9812 ;;;###autoload
9813 (defun anything-lisp-completion-at-point ()
9814 "Anything lisp symbol completion at point."
9815 (interactive)
9816 (let* ((data (lisp-completion-at-point))
9817 (beg (car data))
9818 (end (point)) ; 'cadr data' is wrong when no space after point.
9819 (plist (nthcdr 3 data))
9820 (pred (plist-get plist :predicate))
9821 (lgst-len 0)
9822 (target (and beg end (buffer-substring-no-properties beg end)))
9823 (candidates (all-completions target (nth 2 data) pred))
9824 (anything-quit-if-no-candidate t)
9825 (anything-execute-action-at-once-if-one t)
9826 (anything-match-plugin-enabled
9827 (member 'anything-compile-source--match-plugin
9828 anything-compile-source-functions)))
9829 (if candidates
9830 (with-anything-show-completion beg end
9831 ;; Overlay is initialized now in anything-current-buffer.
9832 (anything
9833 :sources
9834 '((name . "Lisp completion")
9835 (init . (lambda ()
9836 (with-current-buffer (anything-candidate-buffer 'global)
9837 (loop for sym in candidates
9838 for len = (length sym)
9839 when (> len lgst-len) do (setq lgst-len len)
9840 do (insert (concat sym "\n"))))))
9841 (candidates-in-buffer)
9842 (persistent-action . anything-lisp-completion-persistent-action)
9843 (persistent-help . "Show brief doc in mode-line")
9844 (filtered-candidate-transformer anything-lisp-completion-transformer)
9845 (action . (lambda (candidate)
9846 (delete-region beg end)
9847 (insert candidate))))
9848 :input (if anything-match-plugin-enabled (concat target " ") target)))
9849 (message "[No Match]"))))
9851 (defun anything-lisp-completion-persistent-action (candidate)
9852 (let ((cursor-in-echo-area t)
9853 mode-line-in-non-selected-windows)
9854 (anything-c-eldoc-show-in-mode-line
9855 (propertize
9856 (anything-c-get-first-line-documentation
9857 (intern candidate))
9858 'face 'anything-lisp-completion-info))))
9860 (defun anything-lisp-completion-transformer (candidates source)
9861 "Anything candidates transformer for lisp completion."
9862 (declare (special lgst-len))
9863 (loop for c in candidates
9864 for sym = (intern c)
9865 for annot = (cond ((commandp sym) " (Com)")
9866 ((fboundp sym) " (Fun)")
9867 ((boundp sym) " (Var)")
9868 ((facep sym) " (Face)"))
9869 for spaces = (make-string (- lgst-len (length c)) ? )
9870 collect (cons (concat c spaces annot) c)))
9872 (defun anything-c-get-first-line-documentation (sym)
9873 "Return first line documentation of symbol SYM.
9874 If SYM is not documented, return \"Not documented\"."
9875 (let ((doc (cond ((fboundp sym)
9876 (documentation sym t))
9877 ((boundp sym)
9878 (documentation-property sym 'variable-documentation t))
9879 ((facep sym)
9880 (face-documentation sym))
9881 (t nil))))
9882 (if (and doc (not (string= doc ""))
9883 ;; `documentation' return "\n\n(args...)"
9884 ;; for CL-style functions.
9885 (not (string-match-p "^\n\n" doc)))
9886 (car (split-string doc "\n"))
9887 "Not documented")))
9889 ;;; File completion.
9891 ;; Complete file name at point.
9892 (defun anything-c-thing-before-point ()
9893 "Get symbol name before point.
9894 Borrowed from anything-complete.el, inlined here for compatibility."
9895 (save-excursion
9896 (let ((beg (point)))
9897 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9898 (when (re-search-backward
9899 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9900 (buffer-substring-no-properties beg (match-end 0))))))
9902 ;;;###autoload
9903 (defun anything-c-complete-file-name-at-point ()
9904 "Complete file name at point."
9905 (interactive)
9906 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9907 (end (point))
9908 (beg (- (point) (length init)))
9909 (anything-quit-if-no-candidate t)
9910 (anything-execute-action-at-once-if-one t)
9911 completion)
9912 (with-anything-show-completion beg end
9913 (setq completion (anything-c-read-file-name "FileName: "
9914 :initial-input init)))
9915 (anything-c-insert-file-name-completion-at-point completion)))
9917 ;; Internal
9918 (defvar anything-lisp-completion-counter 0)
9919 ;;;###autoload
9920 (defun anything-lisp-completion-at-point-or-indent (arg)
9921 "First call indent and second call complete lisp symbol.
9922 The second call should happen before `anything-lisp-completion-or-indent-delay',
9923 after this delay, next call will indent again.
9924 After completion, next call is always indent.
9925 See that like click and double mouse click.
9926 One hit indent, two quick hits maybe indent and complete."
9927 (interactive "P")
9928 ;; Be sure `indent-for-tab-command' will not try
9929 ;; to use `completion-at-point'.
9930 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9931 t tab-always-indent)))
9932 (incf anything-lisp-completion-counter)
9933 (unwind-protect
9934 (if (> anything-lisp-completion-counter 1)
9935 (anything-lisp-completion-or-file-name-at-point)
9936 (indent-for-tab-command arg))
9937 ;; After `anything-lisp-completion-or-indent-delay' seconds
9938 ;; reset to 0.
9939 (run-with-timer anything-lisp-completion-or-indent-delay nil
9940 #'(lambda ()
9941 (setq anything-lisp-completion-counter 0)))
9942 ;; Always reset to 0 at second hit.
9943 (when (eq anything-lisp-completion-counter 2)
9944 (setq anything-lisp-completion-counter 0)))))
9946 ;;;###autoload
9947 (defun anything-lisp-completion-or-file-name-at-point ()
9948 "Complete lisp symbol or filename at point.
9949 Filename completion happen if filename is started in
9950 or between double quotes."
9951 (interactive)
9952 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9953 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9954 (save-excursion (search-backward "\"" (point-at-bol) t)))
9955 (anything-c-complete-file-name-at-point)
9956 (anything-lisp-completion-at-point))))
9958 (defun anything-c-apropos-init (test default)
9959 "Init candidates buffer for `anything-c-apropos' sources."
9960 (with-current-buffer (anything-candidate-buffer 'global)
9961 (goto-char (point-min))
9962 (when (and default (stringp default)
9963 ;; Some defaults args result as
9964 ;; (symbol-name nil) == "nil".
9965 ;; e.g debug-on-entry.
9966 (not (string= default "nil"))
9967 (funcall test (intern default)))
9968 (insert (concat default "\n")))
9969 (loop with all = (all-completions "" obarray test)
9970 for sym in all
9971 unless (and default (eq sym default))
9972 do (insert (concat sym "\n")))))
9975 ;;; Run Externals commands within Emacs with anything completion
9978 (defvar anything-external-command-history nil)
9980 (defun anything-c-external-commands-list-1 (&optional sort)
9981 "Returns a list of all external commands the user can execute.
9982 If `anything-c-external-commands-list' is non-nil it will
9983 return its contents. Else it calculates all external commands
9984 and sets `anything-c-external-commands-list'."
9985 (if anything-c-external-commands-list
9986 anything-c-external-commands-list
9987 (setq anything-c-external-commands-list
9988 (loop
9989 with paths = (split-string (getenv "PATH") path-separator)
9990 with completions = ()
9991 for dir in paths
9992 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9993 for lsdir = (loop for i in (directory-files dir t)
9994 for bn = (file-name-nondirectory i)
9995 when (and (not (member bn completions))
9996 (not (file-directory-p i))
9997 (file-executable-p i))
9998 collect bn)
9999 append lsdir into completions
10000 finally return (if sort (sort completions 'string-lessp) completions)))))
10002 (defun anything-run-or-raise (exe &optional file)
10003 "Generic command that run asynchronously EXE.
10004 If EXE is already running just jump to his window if `anything-raise-command'
10005 is non--nil.
10006 When FILE argument is provided run EXE with FILE.
10007 In this case EXE must be provided as \"EXE %s\"."
10008 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10009 "%s" "" exe))))
10010 (proc (if file (concat real-com " " file) real-com)))
10011 (if (get-process proc)
10012 (if anything-raise-command
10013 (shell-command (format anything-raise-command real-com))
10014 (error "Error: %s is already running" real-com))
10015 (when (loop for i in anything-c-external-commands-list thereis real-com)
10016 (message "Starting %s..." real-com)
10017 (if file
10018 (start-process-shell-command
10019 proc nil (format exe (shell-quote-argument file)))
10020 (start-process-shell-command proc nil real-com))
10021 (set-process-sentinel
10022 (get-process proc)
10023 #'(lambda (process event)
10024 (when (and (string= event "finished\n")
10025 anything-raise-command
10026 (not (anything-c-get-pid-from-process-name real-com)))
10027 (shell-command (format anything-raise-command "emacs")))
10028 (message "%s process...Finished." process))))
10029 (setq anything-c-external-commands-list
10030 (cons real-com
10031 (delete real-com anything-c-external-commands-list))))))
10035 ;;; Generic action functions
10038 (defun anything-c-file-buffers (filename)
10039 "Returns a list of buffer names corresponding to FILENAME."
10040 (let ((name (expand-file-name filename))
10041 (buf-list ()))
10042 (dolist (buf (buffer-list) buf-list)
10043 (let ((bfn (buffer-file-name buf)))
10044 (when (and bfn (string= name bfn))
10045 (push (buffer-name buf) buf-list))))))
10047 (defun anything-revert-buffer (candidate)
10048 (with-current-buffer candidate
10049 (when (or (buffer-modified-p)
10050 (not (verify-visited-file-modtime
10051 (get-buffer candidate))))
10052 (revert-buffer t t))))
10054 (defun anything-revert-marked-buffers (ignore)
10055 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10057 (defun anything-kill-marked-buffers (ignore)
10058 (mapc 'kill-buffer (anything-marked-candidates)))
10060 (defun anything-c-delete-file (file)
10061 "Delete the given file after querying the user.
10062 Ask to kill buffers associated with that file, too."
10063 (let ((buffers (anything-c-file-buffers file)))
10064 (if (< emacs-major-version 24)
10065 ;; `dired-delete-file' in Emacs versions < 24
10066 ;; doesn't support delete-by-moving-to-trash
10067 ;; so use `delete-directory' and `delete-file'
10068 ;; that handle it.
10069 (cond ((and (not (file-symlink-p file))
10070 (file-directory-p file)
10071 (directory-files file t dired-re-no-dot))
10072 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10073 (delete-directory file 'recursive)))
10074 ((and (not (file-symlink-p file))
10075 (file-directory-p file))
10076 (delete-directory file))
10077 (t (delete-file file)))
10078 (dired-delete-file
10079 file 'dired-recursive-deletes delete-by-moving-to-trash))
10080 (when buffers
10081 (dolist (buf buffers)
10082 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10083 (kill-buffer buf))))))
10085 (defun anything-get-mailcap-for-file (filename)
10086 "Get the command to use for FILENAME from mailcap files.
10087 The command is like <command %s> and is meant to use with `format'."
10088 (mailcap-parse-mailcaps)
10089 (let* ((ext (file-name-extension filename))
10090 (mime (when ext (mailcap-extension-to-mime ext)))
10091 (result (when mime (mailcap-mime-info mime))))
10092 ;; If elisp file have no associations in .mailcap
10093 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10094 (when (stringp result) result)))
10096 (defun anything-get-default-program-for-file (filename)
10097 "Try to find a default program to open FILENAME.
10098 Try first in `anything-c-external-programs-associations' and then in mailcap file
10099 if nothing found return nil."
10100 (let* ((ext (file-name-extension filename))
10101 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10102 (cond ((and def-prog (not (string= def-prog "")))
10103 (concat def-prog " %s"))
10104 ((and anything-c-default-external-file-browser
10105 (file-directory-p filename))
10106 (concat anything-c-default-external-file-browser " %s"))
10107 (t (anything-get-mailcap-for-file filename)))))
10109 (defun anything-c-open-file-externally (file)
10110 "Open FILE with an external program.
10111 Try to guess which program to use with `anything-get-default-program-for-file'.
10112 If not found or a prefix arg is given query the user which tool to use."
10113 (let* ((fname (expand-file-name file))
10114 (collection (anything-c-external-commands-list-1 'sort))
10115 (def-prog (anything-get-default-program-for-file fname))
10116 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10117 ;; Prefix arg or no default program.
10118 (prog1
10119 (anything-comp-read
10120 "Program: " collection
10121 :must-match t
10122 :name "Open file Externally"
10123 :history anything-external-command-history)
10124 ;; Always prompt to set this program as default.
10125 (setq def-prog nil))
10126 ;; No prefix arg or default program exists.
10127 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10128 (program (concat real-prog-name " %s")))
10129 (unless (or def-prog ; Association exists, no need to record it.
10130 ;; Don't try to record non--filenames associations (e.g urls).
10131 (not (file-exists-p fname)))
10132 (when
10133 (y-or-n-p
10134 (format
10135 "Do you want to make `%s' the default program for this kind of files? "
10136 real-prog-name))
10137 (anything-aif (assoc (file-name-extension fname)
10138 anything-c-external-programs-associations)
10139 (setq anything-c-external-programs-associations
10140 (delete it anything-c-external-programs-associations)))
10141 (push (cons (file-name-extension fname)
10142 (read-string
10143 "Program (Add args maybe and confirm): " real-prog-name))
10144 anything-c-external-programs-associations)
10145 (customize-save-variable 'anything-c-external-programs-associations
10146 anything-c-external-programs-associations)))
10147 (anything-run-or-raise program file)
10148 (setq anything-external-command-history
10149 (cons real-prog-name
10150 (delete real-prog-name
10151 (loop for i in anything-external-command-history
10152 when (executable-find i) collect i))))))
10154 (defun anything-c-find-file-or-marked (candidate)
10155 "Open file CANDIDATE or open anything marked files in background."
10156 (let ((marked (anything-marked-candidates))
10157 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10158 (find-file-wildcards nil))
10159 (if (> (length marked) 1)
10160 ;; Open all marked files in background and display
10161 ;; the first one.
10162 (progn (mapc 'find-file-noselect (cdr marked))
10163 (find-file (car marked)))
10164 (if (and (not (file-exists-p candidate))
10165 (and ffap-url-regexp
10166 (not (string-match ffap-url-regexp candidate)))
10167 (string-match "/$" candidate))
10168 ;; A a non--existing filename ending with /
10169 ;; Create a directory and jump to it.
10170 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10171 (let ((dirfname (directory-file-name candidate)))
10172 (if (file-exists-p dirfname)
10173 (error "Mkdir: Unable to create directory `%s': file exists."
10174 (anything-c-basename dirfname))
10175 (make-directory candidate 'parent)))
10176 (anything-find-files-1 candidate))
10177 ;; A non--existing filename NOT ending with / or
10178 ;; an existing filename, create or jump to it.
10179 (find-file-at-point (car marked))))))
10181 (defun anything-delete-marked-files (ignore)
10182 (let* ((files (anything-marked-candidates))
10183 (len (length files)))
10184 (if (not (y-or-n-p
10185 (format "Delete *%s File(s):\n%s"
10187 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10188 (message "(No deletions performed)")
10189 (dolist (i files)
10190 (set-text-properties 0 (length i) nil i)
10191 (anything-c-delete-file i))
10192 (message "%s File(s) deleted" len))))
10194 (defun anything-ediff-marked-buffers (candidate &optional merge)
10195 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10196 With optional arg MERGE call `ediff-merge-buffers'."
10197 (let ((lg-lst (length (anything-marked-candidates)))
10198 buf1 buf2)
10199 (case lg-lst
10201 (error "Error:You have to mark at least 1 buffer"))
10203 (setq buf1 anything-current-buffer
10204 buf2 (first (anything-marked-candidates))))
10206 (setq buf1 (first (anything-marked-candidates))
10207 buf2 (second (anything-marked-candidates))))
10209 (error "Error:To much buffers marked!")))
10210 (if merge
10211 (ediff-merge-buffers buf1 buf2)
10212 (ediff-buffers buf1 buf2))))
10214 (defun anything-ediff-marked-buffers-merge (candidate)
10215 "Ediff merge `anything-current-buffer' with CANDIDATE.
10216 See `anything-ediff-marked-buffers'."
10217 (anything-ediff-marked-buffers candidate t))
10219 (defun anything-bookmark-get-bookmark-from-name (bmk)
10220 "Return bookmark name even if it is a bookmark with annotation.
10221 e.g prepended with *.
10222 Return nil if bmk is not a valid bookmark."
10223 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10224 (if (assoc bookmark bookmark-alist)
10225 bookmark
10226 (when (assoc bmk bookmark-alist)
10227 bmk))))
10229 (defun anything-delete-marked-bookmarks (ignore)
10230 "Delete this bookmark or all marked bookmarks."
10231 (dolist (i (anything-marked-candidates))
10232 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10233 'batch)))
10235 (defun anything-require-or-error (feature function)
10236 (or (require feature nil t)
10237 (error "Need %s to use `%s'." feature function)))
10239 (defun anything-find-buffer-on-elscreen (candidate)
10240 "Open buffer in new screen, if marked buffers open all in elscreens."
10241 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10242 (anything-aif (anything-marked-candidates)
10243 (dolist (i it)
10244 (let ((target-screen (elscreen-find-screen-by-buffer
10245 (get-buffer i) 'create)))
10246 (elscreen-goto target-screen)))
10247 (let ((target-screen (elscreen-find-screen-by-buffer
10248 (get-buffer candidate) 'create)))
10249 (elscreen-goto target-screen))))
10251 (defun anything-elscreen-find-file (file)
10252 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10253 (elscreen-find-file file))
10255 ;;;###autoload
10256 (defun w32-shell-execute-open-file (file)
10257 (interactive "fOpen file:")
10258 (with-no-warnings
10259 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10260 "/" "\\"
10261 (replace-regexp-in-string ; strip cygdrive paths
10262 "/cygdrive/\\(.\\)" "\\1:"
10263 file nil nil) nil t))))
10265 (defun anything-c-open-file-with-default-tool (file)
10266 "Open FILE with the default tool on this platform."
10267 (if (eq system-type 'windows-nt)
10268 (w32-shell-execute-open-file file)
10269 (start-process "anything-c-open-file-with-default-tool"
10271 (cond ((eq system-type 'gnu/linux)
10272 "xdg-open")
10273 ((or (eq system-type 'darwin) ;; Mac OS X
10274 (eq system-type 'macos)) ;; Mac OS 9
10275 "open"))
10276 file)))
10278 (defun anything-c-open-dired (file)
10279 "Opens a dired buffer in FILE's directory. If FILE is a
10280 directory, open this directory."
10281 (if (file-directory-p file)
10282 (dired file)
10283 (dired (file-name-directory file))
10284 (dired-goto-file file)))
10286 (defun anything-c-display-to-real-line (candidate)
10287 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10288 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10289 (error "Line number not found")))
10291 (defun anything-c-action-line-goto (lineno-and-content)
10292 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10293 (append lineno-and-content
10294 (list (if (and (anything-attr-defined 'target-file)
10295 (not anything-in-persistent-action))
10296 'find-file-other-window
10297 'find-file)))))
10299 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10300 (apply #'anything-goto-file-line
10301 (if (stringp file-line-content)
10302 ;; Case: filtered-candidate-transformer is skipped
10303 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10304 file-line-content)))
10306 (require 'compile)
10307 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10308 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10310 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10311 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10312 (let ((filename (match-string 1 candidate))
10313 (lineno (match-string 2 candidate))
10314 (content (match-string 3 candidate)))
10315 (cons (format "%s:%s\n %s"
10316 (propertize filename 'face compilation-info-face)
10317 (propertize lineno 'face compilation-line-face)
10318 content)
10319 (list (expand-file-name
10320 filename
10321 (or (anything-interpret-value (anything-attr 'default-directory))
10322 (and (anything-candidate-buffer)
10323 (buffer-local-value
10324 'default-directory (anything-candidate-buffer)))))
10325 (string-to-number lineno) content)))))
10327 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10328 (anything-aif (anything-attr 'before-jump-hook)
10329 (funcall it))
10330 (when file (funcall find-file-function file))
10331 (if (anything-attr-defined 'adjust)
10332 (anything-c-goto-line-with-adjustment lineno content)
10333 (anything-goto-line lineno))
10334 (unless (anything-attr-defined 'recenter)
10335 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10336 (anything-aif (anything-attr 'after-jump-hook)
10337 (funcall it))
10338 (when anything-in-persistent-action
10339 (anything-match-line-color-current-line)))
10341 (defun anything-find-file-as-root (candidate)
10342 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10344 (defun anything-find-many-files (ignore)
10345 (mapc 'find-file (anything-marked-candidates)))
10347 ;; borrowed from etags.el
10348 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10349 (defun anything-c-goto-line-with-adjustment (line line-content)
10350 (let ((startpos)
10351 offset found pat)
10352 ;; This constant is 1/2 the initial search window.
10353 ;; There is no sense in making it too small,
10354 ;; since just going around the loop once probably
10355 ;; costs about as much as searching 2000 chars.
10356 (setq offset 1000
10357 found nil
10358 pat (concat (if (eq selective-display t)
10359 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10360 (regexp-quote line-content)))
10361 ;; If no char pos was given, try the given line number.
10362 (setq startpos (progn (anything-goto-line line) (point)))
10363 (or startpos (setq startpos (point-min)))
10364 ;; First see if the tag is right at the specified location.
10365 (goto-char startpos)
10366 (setq found (looking-at pat))
10367 (while (and (not found)
10368 (progn
10369 (goto-char (- startpos offset))
10370 (not (bobp))))
10371 (setq found
10372 (re-search-forward pat (+ startpos offset) t)
10373 offset (* 3 offset))) ; expand search window
10374 (or found
10375 (re-search-forward pat nil t)
10376 (error "not found")))
10377 ;; Position point at the right place
10378 ;; if the search string matched an extra Ctrl-m at the beginning.
10379 (and (eq selective-display t)
10380 (looking-at "\^m")
10381 (forward-char 1))
10382 (beginning-of-line))
10384 (anything-document-attribute 'default-directory "type . file-line"
10385 "`default-directory' to interpret file.")
10386 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10387 "Function to call before jumping to the target location.")
10388 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10389 "Function to call after jumping to the target location.")
10390 (anything-document-attribute 'adjust "type . file-line"
10391 "Search around line matching line contents.")
10392 (anything-document-attribute 'recenter "type . file-line / line"
10393 "`recenter' after jumping.")
10394 (anything-document-attribute 'target-file "type . line"
10395 "Goto line of target-file.")
10397 ;;;###autoload
10398 (defun anything-c-call-interactively (cmd-or-name)
10399 "Execute CMD-OR-NAME as Emacs command.
10400 It is added to `extended-command-history'.
10401 `anything-current-prefix-arg' is used as the command's prefix argument."
10402 (setq extended-command-history
10403 (cons (anything-c-stringify cmd-or-name)
10404 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10405 (let ((current-prefix-arg anything-current-prefix-arg)
10406 (cmd (anything-c-symbolify cmd-or-name)))
10407 (if (stringp (symbol-function cmd))
10408 (execute-kbd-macro (symbol-function cmd))
10409 (setq this-command cmd)
10410 (call-interactively cmd))))
10412 ;;;###autoload
10413 (defun anything-c-set-variable (var)
10414 "Set value to VAR interactively."
10415 (interactive)
10416 (let ((sym (anything-c-symbolify var)))
10417 (set sym (eval-minibuffer (format "Set %s: " var)
10418 (prin1-to-string (symbol-value sym))))))
10419 ;; (setq hh 12)
10420 ;; (anything-c-set-variable 'hh)
10424 ;;; Persistent Action Helpers
10427 (defvar anything-match-line-overlay-face nil)
10428 (defvar anything-match-line-overlay nil)
10430 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10431 "Highlight and underline current position"
10432 (let ((args (list (or start (line-beginning-position))
10433 (or end (1+ (line-end-position)))
10434 buf)))
10435 (if (not anything-match-line-overlay)
10436 (setq anything-match-line-overlay (apply 'make-overlay args))
10437 (apply 'move-overlay anything-match-line-overlay args)))
10438 (overlay-put anything-match-line-overlay
10439 'face (or face anything-match-line-overlay-face))
10440 (when rec
10441 (goto-char start)
10442 (recenter)))
10444 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10447 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10449 (defun anything-match-line-cleanup ()
10450 (when anything-match-line-overlay
10451 (delete-overlay anything-match-line-overlay)
10452 (setq anything-match-line-overlay nil)))
10454 (defun anything-match-line-update ()
10455 (when anything-match-line-overlay
10456 (delete-overlay anything-match-line-overlay)
10457 (anything-match-line-color-current-line)))
10459 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10460 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10463 ;;; Actions Transformers
10466 ;;; Files
10467 (defun anything-c-transform-file-load-el (actions candidate)
10468 "Add action to load the file CANDIDATE if it is an emacs lisp
10469 file. Else return ACTIONS unmodified."
10470 (if (member (file-name-extension candidate) '("el" "elc"))
10471 (append actions '(("Load Emacs Lisp File" . load-file)))
10472 actions))
10474 (defun anything-c-transform-file-browse-url (actions candidate)
10475 "Add an action to browse the file CANDIDATE if it in a html
10476 file or URL. Else return ACTIONS unmodified."
10477 (let ((browse-action '("Browse with Browser" . browse-url)))
10478 (cond ((string-match "^http\\|^ftp" candidate)
10479 (cons browse-action actions))
10480 ((string-match "\\.html?$" candidate)
10481 (append actions (list browse-action)))
10482 (t actions))))
10484 ;;; Function
10485 (defun anything-c-transform-function-call-interactively (actions candidate)
10486 "Add an action to call the function CANDIDATE interactively if
10487 it is a command. Else return ACTIONS unmodified."
10488 (if (commandp (intern-soft candidate))
10489 (append actions '(("Call Interactively"
10491 anything-c-call-interactively)))
10492 actions))
10494 ;;;; S-Expressions
10495 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10496 "If CANDIDATE's `car' is a command, then add an action to
10497 evaluate it and put it onto the `command-history'."
10498 (if (commandp (car (read candidate)))
10499 ;; Make it first entry
10500 (cons '("Eval and put onto command-history" .
10501 (lambda (sexp)
10502 (let ((sym (read sexp)))
10503 (eval sym)
10504 (setq command-history
10505 (cons sym command-history)))))
10506 actions)
10507 actions))
10510 ;;; Candidate Transformers
10513 ;;; Buffers
10514 (defun anything-c-skip-boring-buffers (buffers)
10515 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10517 (defun anything-c-skip-current-buffer (buffers)
10518 (if anything-allow-skipping-current-buffer
10519 (remove (buffer-name anything-current-buffer) buffers)
10520 buffers))
10522 (defun anything-c-shadow-boring-buffers (buffers)
10523 "Buffers matching `anything-c-boring-buffer-regexp' will be
10524 displayed with the `file-name-shadow' face if available."
10525 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10527 (defvar anything-c-buffer-display-string-functions
10528 '(anything-c-buffer-display-string--compilation
10529 anything-c-buffer-display-string--shell
10530 anything-c-buffer-display-string--eshell)
10531 "Functions to setup display string for buffer.
10533 Function has one argument, buffer name.
10534 If it returns string, use it.
10535 If it returns nil, display buffer name.
10536 See `anything-c-buffer-display-string--compilation' for example.")
10538 (defun anything-c-transform-buffer-display-string (buffers)
10539 "Setup display string for buffer candidates
10540 using `anything-c-buffer-display-string-functions'."
10541 (loop for buf in buffers
10542 if (consp buf)
10543 collect buf
10544 else
10545 for disp = (progn (set-buffer buf)
10546 (run-hook-with-args-until-success
10547 'anything-c-buffer-display-string-functions buf))
10548 collect (if disp (cons disp buf) buf)))
10550 (defun anything-c-buffer-display-string--compilation (buf)
10551 (anything-aif (car compilation-arguments)
10552 (format "%s: %s [%s]" buf it default-directory)))
10554 (defun anything-c-buffer-display-string--eshell (buf)
10555 (declare (special eshell-history-ring))
10556 (when (eq major-mode 'eshell-mode)
10557 (format "%s: %s [%s]" buf
10558 (ignore-errors (ring-ref eshell-history-ring 0))
10559 default-directory)))
10561 (defun anything-c-buffer-display-string--shell (buf)
10562 (when (eq major-mode 'shell-mode)
10563 (format "%s: %s [%s]" buf
10564 (ignore-errors (ring-ref comint-input-ring 0))
10565 default-directory)))
10567 ;;; Files
10568 (defun anything-c-shadow-boring-files (files)
10569 "Files matching `anything-c-boring-file-regexp' will be
10570 displayed with the `file-name-shadow' face if available."
10571 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10573 (defun anything-c-skip-boring-files (files)
10574 "Files matching `anything-c-boring-file-regexp' will be skipped."
10575 (anything-c-skip-entries files anything-c-boring-file-regexp))
10576 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10578 (defun anything-c-skip-current-file (files)
10579 "Current file will be skipped."
10580 (remove (buffer-file-name anything-current-buffer) files))
10582 (defun anything-c-w32-pathname-transformer (args)
10583 "Change undesirable features of windows pathnames to ones more acceptable to
10584 other candidate transformers."
10585 (if (eq system-type 'windows-nt)
10586 (mapcar (lambda (x)
10587 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10588 (mapcar (lambda (y)
10589 (replace-regexp-in-string "\\\\" "/" y)) args))
10590 args))
10592 (defun anything-c-shorten-home-path (files)
10593 "Replaces /home/user with ~."
10594 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10595 (getenv "HOME"))))
10596 (mapcar (lambda (file)
10597 (if (and (stringp file) (string-match home file))
10598 (cons (replace-match "~" nil nil file) file)
10599 file))
10600 files)))
10602 ;;; Functions
10603 (defun anything-c-mark-interactive-functions (functions)
10604 "Mark interactive functions (commands) with (i) after the function name."
10605 (let (list)
10606 (loop for function in functions
10607 do (push (cons (concat function
10608 (when (commandp (intern-soft function)) " (i)"))
10609 function)
10610 list)
10611 finally (return (nreverse list)))))
10614 ;;; Adaptive Sorting of Candidates
10617 ;; Internal
10618 (defvar anything-c-adaptive-done nil
10619 "nil if history information is not yet stored for the current
10620 selection.")
10622 (defvar anything-c-adaptive-history nil
10623 "Contains the stored history information.
10624 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10626 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10627 "Reset `anything-c-adaptive-done' when anything is started."
10628 (when anything-c-use-adaptative-sorting
10629 (setq anything-c-adaptive-done nil)))
10631 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10632 "Store history information when action is executed on selected candidate."
10633 (when anything-c-use-adaptative-sorting
10634 (anything-c-adaptive-store-selection)))
10636 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10637 "Store history information when the user goes to the action buffer."
10638 (when anything-c-use-adaptative-sorting
10639 (anything-c-adaptive-store-selection)))
10641 (defun anything-c-source-use-adaptative-p (&optional source-name)
10642 "Return current source only if it use adaptative history, nil otherwise."
10643 (when anything-c-use-adaptative-sorting
10644 (let* ((source (or source-name (anything-get-current-source)))
10645 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10646 (assoc (assoc-default 'type source)
10647 anything-type-attributes))
10648 (assoc-default 'candidate-transformer
10649 (assoc (assoc-default 'type source)
10650 anything-type-attributes))
10651 (assoc-default 'filtered-candidate-transformer source)
10652 (assoc-default 'candidate-transformer source))))
10653 (if (listp adapt-source)
10654 (when (member 'anything-c-adaptive-sort adapt-source) source)
10655 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10657 (defun anything-c-adaptive-store-selection ()
10658 "Store history information for the selected candidate."
10659 (unless anything-c-adaptive-done
10660 (setq anything-c-adaptive-done t)
10661 (let ((source (anything-c-source-use-adaptative-p)))
10662 (when source
10663 (let* ((source-name (or (assoc-default 'type source)
10664 (assoc-default 'name source)))
10665 (source-info (or (assoc source-name anything-c-adaptive-history)
10666 (progn
10667 (push (list source-name) anything-c-adaptive-history)
10668 (car anything-c-adaptive-history))))
10669 (selection (anything-get-selection))
10670 (selection-info (progn
10671 (setcdr source-info
10672 (cons
10673 (let ((found (assoc selection (cdr source-info))))
10674 (if (not found)
10675 ;; new entry
10676 (list selection)
10678 ;; move entry to the beginning of the
10679 ;; list, so that it doesn't get
10680 ;; trimmed when the history is
10681 ;; truncated
10682 (setcdr source-info
10683 (delete found (cdr source-info)))
10684 found))
10685 (cdr source-info)))
10686 (cadr source-info)))
10687 (pattern-info (progn
10688 (setcdr selection-info
10689 (cons
10690 (let ((found (assoc anything-pattern (cdr selection-info))))
10691 (if (not found)
10692 ;; new entry
10693 (cons anything-pattern 0)
10695 ;; move entry to the beginning of the
10696 ;; list, so if two patterns used the
10697 ;; same number of times then the one
10698 ;; used last appears first in the list
10699 (setcdr selection-info
10700 (delete found (cdr selection-info)))
10701 found))
10702 (cdr selection-info)))
10703 (cadr selection-info))))
10705 ;; increase usage count
10706 (setcdr pattern-info (1+ (cdr pattern-info)))
10708 ;; truncate history if needed
10709 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10710 (setcdr selection-info
10711 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10713 (defun anything-c-adaptative-maybe-load-history ()
10714 (when (and anything-c-use-adaptative-sorting
10715 (file-readable-p anything-c-adaptive-history-file))
10716 (load-file anything-c-adaptive-history-file)))
10718 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10719 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10721 (defun anything-c-adaptive-save-history (&optional arg)
10722 "Save history information to file given by `anything-c-adaptive-history-file'."
10723 (interactive "p")
10724 (when anything-c-use-adaptative-sorting
10725 (with-temp-buffer
10726 (insert
10727 ";; -*- mode: emacs-lisp -*-\n"
10728 ";; History entries used for anything adaptive display.\n")
10729 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10730 (current-buffer))
10731 (insert ?\n)
10732 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10733 (unless arg 'quiet)))))
10735 (defun anything-c-adaptive-sort (candidates source)
10736 "Sort the CANDIDATES for SOURCE by usage frequency.
10737 This is a filtered candidate transformer you can use for the
10738 attribute `filtered-candidate-transformer' of a source in
10739 `anything-sources' or a type in `anything-type-attributes'."
10740 (let* ((source-name (or (assoc-default 'type source)
10741 (assoc-default 'name source)))
10742 (source-info (assoc source-name anything-c-adaptive-history)))
10743 (if source-info
10744 (let ((usage
10745 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10746 ;; pairs
10747 (mapcar (lambda (candidate-info)
10748 (let ((count 0))
10749 (dolist (pattern-info (cdr candidate-info))
10750 (if (not (equal (car pattern-info)
10751 anything-pattern))
10752 (incf count (cdr pattern-info))
10754 ;; if current pattern is equal to the previously
10755 ;; used one then this candidate has priority
10756 ;; (that's why its count is boosted by 10000) and
10757 ;; it only has to compete with other candidates
10758 ;; which were also selected with the same pattern
10759 (setq count (+ 10000 (cdr pattern-info)))
10760 (return)))
10761 (cons (car candidate-info) count)))
10762 (cdr source-info)))
10763 sorted)
10764 (if (and usage (consp usage))
10765 ;; sort the list in descending order, so candidates with highest
10766 ;; priorty come first
10767 (progn
10768 (setq usage (sort usage (lambda (first second)
10769 (> (cdr first) (cdr second)))))
10771 ;; put those candidates first which have the highest usage count
10772 (dolist (info usage)
10773 (when (member* (car info) candidates
10774 :test 'anything-c-adaptive-compare)
10775 (push (car info) sorted)
10776 (setq candidates (remove* (car info) candidates
10777 :test 'anything-c-adaptive-compare))))
10779 ;; and append the rest
10780 (append (reverse sorted) candidates nil))
10781 (message "Your `%s' is maybe corrupted or too old, \
10782 you should reinitialize it with `anything-c-reset-adaptative-history'"
10783 anything-c-adaptive-history-file)
10784 (sit-for 1)
10785 candidates))
10786 ;; if there is no information stored for this source then do nothing
10787 candidates)))
10789 ;;;###autoload
10790 (defun anything-c-reset-adaptative-history ()
10791 "Delete all `anything-c-adaptive-history' and his file.
10792 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10793 (interactive)
10794 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10795 (setq anything-c-adaptive-history nil)
10796 (delete-file anything-c-adaptive-history-file)))
10798 (defun anything-c-adaptive-compare (x y)
10799 "Compare candidates X and Y taking into account that the
10800 candidate can be in (DISPLAY . REAL) format."
10801 (equal (if (listp x)
10802 (cdr x)
10804 (if (listp y)
10805 (cdr y)
10806 y)))
10810 ;;; Outliner
10813 (defvar anything-outline-goto-near-line-flag t)
10814 (defvar anything-outline-using nil)
10815 (defun anything-after-update-hook--outline ()
10816 (if (and (eq anything-outline-using t)
10817 (eq anything-outline-goto-near-line-flag t))
10818 (anything-outline-goto-near-line)))
10819 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10821 (defun anything-outline-goto-near-line ()
10822 (with-anything-window
10823 ;; TODO need consideration whether to update position by every input.
10824 (when t ; (equal anything-pattern "")
10825 (anything-goto-line 2)
10826 (let ((lineno (with-anything-current-buffer
10827 (line-number-at-pos (car anything-current-position)))))
10828 (block exit
10829 (while (<= (progn (skip-chars-forward " ")
10830 (or (number-at-point) lineno))
10831 lineno)
10832 (forward-line 1)
10833 (when (eobp)
10834 (forward-line -1)
10835 (return-from exit))))
10836 (forward-line -1)
10837 (and (bobp) (forward-line 1))
10838 (and (anything-pos-header-line-p) (forward-line -2))
10839 (anything-mark-current-line)))))
10843 ;;; Plug-in
10846 ;; Plug-in: info-index
10847 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10848 (let (result)
10849 (unless (anything-candidate-buffer)
10850 (save-window-excursion
10851 (info file)
10852 (let (Info-history
10853 (tobuf (anything-candidate-buffer 'global))
10854 (infobuf (current-buffer))
10855 s e)
10856 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10857 (Info-goto-node node)
10858 (goto-char (point-min))
10859 (while (search-forward "\n* " nil t)
10860 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10861 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10862 (setq s (point-at-bol)
10863 e (point-at-eol))
10864 (with-current-buffer tobuf
10865 (insert-buffer-substring infobuf s e)
10866 (insert "\n"))))))))))
10868 (defun anything-c-info-goto (node-line)
10869 (Info-goto-node (car node-line))
10870 (anything-goto-line (cdr node-line)))
10872 (defun anything-c-info-display-to-real (line)
10873 (and (string-match
10874 ;; This regexp is stolen from Info-apropos-matches
10875 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10876 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10877 (string-to-number (or (match-string 3 line) "1")))))
10879 (defun anything-c-make-info-source (source file)
10880 `(,@source
10881 (name . ,(concat "Info Index: " file))
10882 (info-file . ,file)
10883 (init . anything-c-info-init)
10884 (display-to-real . anything-c-info-display-to-real)
10885 (get-line . buffer-substring)
10886 (candidates-in-buffer)
10887 (action ("Goto node" . anything-c-info-goto))))
10889 (defun anything-compile-source--info-index (source)
10890 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10891 (anything-c-make-info-source source it)
10892 source))
10893 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10895 (anything-document-attribute 'info-index "info-index plugin"
10896 "Create a source of info index very easily.
10898 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10900 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10901 "Index nodes of info file.
10903 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10904 Some info files are missing index specification.
10906 ex. See `anything-c-source-info-screen'.")
10908 ;; Plug-in: candidates-file
10909 (defun anything-compile-source--candidates-file (source)
10910 (if (assoc-default 'candidates-file source)
10911 `((init anything-p-candidats-file-init
10912 ,@(let ((orig-init (assoc-default 'init source)))
10913 (cond ((null orig-init) nil)
10914 ((functionp orig-init) (list orig-init))
10915 (t orig-init))))
10916 (candidates-in-buffer)
10917 ,@source)
10918 source))
10919 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10921 (defun anything-p-candidats-file-init ()
10922 (destructuring-bind (file &optional updating)
10923 (anything-mklist (anything-attr 'candidates-file))
10924 (setq file (anything-interpret-value file))
10925 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10926 (when updating
10927 (buffer-disable-undo)
10928 (font-lock-mode -1)
10929 (auto-revert-mode 1)))))
10931 (anything-document-attribute 'candidates-file "candidates-file plugin"
10932 "Use a file as the candidates buffer.
10934 1st argument is a filename, string or function name or variable name.
10935 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10937 ;; Plug-in: headline
10938 (defun anything-compile-source--anything-headline (source)
10939 (if (assoc-default 'headline source)
10940 (append '((init . anything-headline-init)
10941 (get-line . buffer-substring)
10942 (type . line))
10943 source
10944 '((candidates-in-buffer)
10945 (persistent-help . "Show this line")))
10946 source))
10947 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10949 (defun anything-headline-init ()
10950 (when (and (anything-current-buffer-is-modified)
10951 (with-anything-current-buffer
10952 (eval (or (anything-attr 'condition) t))))
10953 (anything-headline-make-candidate-buffer
10954 (anything-interpret-value (anything-attr 'headline))
10955 (anything-interpret-value (anything-attr 'subexp)))))
10957 (anything-document-attribute 'headline "Headline plug-in"
10958 "Regexp string for anything-headline to scan.")
10959 (anything-document-attribute 'condition "Headline plug-in"
10960 "A sexp representing the condition to use anything-headline.")
10961 (anything-document-attribute 'subexp "Headline plug-in"
10962 "Display (match-string-no-properties subexp).")
10964 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10965 ;; of regexps.
10967 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10968 ;; 2. Sort this list by start-of-match.
10969 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10971 ;; It's quite brilliantly written.
10975 (defun anything-headline-get-candidates (regexp subexp)
10976 (with-anything-current-buffer
10977 (save-excursion
10978 (goto-char (point-min))
10979 (if (functionp regexp) (setq regexp (funcall regexp)))
10980 (let (hierarchy curhead)
10981 (flet ((matched ()
10982 (if (numberp subexp)
10983 (cons (match-string-no-properties subexp) (match-beginning subexp))
10984 (cons (buffer-substring (point-at-bol) (point-at-eol))
10985 (point-at-bol))))
10986 (hierarchies (headlines)
10987 (1+ (loop for (_ . hierarchy) in headlines
10988 maximize hierarchy)))
10989 (vector-0-n (v n)
10990 (loop for i from 0 to hierarchy
10991 collecting (aref curhead i)))
10992 (arrange (headlines)
10993 (unless (null headlines) ; FIX headlines empty bug!
10994 (loop with curhead = (make-vector (hierarchies headlines) "")
10995 for ((str . pt) . hierarchy) in headlines
10996 do (aset curhead hierarchy str)
10997 collecting
10998 (cons
10999 (format "H%d:%s" (1+ hierarchy)
11000 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11001 pt)))))
11002 (if (listp regexp)
11003 (arrange
11004 (sort
11005 (loop for re in regexp
11006 for hierarchy from 0
11007 do (goto-char (point-min))
11008 appending
11009 (loop
11010 while (re-search-forward re nil t)
11011 collect (cons (matched) hierarchy)))
11012 (lambda (a b) (> (cdar b) (cdar a)))))
11013 (loop while (re-search-forward regexp nil t)
11014 collect (matched))))))))
11017 (defun anything-headline-make-candidate-buffer (regexp subexp)
11018 (with-current-buffer (anything-candidate-buffer 'local)
11019 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11020 do (insert
11021 (format "%5d:%s\n"
11022 (with-anything-current-buffer
11023 (line-number-at-pos pos))
11024 content)))))
11026 (defun anything-headline-goto-position (pos recenter)
11027 (goto-char pos)
11028 (unless recenter
11029 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11032 ;; Plug-in: persistent-help
11033 (defun anything-compile-source--persistent-help (source)
11034 (append source '((header-line . anything-persistent-help-string))))
11035 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11037 (defun anything-persistent-help-string ()
11038 (substitute-command-keys
11039 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11040 (or (anything-interpret-value (anything-attr 'persistent-help))
11041 (anything-aif (or (assoc-default 'persistent-action
11042 (anything-get-current-source))
11043 (assoc-default 'action
11044 (anything-get-current-source)))
11045 (cond ((symbolp it) (symbol-name it))
11046 ((listp it) (or (ignore-errors (caar it)) ""))))
11048 " (keeping session)")))
11050 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11051 "A string to explain persistent-action of this source.
11052 It also accepts a function or a variable name.")
11054 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11056 ;; Plug-in: Type customize
11057 (defun anything-c-uniq-list (lst)
11058 "Like `remove-duplicates' in CL.
11059 But cut deeper duplicates and test by `equal'. "
11060 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11061 (defvar anything-additional-type-attributes nil)
11062 (defun anything-c-arrange-type-attribute (type spec)
11063 "Override type attributes by `define-anything-type-attribute'.
11065 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11067 Example: Set `play-sound-file' as default action
11068 (anything-c-arrange-type-attribute 'file
11069 '((action (\"Play sound\" . play-sound-file)
11070 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11073 (add-to-list 'anything-additional-type-attributes
11074 (cons type
11075 (loop with typeattr = (assoc-default type anything-type-attributes)
11076 for (attr . value) in spec
11077 if (listp value)
11078 collect (cons attr
11079 (anything-c-uniq-list
11080 (loop for v in value
11081 if (eq v 'REST)
11082 append (assoc-default attr typeattr)
11083 else
11084 collect v)))
11085 else
11086 collect (cons attr value)))))
11087 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11089 (defun anything-compile-source--type-customize (source)
11090 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11091 (append it source)
11092 source))
11093 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11095 ;; Plug-in: default-action
11096 (defun anything-compile-source--default-action (source)
11097 (anything-aif (assoc-default 'default-action source)
11098 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11099 source)
11100 source))
11101 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11102 (anything-document-attribute 'default-action "default-action plug-in"
11103 "Default action.")
11106 ;;; Toggle anything-match-plugin
11109 (defvar anything-mp-initial-highlight-delay nil)
11111 ;;;###autoload
11112 (defun anything-c-toggle-match-plugin ()
11113 "Toggle anything-match-plugin."
11114 (interactive)
11115 (let ((anything-match-plugin-enabled
11116 (member 'anything-compile-source--match-plugin
11117 anything-compile-source-functions)))
11118 (flet ((disable-match-plugin ()
11119 (setq anything-compile-source-functions
11120 (delq 'anything-compile-source--match-plugin
11121 anything-compile-source-functions))
11122 (setq anything-mp-initial-highlight-delay
11123 anything-mp-highlight-delay)
11124 (setq anything-mp-highlight-delay nil))
11125 (enable-match-plugin ()
11126 (require 'anything-match-plugin)
11127 (unless anything-mp-initial-highlight-delay
11128 (setq anything-mp-initial-highlight-delay
11129 anything-mp-highlight-delay))
11130 (setq anything-compile-source-functions
11131 (cons 'anything-compile-source--match-plugin
11132 anything-compile-source-functions))
11133 (unless anything-mp-highlight-delay
11134 (setq anything-mp-highlight-delay
11135 anything-mp-initial-highlight-delay))))
11136 (if anything-match-plugin-enabled
11137 (when (y-or-n-p "Really disable match-plugin? ")
11138 (disable-match-plugin)
11139 (message "Anything-match-plugin disabled"))
11140 (when (y-or-n-p "Really enable match-plugin? ")
11141 (enable-match-plugin)
11142 (message "Anything-match-plugin enabled"))))))
11146 ;;; Type Attributes
11149 (define-anything-type-attribute 'buffer
11150 `((action
11151 ("Switch to buffer" . anything-c-switch-to-buffer)
11152 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11153 ("Switch to buffer other window" . switch-to-buffer-other-window)
11154 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11155 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11156 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11157 ("Query replace" . anything-c-buffer-query-replace)
11158 ("View buffer" . view-buffer)
11159 ("Display buffer" . display-buffer)
11160 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11161 ("Revert buffer(s)" . anything-revert-marked-buffers)
11162 ("Insert buffer" . insert-buffer)
11163 ("Kill buffer(s)" . anything-kill-marked-buffers)
11164 ("Diff with file" . diff-buffer-with-file)
11165 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11166 ("Ediff Merge marked buffers" . (lambda (candidate)
11167 (anything-ediff-marked-buffers candidate t))))
11168 (persistent-help . "Show this buffer")
11169 (candidate-transformer anything-c-skip-current-buffer
11170 anything-c-skip-boring-buffers
11171 anything-c-transform-buffer-display-string))
11172 "Buffer or buffer name.")
11174 (define-anything-type-attribute 'file
11175 `((action
11176 ("Find file" . anything-find-many-files)
11177 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11178 ("Find file as root" . anything-find-file-as-root)
11179 ("Find file other window" . find-file-other-window)
11180 ("Find file other frame" . find-file-other-frame)
11181 ("Open dired in file's directory" . anything-c-open-dired)
11182 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11183 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11184 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11185 ("Checksum File" . anything-ff-checksum)
11186 ("Ediff File" . anything-find-files-ediff-files)
11187 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11188 ("View file" . view-file)
11189 ("Insert file" . insert-file)
11190 ("Delete file(s)" . anything-delete-marked-files)
11191 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11192 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11193 ("Find file in hex dump" . hexl-find-file))
11194 (persistent-help . "Show this file")
11195 (action-transformer anything-c-transform-file-load-el
11196 anything-c-transform-file-browse-url)
11197 (candidate-transformer anything-c-w32-pathname-transformer
11198 anything-c-skip-current-file
11199 anything-c-skip-boring-files
11200 anything-c-shorten-home-path))
11201 "File name.")
11203 (let ((actions '(("Describe command" . describe-function)
11204 ("Add command to kill ring" . anything-c-kill-new)
11205 ("Go to command's definition" . find-function)
11206 ("Debug on entry" . debug-on-entry)
11207 ("Cancel debug on entry" . cancel-debug-on-entry)
11208 ("Trace function" . trace-function)
11209 ("Trace function (background)" . trace-function-background)
11210 ("Untrace function" . untrace-function))))
11211 (define-anything-type-attribute 'command
11212 `((action ("Call interactively" . anything-c-call-interactively)
11213 ,@actions)
11214 ;; Sort commands according to their usage count.
11215 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11216 (coerce . anything-c-symbolify)
11217 (persistent-action . describe-function))
11218 "Command. (string or symbol)")
11220 (define-anything-type-attribute 'function
11221 `((action . ,actions)
11222 (action-transformer anything-c-transform-function-call-interactively)
11223 (candidate-transformer anything-c-mark-interactive-functions)
11224 (coerce . anything-c-symbolify))
11225 "Function. (string or symbol)"))
11227 (define-anything-type-attribute 'variable
11228 '((action ("Describe variable" . describe-variable)
11229 ("Add variable to kill ring" . anything-c-kill-new)
11230 ("Go to variable's definition" . find-variable)
11231 ("Set variable" . anything-c-set-variable))
11232 (coerce . anything-c-symbolify))
11233 "Variable.")
11235 (define-anything-type-attribute 'sexp
11236 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11237 ("Add s-expression to kill ring" . kill-new))
11238 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11239 "String representing S-Expressions.")
11241 (define-anything-type-attribute 'bookmark
11242 `((coerce . anything-bookmark-get-bookmark-from-name)
11243 (action
11244 ("Jump to bookmark" . (lambda (bookmark)
11245 (let ((current-prefix-arg anything-current-prefix-arg))
11246 (bookmark-jump bookmark))
11247 (anything-update)))
11248 ("Jump to BM other window" . (lambda (bookmark)
11249 (bookmark-jump-other-window bookmark)
11250 (anything-update)))
11251 ("Bookmark edit annotation" . bookmark-edit-annotation)
11252 ("Bookmark show annotation" . bookmark-show-annotation)
11253 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11254 ,@(and (locate-library "bookmark-extensions")
11255 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11256 ("Rename bookmark" . bookmark-rename)
11257 ("Relocate bookmark" . bookmark-relocate)))
11258 "Bookmark name.")
11260 (define-anything-type-attribute 'line
11261 '((display-to-real . anything-c-display-to-real-line)
11262 (action ("Go to Line" . anything-c-action-line-goto)))
11263 "LINENO:CONTENT string, eg. \" 16:foo\".
11265 Optional `target-file' attribute is a name of target file.
11267 Optional `before-jump-hook' attribute is a function with no
11268 arguments which is called before jumping to position.
11270 Optional `after-jump-hook' attribute is a function with no
11271 arguments which is called after jumping to position.
11273 If `adjust' attribute is specified, searches the line whose
11274 content is CONTENT near the LINENO.
11276 If `recenter' attribute is specified, the line is displayed at
11277 the center of window, otherwise at the top of window.
11280 (define-anything-type-attribute 'file-line
11281 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11282 (multiline)
11283 (action ("Go to" . anything-c-action-file-line-goto)))
11284 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11286 Optional `default-directory' attribute is a default-directory
11287 FILENAME is interpreted.
11289 Optional `before-jump-hook' attribute is a function with no
11290 arguments which is called before jumping to position.
11292 Optional `after-jump-hook' attribute is a function with no
11293 arguments which is called after jumping to position.
11295 If `adjust' attribute is specified, searches the line whose
11296 content is CONTENT near the LINENO.
11298 If `recenter' attribute is specified, the line is displayed at
11299 the center of window, otherwise at the top of window.
11302 (define-anything-type-attribute 'timer
11303 '((real-to-display . anything-c-timer-real-to-display)
11304 (action ("Cancel Timer" . cancel-timer)
11305 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11306 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11307 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11308 (persistent-help . "Describe Function"))
11309 "Timer.")
11312 ;;; Default `anything-sources'
11313 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11314 ;; tend to invoke M-x anything directly. So I offer default setting.
11315 (setq anything-sources
11316 '(anything-c-source-buffers-list
11317 anything-c-source-recentf
11318 anything-c-source-files-in-current-dir+))
11321 ;;; Preconfigured Anything
11324 ;;;###autoload
11325 (defun anything-mini ()
11326 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11327 (interactive)
11328 (anything-other-buffer '(anything-c-source-buffers-list
11329 anything-c-source-recentf
11330 anything-c-source-buffer-not-found)
11331 "*anything mini*"))
11332 ;;;###autoload
11333 (defun anything-for-files ()
11334 "Preconfigured `anything' for opening files.
11335 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11336 (interactive)
11337 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11339 ;;;###autoload
11340 (defun anything-recentf ()
11341 "Preconfigured `anything' for `recentf'."
11342 (interactive)
11343 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11345 ;;;###autoload
11346 (defun anything-info-at-point (arg)
11347 "Preconfigured `anything' for searching info at point.
11348 With a prefix-arg insert symbol at point."
11349 (interactive "P")
11350 (let ((anything-c-google-suggest-default-function
11351 'anything-c-google-suggest-emacs-lisp))
11352 (anything :sources '(anything-c-source-info-elisp
11353 anything-c-source-info-cl
11354 anything-c-source-info-pages
11355 anything-c-source-google-suggest)
11356 :input (and arg (thing-at-point 'symbol))
11357 :buffer "*anything info*")))
11359 ;;;###autoload
11360 (defun anything-info-emacs ()
11361 "Preconfigured anything for Emacs manual index."
11362 (interactive)
11363 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11365 ;;;###autoload
11366 (defun anything-show-kill-ring ()
11367 "Preconfigured `anything' for `kill-ring'.
11368 It is drop-in replacement of `yank-pop'.
11369 You may bind this command to M-y.
11370 First call open the kill-ring browser, next calls move to next line."
11371 (interactive)
11372 (let ((buf "*anything kill-ring*"))
11373 (if (get-buffer-window buf)
11374 (with-anything-window
11375 (if (eq (overlay-end anything-selection-overlay) (point-max))
11376 (anything-beginning-of-buffer)
11377 (anything-next-line)))
11378 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11380 ;;;###autoload
11381 (defun anything-minibuffer-history ()
11382 "Preconfigured `anything' for `minibuffer-history'."
11383 (interactive)
11384 (let ((enable-recursive-minibuffers t))
11385 (anything-other-buffer 'anything-c-source-minibuffer-history
11386 "*anything minibuffer-history*")))
11388 ;;;###autoload
11389 (defun anything-gentoo ()
11390 "Preconfigured `anything' for gentoo linux."
11391 (interactive)
11392 (anything-other-buffer '(anything-c-source-gentoo
11393 anything-c-source-use-flags)
11394 "*anything gentoo*"))
11396 ;;;###autoload
11397 (defun anything-imenu ()
11398 "Preconfigured `anything' for `imenu'."
11399 (interactive)
11400 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11402 ;;;###autoload
11403 (defun anything-google-suggest ()
11404 "Preconfigured `anything' for google search with google suggest."
11405 (interactive)
11406 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11408 ;;;###autoload
11409 (defun anything-yahoo-suggest ()
11410 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11411 (interactive)
11412 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11414 ;;; Converted from anything-show-*-only
11415 ;;;###autoload
11416 (defun anything-for-buffers ()
11417 "Preconfigured `anything' for buffer."
11418 (interactive)
11419 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11421 ;;;###autoload
11422 (defun anything-buffers-list ()
11423 "Enhanced preconfigured `anything' for buffer."
11424 (interactive)
11425 (anything :sources '(anything-c-source-buffers-list
11426 anything-c-source-buffer-not-found)
11427 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11429 ;;;###autoload
11430 (defun anything-bbdb ()
11431 "Preconfigured `anything' for BBDB.
11433 Needs BBDB.
11435 http://bbdb.sourceforge.net/"
11436 (interactive)
11437 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11439 ;;;###autoload
11440 (defun anything-locate (arg)
11441 "Preconfigured `anything' for Locate.
11442 Note: you can add locate options after entering pattern.
11443 See 'man locate' for valid options.
11445 You can specify a specific database with prefix argument ARG \(C-u\).
11446 Many databases can be used: navigate and mark them.
11447 See also `anything-locate-with-db'.
11449 To create a user specific db, use
11450 \"updatedb -l 0 -o db_path -U directory\".
11451 Where db_path is a filename matched by
11452 `anything-locate-db-file-regexp'."
11453 (interactive "P")
11454 (anything-locate-1 arg))
11456 ;;;###autoload
11457 (defun anything-w3m-bookmarks ()
11458 "Preconfigured `anything' for w3m bookmark.
11460 Needs w3m and emacs-w3m.
11462 http://w3m.sourceforge.net/
11463 http://emacs-w3m.namazu.org/"
11464 (interactive)
11465 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11466 "*anything w3m bookmarks*"))
11468 ;;;###autoload
11469 (defun anything-firefox-bookmarks ()
11470 "Preconfigured `anything' for firefox bookmark.
11471 You will have to enable html bookmarks in firefox:
11472 open about:config in firefox and double click on this line to enable value \
11473 to true:
11475 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11477 You should have now:
11479 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11481 After closing firefox, you will be able to browse you bookmarks.
11483 (interactive)
11484 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11485 "*Anything Firefox*"))
11487 ;;;###autoload
11488 (defun anything-colors ()
11489 "Preconfigured `anything' for color."
11490 (interactive)
11491 (anything-other-buffer
11492 '(anything-c-source-colors anything-c-source-customize-face)
11493 "*anything colors*"))
11495 ;;;###autoload
11496 (defun anything-bookmarks ()
11497 "Preconfigured `anything' for bookmarks."
11498 (interactive)
11499 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11501 ;;;###autoload
11502 (defun anything-c-pp-bookmarks ()
11503 "Preconfigured `anything' for bookmarks (pretty-printed)."
11504 (interactive)
11505 (anything-other-buffer '(anything-c-source-bookmarks-local
11506 anything-c-source-bookmarks-su
11507 anything-c-source-bookmarks-ssh)
11508 "*anything pp bookmarks*"))
11510 ;;;###autoload
11511 (defun anything-c-insert-latex-math ()
11512 "Preconfigured anything for latex math symbols completion."
11513 (interactive)
11514 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11516 ;;;###autoload
11517 (defun anything-register ()
11518 "Preconfigured `anything' for Emacs registers."
11519 (interactive)
11520 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11522 ;;;###autoload
11523 (defun anything-man-woman ()
11524 "Preconfigured `anything' for Man and Woman pages."
11525 (interactive)
11526 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11528 ;;;###autoload
11529 (defun anything-org-keywords ()
11530 "Preconfigured `anything' for org keywords."
11531 (interactive)
11532 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11534 ;;;###autoload
11535 (defun anything-emms ()
11536 "Preconfigured `anything' for emms sources."
11537 (interactive)
11538 (anything '(anything-c-source-emms-streams
11539 anything-c-source-emms-files
11540 anything-c-source-emms-dired)
11541 nil nil nil nil
11542 "*Anything Emms*"))
11544 ;;;###autoload
11545 (defun anything-eev-anchors ()
11546 "Preconfigured `anything' for eev anchors."
11547 (interactive)
11548 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11550 ;;;###autoload
11551 (defun anything-bm-list ()
11552 "Preconfigured `anything' for visible bookmarks.
11554 Needs bm.el
11556 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11557 (interactive)
11558 (let ((anything-outline-using t))
11559 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11561 ;;;###autoload
11562 (defun anything-timers ()
11563 "Preconfigured `anything' for timers."
11564 (interactive)
11565 (anything-other-buffer '(anything-c-source-absolute-time-timers
11566 anything-c-source-idle-time-timers)
11567 "*anything timers*"))
11569 ;;;###autoload
11570 (defun anything-list-emacs-process ()
11571 "Preconfigured `anything' for emacs process."
11572 (interactive)
11573 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11575 ;;;###autoload
11576 (defun anything-occur ()
11577 "Preconfigured Anything for Occur source.
11578 If region is active, search only in region,
11579 otherwise search in whole buffer."
11580 (interactive)
11581 (let ((anything-compile-source-functions
11582 ;; rule out anything-match-plugin because the input is one regexp.
11583 (delq 'anything-compile-source--match-plugin
11584 (copy-sequence anything-compile-source-functions))))
11585 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11587 ;;;###autoload
11588 (defun anything-browse-code ()
11589 "Preconfigured anything to browse code."
11590 (interactive)
11591 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11593 ;;;###autoload
11594 (defun anything-org-headlines ()
11595 "Preconfigured anything to show org headlines."
11596 (interactive)
11597 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11599 ;;;###autoload
11600 (defun anything-info-gnus ()
11601 "Preconfigured anything to browse Gnus Manual."
11602 (interactive)
11603 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11605 ;;;###autoload
11606 (defun anything-regexp ()
11607 "Preconfigured anything to build regexps and run query-replace-regexp \
11608 against."
11609 (interactive)
11610 (save-restriction
11611 (let ((anything-compile-source-functions
11612 ;; rule out anything-match-plugin because the input is one regexp.
11613 (delq 'anything-compile-source--match-plugin
11614 (copy-sequence anything-compile-source-functions))))
11615 (when (and (anything-region-active-p)
11616 ;; Don't narrow to region if buffer is already narrowed.
11617 (not (anything-current-buffer-narrowed-p)))
11618 (narrow-to-region (region-beginning) (region-end)))
11619 (anything :sources
11620 anything-c-source-regexp
11621 :buffer "*anything regexp*"
11622 :prompt "Regexp: "))))
11624 (defun anything-c-copy-files-async ()
11625 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11626 (interactive)
11627 (let* ((flist (anything-c-read-file-name
11628 "Copy File async: "
11629 :marked-candidates t))
11630 (dest (anything-c-read-file-name
11631 "Copy File async To: "
11632 :preselect (car flist)
11633 :initial-input (car anything-ff-history)
11634 :history (anything-find-files-history :comp-read nil))))
11635 (anything-c-copy-async-with-log flist dest)))
11637 ;;;###autoload
11638 (defun anything-find-files (arg)
11639 "Preconfigured `anything' for anything implementation of `find-file'.
11640 Called with a prefix arg show history if some.
11641 Don't call it from programs, use `anything-find-files-1' instead.
11642 This is the starting point for nearly all actions you can do on files."
11643 (interactive "P")
11644 (let ((any-input (if (and arg anything-ff-history)
11645 (anything-find-files-history)
11646 (anything-find-files-initial-input)))
11647 (presel (buffer-file-name (current-buffer))))
11648 (when (and (eq major-mode 'org-agenda-mode)
11649 org-directory
11650 (not any-input))
11651 (setq any-input (expand-file-name org-directory)))
11652 (set-text-properties 0 (length any-input) nil any-input)
11653 (if any-input
11654 (anything-find-files-1 any-input)
11655 (setq any-input (expand-file-name (anything-c-current-directory)))
11656 (anything-find-files-1
11657 any-input (if anything-ff-transformer-show-only-basename
11658 (and presel (anything-c-basename presel))
11659 presel)))))
11661 ;;;###autoload
11662 (defun anything-write-file ()
11663 "Preconfigured `anything' providing completion for `write-file'."
11664 (interactive)
11665 (let ((anything-mp-highlight-delay nil))
11666 (anything :sources 'anything-c-source-write-file
11667 :input (expand-file-name default-directory)
11668 :prompt "Write buffer to file: "
11669 :buffer "*Anything write file*")))
11671 ;;;###autoload
11672 (defun anything-insert-file ()
11673 "Preconfigured `anything' providing completion for `insert-file'."
11674 (interactive)
11675 (let ((anything-mp-highlight-delay nil))
11676 (anything :sources 'anything-c-source-insert-file
11677 :input (expand-file-name default-directory)
11678 :prompt "Insert file: "
11679 :buffer "*Anything insert file*")))
11681 ;;;###autoload
11682 (defun anything-dired-rename-file ()
11683 "Preconfigured `anything' to rename files from dired."
11684 (interactive)
11685 (anything-dired-do-action-on-file :action 'rename))
11687 ;;;###autoload
11688 (defun anything-dired-copy-file ()
11689 "Preconfigured `anything' to copy files from dired."
11690 (interactive)
11691 (anything-dired-do-action-on-file :action 'copy))
11693 ;;;###autoload
11694 (defun anything-dired-symlink-file ()
11695 "Preconfigured `anything' to symlink files from dired."
11696 (interactive)
11697 (anything-dired-do-action-on-file :action 'symlink))
11699 ;;;###autoload
11700 (defun anything-dired-hardlink-file ()
11701 "Preconfigured `anything' to hardlink files from dired."
11702 (interactive)
11703 (anything-dired-do-action-on-file :action 'hardlink))
11705 ;;;###autoload
11706 (defun anything-do-grep ()
11707 "Preconfigured anything for grep.
11708 Contrarily to Emacs `grep' no default directory is given, but
11709 the full path of candidates in ONLY.
11710 That allow to grep different files not only in `default-directory' but anywhere
11711 by marking them (C-<SPACE>). If one or more directory is selected
11712 grep will search in all files of these directories.
11713 You can use also wildcard in the base name of candidate.
11714 If a prefix arg is given use the -r option of grep.
11715 The prefix arg can be passed before or after start.
11716 See also `anything-do-grep-1'."
11717 (interactive)
11718 (let ((only (anything-c-read-file-name
11719 "Search in file(s): "
11720 :marked-candidates t
11721 :preselect (or (dired-get-filename nil t)
11722 (buffer-file-name (current-buffer)))))
11723 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11724 (anything-do-grep-1 only prefarg)))
11726 ;;;###autoload
11727 (defun anything-do-zgrep (candidate)
11728 "Preconfigured anything for zgrep."
11729 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11730 (ls (anything-c-read-file-name
11731 "Search in file(s): "
11732 :marked-candidates t
11733 :preselect (or (dired-get-filename nil t)
11734 (buffer-file-name (current-buffer))))))
11735 (anything-ff-zgrep-1 ls prefarg)))
11737 (defun anything-c-etags-select (arg)
11738 "Preconfigured anything for etags.
11739 Called with one prefix arg use symbol at point as initial input.
11740 Called with two prefix arg reinitialize cache.
11741 If tag file have been modified reinitialize cache."
11742 (interactive "P")
11743 (let ((tag (anything-c-etags-get-tag-file))
11744 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11745 (anything-quit-if-no-candidate t)
11746 (anything-execute-action-at-once-if-one t)
11747 (anything-compile-source-functions
11748 (if anything-c-etags-use-regexp-search
11749 ;; rule out anything-match-plugin because the input is one regexp.
11750 (delq 'anything-compile-source--match-plugin
11751 (copy-sequence anything-compile-source-functions))
11752 anything-compile-source-functions)))
11753 (when (or (equal arg '(16))
11754 (and anything-c-etags-mtime-alist
11755 (anything-c-etags-file-modified-p tag)))
11756 (remhash tag anything-c-etags-cache))
11757 (if (and tag (file-exists-p tag))
11758 (anything :sources 'anything-c-source-etags-select
11759 :keymap anything-c-etags-map
11760 :input init
11761 :buffer "*anything etags*")
11762 (message "Error: No tag file found, please create one with etags shell command."))))
11764 ;;;###autoload
11765 (defun anything-filelist ()
11766 "Preconfigured `anything' to open files instantly.
11768 See `anything-c-filelist-file-name' docstring for usage."
11769 (interactive)
11770 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11772 ;;;###autoload
11773 (defun anything-filelist+ ()
11774 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11776 This is a replacement for `anything-for-files'.
11777 See `anything-c-filelist-file-name' docstring for usage."
11778 (interactive)
11779 (anything-other-buffer
11780 '(anything-c-source-ffap-line
11781 anything-c-source-ffap-guesser
11782 anything-c-source-buffers-list
11783 anything-c-source-recentf
11784 anything-c-source-bookmarks
11785 anything-c-source-file-cache
11786 anything-c-source-filelist)
11787 "*anything file list*"))
11789 ;;;###autoload
11790 (defun anything-M-x ()
11791 "Preconfigured `anything' for Emacs commands.
11792 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11793 (interactive)
11794 (let* (in-help
11795 help-cand
11796 anything-persistent-action-use-special-display
11797 (history (loop with hist
11798 for i in extended-command-history
11799 for com = (intern i)
11800 when (fboundp com)
11801 collect i into hist finally return hist)))
11802 (flet ((pers-help (candidate)
11803 (let ((hbuf (get-buffer (help-buffer))))
11804 (if (and in-help (string= candidate help-cand))
11805 (progn
11806 ;; When M-x is started from a help buffer,
11807 ;; Don't kill it as it is anything-current-buffer.
11808 (unless (equal hbuf anything-current-buffer)
11809 (kill-buffer hbuf))
11810 (setq in-help nil))
11811 ;; Be sure anything-current-buffer
11812 ;; have not a dedicated window.
11813 (set-window-dedicated-p
11814 (get-buffer-window anything-current-buffer) nil)
11815 (describe-function (intern candidate))
11816 (message nil) ; Erase the new stupid message Type "q"[...]
11817 (setq in-help t))
11818 (setq help-cand candidate))))
11819 (let* ((command
11821 (anything
11822 :sources
11823 '(((name . "Emacs Commands history")
11824 (candidates . history)
11825 (filtered-candidate-transformer
11826 . (lambda (candidates sources)
11827 (loop for i in candidates
11828 do (set-text-properties 0 (length i) nil i)
11829 collect i)))
11830 (persistent-action . pers-help)
11831 (persistent-help . "Describe this command")
11832 (action . identity))
11833 ((name . "Emacs Commands")
11834 (init
11835 . (lambda ()
11836 (with-current-buffer (anything-candidate-buffer 'global)
11837 (goto-char (point-min))
11838 (loop
11839 for sym in (all-completions "" obarray 'commandp)
11840 do (insert (concat sym "\n"))))))
11841 (persistent-action . pers-help)
11842 (persistent-help . "Describe this command")
11843 (filtered-candidate-transformer . anything-M-x-transformer)
11844 (candidates-in-buffer)
11845 (action . identity)))
11846 :buffer "*anything M-x*")
11847 (keyboard-quit)))
11848 (sym-com (intern command)))
11849 (unless current-prefix-arg
11850 (setq current-prefix-arg anything-current-prefix-arg))
11851 ;; Avoid having `this-command' set to *exit-minibuffer.
11852 (setq this-command sym-com)
11853 (call-interactively sym-com)
11854 (setq extended-command-history
11855 (cons command (delete command history)))))))
11857 ;;;###autoload
11858 (defun anything-manage-advice ()
11859 "Preconfigured `anything' to disable/enable function advices."
11860 (interactive)
11861 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11863 ;;;###autoload
11864 (defun anything-bookmark-ext ()
11865 "Preconfigured `anything' for bookmark-extensions sources.
11866 Needs bookmark-ext.el:
11867 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11868 Contain also `anything-c-source-google-suggest'."
11869 (interactive)
11870 (anything
11871 :sources
11872 '(anything-c-source-bookmark-files&dirs
11873 anything-c-source-bookmark-w3m
11874 anything-c-source-google-suggest
11875 anything-c-source-bmkext-addressbook
11876 anything-c-source-bookmark-gnus
11877 anything-c-source-bookmark-info
11878 anything-c-source-bookmark-man
11879 anything-c-source-bookmark-images
11880 anything-c-source-bookmark-su-files&dirs
11881 anything-c-source-bookmark-ssh-files&dirs)
11882 :prompt "SearchBookmark: "
11883 :buffer "*anything bmkext*"))
11885 ;;;###autoload
11886 (defun anything-simple-call-tree ()
11887 "Preconfigured `anything' for simple-call-tree. List function relationships.
11889 Needs simple-call-tree.el.
11890 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11891 (interactive)
11892 (anything-other-buffer
11893 '(anything-c-source-simple-call-tree-functions-callers
11894 anything-c-source-simple-call-tree-callers-functions)
11895 "*anything simple-call-tree*"))
11897 ;;;###autoload
11898 (defun anything-mark-ring ()
11899 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11900 (interactive)
11901 (anything 'anything-c-source-mark-ring))
11903 ;;;###autoload
11904 (defun anything-global-mark-ring ()
11905 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11906 (interactive)
11907 (anything 'anything-c-source-global-mark-ring))
11909 ;;;###autoload
11910 (defun anything-all-mark-rings ()
11911 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11912 `anything-c-source-mark-ring'."
11913 (interactive)
11914 (anything '(anything-c-source-mark-ring
11915 anything-c-source-global-mark-ring)))
11917 ;;;###autoload
11918 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11919 "Preconfigured `anything' to edit or view EmacsWiki page.
11921 Needs yaoddmuse.el.
11923 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11924 (interactive)
11925 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11927 ;;;###autoload
11928 (defun anything-yaoddmuse-emacswiki-post-library ()
11929 "Preconfigured `anything' to post library to EmacsWiki.
11931 Needs yaoddmuse.el.
11933 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11934 (interactive)
11935 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11937 ;;;###autoload
11938 (defun anything-eval-expression (arg)
11939 "Preconfigured anything for `anything-c-source-evaluation-result'."
11940 (interactive "P")
11941 (anything :sources 'anything-c-source-evaluation-result
11942 :input (when arg (thing-at-point 'sexp))
11943 :buffer "*anything eval*"
11944 :keymap anything-eval-expression-map))
11946 ;;;###autoload
11947 (defun anything-eval-expression-with-eldoc ()
11948 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11949 (interactive)
11950 (declare (special eldoc-idle-delay))
11951 (let ((timer (run-with-idle-timer eldoc-idle-delay
11952 'repeat 'anything-eldoc-show-in-eval))
11953 (minibuffer-completing-symbol t) ; Enable lisp completion.
11954 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11955 (unwind-protect
11956 (minibuffer-with-setup-hook
11957 'anything-eldoc-store-minibuffer
11958 (call-interactively 'anything-eval-expression))
11959 (and timer (cancel-timer timer))
11960 (setq anything-eldoc-active-minibuffers-list
11961 (cdr anything-eldoc-active-minibuffers-list)))))
11963 ;;;###autoload
11964 (defun anything-calcul-expression ()
11965 "Preconfigured anything for `anything-c-source-calculation-result'."
11966 (interactive)
11967 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11969 ;;;###autoload
11970 (defun anything-surfraw (pattern engine)
11971 "Preconfigured `anything' to search PATTERN with search ENGINE."
11972 (interactive (list (read-string "SearchFor: ")
11973 (anything-comp-read
11974 "Engine: "
11975 (anything-c-build-elvi-list)
11976 :must-match t
11977 :name "Surfraw Search Engines"
11978 :history anything-surfraw-engines-history)))
11979 (let* ((engine-nodesc (car (split-string engine)))
11980 (url (with-temp-buffer
11981 (apply 'call-process "surfraw" nil t nil
11982 ;;JAVE
11983 (append (list engine-nodesc "-p") (split-string pattern)))
11984 (replace-regexp-in-string
11985 "\n" "" (buffer-string))))
11986 (browse-url-browser-function (or anything-surfraw-default-browser-function
11987 browse-url-browser-function)))
11988 (if (string= engine-nodesc "W")
11989 (anything-c-browse-url)
11990 (anything-c-browse-url url)
11991 (setq anything-surfraw-engines-history
11992 (cons engine (delete engine anything-surfraw-engines-history))))))
11994 ;;;###autoload
11995 (defun anything-call-source ()
11996 "Preconfigured `anything' to call anything source."
11997 (interactive)
11998 (anything 'anything-c-source-call-source nil nil nil nil
11999 anything-source-select-buffer))
12001 ;;;###autoload
12002 (defun anything-execute-anything-command ()
12003 "Preconfigured `anything' to execute preconfigured `anything'."
12004 (interactive)
12005 (anything-other-buffer 'anything-c-source-anything-commands
12006 "*anything commands*"))
12008 ;;;###autoload
12009 (defun anything-create (&optional string initial-input)
12010 "Preconfigured `anything' to do many create actions from STRING.
12011 See also `anything-create--actions'."
12012 (interactive)
12013 (setq string (or string (read-string "Create Anything: " initial-input)))
12014 (anything '(((name . "Anything Create")
12015 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12016 (candidates . anything-create--actions)
12017 (candidate-number-limit)
12018 (action . (lambda (func) (funcall func string)))))))
12020 ;;;###autoload
12021 (defun anything-top ()
12022 "Preconfigured `anything' for top command."
12023 (interactive)
12024 (let ((anything-samewindow t)
12025 (anything-enable-shortcuts)
12026 (anything-display-function 'anything-default-display-buffer)
12027 (anything-candidate-number-limit 9999))
12028 (save-window-excursion
12029 (delete-other-windows)
12030 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12032 ;;;###autoload
12033 (defun anything-select-xfont ()
12034 "Preconfigured `anything' to select Xfont."
12035 (interactive)
12036 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12038 ;;;###autoload
12039 (defun anything-world-time ()
12040 "Preconfigured `anything' to show world time."
12041 (interactive)
12042 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12044 ;;;###autoload
12045 (defun anything-apt (arg query)
12046 "Preconfigured `anything' : frontend of APT package manager.
12047 With a prefix arg reload cache."
12048 (interactive "P\nsSearch Package: ")
12049 (when arg
12050 (setq anything-c-apt-installed-packages nil)
12051 (setq anything-c-apt-all-packages nil))
12052 (anything :sources 'anything-c-source-apt
12053 :prompt "Search Package: " :input query))
12055 ;;;###autoload
12056 (defun anything-esh-pcomplete ()
12057 "Preconfigured anything to provide anything completion in eshell."
12058 (interactive)
12059 (let* ((anything-quit-if-no-candidate t)
12060 (anything-execute-action-at-once-if-one t)
12061 (target (thing-at-point 'symbol))
12062 (end (point))
12063 (beg (or (and target (- end (length target)))
12064 ;; Nothing at point.
12065 (progn (insert " ") (point)))))
12066 (setq anything-ec-target (or target " "))
12067 (with-anything-show-completion beg end
12068 (anything :sources 'anything-c-source-esh
12069 :input (anything-ff-set-pattern ; Handle tramp filenames.
12070 (car (last (ignore-errors ; Needed in lisp symbols completion.
12071 (pcomplete-parse-arguments)))))))))
12073 ;;;###autoload
12074 (defun anything-eshell-history ()
12075 "Preconfigured anything for eshell history."
12076 (interactive)
12077 (let* ((end (point))
12078 (beg (save-excursion (eshell-bol) (point)))
12079 flag-empty)
12080 (when (eq beg end)
12081 (insert " ")
12082 (setq flag-empty t)
12083 (setq end (point)))
12084 (unwind-protect
12085 (with-anything-show-completion beg end
12086 (anything :sources 'anything-c-source-eshell-history
12087 :buffer "*Eshell history*"))
12088 (when (and flag-empty
12089 (looking-back " "))
12090 (delete-char -1)))))
12092 ;;;###autoload
12093 (defun anything-c-run-external-command (program)
12094 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12095 If program is already running exit with error.
12096 You can set your own list of commands with
12097 `anything-c-external-commands-list'."
12098 (interactive (list
12099 (anything-comp-read
12100 "RunProgram: "
12101 (anything-c-external-commands-list-1 'sort)
12102 :must-match t
12103 :name "External Commands"
12104 :history anything-external-command-history)))
12105 (anything-run-or-raise program)
12106 (setq anything-external-command-history
12107 (cons program (delete program
12108 (loop for i in anything-external-command-history
12109 when (executable-find i) collect i)))))
12111 ;;;###autoload
12112 (defun anything-ratpoison-commands ()
12113 "Preconfigured `anything' to execute ratpoison commands."
12114 (interactive)
12115 (anything-other-buffer 'anything-c-source-ratpoison-commands
12116 "*anything ratpoison commands*"))
12118 ;;;###autoload
12119 (defun anything-ucs ()
12120 "Preconfigured anything for `ucs-names' math symbols."
12121 (interactive)
12122 (anything :sources 'anything-c-source-ucs
12123 :keymap anything-c-ucs-map))
12125 ;;;###autoload
12126 (defun anything-c-apropos ()
12127 "Preconfigured anything to describe commands, functions, variables and faces."
12128 (interactive)
12129 (let ((default (thing-at-point 'symbol)))
12130 (anything :sources
12131 `(((name . "Commands")
12132 (init . (lambda ()
12133 (anything-c-apropos-init 'commandp ,default)))
12134 (persistent-action . anything-lisp-completion-persistent-action)
12135 (persistent-help . "Show brief doc in mode-line")
12136 (candidates-in-buffer)
12137 (action . (lambda (candidate)
12138 (describe-function (intern candidate)))))
12139 ((name . "Functions")
12140 (init . (lambda ()
12141 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12142 (not (commandp x))))
12143 ,default)))
12144 (persistent-action . anything-lisp-completion-persistent-action)
12145 (persistent-help . "Show brief doc in mode-line")
12146 (candidates-in-buffer)
12147 (action . (lambda (candidate)
12148 (describe-function (intern candidate)))))
12149 ((name . "Variables")
12150 (init . (lambda ()
12151 (anything-c-apropos-init 'boundp ,default)))
12152 (persistent-action . anything-lisp-completion-persistent-action)
12153 (persistent-help . "Show brief doc in mode-line")
12154 (candidates-in-buffer)
12155 (action . (lambda (candidate)
12156 (describe-variable (intern candidate)))))
12157 ((name . "Faces")
12158 (init . (lambda ()
12159 (anything-c-apropos-init 'facep ,default)))
12160 (persistent-action . anything-lisp-completion-persistent-action)
12161 (persistent-help . "Show brief doc in mode-line")
12162 (candidates-in-buffer)
12163 (filtered-candidate-transformer . (lambda (candidates source)
12164 (loop for c in candidates
12165 collect (propertize c 'face (intern c)))))
12166 (action . (lambda (candidate)
12167 (describe-face (intern candidate)))))
12168 ((name . "Anything attributes")
12169 (candidates . (lambda ()
12170 (mapcar 'symbol-name anything-additional-attributes)))
12171 (action . (lambda (candidate)
12172 (with-output-to-temp-buffer "*Help*"
12173 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12176 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12179 (provide 'anything-config)
12181 ;;; Local Variables:
12182 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12183 ;;; End:
12185 ;; How to save (DO NOT REMOVE!!)
12186 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12187 ;;; anything-config.el ends here
12189 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12190 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12191 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12192 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12193 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12194 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12195 ;;; LocalWords: dotimes Thierry online vname
12196 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12197 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12198 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12199 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12200 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12201 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12202 ;;; LocalWords: startpos noselect dont desc