* anything.el (anything-execute-selection-action-1): Set exit status here.
[anything-config.git] / anything-config.el
bloba55dfd568deb163f46d222b26ecd596c013c9429
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-show-this-source-only'
106 ;; Show all candidates of this source.
107 ;; `anything-test-sources'
108 ;; List all anything sources for test.
109 ;; `anything-select-source'
110 ;; [OBSOLETE] Select source.
111 ;; `anything-quit-and-find-file'
112 ;; Drop into `anything-find-files' from `anything'.
113 ;; `anything-mark-all'
114 ;; Mark all visible unmarked candidates in current source.
115 ;; `anything-unmark-all'
116 ;; Unmark all candidates in all sources of current anything session.
117 ;; `anything-toggle-all-marks'
118 ;; Toggle all marks.
119 ;; `anything-buffer-diff-persistent'
120 ;; Toggle diff buffer without quitting anything.
121 ;; `anything-buffer-revert-persistent'
122 ;; Revert buffer without quitting anything.
123 ;; `anything-buffer-save-persistent'
124 ;; Save buffer without quitting anything.
125 ;; `anything-buffer-run-kill-buffers'
126 ;; Run kill buffer action from `anything-c-source-buffers-list'.
127 ;; `anything-buffer-run-grep'
128 ;; Run Grep action from `anything-c-source-buffers-list'.
129 ;; `anything-buffer-run-zgrep'
130 ;; Run Grep action from `anything-c-source-buffers-list'.
131 ;; `anything-buffer-run-query-replace-regexp'
132 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
133 ;; `anything-buffer-run-query-replace'
134 ;; Run Query replace action from `anything-c-source-buffers-list'.
135 ;; `anything-buffer-switch-other-window'
136 ;; Run switch to other window action from `anything-c-source-buffers-list'.
137 ;; `anything-buffer-switch-other-frame'
138 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
139 ;; `anything-buffer-switch-to-elscreen'
140 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
141 ;; `anything-buffer-run-ediff'
142 ;; Run ediff action from `anything-c-source-buffers-list'.
143 ;; `anything-buffer-run-ediff-merge'
144 ;; Run ediff action from `anything-c-source-buffers-list'.
145 ;; `anything-ff-run-toggle-auto-update'
146 ;; Not documented.
147 ;; `anything-ff-run-switch-to-history'
148 ;; Run Switch to history action from `anything-c-source-find-files'.
149 ;; `anything-ff-run-grep'
150 ;; Run Grep action from `anything-c-source-find-files'.
151 ;; `anything-ff-run-pdfgrep'
152 ;; Run Pdfgrep action from `anything-c-source-find-files'.
153 ;; `anything-ff-run-zgrep'
154 ;; Run Grep action from `anything-c-source-find-files'.
155 ;; `anything-ff-run-copy-file'
156 ;; Run Copy file action from `anything-c-source-find-files'.
157 ;; `anything-ff-run-rename-file'
158 ;; Run Rename file action from `anything-c-source-find-files'.
159 ;; `anything-ff-run-byte-compile-file'
160 ;; Run Byte compile file action from `anything-c-source-find-files'.
161 ;; `anything-ff-run-load-file'
162 ;; Run Load file action from `anything-c-source-find-files'.
163 ;; `anything-ff-run-eshell-command-on-file'
164 ;; Run eshell command on file action from `anything-c-source-find-files'.
165 ;; `anything-ff-run-ediff-file'
166 ;; Run Ediff file action from `anything-c-source-find-files'.
167 ;; `anything-ff-run-ediff-merge-file'
168 ;; Run Ediff merge file action from `anything-c-source-find-files'.
169 ;; `anything-ff-run-symlink-file'
170 ;; Run Symlink file action from `anything-c-source-find-files'.
171 ;; `anything-ff-run-delete-file'
172 ;; Run Delete file action from `anything-c-source-find-files'.
173 ;; `anything-ff-run-complete-fn-at-point'
174 ;; Run complete file name action from `anything-c-source-find-files'.
175 ;; `anything-ff-run-switch-to-eshell'
176 ;; Run switch to eshell action from `anything-c-source-find-files'.
177 ;; `anything-ff-run-switch-other-window'
178 ;; Run switch to other window action from `anything-c-source-find-files'.
179 ;; `anything-ff-run-switch-other-frame'
180 ;; Run switch to other frame action from `anything-c-source-find-files'.
181 ;; `anything-ff-run-open-file-externally'
182 ;; Run open file externally command action from `anything-c-source-find-files'.
183 ;; `anything-ff-run-locate'
184 ;; Run locate action from `anything-c-source-find-files'.
185 ;; `anything-ff-run-gnus-attach-files'
186 ;; Run gnus attach files command action from `anything-c-source-find-files'.
187 ;; `anything-ff-run-etags'
188 ;; Run Etags command action from `anything-c-source-find-files'.
189 ;; `anything-ff-run-print-file'
190 ;; Run Print file action from `anything-c-source-find-files'.
191 ;; `anything-ff-run-toggle-basename'
192 ;; Not documented.
193 ;; `anything-find-files-down-one-level'
194 ;; Go down one level like unix command `cd ..'.
195 ;; `anything-ff-properties-persistent'
196 ;; Show properties without quitting anything.
197 ;; `anything-ff-run-kill-buffer-persistent'
198 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
199 ;; `anything-ff-rotate-left-persistent'
200 ;; Rotate image left without quitting anything.
201 ;; `anything-ff-rotate-right-persistent'
202 ;; Rotate image right without quitting anything.
203 ;; `anything-c-goto-precedent-file'
204 ;; Go to precedent file in anything grep/etags buffers.
205 ;; `anything-c-goto-next-file'
206 ;; Go to precedent file in anything grep/etags buffers.
207 ;; `anything-c-grep-run-persistent-action'
208 ;; Run grep persistent action from `anything-do-grep-1'.
209 ;; `anything-c-grep-run-default-action'
210 ;; Run grep default action from `anything-do-grep-1'.
211 ;; `anything-c-grep-run-other-window-action'
212 ;; Run grep goto other window action from `anything-do-grep-1'.
213 ;; `anything-c-grep-run-save-buffer'
214 ;; Run grep save results action from `anything-do-grep-1'.
215 ;; `anything-do-pdfgrep'
216 ;; Not documented.
217 ;; `anything-yank-text-at-point'
218 ;; Yank text at point in minibuffer.
219 ;; `anything-c-describe-attributes'
220 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
221 ;; `anything-yaoddmuse-cache-pages'
222 ;; Fetch the list of files on emacswiki and create cache file.
223 ;; `anything-eval-new-line-and-indent'
224 ;; Not documented.
225 ;; `anything-call-source-from-anything'
226 ;; Call anything source within `anything' session.
227 ;; `anything-create-from-anything'
228 ;; Run `anything-create' from `anything' as a fallback.
229 ;; `anything-c-ucs-persistent-insert'
230 ;; Not documented.
231 ;; `anything-c-ucs-persistent-forward'
232 ;; Not documented.
233 ;; `anything-c-ucs-persistent-backward'
234 ;; Not documented.
235 ;; `anything-c-ucs-persistent-delete'
236 ;; Not documented.
237 ;; `anything-lisp-completion-at-point'
238 ;; Anything lisp symbol completion at point.
239 ;; `anything-c-complete-file-name-at-point'
240 ;; Complete file name at point.
241 ;; `anything-lisp-completion-at-point-or-indent'
242 ;; First call indent and second call complete lisp symbol.
243 ;; `anything-lisp-completion-or-file-name-at-point'
244 ;; Complete lisp symbol or filename at point.
245 ;; `anything-c-set-variable'
246 ;; Set value to VAR interactively.
247 ;; `anything-c-adaptive-save-history'
248 ;; Save history information to file given by `anything-c-adaptive-history-file'.
249 ;; `anything-c-reset-adaptative-history'
250 ;; Delete all `anything-c-adaptive-history' and his file.
251 ;; `anything-c-toggle-match-plugin'
252 ;; Toggle anything-match-plugin.
253 ;; `anything-mini'
254 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
255 ;; `anything-for-files'
256 ;; Preconfigured `anything' for opening files.
257 ;; `anything-recentf'
258 ;; Preconfigured `anything' for `recentf'.
259 ;; `anything-info-at-point'
260 ;; Preconfigured `anything' for searching info at point.
261 ;; `anything-info-emacs'
262 ;; Preconfigured anything for Emacs manual index.
263 ;; `anything-show-kill-ring'
264 ;; Preconfigured `anything' for `kill-ring'.
265 ;; `anything-minibuffer-history'
266 ;; Preconfigured `anything' for `minibuffer-history'.
267 ;; `anything-gentoo'
268 ;; Preconfigured `anything' for gentoo linux.
269 ;; `anything-imenu'
270 ;; Preconfigured `anything' for `imenu'.
271 ;; `anything-google-suggest'
272 ;; Preconfigured `anything' for google search with google suggest.
273 ;; `anything-yahoo-suggest'
274 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
275 ;; `anything-for-buffers'
276 ;; Preconfigured `anything' for buffer.
277 ;; `anything-buffers-list'
278 ;; Enhanced preconfigured `anything' for buffer.
279 ;; `anything-bbdb'
280 ;; Preconfigured `anything' for BBDB.
281 ;; `anything-locate'
282 ;; Preconfigured `anything' for Locate.
283 ;; `anything-w3m-bookmarks'
284 ;; Preconfigured `anything' for w3m bookmark.
285 ;; `anything-firefox-bookmarks'
286 ;; Preconfigured `anything' for firefox bookmark.
287 ;; `anything-colors'
288 ;; Preconfigured `anything' for color.
289 ;; `anything-bookmarks'
290 ;; Preconfigured `anything' for bookmarks.
291 ;; `anything-c-pp-bookmarks'
292 ;; Preconfigured `anything' for bookmarks (pretty-printed).
293 ;; `anything-c-insert-latex-math'
294 ;; Preconfigured anything for latex math symbols completion.
295 ;; `anything-register'
296 ;; Preconfigured `anything' for Emacs registers.
297 ;; `anything-man-woman'
298 ;; Preconfigured `anything' for Man and Woman pages.
299 ;; `anything-org-keywords'
300 ;; Preconfigured `anything' for org keywords.
301 ;; `anything-emms'
302 ;; Preconfigured `anything' for emms sources.
303 ;; `anything-eev-anchors'
304 ;; Preconfigured `anything' for eev anchors.
305 ;; `anything-bm-list'
306 ;; Preconfigured `anything' for visible bookmarks.
307 ;; `anything-timers'
308 ;; Preconfigured `anything' for timers.
309 ;; `anything-list-emacs-process'
310 ;; Preconfigured `anything' for emacs process.
311 ;; `anything-occur'
312 ;; Preconfigured Anything for Occur source.
313 ;; `anything-browse-code'
314 ;; Preconfigured anything to browse code.
315 ;; `anything-org-headlines'
316 ;; Preconfigured anything to show org headlines.
317 ;; `anything-info-gnus'
318 ;; Preconfigured anything to browse Gnus Manual.
319 ;; `anything-regexp'
320 ;; Preconfigured anything to build regexps.
321 ;; `anything-c-copy-files-async'
322 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
323 ;; `anything-find-files'
324 ;; Preconfigured `anything' for anything implementation of `find-file'.
325 ;; `anything-write-file'
326 ;; Preconfigured `anything' providing completion for `write-file'.
327 ;; `anything-insert-file'
328 ;; Preconfigured `anything' providing completion for `insert-file'.
329 ;; `anything-dired-rename-file'
330 ;; Preconfigured `anything' to rename files from dired.
331 ;; `anything-dired-copy-file'
332 ;; Preconfigured `anything' to copy files from dired.
333 ;; `anything-dired-symlink-file'
334 ;; Preconfigured `anything' to symlink files from dired.
335 ;; `anything-dired-hardlink-file'
336 ;; Preconfigured `anything' to hardlink files from dired.
337 ;; `anything-do-grep'
338 ;; Preconfigured anything for grep.
339 ;; `anything-c-etags-select'
340 ;; Preconfigured anything for etags.
341 ;; `anything-filelist'
342 ;; Preconfigured `anything' to open files instantly.
343 ;; `anything-filelist+'
344 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
345 ;; `anything-M-x'
346 ;; Preconfigured `anything' for Emacs commands.
347 ;; `anything-manage-advice'
348 ;; Preconfigured `anything' to disable/enable function advices.
349 ;; `anything-bookmark-ext'
350 ;; Preconfigured `anything' for bookmark-extensions sources.
351 ;; `anything-simple-call-tree'
352 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
353 ;; `anything-mark-ring'
354 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
355 ;; `anything-global-mark-ring'
356 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
357 ;; `anything-all-mark-rings'
358 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
359 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
360 ;; Preconfigured `anything' to edit or view EmacsWiki page.
361 ;; `anything-yaoddmuse-emacswiki-post-library'
362 ;; Preconfigured `anything' to post library to EmacsWiki.
363 ;; `anything-eval-expression'
364 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
365 ;; `anything-eval-expression-with-eldoc'
366 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
367 ;; `anything-calcul-expression'
368 ;; Preconfigured anything for `anything-c-source-calculation-result'.
369 ;; `anything-surfraw'
370 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
371 ;; `anything-call-source'
372 ;; Preconfigured `anything' to call anything source.
373 ;; `anything-execute-anything-command'
374 ;; Preconfigured `anything' to execute preconfigured `anything'.
375 ;; `anything-create'
376 ;; Preconfigured `anything' to do many create actions from STRING.
377 ;; `anything-top'
378 ;; Preconfigured `anything' for top command.
379 ;; `anything-select-xfont'
380 ;; Preconfigured `anything' to select Xfont.
381 ;; `anything-world-time'
382 ;; Preconfigured `anything' to show world time.
383 ;; `anything-apt'
384 ;; Preconfigured `anything' : frontend of APT package manager.
385 ;; `anything-esh-pcomplete'
386 ;; Preconfigured anything to provide anything completion in eshell.
387 ;; `anything-eshell-history'
388 ;; Preconfigured anything for eshell history.
389 ;; `anything-c-run-external-command'
390 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
391 ;; `anything-ratpoison-commands'
392 ;; Preconfigured `anything' to execute ratpoison commands.
393 ;; `anything-ucs'
394 ;; Preconfigured anything for `ucs-names' math symbols.
395 ;; `anything-c-apropos'
396 ;; Preconfigured anything to describe commands, functions, variables and faces.
398 ;; * User variables defined here:
399 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
400 ;; `anything-c-adaptive-history-file'
401 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
402 ;; `anything-c-adaptive-history-length'
403 ;; Default Value: 50
404 ;; `anything-c-google-suggest-url'
405 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
406 ;; `anything-c-google-suggest-search-url'
407 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
408 ;; `anything-google-suggest-use-curl-p'
409 ;; Default Value: nil
410 ;; `anything-c-yahoo-suggest-url'
411 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
412 ;; `anything-c-yahoo-suggest-search-url'
413 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
414 ;; `anything-c-boring-buffer-regexp'
415 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\|\\*ac-mode\\| \\*Echo Area\\| \\*Minibuf"
416 ;; `anything-c-boring-file-regexp'
417 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
418 ;; `anything-kill-ring-threshold'
419 ;; Default Value: 10
420 ;; `anything-c-kill-ring-max-lines-number'
421 ;; Default Value: nil
422 ;; `anything-su-or-sudo'
423 ;; Default Value: "su"
424 ;; `anything-for-files-prefered-list'
425 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
426 ;; `anything-create--actions-private'
427 ;; Default Value: nil
428 ;; `anything-allow-skipping-current-buffer'
429 ;; Default Value: t
430 ;; `anything-c-enable-eval-defun-hack'
431 ;; Default Value: t
432 ;; `anything-tramp-verbose'
433 ;; Default Value: 0
434 ;; `anything-raise-command'
435 ;; Default Value: nil
436 ;; `anything-command-map-prefix-key'
437 ;; Default Value: "<f5> a"
438 ;; `anything-c-browse-code-regexp-lisp'
439 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
440 ;; `anything-c-browse-code-regexp-python'
441 ;; Default Value: "\\<def\\>\\|\\<class\\>"
442 ;; `anything-c-browse-code-regexp-alist'
443 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
444 ;; `anything-c-external-programs-associations'
445 ;; Default Value: nil
446 ;; `anything-ff-auto-update-initial-value'
447 ;; Default Value: t
448 ;; `anything-c-copy-async-prefered-emacs'
449 ;; Default Value: "emacs"
450 ;; `anything-ff-lynx-style-map'
451 ;; Default Value: t
452 ;; `anything-ff-history-max-length'
453 ;; Default Value: 100
454 ;; `anything-ff-smart-completion'
455 ;; Default Value: t
456 ;; `anything-ff-default-kbsize'
457 ;; Default Value: 1024.0
458 ;; `anything-ff-tramp-not-fancy'
459 ;; Default Value: t
460 ;; `anything-ff-exif-data-program'
461 ;; Default Value: "exiftran"
462 ;; `anything-ff-exif-data-program-args'
463 ;; Default Value: "-d"
464 ;; `anything-c-grep-use-ioccur-style-keys'
465 ;; Default Value: t
466 ;; `anything-c-pdfgrep-default-read-command'
467 ;; Default Value: "xpdf '%f' %p"
468 ;; `anything-c-etags-tag-file-name'
469 ;; Default Value: "TAGS"
470 ;; `anything-c-etags-tag-file-search-limit'
471 ;; Default Value: 10
472 ;; `anything-c-etags-use-regexp-search'
473 ;; Default Value: nil
474 ;; `anything-c-etags-search-regexp'
475 ;; Default Value: "^.+: .+ \\<%s"
476 ;; `anything-c-filelist-file-name'
477 ;; Default Value: nil
478 ;; `anything-c-eldoc-in-minibuffer-show-fn'
479 ;; Default Value: anything-c-show-info-in-mode-line
480 ;; `anything-c-turn-on-show-completion'
481 ;; Default Value: t
482 ;; `anything-lisp-completion-or-indent-delay'
483 ;; Default Value: 0.6
484 ;; `anything-c-default-external-file-browser'
485 ;; Default Value: "nautilus"
486 ;; `anything-c-use-adaptative-sorting'
487 ;; Default Value: nil
488 ;; `anything-ff-newfile-prompt-p'
489 ;; Default Value: t
490 ;; `anything-ff-avfs-directory'
491 ;; Default Value: nil
492 ;; `anything-ff-file-compressed-list'
493 ;; Default Value: ("gz" "bz2" "zip" "7z")
494 ;; `anything-locate-db-file-regexp'
495 ;; Default Value: "m?locate.db$"
496 ;; `anything-c-show-info-in-mode-line-delay'
497 ;; Default Value: 12
498 ;; `anything-c-copy-files-async-log-file'
499 ;; Default Value: "/tmp/dired.log"
500 ;; `anything-ff-printer-list'
501 ;; Default Value: nil
502 ;; `anything-ff-transformer-show-only-basename'
503 ;; Default Value: nil
504 ;; `anything-completing-read-handlers-alist'
505 ;; Default Value: ((describe-function . anything-completing-read-symbols) (describe-variabl [...]
507 ;; * Anything sources defined here:
508 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
509 ;; `anything-c-source-regexp' (Regexp Builder)
510 ;; `anything-c-source-buffers' (Buffers)
511 ;; `anything-c-source-buffer-not-found' (Create buffer)
512 ;; `anything-c-source-buffers-list' (Buffers)
513 ;; `anything-c-source-file-name-history' (File Name History)
514 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
515 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
516 ;; `anything-c-source-find-files' (Find Files)
517 ;; `anything-c-source-write-file' (Write File)
518 ;; `anything-c-source-insert-file' (Insert File)
519 ;; `anything-c-source-copy-files' (Copy Files)
520 ;; `anything-c-source-symlink-files' (Symlink Files)
521 ;; `anything-c-source-hardlink-files' (Hardlink Files)
522 ;; `anything-c-source-file-cache' (File Cache)
523 ;; `anything-c-source-locate' (Locate)
524 ;; `anything-c-source-recentf' (Recentf)
525 ;; `anything-c-source-ffap-guesser' (File at point)
526 ;; `anything-c-source-ffap-line' (File/Lineno at point)
527 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
528 ;; `anything-c-source-filelist' (FileList)
529 ;; `anything-c-source-info-pages' (Info Pages)
530 ;; `anything-c-source-info-elisp' (Info index: elisp)
531 ;; `anything-c-source-info-cl' (Info index: cl)
532 ;; `anything-c-source-info-org' (Info index: org)
533 ;; `anything-c-source-info-gnus' (Info index: Gnus)
534 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
535 ;; `anything-c-source-info-zsh' (Info index: zsh)
536 ;; `anything-c-source-info-bash' (Info index: bash)
537 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
538 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
539 ;; `anything-c-source-info-find' (Info index: find)
540 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
541 ;; `anything-c-source-info-textutils' (Info index: textutils)
542 ;; `anything-c-source-info-libc' (Info index: libc)
543 ;; `anything-c-source-info-make' (Info index: make)
544 ;; `anything-c-source-info-automake' (Info index: automake)
545 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
546 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
547 ;; `anything-c-source-info-emacs' (Info index: emacs)
548 ;; `anything-c-source-info-elib' (Info index: elib)
549 ;; `anything-c-source-info-eieio' (Info index: eieio)
550 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
551 ;; `anything-c-source-info-guile' (Info index: guile)
552 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
553 ;; `anything-c-source-info-goops' (Info index: goops)
554 ;; `anything-c-source-info-screen' (Info index: screen)
555 ;; `anything-c-source-info-latex' (Info index: latex)
556 ;; `anything-c-source-info-gawk' (Info index: gawk)
557 ;; `anything-c-source-info-sed' (Info index: sed)
558 ;; `anything-c-source-info-m4' (Info index: m4)
559 ;; `anything-c-source-info-wget' (Info index: wget)
560 ;; `anything-c-source-info-binutils' (Info index: binutils)
561 ;; `anything-c-source-info-as' (Info index: as)
562 ;; `anything-c-source-info-bfd' (Info index: bfd)
563 ;; `anything-c-source-info-gprof' (Info index: gprof)
564 ;; `anything-c-source-info-ld' (Info index: ld)
565 ;; `anything-c-source-info-diff' (Info index: diff)
566 ;; `anything-c-source-info-flex' (Info index: flex)
567 ;; `anything-c-source-info-grep' (Info index: grep)
568 ;; `anything-c-source-info-gzip' (Info index: gzip)
569 ;; `anything-c-source-info-libtool' (Info index: libtool)
570 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
571 ;; `anything-c-source-info-info' (Info index: info)
572 ;; `anything-c-source-info-gdb' (Info index: gdb)
573 ;; `anything-c-source-info-stabs' (Info index: stabs)
574 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
575 ;; `anything-c-source-info-cvs' (Info index: cvs)
576 ;; `anything-c-source-info-bison' (Info index: bison)
577 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
578 ;; `anything-c-source-info-global' (Info index: global)
579 ;; `anything-c-source-man-pages' (Manual Pages)
580 ;; `anything-c-source-complex-command-history' (Complex Command History)
581 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
582 ;; `anything-c-source-emacs-commands' (Emacs Commands)
583 ;; `anything-c-source-emacs-functions' (Emacs Functions)
584 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
585 ;; `anything-c-source-advice' (Function Advice)
586 ;; `anything-c-source-emacs-variables' (Emacs Variables)
587 ;; `anything-c-source-lacarte' (Lacarte)
588 ;; `anything-c-source-bookmarks' (Bookmarks)
589 ;; `anything-c-source-bookmark-set' (Set Bookmark)
590 ;; `anything-c-source-bm' (Visible Bookmarks)
591 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
592 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
593 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
594 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
595 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
596 ;; `anything-c-source-bookmark-images' (Bookmark Images)
597 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
598 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
599 ;; `anything-c-source-bookmark-info' (Bookmark Info)
600 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
601 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
602 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
603 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
604 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
605 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
606 ;; `anything-c-source-imenu' (Imenu)
607 ;; `anything-c-source-ctags' (Exuberant ctags)
608 ;; `anything-c-source-etags-select' (Etags)
609 ;; `anything-c-source-semantic' (Semantic Tags)
610 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
611 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
612 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
613 ;; `anything-c-source-customize-face' (Customize Face)
614 ;; `anything-c-source-colors' (Colors)
615 ;; `anything-c-source-tracker-search' (Tracker Search)
616 ;; `anything-c-source-mac-spotlight' (mdfind)
617 ;; `anything-c-source-picklist' (Picklist)
618 ;; `anything-c-source-kill-ring' (Kill Ring)
619 ;; `anything-c-source-mark-ring' (mark-ring)
620 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
621 ;; `anything-c-source-register' (Registers)
622 ;; `anything-c-source-latex-math' (Latex Math Menu)
623 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
624 ;; `anything-c-source-rd-headline' (RD HeadLine)
625 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
626 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
627 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
628 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
629 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
630 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
631 ;; `anything-c-source-eev-anchor' (Anchors)
632 ;; `anything-c-source-org-headline' (Org HeadLine)
633 ;; `anything-c-source-org-keywords' (Org Keywords)
634 ;; `anything-c-source-bbdb' (BBDB)
635 ;; `anything-c-source-evaluation-result' (Evaluation Result)
636 ;; `anything-c-source-calculation-result' (Calculation Result)
637 ;; `anything-c-source-google-suggest' (Google Suggest)
638 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
639 ;; `anything-c-source-emms-streams' (Emms Streams)
640 ;; `anything-c-source-emms-dired' (Music Directory)
641 ;; `anything-c-source-emms-files' (Emms files)
642 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
643 ;; `anything-c-source-call-source' (Call anything source)
644 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
645 ;; `anything-c-source-occur' (Occur)
646 ;; `anything-c-source-browse-code' (Browse code)
647 ;; `anything-c-source-create' (Create)
648 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
649 ;; `anything-c-source-elscreen' (Elscreen)
650 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
651 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
652 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
653 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
654 ;; `anything-c-source-xfonts' (X Fonts)
655 ;; `anything-c-source-ucs' (Ucs names)
656 ;; `anything-c-source-emacs-process' (Emacs Process)
657 ;; `anything-c-source-time-world' (Time World List)
658 ;; `anything-c-source-apt' (APT)
659 ;; `anything-c-source-gentoo' (Portage sources)
660 ;; `anything-c-source-use-flags' (Use Flags)
661 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
662 ;; `anything-c-source-esh' (Eshell completions)
663 ;; `anything-c-source-eshell-history' (Eshell history)
665 ;; *** END auto-documentation
667 ;;; For Maintainers:
669 ;; Install developer-tools/autodoc.el and
670 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
671 ;; This function generates anything-c-source-* / functions / options list.
673 ;; [EVAL IT] (autodoc-update-all)
675 ;; Please write details documentation about function, then others will
676 ;; read code more easier. -- Andy Stewart
680 ;;; Change log:
682 ;; Change log of this file is found at
683 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
685 ;; Change log of this project is found at
686 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
688 ;;; Contributors:
690 ;; Tamas Patrovics
691 ;; Tassilo Horn <tassilo@member.fsf.org>
692 ;; Vagn Johansen <gonz808@hotmail.com>
693 ;; Mathias Dahl <mathias.dahl@gmail.com>
694 ;; Bill Clementson <billclem@gmail.com>
695 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
696 ;; Drew Adams <drew.adams@oracle.com>
697 ;; Jason McBrayer <jmcbray@carcosa.net>
698 ;; Andy Stewart <lazycat.manatee@gmail.com>
699 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
700 ;; rubikitch <rubikitch@ruby-lang.org>
701 ;; Scott Vokes <vokes.s@gmail.com>
702 ;; Kenichirou Oyama <k1lowxb@gmail.com>
705 ;;; TODO
707 ;; - Fix documentation, now many functions haven't documentations.
711 ;;; Code:
713 ;;; Require
716 (require 'anything)
717 (require 'thingatpt)
718 (require 'ffap)
719 (require 'cl)
720 (require 'dired-aux)
721 (require 'dired-x)
722 (require 'tramp)
723 (require 'grep)
724 (require 'url)
725 (require 'xml)
726 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
727 (eval-when-compile (require 'semantic nil t))
728 (require 'anything-match-plugin)
732 ;;; Declare external functions
735 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
736 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
737 (declare-function image-dired-update-property "image-dired.el" (prop value))
738 (declare-function woman-file-name-all-completions "woman.el" (topic))
739 (declare-function Man-getpage-in-background "man.el" (topic))
740 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
741 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
742 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
743 (declare-function org-get-current-options "ext:org-exp.el")
744 (declare-function emms-streams "ext:emms-streams")
745 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
746 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
747 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
748 (declare-function emms-stream-quit "ext:emms-streams")
749 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
750 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
751 (declare-function emms-playlist-first "ext:emms")
752 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
753 (declare-function term-line-mode "term")
754 (declare-function term-char-mode "term")
755 (declare-function term-send-input "term")
756 (declare-function term-send-eof "term")
757 (declare-function Info-index-nodes "info" (&optional file))
758 (declare-function Info-goto-node "info" (&optional fork))
759 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
760 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
761 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
762 (declare-function elscreen-goto "ext:elscreen.el" (screen))
763 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
764 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
765 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
766 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
767 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
768 (declare-function bbdb "ext:bbdb-com")
769 (declare-function bbdb-current-record "ext:bbdb-com")
770 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
771 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
772 (declare-function bbdb-current-record "ext:bbdb-com")
773 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
774 (declare-function bbdb-records "ext:bbdb-com"
775 (&optional dont-check-disk already-in-db-buffer))
776 (declare-function eshell-read-aliases-list "em-alias")
777 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
778 (declare-function eshell-bol "esh-mode")
779 (declare-function eldoc-current-symbol "eldoc")
780 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
781 (declare-function eldoc-get-var-docstring "eldoc" (sym))
782 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
783 (declare-function find-library-name "find-func.el" (library))
784 (declare-function adoc-construct "ext:auto-document.el" (buf))
785 (declare-function adoc-first-line "ext:auto-document.el" (str))
786 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
787 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
788 (declare-function w32-shell-execute "ext:w32fns.c" (operation document &optional parameters show-flag))
791 ;;; compatibility
794 (unless (fboundp 'window-system)
795 (defun window-system (&optional arg)
796 window-system))
800 ;;; Customize
803 (defgroup anything-config nil
804 "Predefined configurations for `anything.el'."
805 :group 'anything)
807 (defcustom anything-c-adaptive-history-file
808 "~/.emacs.d/anything-c-adaptive-history"
809 "Path of file where history information is stored."
810 :type 'string
811 :group 'anything-config)
813 (defcustom anything-c-adaptive-history-length 50
814 "Maximum number of candidates stored for a source."
815 :type 'number
816 :group 'anything-config)
818 (defcustom anything-c-google-suggest-url
819 "http://google.com/complete/search?output=toolbar&q="
820 "URL used for looking up Google suggestions."
821 :type 'string
822 :group 'anything-config)
824 (defcustom anything-c-google-suggest-search-url
825 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
826 "URL used for Google searching."
827 :type 'string
828 :group 'anything-config)
830 (defcustom anything-google-suggest-use-curl-p nil
831 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
832 Otherwise `url-retrieve-synchronously' is used."
833 :type 'boolean
834 :group 'anything-config)
836 (defcustom anything-c-yahoo-suggest-url
837 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
838 "Url used for looking up Yahoo suggestions."
839 :type 'string
840 :group 'anything-config)
842 (defcustom anything-c-yahoo-suggest-search-url
843 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
844 "Url used for Yahoo searching."
845 :type 'string
846 :group 'anything-config)
848 (defcustom anything-c-boring-buffer-regexp
849 (rx (or
850 (group bos " ")
851 ;; anything-buffers
852 "*anything" "*ac-mode"
853 ;; echo area
854 " *Echo Area" " *Minibuf"))
855 "The regexp that match boring buffers.
856 Buffer candidates matching this regular expression will be
857 filtered from the list of candidates if the
858 `anything-c-skip-boring-buffers' candidate transformer is used, or
859 they will be displayed with face `file-name-shadow' if
860 `anything-c-shadow-boring-buffers' is used."
861 :type 'string
862 :group 'anything-config)
863 ;; (string-match anything-c-boring-buffer-regexp "buf")
864 ;; (string-match anything-c-boring-buffer-regexp " hidden")
865 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
867 (defcustom anything-c-boring-file-regexp
868 (rx (or
869 ;; Boring directories
870 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
871 ;; Boring files
872 (and line-start ".#")
873 (and (or ".class" ".la" ".o" "~") eol)))
874 "The regexp that match boring files.
875 File candidates matching this regular expression will be
876 filtered from the list of candidates if the
877 `anything-c-skip-boring-files' candidate transformer is used, or
878 they will be displayed with face `file-name-shadow' if
879 `anything-c-shadow-boring-files' is used."
880 :type 'string
881 :group 'anything-config)
883 (defcustom anything-kill-ring-threshold 10
884 "*Minimum length to be listed by `anything-c-source-kill-ring'."
885 :type 'integer
886 :group 'anything-config)
888 (defcustom anything-c-kill-ring-max-lines-number nil
889 "Max number of lines displayed per candidate in kill-ring browser.
890 If nil or zero, don't truncate candidate, show all."
891 :type 'integer
892 :group 'anything-config)
894 (defcustom anything-su-or-sudo "su"
895 "What command to use for root access."
896 :type 'string
897 :group 'anything-config)
899 (defcustom anything-for-files-prefered-list
900 '(anything-c-source-ffap-line
901 anything-c-source-ffap-guesser
902 anything-c-source-buffers-list
903 anything-c-source-recentf
904 anything-c-source-bookmarks
905 anything-c-source-file-cache
906 anything-c-source-files-in-current-dir+
907 anything-c-source-locate)
908 "Your prefered sources to find files."
909 :type 'list
910 :group 'anything-config)
912 (defcustom anything-create--actions-private nil
913 "User defined actions for `anything-create' / `anything-c-source-create'.
914 It is a list of (DISPLAY . FUNCTION) pairs like `action'
915 attribute of `anything-sources'.
917 It is prepended to predefined pairs."
918 :type 'list
919 :group 'anything-config)
921 (defcustom anything-allow-skipping-current-buffer t
922 "Show current buffer or not in anything buffer"
923 :type 'boolean
924 :group 'anything-config)
926 (defcustom anything-c-enable-eval-defun-hack t
927 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
928 This hack is invoked when pressing C-M-x in the form \
929 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
930 :type 'boolean
931 :group 'anything-config)
933 (defcustom anything-tramp-verbose 0
934 "*Just like `tramp-verbose' but specific to anything.
935 When set to 0 don't show tramp messages in anything.
936 If you want to have the default tramp messages set it to 3."
937 :type 'integer
938 :group 'anything-config)
940 (defcustom anything-raise-command nil
941 "*A shell command to jump to a window running specific program.
942 Need external program wmctrl.
943 This will be use with `format', so use something like \"wmctrl -xa %s\"."
944 :type 'string
945 :group 'anything-config)
947 (defun anything-set-anything-command-map-prefix-key (var key)
948 (declare (special anything-command-map-prefix-key))
949 (when (boundp 'anything-command-map-prefix-key)
950 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
951 (setq anything-command-map-prefix-key key)
952 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
953 'anything-command-map))
955 (defcustom anything-command-map-prefix-key "<f5> a"
956 "*The prefix key for all `anything-command-map' commands.
958 !!WARNING!!
959 This default value is very likely to be changed,
960 because it is under discussion."
961 :type 'string
962 :set 'anything-set-anything-command-map-prefix-key
963 :group 'anything-config)
965 (defcustom anything-c-browse-code-regexp-lisp
966 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
967 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
968 "*Regexp used to parse lisp buffer when browsing code."
969 :type 'string
970 :group 'anything-config)
972 (defcustom anything-c-browse-code-regexp-python
973 "\\<def\\>\\|\\<class\\>"
974 "*Regexp used to parse python buffer when browsing code."
975 :type 'string
976 :group 'anything-config)
978 (defcustom anything-c-browse-code-regexp-alist
979 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
980 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
981 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
982 (python-mode . ,anything-c-browse-code-regexp-python))
983 "*Alist to store regexps for browsing code corresponding \
984 to a specific `major-mode'."
985 :type 'list
986 :group 'anything-config)
988 (defcustom anything-c-external-programs-associations nil
989 "*Alist to store externals programs associated with file extension.
990 This variable overhide setting in .mailcap file.
991 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
992 :type 'list
993 :group 'anything-config)
995 (defcustom anything-ff-auto-update-initial-value t
996 "Auto update when only one candidate directory is matched.
997 This is the default value when starting `anything-find-files'."
998 :group 'anything-config
999 :type 'boolean)
1001 (defcustom anything-c-copy-async-prefered-emacs "emacs"
1002 "Path to the emacs you want to use for copying async.
1003 Emacs versions < 24 fail to copy directory due to a bug not fixed
1004 in `copy-directory'."
1005 :group 'anything-config
1006 :type 'string)
1008 (defcustom anything-ff-lynx-style-map t
1009 "Use arrow keys to navigate with `anything-find-files'.
1010 You will have to restart Emacs or reeval `anything-find-files-map'
1011 and `anything-c-read-file-map' for this take effect."
1012 :group 'anything-config
1013 :type 'boolean)
1015 (defcustom anything-ff-history-max-length 100
1016 "*Number of elements shown in `anything-find-files' history."
1017 :group 'anything-config
1018 :type 'integer)
1020 (defcustom anything-ff-smart-completion t
1021 "Try to complete filenames smarter when non--nil.
1022 See `anything-ff-transform-fname-for-completion' for more info."
1023 :group 'anything-config
1024 :type 'boolean)
1026 (defcustom anything-ff-default-kbsize 1024.0
1027 "Default Kbsize to use for showing files size.
1028 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1029 :group 'anything-config
1030 :type 'float)
1032 (defcustom anything-ff-tramp-not-fancy t
1033 "No colors when listing remote files when set to non--nil.
1034 This make listing much faster, specially on slow machines."
1035 :group 'anything-config
1036 :type 'boolean)
1038 (defcustom anything-ff-exif-data-program "exiftran"
1039 "*Program used to extract exif data of an image file."
1040 :group 'anything-config
1041 :type 'string)
1043 (defcustom anything-ff-exif-data-program-args "-d"
1044 "*Arguments used for `anything-ff-exif-data-program'."
1045 :group 'anything-config
1046 :type 'string)
1048 (defcustom anything-c-grep-use-ioccur-style-keys t
1049 "Use Arrow keys to jump to occurences."
1050 :group 'anything-config
1051 :type 'boolean)
1053 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1054 "Default command to read pdf files from pdfgrep.
1055 Where '%f' format spec is filename and '%p' is page number"
1056 :group 'anything-config
1057 :type 'string)
1059 (defcustom anything-c-etags-tag-file-name "TAGS"
1060 "Etags tag file name."
1061 :type 'string
1062 :group 'anything-config)
1064 (defcustom anything-c-etags-tag-file-search-limit 10
1065 "The limit level of directory to search tag file.
1066 Don't search tag file deeply if outside this value."
1067 :type 'number
1068 :group 'anything-config)
1070 (defcustom anything-c-etags-use-regexp-search nil
1071 "When non--nil search etags candidates by regexp.
1072 This disable anything-match-plugin when enabled.
1073 When nil search is performed directly on patter and *match-plugin is used
1074 if available. You can customize `anything-c-etags-search-regexp'."
1075 :group 'anything-config
1076 :type 'boolean)
1078 (defcustom anything-c-etags-search-regexp "^.+: .+ \\<%s"
1079 "Regexp that match tags in an anything etags buffer.
1080 The format spec is replaced by pattern.
1081 This regexp have no effect when `anything-c-etags-use-regexp-search'
1082 is nil."
1083 :group 'anything-config
1084 :type 'regexp)
1086 (defcustom anything-c-filelist-file-name nil
1087 "Filename of file list.
1088 Accept a list of string for multiple files.
1090 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1091 File list is created by make-filelist.rb script.
1093 Usage:
1094 ruby make-filelist.rb > /tmp/all.filelist
1096 Then
1097 ;; Assume that /tmp is ramdisk or tmpfs
1098 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1099 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1101 :type 'string
1102 :group 'anything-config)
1104 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1105 'anything-c-show-info-in-mode-line
1106 "A function to display eldoc info.
1107 Should take one arg: the string to display."
1108 :group 'anything-config
1109 :type 'symbol)
1111 (defcustom anything-c-turn-on-show-completion t
1112 "Display candidate in buffer while moving selection when non--nil."
1113 :group 'anything-config
1114 :type 'boolean)
1116 (defcustom anything-lisp-completion-or-indent-delay 0.6
1117 "After this delay `anything-lisp-completion-counter' is reset to 0.
1118 This allow to indent again without completing lisp symbol after this delay.
1119 Default is 0.6 seconds."
1120 :group 'anything-config
1121 :type 'number)
1123 (defcustom anything-c-default-external-file-browser "nautilus"
1124 "Default external file browser for your system.
1125 Directories will be opened externally with it when
1126 opening file externally in `anything-find-files'.
1127 Set to nil if you do not have external file browser
1128 or do not want to use it.
1129 Windows users should set that to \"explorer.exe\"."
1130 :group 'anything-config
1131 :type 'string)
1133 (defcustom anything-c-use-adaptative-sorting nil
1134 "*Wheter to use or not adaptative sorting.
1135 Even if a source use it, it will have no effect when set to nil."
1136 :type 'boolean
1137 :group 'anything-config)
1139 (defcustom anything-ff-newfile-prompt-p t
1140 "Whether Prompt or not when creating new file.
1141 This set `ffap-newfile-prompt'."
1142 :type 'boolean
1143 :group 'anything-config)
1146 (defcustom anything-ff-avfs-directory nil
1147 "*The default avfs directory, usually '.avfs'.
1148 When this is set you will be able to expand archive filenames with `C-z'
1149 inside an avfs directory mounted with mountavfs.
1150 See <http://sourceforge.net/projects/avf/>."
1151 :type 'boolean
1152 :group 'anything-config)
1154 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1155 "*Minimal list of compressed files extension."
1156 :type 'list
1157 :group 'anything-config)
1159 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1160 "Default regexp to match locate database.
1161 If nil Search in all files."
1162 :type 'string
1163 :group 'anything-config)
1165 (defcustom anything-c-locate-command nil
1166 "A list of arguments for locate program.
1167 If nil it will be calculated when `anything-locate' startup
1168 with these default values for different systems:
1170 Gnu/linux: \"locate -i -r %s\"
1171 berkeley-unix: \"locate -i %s\"
1172 windows-nt: \"es -i -r %s\"
1173 Others: \"locate %s\"
1175 This string will be passed to format so it should end with `%s'.
1176 The \"-r\" option must be the last option."
1177 :type 'string
1178 :group 'anything-config)
1180 (defcustom anything-c-show-info-in-mode-line-delay 12
1181 "Eldoc will show info in mode-line during this delay if user is idle."
1182 :type 'integer
1183 :group 'anything-config)
1185 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1186 "The file used to communicate with two emacs when copying files async."
1187 :type 'string
1188 :group 'anything-config)
1190 (defcustom anything-ff-printer-list nil
1191 "A list of available printers on your system.
1192 When non--nil let you choose a printer to print file.
1193 Otherwise when nil the variable `printer-name' will be used.
1194 On Unix based systems (lpstat command needed) you don't need to set this,
1195 `anything-ff-find-printers' will find a list of available printers for you."
1196 :type 'list
1197 :group 'anything-config)
1199 (defcustom anything-ff-transformer-show-only-basename nil
1200 "Show only basename of candidates in `anything-find-files'.
1201 This can be toggled at anytime from `anything-find-files' with \
1202 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1203 :type 'boolean
1204 :group 'anything-config)
1206 (defcustom anything-ff-quick-delete-dont-prompt-for-deletion nil
1207 "Don't ask in persistent deletion of files when non--nil."
1208 :group 'anything-config
1209 :type 'boolean)
1211 (defcustom anything-ff-signal-error-on-dot-files t
1212 "Signal error when file is `.' or `..' on file deletion when non--nil.
1213 Default is non--nil."
1214 :group 'anything-config
1215 :type 'boolean)
1217 (defcustom anything-completing-read-handlers-alist
1218 '((describe-function . anything-completing-read-symbols)
1219 (describe-variable . anything-completing-read-symbols)
1220 (debug-on-entry . anything-completing-read-symbols)
1221 (find-function . anything-completing-read-symbols)
1222 (trace-function . anything-completing-read-symbols)
1223 (trace-function-background . anything-completing-read-symbols)
1224 (find-tag . anything-completing-read-with-cands-in-buffer)
1225 (ffap-alternate-file . nil))
1226 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1227 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1228 where key and value are symbols.
1230 Each key is an Emacs command that use originaly `completing-read'.
1232 Each value maybe an anything function that take same arguments as
1233 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1234 anything source and BUFFER the name of the buffer we will use.
1235 This function prefix name must start by \"anything\".
1237 See `anything-completing-read-symbols' for example.
1239 If the value of an entry is nil completion will fall back to
1240 emacs vanilla behavior.
1241 e.g If you want to disable anything completion for `describe-function':
1242 \(describe-function . nil\).
1244 Ido is also supported, you can use `ido-completing-read' and
1245 `ido-read-file-name' as value of an entry or just 'ido.
1246 e.g ido completion for `find-file':
1247 \(find-file . ido\)
1248 same as
1249 \(find-file . ido-read-file-name\)
1250 Note that you don't need to enable `ido-mode' for this to work."
1251 :group 'anything-config
1252 :type '(alist :key-type symbol :value-type symbol))
1256 ;;; General internal variables
1258 ;; Some internals variable that need to be loaded
1259 ;; here to avoid compiler warnings.
1260 (defvar anything-c-external-commands-list nil
1261 "A list of all external commands the user can execute. If this
1262 variable is not set by the user, it will be calculated
1263 automatically.")
1265 (defvar anything-c-show-completion-overlay nil)
1269 ;;; Faces
1272 (defface anything-buffer-saved-out
1273 '((t (:foreground "red")))
1274 "*Face used for buffer files modified outside of emacs."
1275 :group 'anything-config)
1277 (defface anything-buffer-not-saved
1278 '((t (:foreground "Indianred2")))
1279 "*Face used for buffer files not already saved on disk."
1280 :group 'anything-config)
1282 (defface anything-ff-prefix
1283 '((t (:background "yellow" :foreground "black")))
1284 "*Face used to prefix new file or url paths in `anything-find-files'."
1285 :group 'anything-config)
1287 (defface anything-ff-executable
1288 '((t (:foreground "green")))
1289 "*Face used for executable files in `anything-find-files'."
1290 :group 'anything-config)
1292 (defface anything-ff-directory
1293 '((t (:foreground "DarkRed" :background "LightGray")))
1294 "*Face used for directories in `anything-find-files'."
1295 :group 'anything-config)
1297 (defface anything-ff-symlink
1298 '((t (:foreground "DarkOrange")))
1299 "*Face used for symlinks in `anything-find-files'."
1300 :group 'anything-config)
1302 (defface anything-ff-invalid-symlink
1303 '((t (:foreground "black" :background "red")))
1304 "*Face used for invalid symlinks in `anything-find-files'."
1305 :group 'anything-config)
1307 (defface anything-ff-file
1308 '((t (:foreground "CadetBlue" :underline t)))
1309 "*Face used for file names in `anything-find-files'."
1310 :group 'anything-config)
1312 (defface anything-grep-match
1313 '((t (:inherit match)))
1314 "Face used to highlight grep matches."
1315 :group 'anything-config)
1317 (defface anything-grep-file
1318 '((t (:foreground "BlueViolet" :underline t)))
1319 "Face used to highlight grep results filenames."
1320 :group 'anything-config)
1322 (defface anything-grep-lineno
1323 '((t (:foreground "Darkorange1")))
1324 "Face used to highlight grep number lines."
1325 :group 'anything-config)
1327 (defface anything-grep-running
1328 '((t (:foreground "Red")))
1329 "Face used in mode line when grep is running."
1330 :group 'anything-config)
1332 (defface anything-grep-finish
1333 '((t (:foreground "Green")))
1334 "Face used in mode line when grep is finish."
1335 :group 'anything-config)
1337 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1338 "*Face used in anything-M-x to show keybinding."
1339 :group 'anything)
1341 (defface anything-bmkext-info
1342 '((t (:foreground "green")))
1343 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1344 :group 'anything)
1346 (defface anything-bmkext-w3m
1347 '((t (:foreground "yellow")))
1348 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1349 :group 'anything)
1351 (defface anything-bmkext-gnus
1352 '((t (:foreground "magenta")))
1353 "*Face used for Gnus bookmarks."
1354 :group 'anything)
1356 (defface anything-bmkext-man
1357 '((t (:foreground "Orange4")))
1358 "*Face used for Woman/man bookmarks."
1359 :group 'anything)
1361 (defface anything-bmkext-no--file
1362 '((t (:foreground "grey")))
1363 "*Face used for non--file bookmarks."
1364 :group 'anything)
1366 (defface anything-bmkext-file
1367 '((t (:foreground "Deepskyblue2")))
1368 "*Face used for non--file bookmarks."
1369 :group 'anything)
1371 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1372 "Face for su/sudo bookmarks."
1373 :group 'anything)
1375 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1376 "Face for w3m bookmarks" :group 'anything)
1378 (defface anything-emms-playlist
1379 '((t (:foreground "Springgreen4" :underline t)))
1380 "*Face used for tracks in current emms playlist."
1381 :group 'anything)
1383 (defface anything-apt-installed
1384 '((t (:foreground "green")))
1385 "*Face used for apt installed candidates."
1386 :group 'anything)
1388 (defface anything-gentoo-match-face '((t (:foreground "red")))
1389 "Face for anything-gentoo installed packages."
1390 :group 'traverse-faces)
1392 (defface anything-lisp-show-completion
1393 '((t (:background "DarkSlateGray")))
1394 "*Face used for showing candidates in `anything-lisp-completion'."
1395 :group 'anything-config)
1397 (defface anything-lisp-completion-info
1398 '((t (:foreground "red")))
1399 "*Face used for showing info in `anything-lisp-completion'."
1400 :group 'anything-config)
1402 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1403 "Face for source header in the anything buffer." :group 'anything)
1405 ;;;###autoload
1406 (defun anything-configuration ()
1407 "Customize `anything'."
1408 (interactive)
1409 (customize-group "anything-config"))
1413 ;;; Anything-command-map
1416 ;;;###autoload
1417 (defvar anything-command-map)
1418 (define-prefix-command 'anything-command-map)
1421 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1422 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1423 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1424 (define-key anything-command-map (kbd "l") 'anything-locate)
1425 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1426 (define-key anything-command-map (kbd "r") 'anything-regexp)
1427 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1428 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1429 (define-key anything-command-map (kbd "#") 'anything-emms)
1430 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1431 (define-key anything-command-map (kbd "t") 'anything-top)
1432 (define-key anything-command-map (kbd "i") 'anything-imenu)
1433 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1434 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1435 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1436 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1437 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1438 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1439 (define-key anything-command-map (kbd "f") 'anything-for-files)
1440 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1441 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1442 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1443 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1444 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1445 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1446 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1447 (define-key anything-command-map (kbd "c") 'anything-colors)
1448 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1449 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1450 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1451 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1452 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1453 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1454 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1455 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1456 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1457 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1459 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1460 ;; minibuffer-local-filename-must-match-map.
1461 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1462 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1463 (dolist (map (list minibuffer-local-filename-completion-map
1464 minibuffer-local-completion-map
1465 minibuffer-local-must-match-filename-map
1466 minibuffer-local-filename-must-match-map
1467 minibuffer-local-map
1468 minibuffer-local-isearch-map
1469 minibuffer-local-must-match-map
1470 minibuffer-local-ns-map))
1471 (define-key map "\C-r" 'anything-minibuffer-history))
1475 ;;; Menu
1478 (easy-menu-define nil global-map
1479 "`anything' menu"
1480 '("Anything"
1481 ["All anything commands" anything-execute-anything-command t]
1482 ["Find any Files/Buffers" anything-for-files t]
1483 ["Anything Everywhere (Toggle)" ac-mode t]
1484 "----"
1485 ("Files:"
1486 ["Find files" anything-find-files t]
1487 ["Recent Files" anything-recentf t]
1488 ["Locate" anything-locate t]
1489 ["Bookmarks" anything-c-pp-bookmarks t])
1490 ("Buffers:"
1491 ["Find buffers" anything-buffers-list t])
1492 ("Commands:"
1493 ["Emacs Commands" anything-M-x t]
1494 ["Externals Commands" anything-c-run-external-command t])
1495 ("Help:"
1496 ["Anything Apropos" anything-c-apropos t])
1497 ("Info:"
1498 ["Info at point" anything-info-at-point t]
1499 ["Emacs Manual index" anything-info-emacs t]
1500 ["Gnus Manual index" anything-info-gnus t])
1501 ("Org:"
1502 ["Org keywords" anything-org-keywords t]
1503 ["Org headlines" anything-org-headlines t])
1504 ("Tools:"
1505 ["Occur" anything-occur t]
1506 ["Grep" anything-do-grep t]
1507 ["Etags" anything-c-etags-select t]
1508 ["Lisp complete at point" anything-lisp-completion-at-point t]
1509 ["Browse Kill ring" anything-show-kill-ring t]
1510 ["Browse register" anything-register t]
1511 ["Browse code" anything-browse-code t]
1512 ["Mark Ring" anything-all-mark-rings t]
1513 ["Regexp handler" anything-regexp t]
1514 ["Colors & Faces" anything-colors t]
1515 ["Show xfonts" anything-select-xfont t]
1516 ["Ucs Symbols" anything-ucs t]
1517 ["Imenu" anything-imenu t]
1518 ["Google Suggest" anything-google-suggest t]
1519 ["Eval expression" anything-eval-expression-with-eldoc t]
1520 ["Calcul expression" anything-calcul-expression t]
1521 ["Man pages" anything-man-woman t]
1522 ["Top externals process" anything-top t]
1523 ["Emacs internals process" anything-list-emacs-process t])
1524 "----"
1525 ["Prefered Options" anything-configuration t]))
1527 ;;; Anything map add ons
1530 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1531 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1532 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1535 ;;; Specialized keymaps
1538 (defvar anything-c-buffer-map
1539 (let ((map (copy-keymap anything-map)))
1540 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1541 ;; No need to have separate command for grep and zgrep
1542 ;; as we don't use recursivity for buffers.
1543 ;; So use zgrep for both as it is capable to handle non--compressed files.
1544 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1545 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1546 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1547 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1548 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1549 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1550 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1551 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1552 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1553 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1554 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1555 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1556 (define-key map (kbd "M-a") 'anything-mark-all)
1557 (when (locate-library "elscreen")
1558 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1559 (delq nil map))
1560 "Keymap for buffer sources in anything.")
1562 (defvar anything-find-files-map
1563 (let ((map (copy-keymap anything-map)))
1564 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1565 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1566 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1567 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1568 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1569 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1570 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1571 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1572 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1573 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1574 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1575 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1576 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1577 (define-key map (kbd "C-d") 'anything-ff-persistent-delete)
1578 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1579 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1580 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1581 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1582 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1583 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1584 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1585 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1586 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1587 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1588 (define-key map (kbd "C-c ?") 'anything-ff-help)
1589 (define-key map (kbd "C-}") 'anything-narrow-window)
1590 (define-key map (kbd "C-{") 'anything-enlarge-window)
1591 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1592 (define-key map (kbd "M-a") 'anything-mark-all)
1593 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1594 (define-key map (kbd "M-u") 'anything-unmark-all)
1595 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1596 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1597 ;; Next 2 have no effect if candidate is not an image file.
1598 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1599 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1600 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1601 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1602 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1603 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1604 (when anything-ff-lynx-style-map
1605 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1606 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1607 (delq nil map))
1608 "Keymap for `anything-find-files'.")
1610 (defvar anything-c-read-file-map
1611 (let ((map (copy-keymap anything-map)))
1612 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1613 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1614 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1615 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1616 (when anything-ff-lynx-style-map
1617 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1618 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1619 (define-key map (kbd "<M-left>") 'anything-previous-source)
1620 (define-key map (kbd "<M-right>") 'anything-next-source))
1621 (delq nil map))
1622 "Keymap for `anything-c-read-file-name'.")
1624 (defvar anything-generic-files-map
1625 (let ((map (copy-keymap anything-map)))
1626 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1627 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1628 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1629 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1630 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1631 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1632 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1633 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1634 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1635 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1636 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1637 map)
1638 "Generic Keymap for files.")
1640 (defvar anything-c-grep-map
1641 (let ((map (copy-keymap anything-map)))
1642 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1643 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1644 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1645 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1646 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1647 (when anything-c-grep-use-ioccur-style-keys
1648 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1649 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1650 (define-key map (kbd "C-c ?") 'anything-grep-help)
1651 (delq nil map))
1652 "Keymap used in Grep sources.")
1654 (defvar anything-c-pdfgrep-map
1655 (let ((map (copy-keymap anything-map)))
1656 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1657 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1658 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1659 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1660 map)
1661 "Keymap used in pdfgrep.")
1663 (defvar anything-c-etags-map
1664 (let ((map (copy-keymap anything-map)))
1665 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1666 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1667 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1668 (define-key map (kbd "C-c ?") 'anything-etags-help)
1669 map)
1670 "Keymap used in Etags.")
1672 (defvar anything-eval-expression-map
1673 (let ((map (copy-keymap anything-map)))
1674 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1675 (define-key map (kbd "<tab>") 'lisp-indent-line)
1676 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1677 (define-key map (kbd "C-p") 'previous-line)
1678 (define-key map (kbd "C-n") 'next-line)
1679 (define-key map (kbd "<up>") 'previous-line)
1680 (define-key map (kbd "<down>") 'next-line)
1681 (define-key map (kbd "<right>") 'forward-char)
1682 (define-key map (kbd "<left>") 'backward-char)
1683 map))
1685 (defvar anything-c-ucs-map
1686 (let ((map (copy-keymap anything-map)))
1687 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1688 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1689 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1690 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1691 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1692 map)
1693 "Keymap for `anything-ucs'.")
1697 ;;; Embeded documentation.
1700 (defun anything-c-list-preconfigured-anything ()
1701 "Collect preconfigured anything functions in this file."
1702 (loop with doc
1703 with sym
1704 for entry in (cdr (assoc
1705 (file-truename (locate-library "anything-config"))
1706 load-history))
1707 if (and (consp entry)
1708 (eq (car entry) 'defun)
1709 (string-match "^Preconfigured.+$"
1710 (setq doc (or (documentation (setq sym (cdr entry)))
1711 ""))))
1712 collect (cons sym (match-string 0 doc))))
1714 (defun anything-c-format-preconfigured-anything ()
1715 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1716 (anything-c-list-preconfigured-anything)))
1718 ;;; Global help message - Used by `anything-help'
1721 (setq anything-help-message
1722 (lambda ()
1723 (concat
1724 "\\<anything-map>"
1725 "`anything' is QuickSilver-like candidate-selection framework.
1727 Narrow the list by typing some pattern,
1728 Multiple patterns are allowed by splitting by space.
1729 Select with natural Emacs operations, choose with RET.
1731 If you have any problems, press C-c C-x C-b!!
1732 Feel free to send bug reports. I'll fix them.
1733 The steps are described in the beginning of anything.el file.
1735 == Basic Operations ==
1736 C-p, Up: Previous Line
1737 C-n, Down : Next Line
1738 M-v, PageUp : Previous Page
1739 C-v, PageDown : Next Page
1740 Enter : Execute first (default) action / Select
1741 M-< : First Line
1742 M-> : Last Line
1743 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1744 M-PageDown, C-M-v : Next Page (other-window)
1746 Tab, C-i : Show action list
1747 Left : Previous Source
1748 Right, C-o : Next Source
1749 C-k : Delete pattern
1750 C-z : Persistent Action (Execute action with anything session kept)
1751 C-c C-x C-b: Send a bug report
1753 == Shortcuts For 2nd/3rd Action ==
1754 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1755 \\[anything-select-3rd-action] : Execute 3rd Action
1757 == Visible Marks ==
1758 Visible marks store candidate. Some actions uses marked candidates.
1760 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1761 \\[anything-prev-visible-mark] : Previous Mark
1762 \\[anything-next-visible-mark] : Next Mark
1764 == Miscellaneous Commands ==
1765 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1766 \\[anything-quit-and-find-file] : Drop into `find-file'
1767 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1768 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1769 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1770 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1771 \\[anything-force-update] : Recalculate And Redisplay Candidates
1773 == Global Commands ==
1774 \\<global-map>\\[anything-resume] revives last `anything' session.
1775 It is very useful, so you should bind any key.
1777 Single source is executed by \\[anything-call-source].
1779 == Preconfigured `anything' ==
1780 Preconfigured `anything' is commands that uses `anything' interface.
1781 You can use them without configuration.
1784 (apply 'concat (anything-c-format-preconfigured-anything))
1786 Enjoy!")))
1788 ;;; `anything-buffer-list' help
1791 ;;;###autoload
1792 (defun anything-c-buffer-help ()
1793 "Help command for anything buffers."
1794 (interactive)
1795 (let ((anything-help-message "== Anything Buffer ==
1796 \nTips:
1797 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1798 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1799 \nSpecific commands for `anything-buffers-list':
1800 \\<anything-c-buffer-map>
1801 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1802 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1803 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1804 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1805 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1806 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1807 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1808 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1809 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1810 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1811 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1812 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1813 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1814 \\[anything-mark-all]\t\t->Mark all.
1815 \\[anything-c-buffer-help]\t\t->Display this help.
1816 \n== Anything Map ==
1817 \\{anything-map}
1819 (anything-help)))
1822 ;;; Find files help (`anything-find-files')
1825 ;;;###autoload
1826 (defun anything-ff-help ()
1827 "Help command for `anything-find-files'."
1828 (interactive)
1829 (let ((anything-help-message "== Anything Find Files ==
1830 \nTips:
1831 \n- Enter `~/' at end of pattern to quickly reach home directory.
1832 - Enter `/' at end of pattern to quickly reach root of your file system.
1833 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1834 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1835 - Use `C-u C-z' to watch an image.
1836 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1837 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1839 \nSpecific commands for `anything-find-files':
1840 \\<anything-find-files-map>
1841 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1842 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1843 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1844 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1845 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1846 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1847 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1848 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1849 \\[anything-ff-run-load-file]\t\t->Load File.
1850 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1851 \\[anything-ff-run-delete-file]\t\t->Delete File.
1852 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1853 \\[anything-ff-persistent-delete]\t->Delete file without quitting.
1854 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1855 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1856 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1857 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1858 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1859 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1860 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1861 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1862 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1863 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1864 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1865 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1866 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1867 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1868 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1869 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1870 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1871 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1872 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1873 \\[anything-narrow-window]\t\t->Narrow anything window.
1874 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1875 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1876 \\[anything-ff-help]\t\t->Display this help info.
1877 \n== Anything Map ==
1878 \\{anything-map}
1880 (anything-help)))
1882 ;;; Help for `anything-c-read-file-name'
1885 ;;;###autoload
1886 (defun anything-read-file-name-help ()
1887 (interactive)
1888 (let ((anything-help-message "== Anything read file name Map ==\
1889 \nSpecific commands for anything-c-read-file-name:
1890 \\<anything-c-read-file-map>
1891 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1892 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1893 \\[anything-next-source]\t\t->Goto next source.
1894 \\[anything-previous-source]\t->Goto previous source.
1895 \\[anything-read-file-name-help]\t\t->Display this help info.
1896 \n== Anything Map ==
1897 \\{anything-map}
1899 (anything-help)))
1901 ;;; Generic file help - Used by locate.
1904 ;;;###autoload
1905 (defun anything-generic-file-help ()
1906 (interactive)
1907 (let ((anything-help-message "== Anything Generic files Map ==\
1908 \nSpecific commands for anything locate and others files sources:
1909 \\<anything-generic-files-map>
1910 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1911 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1912 \\[anything-ff-run-delete-file]\t\t->Delete file.
1913 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1914 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1915 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1916 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1917 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1918 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1919 \nLocate tips:
1920 You can add after writing search pattern any of the locate command line options.
1921 e.g -b, -e, -n <number>...etc.
1922 See Man locate for more infos.
1923 \n== Anything Map ==
1924 \\{anything-map}"))
1925 (anything-help)))
1928 ;;; Grep help
1931 ;;;###autoload
1932 (defun anything-grep-help ()
1933 (interactive)
1934 (let ((anything-help-message "== Anything Grep Map ==\
1935 \nSpecific commands for Grep and Etags:
1936 \\<anything-c-grep-map>
1937 \\[anything-c-goto-next-file]\t->Next File.
1938 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1939 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1940 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1941 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1942 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1943 \\[anything-grep-help]\t\t->Show this help.
1944 \n== Anything Map ==
1945 \\{anything-map}"))
1946 (anything-help)))
1948 ;;; Pdf grep help
1951 ;;;###autoload
1952 (defun anything-pdfgrep-help ()
1953 (interactive)
1954 (let ((anything-help-message "== Anything PdfGrep Map ==\
1955 \nSpecific commands for Pdf Grep:
1956 \\<anything-c-pdfgrep-map>
1957 \\[anything-c-goto-next-file]\t->Next File.
1958 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1959 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1960 \\[anything-pdfgrep-help]\t\t->Show this help.
1961 \n== Anything Map ==
1962 \\{anything-map}"))
1963 (anything-help)))
1965 ;;; Etags help
1968 ;;;###autoload
1969 (defun anything-etags-help ()
1970 "The help function for etags."
1971 (interactive)
1972 (let ((anything-help-message "== Anything Etags Map ==\
1973 \nSpecific commands for Etags:
1974 \\<anything-c-etags-map>
1975 \\[anything-c-goto-next-file]\t->Next File.
1976 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1977 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1978 \\[anything-etags-help]\t\t->Show this help.
1979 \n== Anything Map ==
1980 \\{anything-map}"))
1981 (anything-help)))
1983 ;;; Ucs help
1986 (defun anything-c-ucs-help ()
1987 "Help command for `anything-ucs'."
1988 (interactive)
1989 (let ((anything-help-message "== Anything Ucs ==
1990 \nSpecific commands for `anything-ucs':
1991 \\<anything-c-ucs-map>
1992 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1993 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1994 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1995 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1996 \\[anything-c-ucs-help]\t\t->Show this help.
1998 \n== Anything Map ==
1999 \\{anything-map}
2001 (anything-help)))
2005 ;;; Mode line strings
2008 (defvar anything-buffer-mode-line-string
2009 '("Buffer(s)"
2010 "\\<anything-c-buffer-map>\
2011 \\[anything-c-buffer-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-c-source-buffers-list'"))
2019 (defvar anything-ff-mode-line-string
2020 "\\<anything-find-files-map>\
2021 \\[anything-ff-help]:Help, \
2022 \\[anything-send-bug-report-from-anything]:BugReport, \
2023 \\<anything-map>\
2024 \\[anything-select-action]:Acts, \
2025 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2026 \\[anything-select-3rd-action]:NthAct"
2027 "String displayed in mode-line in `anything-c-source-find-files'")
2029 (defvar anything-read-file-name-mode-line-string
2030 "\\<anything-c-read-file-map>\
2031 \\[anything-read-file-name-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 "String displayed in mode-line in `anything-c-source-find-files'")
2038 (defvar anything-generic-file-mode-line-string
2039 "\\<anything-generic-files-map>\
2040 \\[anything-generic-file-help]:Help, \
2041 \\<anything-map>\
2042 \\[anything-select-action]:Acts,\
2043 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2044 \\[anything-select-3rd-action]:NthAct,\
2045 \\[anything-send-bug-report-from-anything]:BugReport."
2046 "String displayed in mode-line in Locate.")
2048 (defvar anything-grep-mode-line-string
2049 "\\<anything-c-grep-map>\
2050 \\[anything-grep-help]:Help,\
2051 \\<anything-map>\
2052 \\[anything-select-action]:Acts,\
2053 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2054 \\[anything-select-3rd-action]:NthAct,\
2055 \\[anything-send-bug-report-from-anything]:BugReport."
2056 "String displayed in mode-line in `anything-do-grep'.")
2058 (defvar anything-pdfgrep-mode-line-string
2059 "\\<anything-c-pdfgrep-map>\
2060 \\[anything-pdfgrep-help]:Help,\
2061 \\<anything-map>\
2062 \\[anything-select-action]:Acts,\
2063 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2064 \\[anything-select-3rd-action]:NthAct,\
2065 \\[anything-send-bug-report-from-anything]:BugReport."
2066 "String displayed in mode-line in `anything-do-pdfgrep'.")
2068 (defvar anything-etags-mode-line-string
2069 "\\<anything-c-etags-map>\
2070 \\[anything-etags-help]:Help,\
2071 \\<anything-map>\
2072 \\[anything-select-action]:Acts,\
2073 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2074 \\[anything-select-3rd-action]:NthAct,\
2075 \\[anything-send-bug-report-from-anything]:BugReport."
2076 "String displayed in mode-line in `anything-c-etags-select'.")
2079 (defvar anything-c-ucs-mode-line-string
2080 "\\<anything-c-ucs-map>\
2081 \\[anything-c-ucs-help]:Help, \
2082 \\<anything-map>\
2083 \\[anything-select-action]:Acts,\
2084 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2085 \\[anything-select-3rd-action]:NthAct."
2086 "String displayed in mode-line in `anything-ucs'.")
2090 ;;; Utilities Functions
2093 (defun anything-ff-find-printers ()
2094 "Return a list of available printers on Unix systems."
2095 (when (executable-find "lpstat")
2096 (let ((printer-list (with-temp-buffer
2097 (call-process "lpstat" nil t nil "-a")
2098 (split-string (buffer-string) "\n"))))
2099 (loop for p in printer-list
2100 for printer = (car (split-string p))
2101 when printer
2102 collect printer))))
2104 ;; Shut up byte compiler in emacs24*.
2105 (defun anything-c-switch-to-buffer (buffer-or-name)
2106 "Same as `switch-to-buffer' whithout warnings at compile time."
2107 (with-no-warnings
2108 (switch-to-buffer buffer-or-name)))
2110 (defsubst* anything-c-position (item seq &key (test 'eq))
2111 "A simple and faster replacement of CL `position'."
2112 (loop for i in seq for index from 0
2113 when (funcall test i item) return index))
2115 (defun anything-c-get-pid-from-process-name (process-name)
2116 "Get pid from running process PROCESS-NAME."
2117 (loop with process-list = (list-system-processes)
2118 for pid in process-list
2119 for process = (assoc-default 'comm (process-attributes pid))
2120 when (and process (string-match process-name process))
2121 return pid))
2123 (defun* anything-current-buffer-narrowed-p (&optional
2124 (buffer anything-current-buffer))
2125 "Check if BUFFER is narrowed.
2126 Default is `anything-current-buffer'."
2127 (with-current-buffer buffer
2128 (let ((beg (point-min))
2129 (end (point-max))
2130 (total (buffer-size)))
2131 (or (/= beg 1) (/= end (1+ total))))))
2133 (defun anything-region-active-p ()
2134 (and transient-mark-mode mark-active (/= (mark) (point))))
2136 (defun anything-goto-line (lineno)
2137 "Goto LINENO opening only outline headline if needed."
2138 (goto-char (point-min)) (forward-line (1- lineno))
2139 (when (or (eq major-mode 'org-mode)
2140 (and (boundp 'outline-minor-mode)
2141 outline-minor-mode))
2142 (require 'org) ; On some old Emacs versions org may not be loaded.
2143 (org-reveal))
2144 (anything-match-line-color-current-line) (sit-for 0.3)
2145 (anything-match-line-cleanup))
2147 (defun anything-show-this-source-only ()
2148 "Show all candidates of this source."
2149 (interactive)
2150 (setq anything-candidate-number-limit nil)
2151 (anything-set-source-filter
2152 (list (assoc-default 'name (anything-get-current-source)))))
2154 ;;;###autoload
2155 (defun anything-test-sources ()
2156 "List all anything sources for test.
2157 The output is sexps which are evaluated by \\[eval-last-sexp]."
2158 (interactive)
2159 (with-output-to-temp-buffer "*Anything Test Sources*"
2160 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2161 (apropos-internal "^anything-c-source" #'boundp))
2162 (pop-to-buffer standard-output)))
2164 (defun anything-nest (&rest same-as-anything)
2165 "Nested `anything'. If you use `anything' within `anything', use it."
2166 (with-selected-window (anything-window)
2167 (let (anything-current-position
2168 anything-current-buffer
2169 (orig-anything-buffer anything-buffer)
2170 anything-pattern
2171 anything-buffer
2172 anything-sources
2173 anything-compiled-sources
2174 anything-buffer-chars-modified-tick
2175 (anything-samewindow t)
2176 (enable-recursive-minibuffers t))
2177 (unwind-protect
2178 (apply #'anything same-as-anything)
2179 (anything-initialize-overlays orig-anything-buffer)
2180 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2182 (defun anything-displaying-source-names ()
2183 "Display sources name."
2184 (with-current-buffer anything-buffer
2185 (goto-char (point-min))
2186 (loop with pos
2187 while (setq pos (next-single-property-change (point) 'anything-header))
2188 do (goto-char pos)
2189 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2190 do (forward-line 1))))
2192 ;; [Obsolete]
2193 (defun anything-select-source ()
2194 "[OBSOLETE] Select source."
2195 (interactive)
2196 (let ((default (assoc-default 'name (anything-get-current-source)))
2197 (source-names (anything-displaying-source-names))
2198 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2199 (anything-get-sources))))
2200 (setq anything-candidate-number-limit 9999)
2201 (anything-aif
2202 (let (anything-source-filter)
2203 (anything-nest '(((name . "Anything Source")
2204 (candidates . source-names)
2205 (action . identity))
2206 ((name . "Anything Source (ALL)")
2207 (candidates . all-source-names)
2208 (action . identity)))
2209 nil "Source: " nil
2210 default "*anything select source*"))
2211 (anything-set-source-filter (list it))
2212 (anything-set-source-filter nil))))
2214 ;; Same as anything-set-pattern but bad written, please fix.
2215 (defun anything-insert-string (str)
2216 "Insert STR."
2217 (delete-minibuffer-contents)
2218 (insert str))
2220 ;;;###autoload
2221 (defun anything-insert-buffer-name ()
2222 "Insert buffer name."
2223 (interactive)
2224 (anything-set-pattern
2225 (with-anything-current-buffer
2226 (if buffer-file-name (file-name-nondirectory buffer-file-name)
2227 (buffer-name)))))
2229 (defalias 'anything-insert-symbol 'next-history-element)
2230 (defalias 'anything-insert-selection 'anything-yank-selection)
2232 (defun anything-c-match-on-file-name (candidate)
2233 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2234 (string-match anything-pattern (file-name-nondirectory candidate)))
2236 (defun anything-c-match-on-directory-name (candidate)
2237 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2238 (anything-aif (file-name-directory candidate)
2239 (string-match anything-pattern it)))
2241 (defun anything-c-match-on-basename (candidate)
2242 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2243 (string-match anything-pattern (anything-c-basename candidate)))
2245 (defun anything-c-string-match (candidate)
2246 "Return non-nil if `anything-pattern' match CANDIDATE.
2247 The match is done with `string-match'."
2248 (string-match anything-pattern candidate))
2250 (defun anything-c-skip-entries (list regexp)
2251 "Remove entries which matches REGEXP from LIST."
2252 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2253 list))
2255 (defun anything-c-shadow-entries (list regexp)
2256 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2257 (mapcar (lambda (file)
2258 ;; Add shadow face property to boring files.
2259 (let ((face (if (facep 'file-name-shadow)
2260 'file-name-shadow
2261 ;; fall back to default on XEmacs
2262 'default)))
2263 (if (string-match regexp file)
2264 (setq file (propertize file 'face face))))
2265 file)
2266 list))
2268 (defsubst anything-c-stringify (str-or-sym)
2269 "Get string of STR-OR-SYM."
2270 (if (stringp str-or-sym)
2271 str-or-sym
2272 (symbol-name str-or-sym)))
2274 (defsubst anything-c-symbolify (str-or-sym)
2275 "Get symbol of STR-OR-SYM."
2276 (if (symbolp str-or-sym)
2277 str-or-sym
2278 (intern str-or-sym)))
2280 (defun anything-c-describe-function (func)
2281 "FUNC is symbol or string."
2282 (describe-function (anything-c-symbolify func)))
2284 (defun anything-c-describe-variable (var)
2285 "VAR is symbol or string."
2286 (describe-variable (anything-c-symbolify var)))
2288 (defun anything-c-find-function (func)
2289 "FUNC is symbol or string."
2290 (find-function (anything-c-symbolify func)))
2292 (defun anything-c-find-variable (var)
2293 "VAR is symbol or string."
2294 (find-variable (anything-c-symbolify var)))
2296 (defun anything-c-kill-new (candidate &optional replace)
2297 "CANDIDATE is symbol or string.
2298 See `kill-new' for argument REPLACE."
2299 (kill-new (anything-c-stringify candidate) replace))
2301 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2302 "Remove duplicates elements in list SEQ.
2303 This is same as `remove-duplicates' but with memoisation.
2304 It is much faster, especially in large lists.
2305 A test function can be provided with TEST argument key.
2306 Default is `eq'."
2307 (loop with cont = (make-hash-table :test test)
2308 for elm in seq
2309 unless (gethash elm cont)
2310 do (puthash elm elm cont)
2311 finally return
2312 (loop for i being the hash-values in cont collect i)))
2314 (defadvice eval-defun (after anything-source-hack activate)
2315 "Allow immediate execution of anything source when evaling it.
2316 See `anything-c-enable-eval-defun-hack'."
2317 (when anything-c-enable-eval-defun-hack
2318 (let ((varsym (save-excursion
2319 (beginning-of-defun)
2320 (forward-char 1)
2321 (when (memq (read (current-buffer)) '(defvar setq))
2322 (read (current-buffer))))))
2323 (when (string-match "^anything-c-source-" (symbol-name varsym))
2324 (anything varsym)))))
2325 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2328 ;; Move this function from anything.el and redefine here
2329 ;; to avoid an unneeded defadvice.
2330 (defun anything-quit-and-find-file ()
2331 "Drop into `anything-find-files' from `anything'.
2332 If current selection is a buffer or a file, `anything-find-files'
2333 from its directory."
2334 (interactive)
2335 (anything-run-after-quit
2336 (lambda (f)
2337 (if (file-exists-p f)
2338 (anything-find-files-1 (file-name-directory f)
2339 (if anything-ff-transformer-show-only-basename
2340 (anything-c-basename f) f))
2341 (anything-find-files-1 f)))
2342 (anything-aif (get-buffer (anything-get-selection))
2343 (or (buffer-file-name it)
2344 (car (rassoc it dired-buffers))
2345 (and (with-current-buffer it
2346 (eq major-mode 'org-agenda-mode))
2347 org-directory
2348 (expand-file-name org-directory))
2349 default-directory)
2350 (let ((sel (anything-get-selection)))
2351 (if (file-exists-p sel)
2352 (expand-file-name sel)
2353 default-directory)))))
2356 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2357 "Walk through DIRECTORY tree.
2358 PATH can be one of basename, relative, or full.
2359 DIRECTORIES when non--nil (default) return also directories names, otherwise
2360 skip directories names.
2361 MATCH match only filenames matching regexp MATCH."
2362 `(let (result
2363 (fn (case ,path
2364 (basename 'file-name-nondirectory)
2365 (relative 'file-relative-name)
2366 (full 'identity)
2367 (t 'file-name-nondirectory))))
2368 (labels ((ls-R (dir)
2369 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2370 for f in ls
2371 if (file-directory-p f)
2372 do (progn (when ,directories
2373 (push (funcall fn f) result))
2374 ;; Don't recurse in directory symlink.
2375 (unless (file-symlink-p f)
2376 (ls-R f)))
2377 else do
2378 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2379 (push (funcall fn f) result)))))
2380 (ls-R ,directory)
2381 (nreverse result))))
2383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2385 ;;; Anything regexp.
2388 (defvar anything-build-regexp-history nil)
2389 (defun anything-c-query-replace-regexp (candidate)
2390 "Query replace regexp from `anything-regexp'.
2391 With a prefix arg replace only matches surrounded by word boundaries,
2392 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2393 (let ((regexp (funcall (anything-attr 'regexp))))
2394 (apply 'query-replace-regexp
2395 (anything-c-query-replace-args regexp))))
2397 (defun anything-c-kill-regexp-as-sexp (candidate)
2398 "Kill regexp in a format usable in lisp code."
2399 (anything-c-regexp-kill-new
2400 (prin1-to-string (funcall (anything-attr 'regexp)))))
2402 (defun anything-c-kill-regexp (candidate)
2403 "Kill regexp as it is in `anything-pattern'."
2404 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2406 (defun anything-c-query-replace-args (regexp)
2407 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2408 (let ((region-only (anything-region-active-p)))
2409 (list
2410 regexp
2411 (query-replace-read-to regexp
2412 (format "Query replace %sregexp %s"
2413 (if anything-current-prefix-arg "word " "")
2414 (if region-only "in region " ""))
2416 anything-current-prefix-arg
2417 (when region-only (region-beginning))
2418 (when region-only (region-end)))))
2420 (defvar anything-c-source-regexp
2421 '((name . "Regexp Builder")
2422 (init . (lambda ()
2423 (anything-candidate-buffer anything-current-buffer)))
2424 (candidates-in-buffer)
2425 (get-line . anything-c-regexp-get-line)
2426 (persistent-action . anything-c-regexp-persistent-action)
2427 (persistent-help . "Show this line")
2428 (multiline)
2429 (delayed)
2430 (requires-pattern . 2)
2431 (mode-line . "Press TAB to select action.")
2432 (regexp . (lambda () anything-input))
2433 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2434 ("Query Replace Regexp (C-u Not inside word.)"
2435 . anything-c-query-replace-regexp)
2436 ("Kill Regexp" . anything-c-kill-regexp)))))
2438 (defun anything-c-regexp-get-line (s e)
2439 (propertize
2440 (apply 'concat
2441 ;; Line contents
2442 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2443 ;; subexps
2444 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2445 collect (format "\n %s'%s'"
2446 (if (zerop i) "Group 0: " (format "Group %d: " i))
2447 (match-string i))))
2448 ;; match beginning
2449 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2450 ;; It is implementation problem of candidates-in-buffer.
2451 'anything-realvalue
2452 (1- s)))
2454 (defun anything-c-regexp-persistent-action (pt)
2455 (goto-char pt)
2456 (anything-persistent-highlight-point))
2458 (defun anything-c-regexp-kill-new (input)
2459 (kill-new input)
2460 (message "Killed: %s" input))
2464 ;;; Toggle all marks.
2467 ;;;###autoload
2468 (defun anything-mark-all ()
2469 "Mark all visible unmarked candidates in current source."
2470 (interactive)
2471 (with-anything-window
2472 (save-excursion
2473 (goto-char (anything-get-previous-header-pos))
2474 (anything-next-line)
2475 (let* ((next-head (anything-get-next-header-pos))
2476 (end (and next-head
2477 (save-excursion
2478 (goto-char next-head)
2479 (forward-line -1)
2480 (point))))
2481 (maxpoint (or end (point-max))))
2482 (while (< (point) maxpoint)
2483 (anything-mark-current-line)
2484 (let ((prefix (get-text-property (point-at-bol) 'display))
2485 (bn (anything-c-basename (anything-get-selection)))
2486 (src (assoc-default 'name (anything-get-current-source))))
2487 (when (and (not (anything-this-visible-mark))
2488 (not (or (string= prefix "[?]")
2489 (string= prefix "[@]"))))
2490 ;; Don't mark possibles directories ending with . or ..
2491 ;; and also autosave files/links.
2492 (unless
2493 (and (or (anything-file-completion-source-p)
2494 (equal src "Files from Current Directory"))
2495 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2496 (anything-make-visible-mark))))
2497 (forward-line 1) (end-of-line))))
2498 (anything-mark-current-line)
2499 (message "%s candidates marked" (length anything-marked-candidates))))
2501 ;;;###autoload
2502 (defun anything-unmark-all ()
2503 "Unmark all candidates in all sources of current anything session."
2504 (interactive)
2505 (with-anything-window
2506 (let ((len (length anything-marked-candidates)))
2507 (save-excursion
2508 (anything-clear-visible-mark))
2509 (setq anything-marked-candidates nil)
2510 (anything-mark-current-line)
2511 (message "%s candidates unmarked" len))))
2513 ;;;###autoload
2514 (defun anything-toggle-all-marks ()
2515 "Toggle all marks.
2516 Mark all visible candidates of current source or unmark all candidates
2517 visible or invisible in all sources of current anything session"
2518 (interactive)
2519 (let ((marked (anything-marked-candidates)))
2520 (if (and (>= (length marked) 1)
2521 (with-anything-window anything-visible-mark-overlays))
2522 (anything-unmark-all)
2523 (anything-mark-all))))
2527 ;;; Buffers
2530 (defun anything-c-buffer-list ()
2531 "Return the list of names of buffers with boring buffers filtered out.
2532 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2533 The first buffer in the list will be the last recently used
2534 buffer that is not the current buffer."
2535 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2536 (append (cdr buffers) (list (car buffers)))))
2538 (defvar anything-c-source-buffers
2539 '((name . "Buffers")
2540 (candidates . anything-c-buffer-list)
2541 (type . buffer)))
2542 ;; (anything 'anything-c-source-buffers)
2544 (defvar anything-c-source-buffer-not-found
2545 '((name . "Create buffer")
2546 (dummy)
2547 (filtered-candidate-transformer (lambda (cands source)
2548 (list anything-pattern)))
2549 (action . (lambda (candidate)
2550 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2551 ;; (anything 'anything-c-source-buffer-not-found)
2553 ;;; Buffers-list (was buffers+)
2556 (eval-when-compile (require 'dired))
2558 (defun anything-c-highlight-buffers (buffers)
2559 (loop for i in buffers
2560 for buf = (get-buffer i)
2561 for bfname = (buffer-file-name buf)
2562 collect
2563 (cond (;; A dired buffer.
2564 (rassoc buf dired-buffers)
2565 (propertize i 'face 'anything-ff-directory
2566 'help-echo (car (rassoc buf dired-buffers))))
2567 ;; A buffer file modified somewhere outside of emacs.
2568 ((and bfname (not (file-remote-p bfname))
2569 (file-exists-p bfname)
2570 (not (verify-visited-file-modtime buf)))
2571 (propertize i 'face 'anything-buffer-saved-out
2572 'help-echo bfname))
2573 ;; A new buffer file not already saved on disk.
2574 ((and bfname (not (file-remote-p bfname))
2575 (not (verify-visited-file-modtime buf)))
2576 (propertize i 'face 'anything-buffer-not-saved
2577 'help-echo bfname))
2578 ;; A Remote buffer file modified and not saved on disk.
2579 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2580 (let ((prefix (propertize
2581 " " 'display
2582 (propertize "@ " 'face 'anything-ff-prefix))))
2583 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2584 'help-echo bfname)) i)))
2585 ;; A buffer file modified and not saved on disk.
2586 ((and bfname (buffer-modified-p buf))
2587 (propertize i 'face 'anything-ff-symlink
2588 'help-echo bfname))
2589 ;; A remote buffer file not modified and saved on disk.
2590 ((and bfname (file-remote-p bfname))
2591 (let ((prefix (propertize
2592 " " 'display
2593 (propertize "@ " 'face 'anything-ff-prefix))))
2594 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2595 'help-echo bfname)) i)))
2596 ;; A buffer file not modified and saved on disk.
2597 (bfname
2598 (propertize i 'face 'font-lock-type-face
2599 'help-echo bfname))
2600 ;; Any non--file buffer.
2601 (t (propertize i 'face 'italic)))))
2604 (defvar anything-c-source-buffers-list
2605 '((name . "Buffers")
2606 (candidates . anything-c-buffer-list)
2607 (type . buffer)
2608 (match anything-c-buffer-match-major-mode)
2609 (candidate-transformer
2610 anything-c-skip-current-buffer
2611 anything-c-skip-boring-buffers
2612 anything-c-highlight-buffers)
2613 (persistent-action . anything-c-buffers-list-persistent-action)
2614 (volatile)
2615 (mode-line . anything-buffer-mode-line-string)
2616 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2617 ;; (anything 'anything-c-source-buffers-list)
2618 (defvaralias 'anything-c-source-buffers+ 'anything-c-source-buffers-list)
2620 (defun anything-c-buffer-match-major-mode (candidate)
2621 "Match maybe buffer by major-mode.
2622 If you give a major-mode or partial major-mode,
2623 it will list all buffers of this major-mode and/or buffers with name
2624 matching this major-mode.
2625 If you add a space after major-mode and then a space,
2626 it will match all buffers of the major-mode
2627 before space matching pattern after space.
2628 If you give a pattern which doesn't match a major-mode, it will search buffer
2629 with name matching pattern."
2630 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2631 (buf (get-buffer cand)))
2632 (when buf
2633 (with-current-buffer buf
2634 (let ((mjm (symbol-name major-mode))
2635 (split (split-string anything-pattern)))
2636 (cond ((string-match "\\s-$" anything-pattern)
2637 (string-match (car split) mjm))
2638 ((string-match "\\s-" anything-pattern)
2639 (and (string-match (car split) mjm)
2640 (string-match (cadr split) cand)))
2641 (t (or (string-match anything-pattern mjm)
2642 (string-match anything-pattern cand)))))))))
2644 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2645 "Query replace in marked buffers.
2646 If REGEXP-FLAG is given use `query-replace-regexp'."
2647 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2648 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2649 (bufs (anything-marked-candidates)))
2650 (loop
2651 with replace = (query-replace-read-from prompt regexp-flag)
2652 with tostring = (unless (consp replace)
2653 (query-replace-read-to
2654 replace prompt regexp-flag))
2655 for buf in bufs
2657 (save-window-excursion
2658 (anything-c-switch-to-buffer buf)
2659 (save-excursion
2660 (let ((case-fold-search t))
2661 (goto-char (point-min))
2662 (if (consp replace)
2663 (apply fn (list (car replace) (cdr replace)))
2664 (apply fn (list replace tostring)))))))))
2666 (defun anything-c-buffer-query-replace-regexp (candidate)
2667 (anything-c-buffer-query-replace-1 'regexp))
2669 (defun anything-c-buffer-query-replace (candidate)
2670 (anything-c-buffer-query-replace-1))
2672 (defun anything-buffer-toggle-diff (candidate)
2673 "Toggle diff buffer CANDIDATE with it's file."
2674 (if (get-buffer-window "*Diff*")
2675 (kill-buffer "*Diff*")
2676 (diff-buffer-with-file (get-buffer candidate))))
2678 ;;;###autoload
2679 (defun anything-buffer-diff-persistent ()
2680 "Toggle diff buffer without quitting anything."
2681 (interactive)
2682 (anything-attrset 'diff-action 'anything-buffer-toggle-diff)
2683 (anything-execute-persistent-action 'diff-action))
2685 (defun anything-buffer-revert-and-update (candidate)
2686 (let ((marked (anything-marked-candidates)))
2687 (loop for buf in marked do (anything-revert-buffer buf))
2688 (anything-force-update candidate)))
2690 ;;;###autoload
2691 (defun anything-buffer-revert-persistent ()
2692 "Revert buffer without quitting anything."
2693 (interactive)
2694 (anything-attrset 'revert-action 'anything-buffer-revert-and-update)
2695 (anything-execute-persistent-action 'revert-action 'onewindow))
2697 (defun anything-buffer-save-and-update (candidate)
2698 (let ((marked (anything-marked-candidates))
2699 (enable-recursive-minibuffers t))
2700 (loop for buf in marked do
2701 (with-current-buffer (get-buffer buf)
2702 (save-buffer)))
2703 (anything-force-update candidate)))
2705 ;;;###autoload
2706 (defun anything-buffer-save-persistent ()
2707 "Save buffer without quitting anything."
2708 (interactive)
2709 (anything-attrset 'save-action 'anything-buffer-save-and-update)
2710 (anything-execute-persistent-action 'save-action 'onewindow))
2712 ;;;###autoload
2713 (defun anything-buffer-run-kill-buffers ()
2714 "Run kill buffer action from `anything-c-source-buffers-list'."
2715 (interactive)
2716 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2718 ;;;###autoload
2719 (defun anything-buffer-run-grep ()
2720 "Run Grep action from `anything-c-source-buffers-list'."
2721 (interactive)
2722 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2724 ;;;###autoload
2725 (defun anything-buffer-run-zgrep ()
2726 "Run Grep action from `anything-c-source-buffers-list'."
2727 (interactive)
2728 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2730 ;;;###autoload
2731 (defun anything-buffer-run-query-replace-regexp ()
2732 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2733 (interactive)
2734 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2736 ;;;###autoload
2737 (defun anything-buffer-run-query-replace ()
2738 "Run Query replace action from `anything-c-source-buffers-list'."
2739 (interactive)
2740 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2742 ;;;###autoload
2743 (defun anything-buffer-switch-other-window ()
2744 "Run switch to other window action from `anything-c-source-buffers-list'."
2745 (interactive)
2746 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2748 ;;;###autoload
2749 (defun anything-buffer-switch-other-frame ()
2750 "Run switch to other frame action from `anything-c-source-buffers-list'."
2751 (interactive)
2752 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2754 ;;;###autoload
2755 (defun anything-buffer-switch-to-elscreen ()
2756 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2757 (interactive)
2758 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2760 ;;;###autoload
2761 (defun anything-buffer-run-ediff ()
2762 "Run ediff action from `anything-c-source-buffers-list'."
2763 (interactive)
2764 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2766 (defun anything-buffer-run-ediff-merge ()
2767 "Run ediff action from `anything-c-source-buffers-list'."
2768 (interactive)
2769 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2771 (defun anything-c-buffers-persistent-kill (buffer)
2772 "Persistent action to kill buffer."
2773 (with-current-buffer (get-buffer buffer)
2774 (if (and (buffer-modified-p)
2775 (buffer-file-name (current-buffer)))
2776 (progn
2777 (save-buffer)
2778 (kill-buffer buffer))
2779 (kill-buffer buffer)))
2780 (anything-delete-current-selection))
2782 (defun anything-c-buffers-list-persistent-action (candidate)
2783 (if current-prefix-arg
2784 (anything-c-buffers-persistent-kill candidate)
2785 (anything-c-switch-to-buffer candidate)))
2788 ;;;; <File>
2791 ;;; File name history
2792 (defvar anything-c-source-file-name-history
2793 '((name . "File Name History")
2794 (candidates . file-name-history)
2795 (match anything-c-match-on-basename)
2796 (type . file)))
2797 ;; (anything 'anything-c-source-file-name-history)
2799 ;;; Files in current dir
2802 (defvar anything-c-source-files-in-current-dir
2803 '((name . "Files from Current Directory")
2804 (candidates . (lambda ()
2805 (with-anything-current-buffer
2806 (directory-files (anything-c-current-directory)))))
2807 ;; volatile is not needed, I think.
2808 (type . file)))
2809 ;; (anything 'anything-c-source-files-in-current-dir)
2811 (defun anything-c-highlight-files (files)
2812 (loop for i in files
2813 if (file-directory-p i)
2814 collect (propertize (file-name-nondirectory i)
2815 'face 'anything-ff-directory
2816 'help-echo (expand-file-name i))
2817 else
2818 collect (propertize (file-name-nondirectory i)
2819 'face 'anything-ff-file
2820 'help-echo (expand-file-name i))))
2822 (defvar anything-c-source-files-in-current-dir+
2823 '((name . "Files from Current Directory")
2824 (candidates . (lambda ()
2825 (with-anything-current-buffer
2826 (directory-files (anything-c-current-directory) t))))
2827 (candidate-transformer anything-c-highlight-files)
2828 ;; volatile is not needed, I think.
2829 (type . file)))
2830 ;; (anything 'anything-c-source-files-in-current-dir+)
2834 ;;; Anything-find-files - The anything files browser.
2837 ;; Internal.
2838 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2839 "*The doc that is inserted in the Name header of a find-files or dired source.")
2840 (defvar anything-ff-auto-update-flag nil
2841 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2842 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2843 (defvar anything-ff-last-expanded nil
2844 "Store last expanded directory or file.")
2845 (defvar anything-ff-default-directory nil)
2846 (defvar anything-ff-history nil)
2847 (defvar anything-ff-cand-to-mark nil)
2850 (defvar anything-c-source-find-files
2851 `((name . "Find Files")
2852 (header-name . (lambda (name)
2853 (concat name anything-c-find-files-doc-header)))
2854 ;; It is needed for filenames with capital letters
2855 (disable-shortcuts)
2856 (init . (lambda ()
2857 (setq anything-ff-auto-update-flag
2858 anything-ff-auto-update-initial-value)))
2859 (candidates . anything-find-files-get-candidates)
2860 (filtered-candidate-transformer anything-c-find-files-transformer)
2861 (persistent-action . anything-find-files-persistent-action)
2862 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2863 (mode-line . anything-ff-mode-line-string)
2864 (volatile)
2865 (candidate-number-limit . 9999)
2866 (action-transformer . anything-find-files-action-transformer)
2867 (action
2868 . ,(delq
2870 `(("Find File" . anything-c-find-file-or-marked)
2871 ("Find file in Dired" . anything-c-point-file-in-dired)
2872 ,(and (locate-library "elscreen")
2873 '("Find file in Elscreen" . anything-elscreen-find-file))
2874 ,(and (locate-library "popwin")
2875 '("Find file in popup window" . popwin:find-file))
2876 ("Checksum File" . anything-ff-checksum)
2877 ("Complete at point `M-tab'"
2878 . anything-c-insert-file-name-completion-at-point)
2879 ("Open file externally `C-c C-x, C-u to choose'"
2880 . anything-c-open-file-externally)
2881 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2882 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2883 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2884 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2885 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2886 . anything-find-files-eshell-command-on-file)
2887 ("Find file as root" . anything-find-file-as-root)
2888 ("Find file in hex dump" . hexl-find-file)
2889 ("Ediff File `C-='" . anything-find-files-ediff-files)
2890 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2891 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2892 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2893 ("Copy file(s) Async" . anything-ff-copy-async)
2894 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2895 ("Serial rename files" . anything-ff-serial-rename)
2896 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2897 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2898 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2899 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2900 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2901 ("Find file other window `C-o'" . find-file-other-window)
2902 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2903 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2904 ("Print File `C-c p'" . anything-ff-print)
2905 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2906 ;; (anything 'anything-c-source-find-files)
2908 (defun anything-find-files-set-prompt-for-action (action files)
2909 "Set prompt for action ACTION for FILES."
2910 (let ((len (length files)))
2911 (format "%s *%s File(s)\n%s to: "
2912 action len
2913 (mapconcat (lambda (f)
2914 (format "- %s\n" f)) files ""))))
2916 (defun anything-dwim-target-directory ()
2917 "Return value of `default-directory' of buffer in other window.
2918 If there is only one window return the value ot `default-directory'
2919 for current buffer."
2920 (with-anything-current-buffer
2921 (let ((num-windows (length (window-list))))
2922 (if (> num-windows 1)
2923 (save-selected-window
2924 (other-window 1)
2925 default-directory)
2926 (car anything-ff-history)))))
2928 (defun anything-find-files-do-action (action)
2929 "Generic function for creating action from `anything-c-source-find-files'.
2930 ACTION must be an action supported by `anything-dired-action'."
2931 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2932 (anything-marked-candidates)))
2933 (cand (anything-get-selection)) ; Target
2934 (prompt (anything-find-files-set-prompt-for-action
2935 (capitalize (symbol-name action)) ifiles))
2936 (parg anything-current-prefix-arg)
2937 (dest (anything-c-read-file-name
2938 prompt
2939 :preselect (if anything-ff-transformer-show-only-basename
2940 (anything-c-basename cand) cand)
2941 :initial-input (anything-dwim-target-directory)
2942 :history (anything-find-files-history :comp-read nil))))
2943 (anything-dired-action
2944 dest :files ifiles :action action :follow parg)))
2946 (defun anything-find-files-copy (candidate)
2947 "Copy files from `anything-find-files'."
2948 (anything-find-files-do-action 'copy))
2950 (defun anything-find-files-rename (candidate)
2951 "Rename files from `anything-find-files'."
2952 (anything-find-files-do-action 'rename))
2954 (defun anything-find-files-symlink (candidate)
2955 "Symlink files from `anything-find-files'."
2956 (anything-find-files-do-action 'symlink))
2958 (defun anything-find-files-relsymlink (candidate)
2959 "Relsymlink files from `anything-find-files'."
2960 (anything-find-files-do-action 'relsymlink))
2962 (defun anything-find-files-hardlink (candidate)
2963 "Hardlink files from `anything-find-files'."
2964 (anything-find-files-do-action 'hardlink))
2966 (defun anything-find-files-byte-compile (candidate)
2967 "Byte compile elisp files from `anything-find-files'."
2968 (let ((files (anything-marked-candidates))
2969 (parg anything-current-prefix-arg))
2970 (loop for fname in files
2971 do (byte-compile-file fname parg))))
2973 (defun anything-find-files-load-files (candidate)
2974 "Load elisp files from `anything-find-files'."
2975 (let ((files (anything-marked-candidates)))
2976 (loop for fname in files
2977 do (load fname))))
2979 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2980 "Generic function to ediff/merge files in `anything-find-files'."
2981 (let ((bname (anything-c-basename candidate))
2982 (prompt (if merge "Ediff Merge `%s' With File: "
2983 "Ediff `%s' With File: "))
2984 (fun (if merge 'ediff-merge-files 'ediff-files)))
2985 (funcall fun
2986 candidate
2987 (condition-case quit
2988 (anything-c-read-file-name
2989 (format prompt bname))
2990 (quit ;; Hit C-g ask user to fallback to locate.
2991 (if (y-or-n-p "Search file for ediff with locate? ")
2992 (anything-c-locate-read-file-name
2993 (format prompt bname)
2994 ;; Check if -b option is available.
2995 (if (and (eq system-type 'windows-nt)
2996 (string-match "^es" anything-c-locate-command))
2997 bname
2998 (concat bname " -b")))
2999 (error "Error: Ediff Operation aborted")))))))
3001 (defun anything-find-files-ediff-files (candidate)
3002 (anything-find-files-ediff-files-1 candidate))
3004 (defun anything-find-files-ediff-merge-files (candidate)
3005 (anything-find-files-ediff-files-1 candidate 'merge))
3007 (defun anything-find-files-grep (candidate)
3008 "Default action to grep files from `anything-find-files'."
3009 (anything-do-grep-1 (anything-marked-candidates)
3010 anything-current-prefix-arg))
3012 (defun anything-ff-zgrep (candidate)
3013 "Default action to zgrep files from `anything-find-files'."
3014 (let ((prefarg anything-current-prefix-arg)
3015 (ls (anything-marked-candidates)))
3016 (anything-ff-zgrep-1 ls prefarg)))
3018 (defun anything-ff-pdfgrep (candidate)
3019 "Default action to pdfgrep files from `anything-find-files'."
3020 (let ((cands (loop for file in (anything-marked-candidates)
3021 if (or (string= (file-name-extension file) "pdf")
3022 (string= (file-name-extension file) "PDF"))
3023 collect file))
3024 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
3025 (when cands
3026 (anything-do-pdfgrep-1 cands))))
3028 (defun anything-ff-etags-select (candidate)
3029 "Default action to jump to etags from `anything-find-files'."
3030 (when (get-buffer anything-action-buffer)
3031 (kill-buffer anything-action-buffer))
3032 (let ((default-directory anything-ff-default-directory))
3033 (anything-c-etags-select anything-current-prefix-arg)))
3035 (defun anything-find-files-switch-to-hist (candidate)
3036 "Switch to anything-find-files history."
3037 (anything-find-files t))
3039 ;;; Asynchronous copy of files.
3042 (defun anything-c-copy-files-async-1 (flist dest)
3043 "Copy a list of Files FLIST to DEST asynchronously.
3044 It use another emacs process to do the job.
3045 Communication with background emacs is done with temp file
3046 `anything-c-copy-files-async-log-file'."
3047 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3048 "-Q" "--batch" "--eval"
3049 (format "(progn
3050 (require 'dired) (require 'cl)
3051 (let ((dired-recursive-copies 'always)
3052 failures success
3053 (ovw-count 0)
3054 (cpf-count 0))
3055 (dolist (f '%S)
3056 (condition-case err
3057 (let ((file-exists (file-exists-p
3058 (expand-file-name
3059 (file-name-nondirectory (directory-file-name f))
3060 (file-name-directory
3061 (file-name-as-directory \"%s\"))))))
3062 (dired-copy-file f \"%s\" t)
3063 (if file-exists
3064 (progn (push (cons \"Overwriting\" f) success)
3065 (incf ovw-count))
3066 (push (cons \"Copying\" f) success)
3067 (incf cpf-count)))
3068 (file-error
3069 (push (dired-make-relative
3070 (expand-file-name
3071 (file-name-nondirectory (directory-file-name f))
3072 (file-name-directory \"%s\")))
3073 failures))))
3074 (with-current-buffer (find-file-noselect \"%s\")
3075 (erase-buffer)
3076 (when failures
3077 (dolist (fail (reverse failures))
3078 (insert (concat \"Failed to copy \" fail \"\n\"))))
3079 (when success
3080 (loop for (a . s) in (reverse success) do
3081 (insert (concat a \" \" s \" to %s done\n\"))))
3082 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3083 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3084 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3085 (save-buffer))))"
3086 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3088 (defun anything-c-copy-async-with-log (flist dest)
3089 "Copy file list FLIST to DEST showing log.
3090 Log is send to `anything-c-copy-files-async-log-file'.
3091 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3092 (declare (special auto-revert-interval))
3093 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3094 (set (make-local-variable 'auto-revert-interval) 1)
3095 (erase-buffer)
3096 (insert "Wait copying files...\n")
3097 (sit-for 0.5) (save-buffer)
3098 (goto-char (point-max))
3099 (auto-revert-mode 1)
3100 (anything-c-copy-files-async-1 flist dest))
3102 (defun anything-ff-copy-async (candidate)
3103 "Anything find files action to copy files async.
3104 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3105 (let* ((flist (anything-marked-candidates))
3106 (dest (anything-c-read-file-name
3107 (anything-find-files-set-prompt-for-action
3108 "Copy Async" flist)
3109 :preselect candidate
3110 :initial-input (car anything-ff-history)
3111 :history (anything-find-files-history :comp-read nil))))
3112 (anything-c-copy-async-with-log flist dest)))
3114 (defvar eshell-command-aliases-list nil)
3115 (defvar anything-eshell-command-on-file-input-history nil)
3116 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3117 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3119 Basename of CANDIDATE can be a wild-card.
3120 If MAP is given run `eshell-command' on all marked files at once,
3121 Otherwise, run `eshell-command' on each marked files.
3123 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3124 `eshell-command-aliases-list' will not be loaded first time you use this."
3125 (when (or eshell-command-aliases-list
3126 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3127 (and eshell-command-aliases-list (eshell-read-aliases-list))
3128 (let* ((cand-list (anything-marked-candidates))
3129 (default-directory (or anything-ff-default-directory
3130 ;; If candidate is an url *-ff-default-directory is nil
3131 ;; so keep value of default-directory.
3132 default-directory))
3133 (command (anything-comp-read
3134 "Command: "
3135 (loop for (a . c) in eshell-command-aliases-list
3136 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3137 collect (propertize a 'help-echo (car c)) into ls
3138 finally return (sort ls 'string<))
3139 :buffer "*esh command on file*"
3140 :name "Eshell command"
3141 :input-history
3142 'anything-eshell-command-on-file-input-history))
3143 (com-value (car (assoc-default command eshell-command-aliases-list))))
3144 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3145 (> (length cand-list) 1))
3146 ;; Run eshell-command with ALL marked files as arguments.
3147 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3148 (eshell-command (format "%s %s" command mapfiles)))
3149 ;; Run eshell-command on EACH marked files.
3150 (loop
3151 for i in cand-list
3152 for bn = (anything-c-basename i)
3153 for files = (if (and bn (string-match "^\*" bn))
3154 ;; Assume if fname is a wildcard
3155 ;; cand-list have a length of 1.
3156 (mapconcat
3157 'shell-quote-argument
3158 (file-expand-wildcards i t) " ")
3159 (format "'%s'" i))
3160 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3161 ;; This allow to enter other args AFTER filename
3162 ;; i.e <command %s some_more_args>
3163 (format command files)
3164 (format "%s %s" command files))
3165 do (eshell-command com))))))
3167 (defun anything-find-files-eshell-command-on-file (candidate)
3168 "Run `eshell-command' on CANDIDATE or marked candidates.
3169 See `anything-find-files-eshell-command-on-file-1' for more info."
3170 (anything-find-files-eshell-command-on-file-1
3171 candidate anything-current-prefix-arg))
3173 (defun anything-ff-switch-to-eshell (candidate)
3174 "Switch to eshell and cd to `anything-ff-default-directory'."
3175 (flet ((cd-eshell ()
3176 (goto-char (point-max))
3177 (insert
3178 (format "cd '%s'" anything-ff-default-directory))
3179 (eshell-send-input)))
3180 (if (get-buffer "*eshell*")
3181 (progn
3182 (anything-c-switch-to-buffer "*eshell*")
3183 (cd-eshell))
3184 (call-interactively 'eshell)
3185 (cd-eshell))))
3187 (defun anything-ff-serial-rename-action (method)
3188 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3189 See `anything-ff-serial-rename-1'."
3190 (let* ((cands (anything-marked-candidates))
3191 (name (read-string "NewName: "))
3192 (start (read-number "StartAtNumber: "))
3193 (extension (read-string "Extension: " (file-name-extension (car cands))))
3194 (dir (expand-file-name
3195 (anything-c-read-file-name
3196 "Serial Rename to directory: " :initial-input
3197 (expand-file-name anything-ff-default-directory)))))
3198 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3199 (length cands) dir name))
3200 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3201 (anything-find-files-1 dir))))
3203 (defun anything-ff-member-directory-p (file directory)
3204 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3205 (cur-dir (expand-file-name (file-name-as-directory directory))))
3206 (string= dir-file cur-dir)))
3208 (defun* anything-ff-serial-rename-1
3209 (directory collection new-name start-at-num extension &key (method 'rename))
3210 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3211 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3212 EXTENSION is the file extension to use, in empty prompt,
3213 reuse the original extension of file.
3214 METHOD can be one of rename, copy or symlink.
3215 Files will be renamed if they are files of current directory, otherwise they
3216 will be treated with METHOD.
3217 Default METHOD is rename."
3218 ;; Maybe remove directories selected by error in collection.
3219 (setq collection (remove-if 'file-directory-p collection))
3220 (flet ((symlink-file (file dest)
3221 (let ((flist (list file)))
3222 (anything-dired-action
3223 dest :action 'symlink :files flist))))
3225 (let* ((tmp-dir (file-name-as-directory
3226 (concat (file-name-as-directory directory)
3227 (symbol-name (gensym "tmp")))))
3228 (fn (case method
3229 (copy 'copy-file)
3230 (symlink 'symlink-file)
3231 (rename 'rename-file)
3232 (t (error "Error: Unknow method %s" method)))))
3233 (make-directory tmp-dir)
3234 (loop for i in collection
3235 for count from start-at-num
3236 for fnum = (if (< count 10) "0%s" "%s")
3237 for nname = (concat tmp-dir new-name (format fnum count)
3238 (if (not (string= extension ""))
3239 (format ".%s" (replace-regexp-in-string
3240 "[.]" "" extension))
3241 (file-name-extension i 'dot)))
3242 do (if (anything-ff-member-directory-p i directory)
3243 (rename-file i nname)
3244 (funcall fn i nname)))
3245 (loop with dirlist = (directory-files
3246 tmp-dir t directory-files-no-dot-files-regexp)
3247 for f in dirlist do
3248 (if (file-symlink-p f)
3249 (symlink-file (file-truename f)
3250 (concat (file-name-as-directory directory)
3251 (anything-c-basename f)))
3252 (rename-file f directory)))
3253 (delete-directory tmp-dir t))))
3255 (defun anything-ff-serial-rename (candidate)
3256 "Serial rename all marked files to `anything-ff-default-directory'.
3257 Rename only file of current directory, and symlink files coming from
3258 other directories.
3259 See `anything-ff-serial-rename-1'."
3260 (anything-ff-serial-rename-action 'rename))
3262 (defun anything-ff-serial-rename-by-symlink (candidate)
3263 "Serial rename all marked files to `anything-ff-default-directory'.
3264 Rename only file of current directory, and symlink files coming from
3265 other directories.
3266 See `anything-ff-serial-rename-1'."
3267 (anything-ff-serial-rename-action 'symlink))
3269 (defun anything-ff-serial-rename-by-copying (candidate)
3270 "Serial rename all marked files to `anything-ff-default-directory'.
3271 Rename only file of current directory, and copy files coming from
3272 other directories.
3273 See `anything-ff-serial-rename-1'."
3274 (anything-ff-serial-rename-action 'copy))
3276 (defun anything-c-quit-and-execute-action (action)
3277 "Quit current anything session and execute ACTION."
3278 (setq anything-saved-action action)
3279 (anything-exit-minibuffer))
3281 (defun anything-ff-toggle-auto-update (candidate)
3282 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3283 (message "[Auto expansion %s]"
3284 (if anything-ff-auto-update-flag "enabled" "disabled")))
3286 ;;;###autoload
3287 (defun anything-ff-run-toggle-auto-update ()
3288 (interactive)
3289 (anything-attrset 'toggle-auto-update 'anything-ff-toggle-auto-update)
3290 (anything-execute-persistent-action 'toggle-auto-update))
3292 ;;;###autoload
3293 (defun anything-ff-run-switch-to-history ()
3294 "Run Switch to history action from `anything-c-source-find-files'."
3295 (interactive)
3296 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3298 ;;;###autoload
3299 (defun anything-ff-run-grep ()
3300 "Run Grep action from `anything-c-source-find-files'."
3301 (interactive)
3302 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3304 ;;;###autoload
3305 (defun anything-ff-run-pdfgrep ()
3306 "Run Pdfgrep action from `anything-c-source-find-files'."
3307 (interactive)
3308 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3310 ;;;###autoload
3311 (defun anything-ff-run-zgrep ()
3312 "Run Grep action from `anything-c-source-find-files'."
3313 (interactive)
3314 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3316 ;;;###autoload
3317 (defun anything-ff-run-copy-file ()
3318 "Run Copy file action from `anything-c-source-find-files'."
3319 (interactive)
3320 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3322 ;;;###autoload
3323 (defun anything-ff-run-rename-file ()
3324 "Run Rename file action from `anything-c-source-find-files'."
3325 (interactive)
3326 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3328 ;;;###autoload
3329 (defun anything-ff-run-byte-compile-file ()
3330 "Run Byte compile file action from `anything-c-source-find-files'."
3331 (interactive)
3332 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3334 ;;;###autoload
3335 (defun anything-ff-run-load-file ()
3336 "Run Load file action from `anything-c-source-find-files'."
3337 (interactive)
3338 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3340 ;;;###autoload
3341 (defun anything-ff-run-eshell-command-on-file ()
3342 "Run eshell command on file action from `anything-c-source-find-files'."
3343 (interactive)
3344 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3346 ;;;###autoload
3347 (defun anything-ff-run-ediff-file ()
3348 "Run Ediff file action from `anything-c-source-find-files'."
3349 (interactive)
3350 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3352 ;;;###autoload
3353 (defun anything-ff-run-ediff-merge-file ()
3354 "Run Ediff merge file action from `anything-c-source-find-files'."
3355 (interactive)
3356 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3358 ;;;###autoload
3359 (defun anything-ff-run-symlink-file ()
3360 "Run Symlink file action from `anything-c-source-find-files'."
3361 (interactive)
3362 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3364 ;;;###autoload
3365 (defun anything-ff-run-delete-file ()
3366 "Run Delete file action from `anything-c-source-find-files'."
3367 (interactive)
3368 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3370 ;;;###autoload
3371 (defun anything-ff-run-complete-fn-at-point ()
3372 "Run complete file name action from `anything-c-source-find-files'."
3373 (interactive)
3374 (anything-c-quit-and-execute-action
3375 'anything-c-insert-file-name-completion-at-point))
3377 ;;;###autoload
3378 (defun anything-ff-run-switch-to-eshell ()
3379 "Run switch to eshell action from `anything-c-source-find-files'."
3380 (interactive)
3381 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3383 ;;;###autoload
3384 (defun anything-ff-run-switch-other-window ()
3385 "Run switch to other window action from `anything-c-source-find-files'."
3386 (interactive)
3387 (anything-c-quit-and-execute-action 'find-file-other-window))
3389 ;;;###autoload
3390 (defun anything-ff-run-switch-other-frame ()
3391 "Run switch to other frame action from `anything-c-source-find-files'."
3392 (interactive)
3393 (anything-c-quit-and-execute-action 'find-file-other-frame))
3395 ;;;###autoload
3396 (defun anything-ff-run-open-file-externally ()
3397 "Run open file externally command action from `anything-c-source-find-files'."
3398 (interactive)
3399 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3401 (defun anything-ff-locate (candidate)
3402 "Locate action function for `anything-find-files'."
3403 (let ((input (concat (anything-c-basename
3404 (expand-file-name
3405 candidate
3406 anything-ff-default-directory))
3407 ;; The locate '-b' option doesn't exists
3408 ;; in everything.
3409 (unless (and (eq system-type 'windows-nt)
3410 (string-match "^es" anything-c-locate-command))
3411 " -b")))
3412 (anything-mp-highlight-delay 0.7))
3413 (anything-locate-1 anything-current-prefix-arg input)))
3415 ;;;###autoload
3416 (defun anything-ff-run-locate ()
3417 "Run locate action from `anything-c-source-find-files'."
3418 (interactive)
3419 (anything-c-quit-and-execute-action 'anything-ff-locate))
3421 ;;;###autoload
3422 (defun anything-ff-run-gnus-attach-files ()
3423 "Run gnus attach files command action from `anything-c-source-find-files'."
3424 (interactive)
3425 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3427 ;;;###autoload
3428 (defun anything-ff-run-etags ()
3429 "Run Etags command action from `anything-c-source-find-files'."
3430 (interactive)
3431 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3434 (defun anything-ff-print (candidate)
3435 "Print marked files.
3436 You have to set in order
3437 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3439 e.g:
3440 \(setq lpr-command \"gtklp\"\)
3441 \(setq lpr-switches '(\"-P\")\)
3442 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3444 Same as `dired-do-print' but for anything."
3445 (unless anything-ff-printer-list
3446 (setq anything-ff-printer-list
3447 (anything-ff-find-printers)))
3448 (let* ((file-list (anything-marked-candidates))
3449 (len (length file-list))
3450 (printer-name (if anything-ff-printer-list
3451 (anything-comp-read
3452 "Printer: " anything-ff-printer-list)
3453 printer-name))
3454 (command (read-string
3455 (format "Print *%s File(s):\n%s with: "
3457 (mapconcat
3458 (lambda (f) (format "- %s\n" f))
3459 file-list ""))
3460 (when (and lpr-command
3461 (or lpr-switches
3462 printer-name))
3463 (mapconcat 'identity
3464 (cons lpr-command
3465 (append (if (stringp lpr-switches)
3466 (list lpr-switches)
3467 lpr-switches)
3468 (list printer-name)))
3469 " "))))
3470 (file-args (mapconcat #'(lambda (x)
3471 (format "'%s'" x))
3472 file-list " "))
3473 (cmd-line (concat command " " file-args)))
3474 (if command
3475 (start-process-shell-command "anything-print" nil cmd-line)
3476 (error "Error: Please verify your printer settings in Emacs."))))
3478 ;;;###autoload
3479 (defun anything-ff-run-print-file ()
3480 "Run Print file action from `anything-c-source-find-files'."
3481 (interactive)
3482 (anything-c-quit-and-execute-action 'anything-ff-print))
3484 (defun anything-ff-checksum (file)
3485 "Calculate the checksum of FILE.
3486 Provide completion on different algorithms to use on Emacs24.
3487 On Emacs23 only 'sha1' is available.
3488 The checksum is copied to kill-ring."
3489 (let ((algo-list (and (fboundp 'secure-hash)
3490 '(md5 sha1 sha224 sha256 sha384 sha512))))
3491 (kill-new
3492 (if algo-list
3493 (secure-hash (intern
3494 (anything-comp-read
3495 "Algorithm: " algo-list))
3496 file)
3497 (sha1 (with-temp-buffer
3498 (insert-file-contents file)
3499 (buffer-string)))))
3500 (message "Checksum copied to kill-ring.")))
3502 (defun anything-ff-toggle-basename (candidate)
3503 (setq anything-ff-transformer-show-only-basename
3504 (not anything-ff-transformer-show-only-basename))
3505 (let ((target (if anything-ff-transformer-show-only-basename
3506 (anything-c-basename candidate) candidate)))
3507 (anything-force-update target)))
3509 (defun anything-ff-run-toggle-basename ()
3510 (interactive)
3511 (anything-attrset 'toggle-basename 'anything-ff-toggle-basename)
3512 (anything-execute-persistent-action 'toggle-basename))
3514 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3515 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3516 If LEVEL is positive reduce from end else from beginning.
3517 If UNIX-CLOSE is non--nil close filename with /.
3518 If EXPAND is non--nil expand-file-name."
3519 (let* ((exp-fname (expand-file-name fname))
3520 (fname-list (split-string (if (or (string= fname "~/") expand)
3521 exp-fname fname) "/" t))
3522 (len (length fname-list))
3523 (pop-list (if (< level 0)
3524 (subseq fname-list (* level -1))
3525 (subseq fname-list 0 (- len level))))
3526 (result (mapconcat 'identity pop-list "/"))
3527 (empty (string= result "")))
3528 (when unix-close (setq result (concat result "/")))
3529 (if (string-match "^~" result)
3530 (if (string= result "~/") "~/" result)
3531 (if (< level 0)
3532 (if empty "../" (concat "../" result))
3533 (cond ((eq system-type 'windows-nt)
3534 (if empty (expand-file-name "/") ; Expand to "/" or "c:/".
3535 result))
3536 (empty "/")
3538 (concat "/" result)))))))
3540 ;; Internal
3541 (defvar anything-file-completion-sources
3542 '("Find Files" "Read File Name"
3543 "Read File Name History" "Copy Files"
3544 "Rename Files" "Symlink Files"
3545 "Hardlink Files" "Write File" "Insert File")
3546 "Sources that use the *find-files mechanism can be added here.
3547 Sources generated by `ac-mode' don't need to be added here, it will
3548 be done automatically.
3549 You should not modify this yourself unless you know what you do.")
3551 (defun anything-file-completion-source-p ()
3552 "Test if current source is a dired or find-files source."
3553 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3554 (loop for i in anything-file-completion-sources
3555 thereis (string= cur-source i))))
3557 (defun anything-find-files-down-one-level (arg)
3558 "Go down one level like unix command `cd ..'.
3559 If prefix numeric arg is given go ARG level down."
3560 (interactive "p")
3561 (when (and (anything-file-completion-source-p)
3562 (not (anything-ff-invalid-tramp-name-p)))
3563 (with-anything-window
3564 (setq anything-follow-mode nil))
3565 ;; When going to precedent level we want to be at the line
3566 ;; corresponding to actual directory, so store this info
3567 ;; in `anything-ff-last-expanded'.
3568 (if (and (not (file-directory-p anything-pattern))
3569 (file-exists-p anything-pattern))
3570 (setq anything-ff-last-expanded anything-pattern)
3571 (setq anything-ff-last-expanded anything-ff-default-directory))
3572 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3573 :unix-close t :expand t)))
3574 (anything-set-pattern new-pattern))))
3576 (defun anything-ff-retrieve-last-expanded ()
3577 "Move overlay to last visited directory `anything-ff-last-expanded'.
3578 This happen after using `anything-find-files-down-one-level',
3579 or hitting C-z on \"..\"."
3580 (when (and anything-ff-last-expanded
3581 (anything-file-completion-source-p))
3582 (let ((dirname (if anything-ff-transformer-show-only-basename
3583 (anything-c-basename
3584 (directory-file-name anything-ff-last-expanded))
3585 (directory-file-name anything-ff-last-expanded))))
3586 (with-anything-window
3587 (when (or (re-search-forward (concat dirname "$") nil t)
3588 (re-search-forward
3589 (concat anything-ff-last-expanded "$") nil t))
3590 (forward-line 0)
3591 (anything-mark-current-line)))
3592 (setq anything-ff-last-expanded nil))))
3593 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3595 ;; Auto-update - anything-find-files auto expansion of directories.
3597 (defun anything-ff-update-when-only-one-matched ()
3598 "Expand to directory when sole completion.
3599 When only one candidate is remaining and it is a directory,
3600 expand to this directory."
3601 (when (and anything-ff-auto-update-flag
3602 (anything-file-completion-source-p)
3603 (not (anything-ff-invalid-tramp-name-p)))
3604 (let* ((history-p (string= (assoc-default
3605 'name (anything-get-current-source))
3606 "Read File Name History"))
3607 (pat (if (string-match tramp-file-name-regexp
3608 anything-pattern)
3609 (anything-create-tramp-name anything-pattern)
3610 anything-pattern))
3611 (completed-p (string= (file-name-as-directory pat)
3612 anything-ff-default-directory)))
3613 (when (and (or
3614 ;; Only one candidate remaining
3615 ;; and at least 2 char in basename.
3616 (and (<= (anything-approximate-candidate-number) 2)
3617 (>= (length (anything-c-basename anything-pattern)) 2))
3618 ;; Already completed.
3619 completed-p)
3620 (not history-p)) ; Don't try to auto complete in history.
3621 (with-anything-window
3622 (let ((cur-cand (prog2
3623 (unless completed-p
3624 ;; Only one non--existing candidate
3625 ;; and one directory candidate, move to it.
3626 (anything-next-line))
3627 (anything-get-selection))))
3628 (when (file-directory-p cur-cand)
3629 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3630 ;; Maybe we are here because completed-p is true
3631 ;; but check this again to be sure. (Windows fix)
3632 (<= (anything-approximate-candidate-number) 2)) ; [2]
3633 ;; If after going to next line the candidate
3634 ;; is not one of "." or ".." [1]
3635 ;; and only one candidate is remaining [2],
3636 ;; assume candidate is a new directory to expand, and do it.
3637 (anything-set-pattern (file-name-as-directory cur-cand))
3638 ;; The candidate is one of "." or ".."
3639 ;; that mean we have entered the last letter of the directory name
3640 ;; in prompt, so expansion is already done, just add the "/" at end
3641 ;; of name unless anything-pattern ends with "."
3642 ;; (i.e we are writing something starting with ".")
3643 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3644 (anything-set-pattern
3645 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3646 (expand-file-name (file-name-as-directory anything-pattern)))))
3647 (anything-check-minibuffer-input-1))))))))
3648 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3650 ;; Allow expanding to home directory or root
3651 ;; when entering respectively "~/" or "//" at end of pattern.
3652 ;; e.g /home/thierry/labo/anything-config-qp/~/
3653 ;; will expand to "~/"
3654 ;; and /home/thierry/labo/anything-config-qp//
3655 ;; will expand to "/"
3656 (defun anything-ff-auto-expand-to-home-or-root ()
3657 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3658 This happen only in function using sources that are
3659 `anything-file-completion-source-p' compliant."
3660 (when (and (anything-file-completion-source-p)
3661 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3662 anything-pattern))
3663 (let ((match (match-string 1 anything-pattern)))
3664 (cond ((string= match "//")
3665 ;; Expand to "/" or "c:/"
3666 (setq anything-pattern (expand-file-name "/")))
3667 ((string= match "/~/")
3668 (if (eq system-type 'windows-nt)
3669 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3670 (setq anything-pattern "~/")))
3671 ((string= match "/./")
3672 (setq anything-pattern
3673 (with-anything-current-buffer
3674 (expand-file-name default-directory))))))
3675 (setq anything-ff-default-directory anything-pattern)
3676 ;; For some reasons, i must use here with-current-buffer => mini buffer
3677 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3678 (with-current-buffer (window-buffer (minibuffer-window))
3679 (delete-minibuffer-contents)
3680 (insert anything-pattern))))
3682 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3684 (defun anything-c-point-file-in-dired (file)
3685 "Put point on filename FILE in dired buffer."
3686 (dired (file-name-directory file))
3687 (dired-goto-file file))
3689 (defun anything-create-tramp-name (fname)
3690 "Build filename for `anything-pattern' like /su:: or /sudo::."
3691 (apply #'tramp-make-tramp-file-name
3692 (loop with v = (tramp-dissect-file-name fname)
3693 for i across v collect i)))
3695 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3696 "Get a list of hosts for tramp method found in `anything-pattern'.
3697 Argument PATTERN default to `anything-pattern', it is here only for debugging
3698 purpose."
3699 (when (string-match tramp-file-name-regexp pattern)
3700 (let ((method (match-string 1 pattern))
3701 (tn (match-string 0 pattern))
3702 (all-methods (mapcar 'car tramp-methods)))
3703 (remove-duplicates
3704 (loop for (f . h) in (tramp-get-completion-function method)
3705 append (loop for e in (funcall f (car h))
3706 for host = (and (consp e) (cadr e))
3707 when (and host (not (member host all-methods)))
3708 collect (concat tn host)))
3709 :test 'equal))))
3711 (defun anything-ff-before-action-hook-fn ()
3712 "Exit anything when user try to execute action on an invalid tramp fname."
3713 (let ((cand (anything-get-selection)))
3714 (when (and (anything-file-completion-source-p)
3715 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3716 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3717 (error "Error: Unknow file or directory `%s'" cand))))
3718 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3720 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3721 "Return non--nil when PATTERN is an invalid tramp filename."
3722 (string= (anything-ff-set-pattern pattern)
3723 "Invalid tramp file name"))
3725 (defun anything-ff-set-pattern (pattern)
3726 "Handle tramp filenames in `anything-pattern'."
3727 (let ((methods (mapcar 'car tramp-methods))
3728 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3729 cur-method tramp-name)
3730 (cond ((string= pattern "") "")
3731 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3732 (with-anything-current-buffer
3733 (expand-file-name default-directory)))
3734 ((string-match ".*\\(~//\\|//\\)$" pattern)
3735 (expand-file-name "/") ; Expand to "/" or "c:/"
3737 ((string-match "^~\\|.*/~/$" pattern)
3738 (let* ((home (expand-file-name (getenv "HOME"))))
3739 (replace-match home nil t pattern)))
3740 ;; Match "/method:maybe_hostname:"
3741 ((and (string-match reg pattern)
3742 (setq cur-method (match-string 1 pattern))
3743 (member cur-method methods))
3744 (setq tramp-name (anything-create-tramp-name
3745 (match-string 0 pattern)))
3746 (replace-match tramp-name nil t pattern))
3747 ;; Match "/hostname:"
3748 ((and (string-match tramp-file-name-regexp pattern)
3749 (setq cur-method (match-string 1 pattern))
3750 (and cur-method (not (member cur-method methods))))
3751 (setq tramp-name (anything-create-tramp-name
3752 (match-string 0 pattern)))
3753 (replace-match tramp-name nil t pattern))
3754 ;; Match "/method:" in this case don't try to connect.
3755 ((and (not (string-match reg pattern))
3756 (string-match tramp-file-name-regexp pattern)
3757 (member (match-string 1 pattern) methods))
3758 "Invalid tramp file name") ; Write in anything-buffer.
3759 ;; PATTERN is a directory, end it with "/".
3760 ;; This will make PATTERN not ending yet with "/"
3761 ;; candidate for `anything-ff-default-directory',
3762 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3763 ;; when descending level.
3764 ((file-directory-p pattern)
3765 (file-name-as-directory pattern))
3766 ;; Return PATTERN unchanged.
3767 (t pattern))))
3769 (defun anything-find-files-get-candidates ()
3770 "Create candidate list for `anything-c-source-find-files'."
3771 (let* ((path (anything-ff-set-pattern anything-pattern))
3772 (path-name-dir (if (file-directory-p path)
3773 (file-name-as-directory path)
3774 (file-name-directory path)))
3775 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3776 (set-text-properties 0 (length path) nil path)
3777 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3778 ;; like that the actual value (e.g /ssh:) is passed to
3779 ;; `anything-ff-tramp-hostnames'.
3780 (unless (string= path "Invalid tramp file name")
3781 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3782 (setq anything-ff-default-directory
3783 (if (string= anything-pattern "")
3784 (expand-file-name "/") ; Expand to "/" or "c:/"
3785 (unless (string-match ffap-url-regexp path)
3786 ;; If path is an url *default-directory have to be nil.
3787 path-name-dir)))
3788 (cond ((string= path "Invalid tramp file name")
3789 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3790 (prog2
3791 ;; `anything-pattern' have not been modified yet.
3792 ;; Set it here to the value of `path' that should be now
3793 ;; "Invalid tramp file name" and set the candidates list
3794 ;; to ("Invalid tramp file name") to make `anything-pattern'
3795 ;; match single candidate "Invalid tramp file name".
3796 (setq anything-pattern path)
3797 ;; "Invalid tramp file name" is now printed
3798 ;; in `anything-buffer'.
3799 (list path))))
3800 ((or (file-regular-p path)
3801 (and (not (file-exists-p path)) (string-match "/$" path))
3802 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3803 (list path))
3804 ((string= path "") (anything-ff-directory-files "/" t))
3805 ((and (file-directory-p path) (not (file-readable-p path)))
3806 (list (format "Opening directory: access denied, `%s'" path)))
3807 ((file-directory-p path) (anything-ff-directory-files path t))
3809 (append (list path) (anything-ff-directory-files path-name-dir t))))))
3811 (defun anything-ff-directory-files (directory &optional full)
3812 "List contents of DIRECTORY.
3813 Argument FULL mean absolute path.
3814 It is same as `directory-files' but always returns the
3815 dotted filename '.' and '..' on root directories on Windows
3816 systems."
3817 (setq directory (expand-file-name directory))
3818 (if (string-match "^[a-zA-Z]\\{1\\}:/$" directory)
3819 (let* ((dot (concat directory "."))
3820 (dot2 (concat directory ".."))
3821 (lsdir (remove
3822 dot2
3823 (remove
3825 (directory-files directory full)))))
3826 (append (list dot dot2) lsdir))
3827 (directory-files directory full)))
3829 (defun anything-ff-transform-fname-for-completion (fname)
3830 "Return FNAME with it's basename modified as a regexp.
3831 e.g foo => f.*o.*o .
3832 If basename contain one or more space or FNAME is a valid directory name
3833 return FNAME unchanged."
3834 (let ((bn (anything-c-basename fname)))
3835 (if (or (not anything-ff-smart-completion)
3836 (string-match "\\s-" bn)
3837 (string-match "/$" fname) ; Allow mkdir.
3838 (file-directory-p fname))
3839 fname ; Fall back to match-plugin.
3840 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3841 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3842 (concat (file-name-directory fname) bn))))
3844 (defun anything-ff-save-history ()
3845 "Store the last value of `anything-ff-default-directory' \
3846 in `anything-ff-history'."
3847 (when (and anything-ff-default-directory
3848 (anything-file-completion-source-p))
3849 (push anything-ff-default-directory anything-ff-history)))
3850 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3852 (defun anything-ff-valid-symlink-p (file)
3853 (file-exists-p (file-truename file)))
3855 (defun anything-ff-properties (candidate)
3856 "Show file properties of CANDIDATE in a tooltip or message."
3857 (let ((type (anything-ff-attributes candidate :type t))
3858 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3859 (if (window-system)
3860 (tooltip-show
3861 (concat
3862 (anything-c-basename candidate) ": \n"
3863 "Type: " type "\n"
3864 (when (string= type "symlink")
3865 (format "True name: '%s'\n"
3866 (cond ((string-match "^\.#" (anything-c-basename candidate))
3867 "Autosave symlink")
3868 ((anything-ff-valid-symlink-p candidate)
3869 (file-truename candidate))
3870 (t "Invalid Symlink"))))
3871 dired-line))
3872 (message dired-line) (sit-for 5))))
3874 ;;;###autoload
3875 (defun anything-ff-properties-persistent ()
3876 "Show properties without quitting anything."
3877 (interactive)
3878 (anything-attrset 'properties-action 'anything-ff-properties)
3879 (anything-execute-persistent-action 'properties-action))
3881 ;;;###autoload
3882 (defun anything-ff-persistent-delete ()
3883 "Delete current candidate without quitting."
3884 (interactive)
3885 (anything-attrset 'quick-delete 'anything-ff-quick-delete)
3886 (anything-execute-persistent-action 'quick-delete))
3888 (defun anything-ff-dot-file-p (file)
3889 "Check if FILE is `.' or `..'."
3890 (member (anything-c-basename file) '("." "..")))
3892 (defun anything-ff-quick-delete (candidate)
3893 "Delete file CANDIDATE without quitting."
3894 (if (and anything-ff-signal-error-on-dot-files
3895 (anything-ff-dot-file-p candidate))
3896 (message "Error: Cannot operate on `.' or `..'")
3897 (let ((presel (prog1 (save-excursion
3898 (let (sel)
3899 (anything-next-line)
3900 (setq sel (anything-get-selection))
3901 (if (string= sel candidate)
3902 (progn (anything-previous-line)
3903 (anything-get-selection))
3904 sel)))
3905 (anything-mark-current-line))))
3906 (setq presel (if (and anything-ff-transformer-show-only-basename
3907 (not (anything-ff-dot-file-p presel)))
3908 (anything-c-basename presel) presel))
3909 (if anything-ff-quick-delete-dont-prompt-for-deletion
3910 (anything-c-delete-file candidate)
3911 (save-selected-window
3912 (when (y-or-n-p (format "Really Delete file `%s'? " candidate))
3913 (anything-c-delete-file candidate))))
3914 (anything-force-update presel))))
3916 (defun anything-ff-kill-buffer-fname (candidate)
3917 (let* ((buf (get-file-buffer candidate))
3918 (buf-name (buffer-name buf)))
3919 (if buf
3920 (progn
3921 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3922 (message "No buffer to kill"))))
3924 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3925 "Find file CANDIDATE or kill it's buffer if it is visible.
3926 Never kill `anything-current-buffer'.
3927 Never kill buffer modified.
3928 This is called normally on third hit of \
3929 \\<anything-map>\\[anything-execute-persistent-action]
3930 in `anything-find-files-persistent-action'."
3931 (let* ((buf (get-file-buffer candidate))
3932 (buf-name (buffer-name buf)))
3933 (if (and buf (get-buffer-window buf)
3934 (not (eq buf (get-buffer anything-current-buffer)))
3935 (not (buffer-modified-p buf)))
3936 (progn
3937 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3938 (find-file candidate))))
3940 ;;;###autoload
3941 (defun anything-ff-run-kill-buffer-persistent ()
3942 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3943 (interactive)
3944 (anything-attrset 'kill-buffer-fname 'anything-ff-kill-buffer-fname)
3945 (anything-execute-persistent-action 'kill-buffer-fname))
3947 (defun anything-ff-human-size (size)
3948 "Return a string showing SIZE of a file in human readable form.
3949 SIZE can be an integer or a float depending it's value.
3950 `file-attributes' will take care of that to avoid overflow error.
3951 KBSIZE if a floating point number, default value is 1024.0."
3952 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3953 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3954 (K (cons "K" (/ size anything-ff-default-kbsize)))
3955 (B (cons "B" size)))
3956 (loop with result = B
3957 for (a . b) in
3958 (loop for (x . y) in (list M G K B)
3959 unless (< y 1) collect (cons x y))
3960 when (< b (cdr result)) do (setq result (cons a b))
3961 finally return (if (string= (car result) "B")
3962 (format "%s" size)
3963 (format "%.1f%s" (cdr result) (car result))))))
3965 (defun* anything-ff-attributes
3966 (file &key type links uid gid access-time modif-time
3967 status size mode gid-change inode device-num dired human-size)
3968 "Easy interface for `file-attributes'."
3969 (let ((all (destructuring-bind
3970 (type links uid gid access-time modif-time
3971 status size mode gid-change inode device-num)
3972 (file-attributes file 'string)
3973 (list :type type
3974 :links links
3975 :uid uid
3976 :gid gid
3977 :access-time access-time
3978 :modif-time modif-time
3979 :status status
3980 :size size
3981 :mode mode
3982 :gid-change gid-change
3983 :inode inode
3984 :device-num device-num))))
3985 (cond (type
3986 (let ((result (getf all :type)))
3987 (cond ((stringp result)
3988 "symlink")
3989 (result "directory")
3990 (t "file"))))
3991 (links (getf all :links))
3992 (uid (getf all :uid))
3993 (gid (getf all :gid))
3994 (access-time
3995 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3996 (modif-time
3997 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3998 (status
3999 (format-time-string "%Y-%m-%d %R" (getf all :status)))
4000 (size (if human-size (anything-ff-human-size (getf all :size))
4001 (getf all :size)))
4002 (mode (getf all :mode))
4003 (gid-change (getf all :gid-change))
4004 (inode (getf all :inode))
4005 (device-num (getf all :device-num))
4006 (dired
4007 (concat
4008 (getf all :mode) " "
4009 (number-to-string (getf all :links)) " "
4010 (getf all :uid) ":"
4011 (getf all :gid) " "
4012 (if human-size (anything-ff-human-size (getf all :size))
4013 (int-to-string (getf all :size))) " "
4014 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
4015 (t all))))
4017 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
4018 "Return filename FNAME maybe prefixed with [?] or [@].
4019 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4020 existing filename or valid symlink and there is no need to test it.
4021 NEW-FILE when non--nil mean FNAME is a non existing file and
4022 return FNAME prefixed with [?]."
4023 (let* ((prefix-new (propertize
4024 " " 'display
4025 (propertize "[?]" 'face 'anything-ff-prefix)))
4026 (prefix-url (propertize
4027 " " 'display
4028 (propertize "[@]" 'face 'anything-ff-prefix))))
4029 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
4030 ((string-match ffap-url-regexp fname)
4031 (concat prefix-url " " fname))
4032 ((or new-file (not (file-exists-p fname)))
4033 (concat prefix-new " " fname)))))
4035 (defun anything-c-find-files-transformer (files sources)
4036 "Transformer for `anything-c-source-find-files'.
4037 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4038 is non--nil."
4039 (if (and (string-match tramp-file-name-regexp anything-pattern)
4040 anything-ff-tramp-not-fancy)
4041 (if anything-ff-transformer-show-only-basename
4042 (loop for i in files collect
4043 (if (string-match "[.]\\{1,2\\}$" i)
4044 i (cons (anything-c-basename i) i)))
4045 files)
4046 (anything-ff-highlight-files files sources)))
4048 (defun anything-ff-highlight-files (files sources)
4049 "Candidate transformer for `anything-c-source-find-files' without icons."
4050 (loop for i in files
4051 for disp = (if (and anything-ff-transformer-show-only-basename
4052 (not (string-match "[.]\\{1,2\\}$" i))
4053 (not (string-match ffap-url-regexp i)))
4054 (anything-c-basename i) i)
4055 collect
4056 (cond ((and (stringp (car (file-attributes i)))
4057 (not (anything-ff-valid-symlink-p i))
4058 (not (string-match "^\.#" (anything-c-basename i))))
4059 (cons (anything-ff-prefix-filename
4060 (propertize disp 'face 'anything-ff-invalid-symlink) t)
4062 ((stringp (car (file-attributes i)))
4063 (cons (anything-ff-prefix-filename
4064 (propertize disp 'face 'anything-ff-symlink) t)
4066 ((eq t (car (file-attributes i)))
4067 (cons (anything-ff-prefix-filename
4068 (propertize disp 'face 'anything-ff-directory) t)
4070 ((file-executable-p i)
4071 (cons (anything-ff-prefix-filename
4072 (propertize disp 'face 'anything-ff-executable) t)
4074 ((file-exists-p i)
4075 (cons (anything-ff-prefix-filename
4076 (propertize disp 'face 'anything-ff-file) t)
4079 (cons (anything-ff-prefix-filename
4080 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4081 i)))))
4083 (defun anything-find-files-action-transformer (actions candidate)
4084 "Action transformer for `anything-c-source-find-files'."
4085 (cond ((with-anything-current-buffer
4086 (eq major-mode 'message-mode))
4087 (append (subseq actions 0 4)
4088 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4089 (subseq actions 4)))
4090 ((string-match (image-file-name-regexp) candidate)
4091 (append (subseq actions 0 4)
4092 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4093 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4094 (subseq actions 4)))
4095 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4096 (car it) candidate))
4097 (append (subseq actions 0 4)
4098 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4099 . anything-find-files-byte-compile)
4100 ("Load File(s) `M-L'" . anything-find-files-load-files))
4101 (subseq actions 4)))
4102 ((and (string-match "\.html?$" candidate)
4103 (file-exists-p candidate))
4104 (append (subseq actions 0 4)
4105 '(("Browse url file" . browse-url-of-file))
4106 (subseq actions 5)))
4107 ((or (string= (file-name-extension candidate) "pdf")
4108 (string= (file-name-extension candidate) "PDF"))
4109 (append (subseq actions 0 4)
4110 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4111 (subseq actions 5)))
4112 (t actions)))
4114 (defun anything-ff-gnus-attach-files (candidate)
4115 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4116 (let ((flist (anything-marked-candidates)))
4117 (gnus-dired-attach flist)))
4119 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4120 "Rotate current image at NUM-ARG degrees.
4121 This is a destructive operation on FILE made by external tool mogrify."
4122 (declare (special image-dired-display-image-buffer))
4123 (setq file (file-truename file)) ; For symlinked images.
4124 ;; When FILE is not an image-file, do nothing.
4125 (when (string-match (image-file-name-regexp) file)
4126 (if (executable-find "mogrify")
4127 (progn
4128 (shell-command (format "mogrify -rotate %s %s"
4129 (or num-arg 90)
4130 (shell-quote-argument file)))
4131 (when (buffer-live-p image-dired-display-image-buffer)
4132 (kill-buffer image-dired-display-image-buffer))
4133 (image-dired-display-image file)
4134 (message nil)
4135 (display-buffer (get-buffer image-dired-display-image-buffer)))
4136 (error "mogrify not found"))))
4138 (defun anything-ff-rotate-image-left (candidate)
4139 "Rotate image file CANDIDATE left.
4140 This affect directly file CANDIDATE."
4141 (anything-ff-rotate-current-image-1 candidate -90))
4143 (defun anything-ff-rotate-image-right (candidate)
4144 "Rotate image file CANDIDATE right.
4145 This affect directly file CANDIDATE."
4146 (anything-ff-rotate-current-image-1 candidate))
4148 (defun anything-ff-rotate-left-persistent ()
4149 "Rotate image left without quitting anything."
4150 (interactive)
4151 (anything-attrset 'image-action1 'anything-ff-rotate-image-left)
4152 (anything-execute-persistent-action 'image-action1))
4154 (defun anything-ff-rotate-right-persistent ()
4155 "Rotate image right without quitting anything."
4156 (interactive)
4157 (anything-attrset 'image-action2 'anything-ff-rotate-image-right)
4158 (anything-execute-persistent-action 'image-action2))
4160 (defun anything-ff-exif-data (candidate)
4161 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4162 (if (and anything-ff-exif-data-program
4163 (executable-find anything-ff-exif-data-program))
4164 (shell-command-to-string (format "%s %s %s"
4165 anything-ff-exif-data-program
4166 anything-ff-exif-data-program-args
4167 candidate))
4168 (format "No program %s found to extract exif"
4169 anything-ff-exif-data-program)))
4171 (defun anything-find-files-persistent-action (candidate)
4172 "Open subtree CANDIDATE without quitting anything.
4173 If CANDIDATE is not a directory expand CANDIDATE filename.
4174 If CANDIDATE is alone, open file CANDIDATE filename.
4175 That's mean:
4176 First hit on C-z expand CANDIDATE second hit open file.
4177 If a prefix arg is given or `anything-follow-mode' is on open file."
4178 (let ((follow (buffer-local-value
4179 'anything-follow-mode
4180 (get-buffer-create anything-buffer)))
4181 (new-pattern (anything-get-selection))
4182 (num-lines-buf (with-current-buffer anything-buffer
4183 (count-lines (point-min) (point-max)))))
4184 (flet ((insert-in-minibuffer (fname)
4185 (with-selected-window (minibuffer-window)
4186 (unless follow
4187 (delete-minibuffer-contents)
4188 (set-text-properties 0 (length fname) nil fname)
4189 (insert fname)))))
4190 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4191 "Invalid tramp file name")
4192 (string-match tramp-file-name-regexp candidate))
4193 ;; First hit insert hostname and
4194 ;; second hit insert ":" and expand.
4195 (if (string= candidate anything-pattern)
4196 (insert-in-minibuffer (concat candidate ":"))
4197 (insert-in-minibuffer candidate)))
4198 (;; A symlink directory, expand it's truename.
4199 (and (file-directory-p candidate) (file-symlink-p candidate))
4200 (insert-in-minibuffer (file-name-as-directory
4201 (file-truename
4202 (expand-file-name candidate)))))
4203 ;; A directory, open it.
4204 ((file-directory-p candidate)
4205 (when (string= (anything-c-basename candidate) "..")
4206 (setq anything-ff-last-expanded anything-ff-default-directory))
4207 (insert-in-minibuffer (file-name-as-directory
4208 (expand-file-name candidate))))
4209 ;; A symlink file, expand to it's true name. (first hit)
4210 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4211 (insert-in-minibuffer (file-truename candidate)))
4212 ;; A regular file, expand it, (first hit)
4213 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4214 (insert-in-minibuffer new-pattern))
4215 ;; An image file and it is the second hit on C-z,
4216 ;; show the file in `image-dired'.
4217 ((string-match (image-file-name-regexp) candidate)
4218 (when (buffer-live-p image-dired-display-image-buffer)
4219 (kill-buffer image-dired-display-image-buffer))
4220 (image-dired-display-image candidate)
4221 (message nil)
4222 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4223 (with-current-buffer image-dired-display-image-buffer
4224 (let ((exif-data (anything-ff-exif-data candidate)))
4225 (image-dired-update-property 'help-echo exif-data))))
4226 ;; Allow browsing archive on avfs fs.
4227 ;; Assume volume is already mounted with mountavfs.
4228 ((and anything-ff-avfs-directory
4229 (string-match
4230 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4231 (file-name-directory candidate))
4232 (anything-ff-file-compressed-p candidate))
4233 (insert-in-minibuffer (concat candidate "#")))
4234 ;; On second hit we open file.
4235 ;; On Third hit we kill it's buffer maybe.
4237 (anything-ff-kill-or-find-buffer-fname candidate))))))
4239 (defun anything-ff-file-compressed-p (candidate)
4240 "Whether CANDIDATE is a compressed file or not."
4241 (member (file-name-extension candidate)
4242 anything-ff-file-compressed-list))
4244 (defun anything-c-insert-file-name-completion-at-point (candidate)
4245 "Insert file name completion at point."
4246 (with-anything-current-buffer
4247 (if buffer-read-only
4248 (error "Error: Buffer `%s' is read-only" (buffer-name))
4249 (let* ((end (point))
4250 (guess (substring-no-properties (thing-at-point 'filename)))
4251 (beg (- (point) (length guess)))
4252 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4253 (string-match-p "^[^\~]" guess))))
4254 (set-text-properties 0 (length candidate) nil candidate)
4255 (if (and guess (not (string= guess ""))
4256 (string-match-p "^~\\|/.*" guess))
4257 (progn
4258 (delete-region beg end)
4259 (insert (if full-path-p
4260 (expand-file-name candidate)
4261 (abbreviate-file-name candidate))))
4262 (error "Aborting completion: No valid file name at point"))))))
4264 (defun* anything-find-files-history (&key (comp-read t))
4265 "The `anything-find-files' history.
4266 Show the first `anything-ff-history-max-length' elements of
4267 `anything-ff-history' in an `anything-comp-read'."
4268 (let ((history (when anything-ff-history
4269 (anything-fast-remove-dups anything-ff-history
4270 :test 'equal))))
4271 (when history
4272 (setq anything-ff-history
4273 (if (>= (length history) anything-ff-history-max-length)
4274 (subseq history 0 anything-ff-history-max-length)
4275 history))
4276 (if comp-read
4277 (anything-comp-read
4278 "Switch to Directory: "
4279 anything-ff-history
4280 :name "Anything Find Files History"
4281 :must-match t)
4282 anything-ff-history))))
4284 (defun anything-find-files-1 (fname &optional preselect)
4285 "Find FNAME with `anything' completion.
4286 Like `find-file' but with `anything' support.
4287 Use it for non--interactive calls of `anything-find-files'."
4288 (when (get-buffer anything-action-buffer)
4289 (kill-buffer anything-action-buffer))
4290 (let ((anything-mp-highlight-delay nil)
4291 ;; Be sure we don't erase the precedent minibuffer if some.
4292 (anything-ff-auto-update-initial-value
4293 (not (minibuffer-window-active-p (minibuffer-window))))
4294 anything-samewindow)
4295 (anything :sources 'anything-c-source-find-files
4296 :input fname
4297 :preselect preselect
4298 :keymap anything-find-files-map
4299 :prompt "Find Files or Url: "
4300 :buffer "*Anything Find Files*")))
4303 (defun anything-find-files-initial-input (&optional input)
4304 "Return INPUT if present, otherwise try to guess it."
4305 (or (and input (expand-file-name input))
4306 (anything-find-files-input
4307 (ffap-guesser)
4308 (thing-at-point 'filename))))
4310 (defun anything-find-files-input (fap tap)
4311 "Default input of `anything-find-files'."
4312 (let* ((def-dir (anything-c-current-directory))
4313 (lib (anything-find-library-at-point))
4314 (url (anything-ff-find-url-at-point))
4315 (file-p (and fap (not (string= fap ""))
4316 (file-exists-p fap)
4317 tap (not (string= tap ""))
4318 (file-exists-p
4319 (file-name-directory (expand-file-name tap def-dir))))))
4320 (cond (lib) ; e.g we are inside a require sexp.
4321 (url) ; String at point is an hyperlink.
4322 (file-p (expand-file-name tap def-dir))
4323 (t (and (not (string= fap "")) fap)))))
4325 (defun anything-c-current-directory ()
4326 "Return current-directory name at point.
4327 Useful in dired buffers when there is inserted subdirs."
4328 (if (eq major-mode 'dired-mode)
4329 (dired-current-directory)
4330 default-directory))
4332 (defun anything-ff-find-url-at-point ()
4333 "Try to find link to an url in text-property at point."
4334 (let* ((he (get-text-property (point) 'help-echo))
4335 (ov (overlays-at (point)))
4336 (ov-he (and ov (overlay-get
4337 (car (overlays-at (point))) 'help-echo)))
4338 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4339 (nt-prop (get-text-property (point) 'nt-link)))
4340 ;; Org link.
4341 (when (and (stringp he) (string-match "^LINK: " he))
4342 (setq he (replace-match "" t t he)))
4343 (loop for i in (list he ov-he w3m-l nt-prop)
4344 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4346 (defun anything-find-library-at-point ()
4347 "Try to find library path at point.
4348 Find inside `require' and `declare-function' sexp."
4349 (require 'find-func)
4350 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4351 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4352 (sexp (and beg-sexp end-sexp
4353 (buffer-substring-no-properties
4354 (1+ beg-sexp) (1- end-sexp)))))
4355 (ignore-errors
4356 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4357 (find-library-name
4358 (replace-regexp-in-string
4359 "'\\|\)\\|\(" ""
4360 ;; If require use third arg, ignore it,
4361 ;; always use library path found in `load-path'.
4362 (second (split-string (match-string 0 sexp))))))
4363 ((and sexp (string-match-p "^declare-function" sexp))
4364 (find-library-name
4365 (replace-regexp-in-string
4366 "\"\\|ext:" ""
4367 (third (split-string sexp)))))
4368 (t nil)))))
4370 ;;; Anything completion for `write-file'.==> C-x C-w
4371 (defvar anything-c-source-write-file
4372 `((name . "Write File")
4373 (header-name . (lambda (name)
4374 (concat name anything-c-find-files-doc-header)))
4375 ;; It is needed for filenames with capital letters
4376 (disable-shortcuts)
4377 (candidates . anything-find-files-get-candidates)
4378 (filtered-candidate-transformer anything-c-find-files-transformer)
4379 (persistent-action . anything-find-files-persistent-action)
4380 (persistent-help . "Expand Candidate")
4381 (volatile)
4382 (action .
4383 (("Write File" . (lambda (candidate)
4384 (write-file candidate 'confirm)))))))
4386 ;;; Anything completion for `insert-file'.==> C-x i
4387 (defvar anything-c-source-insert-file
4388 `((name . "Insert File")
4389 (header-name . (lambda (name)
4390 (concat name anything-c-find-files-doc-header)))
4391 ;; It is needed for filenames with capital letters
4392 (disable-shortcuts)
4393 (candidates . anything-find-files-get-candidates)
4394 (filtered-candidate-transformer anything-c-find-files-transformer)
4395 (persistent-action . anything-find-files-persistent-action)
4396 (persistent-help . "Expand Candidate")
4397 (volatile)
4398 (action .
4399 (("Insert File" . (lambda (candidate)
4400 (when (y-or-n-p (format "Really insert %s in %s "
4401 candidate anything-current-buffer))
4402 (insert-file-contents candidate))))))))
4404 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4405 (defvar anything-c-source-copy-files
4406 `((name . "Copy Files")
4407 (header-name . (lambda (name)
4408 (concat name anything-c-find-files-doc-header)))
4409 ;; It is needed for filenames with capital letters
4410 (disable-shortcuts)
4411 (candidates . anything-find-files-get-candidates)
4412 (filtered-candidate-transformer anything-c-find-files-transformer)
4413 (persistent-action . anything-find-files-persistent-action)
4414 (persistent-help . "Expand Candidate")
4415 (volatile)
4416 (action .
4417 (("Copy File"
4418 . (lambda (candidate)
4419 (anything-dired-action candidate :action 'copy)))
4420 ("Copy and Follow"
4421 . (lambda (candidate)
4422 (anything-dired-action candidate :action 'copy :follow t)))))))
4425 (defvar anything-c-source-rename-files
4426 `((name . "Rename Files")
4427 (header-name . (lambda (name)
4428 (concat name anything-c-find-files-doc-header)))
4429 ;; It is needed for filenames with capital letters
4430 (disable-shortcuts)
4431 (candidates . anything-find-files-get-candidates)
4432 (filtered-candidate-transformer anything-c-find-files-transformer)
4433 (persistent-action . anything-find-files-persistent-action)
4434 (persistent-help . "Expand Candidate")
4435 (volatile)
4436 (action .
4437 (("Rename File"
4438 . (lambda (candidate)
4439 (anything-dired-action candidate :action 'rename)))
4440 ("Rename and Follow"
4441 . (lambda (candidate)
4442 (anything-dired-action candidate :action 'rename :follow t)))))))
4444 (defvar anything-c-source-symlink-files
4445 `((name . "Symlink Files")
4446 (header-name . (lambda (name)
4447 (concat name anything-c-find-files-doc-header)))
4448 ;; It is needed for filenames with capital letters
4449 (disable-shortcuts)
4450 (candidates . anything-find-files-get-candidates)
4451 (filtered-candidate-transformer anything-c-find-files-transformer)
4452 (persistent-action . anything-find-files-persistent-action)
4453 (persistent-help . "Expand Candidate")
4454 (volatile)
4455 (action
4456 . (("Symlink File"
4457 . (lambda (candidate)
4458 (anything-dired-action candidate :action 'symlink)))
4459 ("RelSymlink File"
4460 . (lambda (candidate)
4461 (anything-dired-action candidate :action 'relsymlink)))))))
4464 (defvar anything-c-source-hardlink-files
4465 `((name . "Hardlink Files")
4466 (header-name . (lambda (name)
4467 (concat name anything-c-find-files-doc-header)))
4468 ;; It is needed for filenames with capital letters
4469 (disable-shortcuts)
4470 (candidates . anything-find-files-get-candidates)
4471 (filtered-candidate-transformer anything-c-find-files-transformer)
4472 (persistent-action . anything-find-files-persistent-action)
4473 (persistent-help . "Expand Candidate")
4474 (volatile)
4475 (action
4476 . (("Hardlink File"
4477 . (lambda (candidate)
4478 (anything-dired-action candidate :action 'hardlink)))))))
4480 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4481 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4482 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4483 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4484 (let ((fn (case action
4485 ('copy 'dired-copy-file)
4486 ('rename 'dired-rename-file)
4487 ('symlink 'make-symbolic-link)
4488 ('relsymlink 'dired-make-relative-symlink)
4489 ('hardlink 'dired-hardlink)))
4490 (marker (case action
4491 ((copy rename) dired-keep-marker-copy)
4492 ('symlink dired-keep-marker-symlink)
4493 ('relsymlink dired-keep-marker-relsymlink)
4494 ('hardlink dired-keep-marker-hardlink)))
4495 (dirflag (and (= (length files) 1)
4496 (file-directory-p (car files))
4497 (not (file-directory-p candidate)))))
4498 (dired-create-files
4499 fn (symbol-name action) files
4500 ;; CANDIDATE is the destination.
4501 (if (file-directory-p candidate)
4502 ;; When CANDIDATE is a directory, build file-name in this directory.
4503 ;; Else we use CANDIDATE.
4504 #'(lambda (from)
4505 (expand-file-name (file-name-nondirectory from) candidate))
4506 #'(lambda (from) candidate))
4507 marker)
4508 (push (file-name-as-directory
4509 (if (file-directory-p candidate)
4510 candidate (file-name-directory candidate)))
4511 anything-ff-history)
4512 (when (and follow (not (get-buffer dired-log-buffer)))
4513 (let ((target (directory-file-name candidate)))
4514 (unwind-protect
4515 (progn
4516 (setq anything-ff-cand-to-mark
4517 (anything-get-dest-fnames-from-list files candidate dirflag))
4518 (if (and dirflag (eq action 'rename))
4519 (anything-find-files-1 (file-name-directory target)
4520 (if anything-ff-transformer-show-only-basename
4521 (anything-c-basename target) target))
4522 (anything-find-files-1 (expand-file-name candidate))))
4523 (setq anything-ff-cand-to-mark nil))))))
4526 (defun anything-c-basename (fname)
4527 "Resolve basename of file or directory named FNAME."
4528 (file-name-nondirectory (directory-file-name fname)))
4530 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4531 "Transform filenames of FLIST to abs of DEST-CAND.
4532 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4533 members of FLIST."
4534 ;; At this point files have been renamed/copied at destination.
4535 ;; That's mean DEST-CAND exists.
4536 (loop
4537 with dest = (expand-file-name dest-cand)
4538 for src in flist
4539 for basename-src = (anything-c-basename src)
4540 for fname = (cond (rename-dir-flag (directory-file-name dest))
4541 ((file-directory-p dest)
4542 (concat (file-name-as-directory dest) basename-src))
4543 (t dest))
4544 when (file-exists-p fname)
4545 collect fname into tmp-list
4546 finally return (sort tmp-list 'string<)))
4548 (defun anything-ff-maybe-mark-candidates ()
4549 "Mark all candidates of list `anything-ff-cand-to-mark'."
4550 (when (and (string= (assoc-default 'name (anything-get-current-source))
4551 (assoc-default 'name anything-c-source-find-files))
4552 anything-ff-cand-to-mark)
4553 (with-anything-window
4554 (while anything-ff-cand-to-mark
4555 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4556 (progn
4557 (anything-make-visible-mark)
4558 (anything-next-line)
4559 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4560 (anything-next-line)))
4561 (unless (anything-this-visible-mark)
4562 (anything-prev-visible-mark)))))
4564 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4566 (defun* anything-dired-do-action-on-file (&key action)
4567 (let* ((files (dired-get-marked-files))
4568 (len (length files))
4569 (fname (if (> len 1)
4570 (format "* %d Files" len)
4571 (car files)))
4572 (source (case action
4573 ('copy 'anything-c-source-copy-files)
4574 ('rename 'anything-c-source-rename-files)
4575 ('symlink 'anything-c-source-symlink-files)
4576 ('hardlink 'anything-c-source-hardlink-files)))
4577 (prompt-fm (case action
4578 ('copy "Copy %s to: ")
4579 ('rename "Rename %s to: ")
4580 ('symlink "Symlink %s to: ")
4581 ('hardlink "Hardlink %s to: ")))
4582 (buffer (case action
4583 ('copy "*Anything Copy Files*")
4584 ('rename "*Anything Rename Files*")
4585 ('symlink "*Anything Symlink Files*")
4586 ('hardlink "*Anything Hardlink Files*")))
4587 (anything-mp-highlight-delay nil))
4588 (anything :sources source
4589 :input (or (dired-dwim-target-directory)
4590 (expand-file-name (anything-c-current-directory)))
4591 :preselect (dired-get-filename)
4592 :prompt (format prompt-fm fname)
4593 :keymap anything-c-read-file-map
4594 :buffer buffer)))
4596 ;;;###autoload
4597 (define-minor-mode anything-dired-mode ()
4598 "Enable anything completion in Dired functions.
4599 Bindings affected are C, R, S, H.
4600 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4601 :group 'anything-config
4602 :global t
4603 (if anything-dired-mode
4604 (progn
4605 (substitute-key-definition
4606 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4607 (substitute-key-definition
4608 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4609 (substitute-key-definition
4610 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4611 (substitute-key-definition
4612 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4613 (substitute-key-definition
4614 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4615 (substitute-key-definition
4616 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4617 (substitute-key-definition
4618 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4619 (substitute-key-definition
4620 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4622 (defalias 'anything-dired-bindings 'anything-dired-mode)
4624 (defun* anything-c-read-file-name (prompt
4625 &key
4626 (name "Read File Name")
4627 (initial-input (expand-file-name default-directory))
4628 (buffer "*Anything Completions*")
4629 test
4630 (preselect nil)
4631 (history nil)
4632 (marked-candidates nil)
4633 (alistp t)
4634 (persistent-action 'anything-find-files-persistent-action)
4635 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4636 "Anything `read-file-name' emulation.
4637 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4638 (when (get-buffer anything-action-buffer)
4639 (kill-buffer anything-action-buffer))
4640 (let ((anything-mp-highlight-delay nil)
4641 ;; Be sure we don't erase the underlying minibuffer if some.
4642 (anything-ff-auto-update-initial-value
4643 (not (minibuffer-window-active-p (minibuffer-window))))
4644 anything-same-window
4645 (hist (and history (anything-comp-read-get-candidates
4646 history nil nil alistp))))
4647 (flet ((action-fn (candidate)
4648 (if marked-candidates
4649 (anything-marked-candidates)
4650 (identity candidate))))
4651 (or (anything
4652 :sources
4653 `(((name . ,(format "%s History" name))
4654 (header-name . (lambda (name)
4655 (concat name anything-c-find-files-doc-header)))
4656 (disable-shortcuts)
4657 (mode-line . anything-read-file-name-mode-line-string)
4658 (candidates . hist)
4659 (persistent-action . ,persistent-action)
4660 (persistent-help . ,persistent-help)
4661 (action . ,'action-fn))
4662 ((name . ,name)
4663 (header-name . (lambda (name)
4664 (concat name anything-c-find-files-doc-header)))
4665 (init . (lambda ()
4666 (setq anything-ff-auto-update-flag
4667 anything-ff-auto-update-initial-value)))
4668 ;; It is needed for filenames with capital letters
4669 (disable-shortcuts)
4670 (mode-line . anything-read-file-name-mode-line-string)
4671 (candidates . (lambda ()
4672 (let ((seq (anything-find-files-get-candidates)))
4673 (if test
4674 (loop for fname in seq
4675 when (funcall test fname) collect fname)
4676 seq))))
4677 (filtered-candidate-transformer anything-c-find-files-transformer)
4678 (persistent-action . ,persistent-action)
4679 (candidate-number-limit . 9999)
4680 (toggle-auto-update . anything-ff-toggle-auto-update)
4681 (persistent-help . ,persistent-help)
4682 (volatile)
4683 (action . ,'action-fn)))
4684 :input initial-input
4685 :prompt prompt
4686 :keymap anything-c-read-file-map
4687 :resume 'noresume
4688 :buffer buffer
4689 :preselect preselect)
4690 (keyboard-quit)))))
4693 ;;; File Cache
4694 (defvar anything-c-file-cache-initialized-p nil)
4696 (defvar anything-c-file-cache-files nil)
4698 (defvar anything-c-source-file-cache
4699 '((name . "File Cache")
4700 (init
4701 . (lambda ()
4702 (require 'filecache nil t)
4703 (unless anything-c-file-cache-initialized-p
4704 (setq anything-c-file-cache-files
4705 (loop for item in file-cache-alist append
4706 (destructuring-bind (base &rest dirs) item
4707 (loop for dir in dirs collect
4708 (concat dir base)))))
4709 (defadvice file-cache-add-file (after file-cache-list activate)
4710 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4711 (setq anything-c-file-cache-initialized-p t))))
4712 (candidates . anything-c-file-cache-files)
4713 (match anything-c-match-on-basename)
4714 (type . file)))
4715 ;; (anything 'anything-c-source-file-cache)
4718 ;;; Locate
4721 ;; NOTE for WINDOZE users:
4722 ;; You have to install Everything with his command line interface here:
4723 ;; http://www.voidtools.com/download.php
4725 (defun anything-locate-1 (&optional localdb init)
4726 "Generic function to run Locate.
4727 if LOCALDB is non--nil search and use a local locate db file.
4728 INIT is a string to use as initial input in prompt.
4729 See `anything-locate-with-db' and `anything-locate'."
4730 (anything-locate-with-db
4731 (and localdb
4732 (anything-c-read-file-name
4733 "LocateDBFiles: "
4734 :marked-candidates t
4735 :preselect anything-locate-db-file-regexp
4736 :test #'(lambda (x)
4737 (if anything-locate-db-file-regexp
4738 ;; Select only locate db files and directories
4739 ;; to allow navigation.
4740 (or (string-match
4741 anything-locate-db-file-regexp x)
4742 (file-directory-p x))
4743 x))))
4744 init))
4745 ;; (anything-locate-1 t)
4747 (defun anything-locate-with-db (&optional db initial-input)
4748 "Run locate -d DB.
4749 If DB is not given or nil use locate without -d option.
4750 Argument DB can be given as a string or list of db files.
4751 Argument INITIAL-INPUT is a string to use as initial-input.
4752 See also `anything-locate'."
4753 (when (and db (stringp db)) (setq db (list db)))
4754 (let ((anything-c-locate-command
4755 (if db
4756 (replace-regexp-in-string
4757 "locate"
4758 (format "locate -d %s"
4759 (mapconcat 'identity
4760 ;; Remove eventually
4761 ;; marked directories by error.
4762 (loop for i in db
4763 unless (file-directory-p i)
4764 collect i) ":"))
4765 anything-c-locate-command)
4766 anything-c-locate-command)))
4767 (anything :sources 'anything-c-source-locate
4768 :buffer "*anything locate*"
4769 :input initial-input
4770 :keymap anything-generic-files-map)))
4771 ;; (anything-locate-with-db "~/locate.db")
4773 (defun anything-c-locate-init ()
4774 "Initialize async locate process for `anything-c-source-locate'."
4775 (setq mode-line-format
4776 '(" " mode-line-buffer-identification " "
4777 (line-number-mode "%l") " "
4778 (:eval (propertize "(Locate Process Running) "
4779 'face '((:foreground "red"))))))
4780 (unless anything-c-locate-command
4781 (setq anything-c-locate-command
4782 (case system-type
4783 ('gnu/linux "locate -i -r %s")
4784 ('berkeley-unix "locate -i %s")
4785 ('windows-nt "es -i -r %s")
4786 (t "locate %s"))))
4787 (prog1
4788 (start-process-shell-command "locate-process" nil
4789 (format anything-c-locate-command
4790 anything-pattern))
4791 (set-process-sentinel (get-process "locate-process")
4792 #'(lambda (process event)
4793 (when (string= event "finished\n")
4794 (with-anything-window
4795 (force-mode-line-update nil)
4796 (anything-update-move-first-line)))))))
4798 (defvar anything-c-source-locate
4799 '((name . "Locate")
4800 (candidates . anything-c-locate-init)
4801 (type . file)
4802 (requires-pattern . 3)
4803 (candidate-number-limit . 9999)
4804 (mode-line . anything-generic-file-mode-line-string)
4805 (delayed))
4806 "Find files matching the current input pattern with locate.")
4807 ;; (anything 'anything-c-source-locate)
4809 (defun anything-c-locate-read-file-name (prompt &optional init)
4810 "Search a file with locate and return it's filename.
4811 Use argument PROMPT and INIT for `anything' arguments
4812 prompt and input."
4813 (anything :sources
4814 '((name . "Locate")
4815 (candidates . anything-c-locate-init)
4816 (action . identity)
4817 (requires-pattern . 3)
4818 (candidate-number-limit . 9999)
4819 (mode-line . anything-generic-file-mode-line-string)
4820 (delayed))
4821 :prompt prompt
4822 :input init
4823 :buffer "*anything locate rfn*"))
4827 ;;; Anything Incremental Grep.
4830 ;; Allow to grep incrementally with anything interface.
4831 ;; It allow also to Grep files recursively without using 'find' shell command.
4832 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4833 (defvar anything-c-grep-default-command
4834 "grep -d skip %e -niH -e %p %f"
4835 "Default grep format command for `anything-do-grep-1'.
4836 Where:
4837 '%e' format spec is for --exclude or --include grep options.
4838 '%p' format spec is for pattern.
4839 '%f' format spec is for filenames.")
4841 (defvar anything-c-grep-default-recurse-command
4842 "grep -d recurse %e -niH -e %p %f"
4843 "Default recursive grep format command for `anything-do-grep-1'.
4844 See `anything-c-grep-default-command' for format specs.")
4846 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4848 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4850 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4852 (defvar anything-c-grep-debug-command-line nil
4853 "Turn on anything grep command-line debugging when non--nil.")
4855 (defvar anything-c-zgrep-recurse-flag nil)
4857 (defvar anything-c-grep-history nil)
4859 (defvar anything-c-grep-max-length-history 100
4860 "*Max number of elements to save in `anything-c-grep-history'.")
4862 (defun anything-c-grep-prepare-candidates (candidates)
4863 "Prepare filenames and directories CANDIDATES for grep command line."
4864 ;; If one or more candidate is a directory, search in all files
4865 ;; of this candidate (e.g /home/user/directory/*).
4866 ;; If r option is enabled search also in subdidrectories.
4867 ;; We need here to expand wildcards to support crap windows filenames
4868 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4869 (if anything-c-zgrep-recurse-flag
4870 (mapconcat 'shell-quote-argument candidates " ")
4871 (loop for i in candidates append
4872 (cond ( ;; Candidate is a directory and we use recursion.
4873 (and (file-directory-p i)
4874 (anything-c-grep-recurse-p))
4875 (list (expand-file-name i)))
4876 ;; Candidate is a directory, search in all files.
4877 ((file-directory-p i)
4878 (file-expand-wildcards
4879 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4880 ;; Candidate is a file or wildcard and we use recursion, use the
4881 ;; current directory instead of candidate.
4882 ((and (or (file-exists-p i) (string-match "\*" i))
4883 (anything-c-grep-recurse-p))
4884 (list (expand-file-name
4885 (directory-file-name ; Needed for windoze.
4886 (file-name-directory (directory-file-name i))))))
4887 ;; Candidate use wildcard.
4888 ((string-match "^\*" (anything-c-basename i))
4889 (file-expand-wildcards i t))
4890 ;; Else should be one or more file.
4891 (t (list i))) into all-files
4892 finally return
4893 (mapconcat 'shell-quote-argument all-files " "))))
4895 (defun anything-c-grep-recurse-p ()
4896 "Check if `anything-do-grep-1' have switched to recursive."
4897 (let ((args (replace-regexp-in-string
4898 "grep" "" anything-c-grep-default-command)))
4899 (string-match-p "r\\|recurse" args)))
4901 (defun anything-c-grep-init (only-files &optional include zgrep)
4902 "Start an asynchronous grep process in ONLY-FILES list."
4903 (let* ((fnargs (anything-c-grep-prepare-candidates
4904 (if (file-remote-p anything-ff-default-directory)
4905 (mapcar #'(lambda (x)
4906 (file-remote-p x 'localname))
4907 only-files)
4908 only-files)))
4909 (ignored-files (mapconcat
4910 #'(lambda (x)
4911 (concat "--exclude=" (shell-quote-argument x)))
4912 grep-find-ignored-files " "))
4913 (ignored-dirs (mapconcat
4914 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4915 #'(lambda (x)
4916 (concat "--exclude-dir=" (shell-quote-argument x)))
4917 grep-find-ignored-directories " "))
4918 (exclude (if (anything-c-grep-recurse-p)
4919 (concat (or include ignored-files) " " ignored-dirs)
4920 ignored-files))
4921 (cmd-line (format-spec
4922 anything-c-grep-default-command
4923 (delq nil
4924 (list (unless zgrep (cons ?e exclude))
4925 (cons ?p (shell-quote-argument anything-pattern))
4926 (cons ?f fnargs))))))
4927 (when anything-c-grep-debug-command-line
4928 (with-current-buffer (get-buffer-create "*any grep debug*")
4929 (goto-char (point-max))
4930 (insert (concat ">>> " cmd-line "\n\n"))))
4931 (setq mode-line-format
4932 '(" " mode-line-buffer-identification " "
4933 (line-number-mode "%l") " "
4934 (:eval (when (get-process "grep-process")
4935 (propertize "[Grep Process Running] "
4936 'face 'anything-grep-running)))))
4937 (force-mode-line-update nil)
4938 (prog1
4939 (let ((default-directory anything-ff-default-directory))
4940 (start-file-process-shell-command "grep-process" nil cmd-line))
4941 (message nil)
4942 (set-process-sentinel
4943 (get-process "grep-process")
4944 #'(lambda (process event)
4945 (when (string= event "finished\n")
4946 (with-anything-window
4947 (anything-update-move-first-line)
4948 (setq mode-line-format
4949 '(" " mode-line-buffer-identification " "
4950 (line-number-mode "%l") " "
4951 (:eval (propertize
4952 (format "[Grep Process Finished - (%s results)] "
4953 (let ((nlines (1- (count-lines
4954 (point-min)
4955 (point-max)))))
4956 (if (> nlines 0) nlines 0)))
4957 'face 'anything-grep-finish))))
4958 (force-mode-line-update nil))))))))
4960 (defun anything-c-grep-action (candidate &optional where mark)
4961 "Define a default action for `anything-do-grep' on CANDIDATE.
4962 WHERE can be one of other-window, elscreen, other-frame."
4963 (let* ((split (anything-c-grep-split-line candidate))
4964 (lineno (string-to-number (nth 1 split)))
4965 (loc-fname (car split))
4966 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4967 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4968 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4969 (fname (if tramp-host
4970 (concat tramp-prefix loc-fname) loc-fname)))
4971 (case where
4972 (other-window (find-file-other-window fname))
4973 (elscreen (anything-elscreen-find-file fname))
4974 (other-frame (find-file-other-frame fname))
4975 (t (find-file fname)))
4976 (anything-goto-line lineno)
4977 (when mark
4978 (set-marker (mark-marker) (point))
4979 (push-mark (point) 'nomsg))
4980 ;; Save history
4981 (unless (or anything-in-persistent-action
4982 (string= anything-pattern ""))
4983 (setq anything-c-grep-history
4984 (cons anything-pattern
4985 (delete anything-pattern anything-c-grep-history)))
4986 (when (> (length anything-c-grep-history)
4987 anything-c-grep-max-length-history)
4988 (setq anything-c-grep-history
4989 (delete (car (last anything-c-grep-history))
4990 anything-c-grep-history))))))
4992 (defun anything-c-grep-other-window (candidate)
4993 "Jump to result in other window from anything grep."
4994 (anything-c-grep-action candidate 'other-window))
4996 (defun anything-c-grep-other-frame (candidate)
4997 "Jump to result in other frame from anything grep."
4998 (anything-c-grep-action candidate 'other-frame))
5000 (defun anything-c-grep-jump-elscreen (candidate)
5001 "Jump to result in elscreen from anything grep."
5002 (anything-c-grep-action candidate 'elscreen))
5004 (defun anything-c-grep-save-results (candidate)
5005 "Save anything grep result in a `grep-mode' buffer."
5006 (let ((buf "*grep*")
5007 new-buf)
5008 (when (get-buffer buf)
5009 (setq new-buf (read-string "GrepBufferName: " buf))
5010 (loop for b in (anything-c-buffer-list)
5011 when (and (string= new-buf b)
5012 (not (y-or-n-p
5013 (format "Buffer `%s' already exists overwrite? "
5014 new-buf))))
5015 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
5016 (setq buf new-buf))
5017 (with-current-buffer (get-buffer-create buf)
5018 (let ((inhibit-read-only t))
5019 (erase-buffer)
5020 (insert "-*- mode: grep -*-\n\n"
5021 (format "Grep Results for `%s':\n\n" anything-pattern))
5022 (save-excursion
5023 (insert (with-current-buffer anything-buffer
5024 (forward-line 1)
5025 (buffer-substring (point) (point-max))))
5026 (grep-mode))))
5027 (message "Anything Grep Results saved in `%s' buffer" buf)))
5029 (defun anything-c-grep-persistent-action (candidate)
5030 "Persistent action for `anything-do-grep'.
5031 With a prefix arg record CANDIDATE in `mark-ring'."
5032 (if current-prefix-arg
5033 (anything-c-grep-action candidate nil 'mark)
5034 (anything-c-grep-action candidate))
5035 (anything-match-line-color-current-line))
5037 (defun anything-c-grep-guess-extensions (files)
5038 "Try to guess file extensions in FILES list when using grep recurse.
5039 These extensions will be added to command line with --include arg of grep."
5040 (loop
5041 with glob-list = nil
5042 with lst = (if (file-directory-p (car files))
5043 (directory-files
5044 (car files) nil
5045 directory-files-no-dot-files-regexp)
5046 files)
5047 for i in lst
5048 for ext = (file-name-extension i t)
5049 for glob = (and ext (not (string= ext ""))
5050 (concat "*" ext))
5051 unless (or (not glob)
5052 (member glob glob-list)
5053 (member glob grep-find-ignored-files))
5054 collect glob into glob-list
5055 finally return glob-list))
5057 (defun anything-do-grep-1 (only &optional recurse zgrep)
5058 "Launch grep with a list of ONLY files.
5059 When RECURSE is given use -r option of grep and prompt user
5060 to set the --include args of grep.
5061 You can give more than one arg separated by space.
5062 e.g *.el *.py *.tex.
5063 If it's empty --exclude `grep-find-ignored-files' is used instead."
5064 (let* ((anything-compile-source-functions
5065 ;; rule out anything-match-plugin because the input is one regexp.
5066 (delq 'anything-compile-source--match-plugin
5067 (copy-sequence anything-compile-source-functions)))
5068 (exts (anything-c-grep-guess-extensions only))
5069 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5070 (include-files (and recurse (not zgrep)
5071 (read-string "OnlyExt(*.[ext]): "
5072 globs)))
5073 ;; Set `minibuffer-history' AFTER includes-files
5074 ;; to avoid storing wild-cards here.
5075 (minibuffer-history anything-c-grep-history)
5076 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5077 (recurse anything-c-grep-default-recurse-command)
5078 (zgrep anything-c-default-zgrep-command)
5079 (t anything-c-grep-default-command)))
5080 ;; Disable match-plugin and use here own highlighting.
5081 (anything-mp-highlight-delay nil))
5082 (when include-files
5083 (setq include-files
5084 (and (not (string= include-files ""))
5085 (mapconcat #'(lambda (x)
5086 (concat "--include=" (shell-quote-argument x)))
5087 (split-string include-files) " "))))
5088 ;; When called as action from an other source e.g *-find-files
5089 ;; we have to kill action buffer.
5090 (when (get-buffer anything-action-buffer)
5091 (kill-buffer anything-action-buffer))
5092 ;; `anything-find-files' haven't already started,
5093 ;; give a default value to `anything-ff-default-directory'.
5094 (setq anything-ff-default-directory (or anything-ff-default-directory
5095 default-directory))
5096 (anything
5097 :sources
5098 `(((name . "Grep (C-c ? Help)")
5099 (candidates
5100 . (lambda ()
5101 (funcall anything-c-grep-default-function only include-files zgrep)))
5102 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5103 (candidate-number-limit . 9999)
5104 (mode-line . anything-grep-mode-line-string)
5105 (action . ,(delq
5107 `(("Find File" . anything-c-grep-action)
5108 ("Find file other frame" . anything-c-grep-other-frame)
5109 ,(and (locate-library "elscreen")
5110 '("Find file in Elscreen"
5111 . anything-c-grep-jump-elscreen))
5112 ("Save results in grep buffer" . anything-c-grep-save-results)
5113 ("Find file other window" . anything-c-grep-other-window))))
5114 (persistent-action . anything-c-grep-persistent-action)
5115 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5116 (requires-pattern . 3)
5117 (delayed)))
5118 :keymap anything-c-grep-map
5119 :buffer "*anything grep*")))
5121 (defun anything-ff-zgrep-1 (flist recursive)
5122 (unwind-protect
5123 (let* ((def-dir (or anything-ff-default-directory
5124 default-directory))
5125 (only (if recursive
5126 (or (gethash def-dir anything-c-rzgrep-cache)
5127 (puthash
5128 def-dir
5129 (anything-c-walk-directory
5130 def-dir
5131 :directories nil
5132 :path 'full
5133 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5134 anything-c-rzgrep-cache))
5135 flist)))
5136 (when recursive (setq anything-c-zgrep-recurse-flag t))
5137 (anything-do-grep-1 only recursive 'zgrep))
5138 (setq anything-c-zgrep-recurse-flag nil)))
5140 (defun anything-c-grep-split-line (line)
5141 "Split a grep output line."
5142 (let (beg fname lineno str)
5143 ;; Don't print until grep line is valid.
5144 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5145 (with-temp-buffer
5146 (insert line)
5147 (goto-char (point-min))
5148 (setq beg (point))
5149 (forward-char 2)
5150 (re-search-forward ":" nil t)
5151 (setq fname (buffer-substring-no-properties beg (1- (point))))
5152 (setq beg (point))
5153 (re-search-forward ":" nil t)
5154 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5155 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5156 (list fname lineno str))))
5158 (defun anything-c-grep-cand-transformer (candidates sources)
5159 "Filtered candidate transformer function for `anything-do-grep'."
5160 (loop for i in candidates
5161 for split = (and i (anything-c-grep-split-line i))
5162 for fname = (car split)
5163 for lineno = (nth 1 split)
5164 for str = (nth 2 split)
5165 when (and fname lineno str)
5166 collect
5167 (cons (concat (propertize (file-name-nondirectory fname)
5168 'face 'anything-grep-file
5169 'help-echo fname) ":"
5170 (propertize lineno 'face 'anything-grep-lineno) ":"
5171 (anything-c-grep-highlight-match str))
5172 i)))
5174 (defun anything-c-grep-highlight-match (str)
5175 "Highlight in string STR all occurences matching `anything-pattern'."
5176 (condition-case nil
5177 (with-temp-buffer
5178 (insert str)
5179 (goto-char (point-min))
5180 (while (and (re-search-forward anything-pattern nil t)
5181 (> (- (match-end 0) (match-beginning 0)) 0))
5182 (add-text-properties
5183 (match-beginning 0) (match-end 0)
5184 '(face anything-grep-match)))
5185 (buffer-string))
5186 (error nil)))
5188 ;; Go to next or precedent file (common to etags and grep).
5189 (defun anything-c-goto-next-or-prec-file (n)
5190 "Go to next or precedent candidate file in anything grep/etags buffers.
5191 If N is positive go forward otherwise go backward."
5192 (with-anything-window
5193 (let* ((current-line-list (split-string
5194 (buffer-substring
5195 (point-at-bol)
5196 (point-at-eol)) ":"))
5197 (current-fname (nth 0 current-line-list))
5198 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5199 (catch 'break
5200 (while (not (funcall fn-b-o-f))
5201 (forward-line n) ; Go forward or backward depending of n value.
5202 (unless (search-forward current-fname (point-at-eol) t)
5203 (anything-mark-current-line)
5204 (throw 'break nil))))
5205 (cond ((and (eq n 1) (eobp))
5206 (re-search-backward ".")
5207 (forward-line 0)
5208 (anything-mark-current-line))
5209 ((and (< n 1) (bobp))
5210 (forward-line 1)
5211 (anything-mark-current-line))))))
5213 ;;;###autoload
5214 (defun anything-c-goto-precedent-file ()
5215 "Go to precedent file in anything grep/etags buffers."
5216 (interactive)
5217 (anything-c-goto-next-or-prec-file -1))
5219 ;;;###autoload
5220 (defun anything-c-goto-next-file ()
5221 "Go to precedent file in anything grep/etags buffers."
5222 (interactive)
5223 (anything-c-goto-next-or-prec-file 1))
5225 ;;;###autoload
5226 (defun anything-c-grep-run-persistent-action ()
5227 "Run grep persistent action from `anything-do-grep-1'."
5228 (interactive)
5229 (anything-attrset 'jump-persistent 'anything-c-grep-persistent-action)
5230 (anything-execute-persistent-action 'jump-persistent))
5232 ;;;###autoload
5233 (defun anything-c-grep-run-default-action ()
5234 "Run grep default action from `anything-do-grep-1'."
5235 (interactive)
5236 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5238 ;;;###autoload
5239 (defun anything-c-grep-run-other-window-action ()
5240 "Run grep goto other window action from `anything-do-grep-1'."
5241 (interactive)
5242 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5244 ;;;###autoload
5245 (defun anything-c-grep-run-save-buffer ()
5246 "Run grep save results action from `anything-do-grep-1'."
5247 (interactive)
5248 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5250 ;; Grep buffers
5251 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5252 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5253 If one of selected buffers is not a file--buffer,
5254 it is ignored and grep will run on all others file--buffers.
5255 If only one candidate is selected and it is not a file--buffer,
5256 switch to this buffer and run `anything-occur'.
5257 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5258 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5259 (cands (if prefarg
5260 (buffer-list)
5261 (anything-marked-candidates)))
5262 (win-conf (current-window-configuration))
5263 ;; Non--fname buffers are ignored.
5264 (bufs (loop for buf in cands
5265 for fname = (buffer-file-name (get-buffer buf))
5266 when fname
5267 collect (expand-file-name fname))))
5268 (if bufs
5269 (if zgrep
5270 (anything-do-grep-1 bufs nil 'zgrep)
5271 (anything-do-grep-1 bufs))
5272 ;; bufs is empty, thats mean we have only CANDIDATE
5273 ;; and it is not a buffer-filename, fallback to occur.
5274 (anything-c-switch-to-buffer candidate)
5275 (when (get-buffer anything-action-buffer)
5276 (kill-buffer anything-action-buffer))
5277 (anything-occur)
5278 (when (eq anything-exit-status 1)
5279 (set-window-configuration win-conf)))))
5281 (defun anything-c-grep-buffers (candidate)
5282 "Action to grep buffers."
5283 (anything-c-grep-buffers-1 candidate))
5285 (defun anything-c-zgrep-buffers (candidate)
5286 "Action to zgrep buffers."
5287 (anything-c-grep-buffers-1 candidate 'zgrep))
5290 ;;; Anything interface for pdfgrep
5291 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5292 ;; and a pdf-reader (e.g xpdf) are needed.
5294 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5295 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5296 (defvar anything-c-pdfgrep-debug-command-line nil)
5298 (defun anything-c-pdfgrep-init (only-files)
5299 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5300 (let* ((fnargs (anything-c-grep-prepare-candidates
5301 (if (file-remote-p anything-ff-default-directory)
5302 (mapcar #'(lambda (x)
5303 (file-remote-p x 'localname))
5304 only-files)
5305 only-files)))
5306 (cmd-line (format anything-c-pdfgrep-default-command
5307 anything-pattern
5308 fnargs)))
5309 (when anything-c-pdfgrep-debug-command-line
5310 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5311 (goto-char (point-max))
5312 (insert (concat ">>> " cmd-line "\n\n"))))
5313 (setq mode-line-format
5314 '(" " mode-line-buffer-identification " "
5315 (line-number-mode "%l") " "
5316 (:eval (propertize "(Pdfgrep Process Running) "
5317 'face '((:foreground "red"))))))
5318 (prog1
5319 (let ((default-directory anything-ff-default-directory))
5320 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5321 (message nil)
5322 (set-process-sentinel
5323 (get-process "pdfgrep-process")
5324 #'(lambda (process event)
5325 (when (string= event "finished\n")
5326 (with-anything-window
5327 (anything-update-move-first-line))
5328 (force-mode-line-update nil)))))))
5331 (defun anything-do-pdfgrep-1 (only)
5332 "Launch pdfgrep with a list of ONLY files."
5333 (unless (executable-find "pdfgrep")
5334 (error "Error: No such program `pdfgrep'."))
5335 (let* ((anything-compile-source-functions
5336 ;; rule out anything-match-plugin because the input is one regexp.
5337 (delq 'anything-compile-source--match-plugin
5338 (copy-sequence anything-compile-source-functions)))
5339 ;; Disable match-plugin and use here own highlighting.
5340 (anything-mp-highlight-delay nil))
5341 ;; When called as action from an other source e.g *-find-files
5342 ;; we have to kill action buffer.
5343 (when (get-buffer anything-action-buffer)
5344 (kill-buffer anything-action-buffer))
5345 ;; If `anything-find-files' haven't already started,
5346 ;; give a default value to `anything-ff-default-directory'.
5347 (setq anything-ff-default-directory (or anything-ff-default-directory
5348 default-directory))
5349 (anything
5350 :sources
5351 `(((name . "PdfGrep")
5352 (candidates
5353 . (lambda ()
5354 (funcall anything-c-pdfgrep-default-function only)))
5355 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5356 (candidate-number-limit . 9999)
5357 (mode-line . anything-pdfgrep-mode-line-string)
5358 (action . anything-c-pdfgrep-action)
5359 (persistent-help . "Jump to PDF Page")
5360 (requires-pattern . 3)
5361 (delayed)))
5362 :keymap anything-c-pdfgrep-map
5363 :buffer "*anything grep*")))
5366 (defun anything-c-pdfgrep-action (candidate)
5367 (let* ((split (anything-c-grep-split-line candidate))
5368 (pageno (nth 1 split))
5369 (fname (car split)))
5370 (start-file-process-shell-command
5371 "pdf-reader" nil
5372 (format-spec anything-c-pdfgrep-default-read-command
5373 (list (cons ?f fname) (cons ?p pageno))))))
5375 (defun anything-do-pdfgrep ()
5376 (interactive)
5377 (let ((only (anything-c-read-file-name
5378 "Search in file(s): "
5379 :marked-candidates t
5380 :test #'(lambda (file)
5381 (or (string= (file-name-extension file) "pdf")
5382 (string= (file-name-extension file) "PDF")
5383 (file-directory-p file)))
5384 :preselect (or (dired-get-filename nil t)
5385 (buffer-file-name (current-buffer)))))
5386 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5387 (anything-do-pdfgrep-1 only)))
5390 ;; Yank text at point.
5393 ;; Internal
5394 (defvar anything-yank-point nil)
5396 ;;;###autoload
5397 (defun anything-yank-text-at-point ()
5398 "Yank text at point in minibuffer."
5399 (interactive)
5400 (let (input)
5401 (flet ((insert-in-minibuffer (word)
5402 (with-selected-window (minibuffer-window)
5403 (let ((str anything-pattern))
5404 (delete-minibuffer-contents)
5405 (set-text-properties 0 (length word) nil word)
5406 (insert (concat str word))))))
5407 (with-anything-current-buffer
5408 ;; Start to initial point if C-w have never been hit.
5409 (unless anything-yank-point (setq anything-yank-point (point)))
5410 (and anything-yank-point (goto-char anything-yank-point))
5411 (forward-word 1)
5412 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5413 (setq anything-yank-point (point))) ; End of last forward-word
5414 (insert-in-minibuffer input))))
5416 (defun anything-reset-yank-point ()
5417 (setq anything-yank-point nil))
5419 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5420 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5423 ;;; Recentf files
5426 (defvar anything-c-source-recentf
5427 '((name . "Recentf")
5428 (init . (lambda ()
5429 (require 'recentf)
5430 (or recentf-mode (recentf-mode 1))))
5431 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5432 (candidates . recentf-list)
5433 (match anything-c-match-on-basename)
5434 (type . file))
5435 "See (info \"(emacs)File Conveniences\").
5436 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5437 ;; (anything 'anything-c-source-recentf)
5439 ;;; ffap
5440 (eval-when-compile (require 'ffap))
5441 (defvar anything-c-source-ffap-guesser
5442 '((name . "File at point")
5443 (init . (lambda () (require 'ffap)))
5444 (candidates . (lambda ()
5445 (anything-aif
5446 (with-anything-current-buffer
5447 (ffap-guesser))
5448 (list it))))
5449 (type . file)))
5450 ;; (anything 'anything-c-source-ffap-guesser)
5452 ;;; ffap with line number
5453 (defun anything-c-ffap-file-line-at-point ()
5454 "Get (FILENAME . LINENO) at point."
5455 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5456 (save-excursion
5457 (beginning-of-line)
5458 (when (and (search-forward it nil t)
5459 (looking-at ":\\([0-9]+\\)"))
5460 (cons it (string-to-number (match-string 1)))))))
5462 (defvar anything-c-ffap-line-location nil
5463 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5464 It is cleared after jumping line.")
5466 (defun anything-c-ffap-line-candidates ()
5467 (with-anything-current-buffer
5468 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5469 (when anything-c-ffap-line-location
5470 (destructuring-bind (file . line) anything-c-ffap-line-location
5471 (list (cons (format "%s (line %d)" file line) file)))))
5473 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5474 (defun anything-c-ffap-line-goto-line ()
5475 (when (car anything-c-ffap-line-location)
5476 (unwind-protect
5477 (ignore-errors
5478 (with-selected-window
5479 (get-buffer-window
5480 (get-file-buffer (car anything-c-ffap-line-location)))
5481 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5482 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5483 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5485 (defvar anything-c-source-ffap-line
5486 '((name . "File/Lineno at point")
5487 (init . (lambda () (require 'ffap)))
5488 (candidates . anything-c-ffap-line-candidates)
5489 (type . file)))
5490 ;; (anything 'anything-c-source-ffap-line)
5492 ;;; list of files gleaned from every dired buffer
5493 (defun anything-c-files-in-all-dired-candidates ()
5494 (save-excursion
5495 (mapcan
5496 (lambda (dir)
5497 (cond ((listp dir) ;filelist
5498 dir)
5499 ((equal "" (file-name-nondirectory dir)) ;dir
5500 (directory-files dir t))
5501 (t ;wildcard
5502 (file-expand-wildcards dir t))))
5503 (delq nil
5504 (mapcar (lambda (buf)
5505 (set-buffer buf)
5506 (when (eq major-mode 'dired-mode)
5507 (if (consp dired-directory)
5508 (cdr dired-directory) ;filelist
5509 dired-directory))) ;dir or wildcard
5510 (buffer-list))))))
5511 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5513 (defvar anything-c-source-files-in-all-dired
5514 '((name . "Files in all dired buffer.")
5515 (candidates . anything-c-files-in-all-dired-candidates)
5516 (type . file)))
5517 ;; (anything 'anything-c-source-files-in-all-dired)
5519 (defvar anything-c-source-filelist
5520 '((name . "FileList")
5521 (grep-candidates . anything-c-filelist-file-name)
5522 (candidate-number-limit . 200)
5523 (requires-pattern . 4)
5524 (type . file))
5525 "Source to find files instantly.
5526 See `anything-c-filelist-file-name' docstring for usage.")
5529 ;;;; <info>
5530 ;;; Info pages
5531 (defvar anything-c-info-pages nil
5532 "All info pages on system.
5533 Will be calculated the first time you invoke anything with this
5534 source.")
5536 (defun anything-c-info-pages-init ()
5537 "Collect candidates for initial Info node Top."
5538 (if anything-c-info-pages
5539 anything-c-info-pages
5540 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5541 topics)
5542 (require 'info)
5543 (with-temp-buffer
5544 (Info-find-node "dir" "top")
5545 (goto-char (point-min))
5546 (while (re-search-forward info-topic-regexp nil t)
5547 (push (match-string-no-properties 1) topics))
5548 (kill-buffer))
5549 (setq anything-c-info-pages topics))))
5551 (defvar anything-c-source-info-pages
5552 `((name . "Info Pages")
5553 (init . anything-c-info-pages-init)
5554 (candidates . anything-c-info-pages)
5555 (action . (("Show with Info" .(lambda (node-str)
5556 (info (replace-regexp-in-string
5557 "^[^:]+: " "" node-str))))))
5558 (requires-pattern . 2)))
5559 ;; (anything 'anything-c-source-info-pages)
5562 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5563 (defun anything-c-describe-attributes (anything-attribute)
5564 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5565 Same as `anything-describe-anything-attribute' but with anything completion."
5566 (interactive (list (intern
5567 (anything-comp-read
5568 "Describe anything attribute: "
5569 (mapcar 'symbol-name anything-additional-attributes)
5570 :must-match t
5571 :persistent-action
5572 #'(lambda (candidate)
5573 (with-output-to-temp-buffer "*Help*"
5574 (princ (get (intern candidate) 'anything-attrdoc))))))))
5575 (with-output-to-temp-buffer "*Help*"
5576 (princ (get anything-attribute 'anything-attrdoc))))
5579 ;;; Use info-index plug-in.
5582 ;; Note that `name' attribute is not needed since
5583 ;; `anything-c-insert-summary' have been removed.
5584 ;; Info Elisp
5585 (defvar anything-c-source-info-elisp
5586 '((name . "Info index: elisp")
5587 (info-index . "elisp")))
5588 ;; (anything 'anything-c-source-info-elisp)
5590 ;; Info-Common-Lisp
5591 (defvar anything-c-source-info-cl
5592 '((name . "Info index: cl")
5593 (info-index . "cl")))
5594 ;; (anything 'anything-c-source-info-cl)
5596 ;; Info Index org
5597 (defvar anything-c-source-info-org
5598 '((name . "Info index: org")
5599 (info-index . "org")))
5600 ;; (anything 'anything-c-source-info-org)
5602 ;; Info Index gnus
5603 (defvar anything-c-source-info-gnus
5604 '((name . "Info index: Gnus")
5605 (info-index . "gnus")))
5607 ;; Info Index ratpoison
5608 (defvar anything-c-source-info-ratpoison
5609 '((name . "Info index: ratpoison")
5610 (info-index . "ratpoison")))
5611 ;; (anything 'anything-c-source-info-ratpoison)
5613 ;; Info Index zsh
5614 (defvar anything-c-source-info-zsh
5615 '((name . "Info index: zsh")
5616 (info-index . "zsh")))
5617 ;; (anything 'anything-c-source-info-zsh)
5619 ;; Info Index bash
5620 (defvar anything-c-source-info-bash
5621 '((name . "Info index: bash")
5622 (info-index . "bash")))
5623 ;; (anything 'anything-c-source-info-bash)
5625 ;; Info Index coreutils
5626 (defvar anything-c-source-info-coreutils
5627 '((name . "Info index: coreutils")
5628 (info-index . "coreutils")))
5629 ;; (anything 'anything-c-source-info-coreutils)
5631 ;; Info Index fileutils
5632 (defvar anything-c-source-info-fileutils
5633 '((name . "Info index: fileutils")
5634 (info-index . "fileutils")))
5635 ;; (anything 'anything-c-source-info-fileutils)
5637 ;; Info Index find
5638 (defvar anything-c-source-info-find
5639 '((name . "Info index: find")
5640 (info-index . "find")))
5641 ;; (anything 'anything-c-source-info-find)
5643 ;; Info Index sh-utils
5644 (defvar anything-c-source-info-sh-utils
5645 '((name . "Info index: sh-utils")
5646 (info-index . "sh-utils")))
5647 ;; (anything 'anything-c-source-info-sh-utils)
5649 ;; Info Index textutils
5650 (defvar anything-c-source-info-textutils
5651 '((name . "Info index: textutils")
5652 (info-index . "textutils")))
5653 ;; (anything 'anything-c-source-info-textutils)
5655 ;; Info Index libc
5656 (defvar anything-c-source-info-libc
5657 '((name . "Info index: libc")
5658 (info-index . "libc")))
5659 ;; (anything 'anything-c-source-info-libc)
5661 ;; Info Index make
5662 (defvar anything-c-source-info-make
5663 '((name . "Info index: make")
5664 (info-index . "make")))
5665 ;; (anything 'anything-c-source-info-make)
5667 ;; Info Index automake
5668 (defvar anything-c-source-info-automake
5669 '((name . "Info index: automake")
5670 (info-index . "automake")))
5671 ;; (anything 'anything-c-source-info-automake)
5673 ;; Info Index autoconf
5674 (defvar anything-c-source-info-autoconf
5675 '((name . "Info index: autoconf")
5676 (info-index . "autoconf")))
5677 ;; (anything 'anything-c-source-info-autoconf)
5679 ;; Info Index emacs-lisp-intro
5680 (defvar anything-c-source-info-emacs-lisp-intro
5681 '((name . "Info index: emacs-lisp-intro")
5682 (info-index . "emacs-lisp-intro")))
5683 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5685 ;; Info Index emacs
5686 (defvar anything-c-source-info-emacs
5687 '((name . "Info index: emacs")
5688 (info-index . "emacs")))
5689 ;; (anything 'anything-c-source-info-emacs)
5691 ;; Info Index elib
5692 (defvar anything-c-source-info-elib
5693 '((name . "Info index: elib")
5694 (info-index . "elib")))
5695 ;; (anything 'anything-c-source-info-elib)
5697 ;; Info Index eieio
5698 (defvar anything-c-source-info-eieio
5699 '((name . "Info index: eieio")
5700 (info-index . "eieio")))
5701 ;; (anything 'anything-c-source-info-eieio)
5703 ;; Info Index gauche-refe
5704 (defvar anything-c-source-info-gauche-refe
5705 '((name . "Info index: gauche")
5706 (info-index . "gauche-refe")))
5707 ;; (anything 'anything-c-source-info-gauche-refe)
5709 ;; Info Index guile
5710 (defvar anything-c-source-info-guile
5711 '((name . "Info index: guile")
5712 (info-index . "guile")))
5713 ;; (anything 'anything-c-source-info-guile)
5715 ;; Info Index guile-tut
5716 (defvar anything-c-source-info-guile-tut
5717 '((name . "Info index: guile-tut")
5718 (info-index . "guile-tut")))
5719 ;; (anything 'anything-c-source-info-guile-tut)
5721 ;; Info Index goops
5722 (defvar anything-c-source-info-goops
5723 '((name . "Info index: goops")
5724 (info-index . "goops")))
5725 ;; (anything 'anything-c-source-info-goops)
5727 ;; Info Index screen
5728 (defvar anything-c-source-info-screen
5729 '((name . "Info index: screen")
5730 (info-index . "screen")
5731 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5732 ;; (anything 'anything-c-source-info-screen)
5734 ;; Info Index latex
5735 (defvar anything-c-source-info-latex
5736 '((name . "Info index: latex")
5737 (info-index . "latex")))
5738 ;; (anything 'anything-c-source-info-latex)
5740 ;; Info Index gawk
5741 (defvar anything-c-source-info-gawk
5742 '((name . "Info index: gawk")
5743 (info-index . "gawk")))
5744 ;; (anything 'anything-c-source-info-gawk)
5746 ;; Info Index sed
5747 (defvar anything-c-source-info-sed
5748 '((name . "Info index: sed")
5749 (info-index . "sed")))
5750 ;; (anything 'anything-c-source-info-sed)
5752 ;; Info Index m4
5753 (defvar anything-c-source-info-m4
5754 '((name . "Info index: m4")
5755 (info-index . "m4")))
5756 ;; (anything 'anything-c-source-info-m4)
5758 ;; Info Index wget
5759 (defvar anything-c-source-info-wget
5760 '((name . "Info index: wget")
5761 (info-index . "wget")))
5762 ;; (anything 'anything-c-source-info-wget)
5764 ;; Info Index binutils
5765 (defvar anything-c-source-info-binutils
5766 '((name . "Info index: binutils")
5767 (info-index . "binutils")))
5768 ;; (anything 'anything-c-source-info-binutils)
5770 ;; Info Index as
5771 (defvar anything-c-source-info-as
5772 '((name . "Info index: as")
5773 (info-index . "as")))
5774 ;; (anything 'anything-c-source-info-as)
5776 ;; Info Index bfd
5777 (defvar anything-c-source-info-bfd
5778 '((name . "Info index: bfd")
5779 (info-index . "bfd")))
5780 ;; (anything 'anything-c-source-info-bfd)
5782 ;; Info Index gprof
5783 (defvar anything-c-source-info-gprof
5784 '((name . "Info index: gprof")
5785 (info-index . "gprof")))
5786 ;; (anything 'anything-c-source-info-gprof)
5788 ;; Info Index ld
5789 (defvar anything-c-source-info-ld
5790 '((name . "Info index: ld")
5791 (info-index . "ld")))
5792 ;; (anything 'anything-c-source-info-ld)
5794 ;; Info Index diff
5795 (defvar anything-c-source-info-diff
5796 '((name . "Info index: diff")
5797 (info-index . "diff")))
5798 ;; (anything 'anything-c-source-info-diff)
5800 ;; Info Index flex
5801 (defvar anything-c-source-info-flex
5802 '((name . "Info index: flex")
5803 (info-index . "flex")))
5804 ;; (anything 'anything-c-source-info-flex)
5806 ;; Info Index grep
5807 (defvar anything-c-source-info-grep
5808 '((name . "Info index: grep")
5809 (info-index . "grep")))
5810 ;; (anything 'anything-c-source-info-grep)
5812 ;; Info Index gzip
5813 (defvar anything-c-source-info-gzip
5814 '((name . "Info index: gzip")
5815 (info-index . "gzip")))
5816 ;; (anything 'anything-c-source-info-gzip)
5818 ;; Info Index libtool
5819 (defvar anything-c-source-info-libtool
5820 '((name . "Info index: libtool")
5821 (info-index . "libtool")))
5822 ;; (anything 'anything-c-source-info-libtool)
5824 ;; Info Index texinfo
5825 (defvar anything-c-source-info-texinfo
5826 '((name . "Info index: texinfo")
5827 (info-index . "texinfo")))
5828 ;; (anything 'anything-c-source-info-texinfo)
5830 ;; Info Index info
5831 (defvar anything-c-source-info-info
5832 '((name . "Info index: info")
5833 (info-index . "info")))
5834 ;; (anything 'anything-c-source-info-info)
5836 ;; Info Index gdb
5837 (defvar anything-c-source-info-gdb
5838 '((name . "Info index: gdb")
5839 (info-index . "gdb")))
5840 ;; (anything 'anything-c-source-info-gdb)
5842 ;; Info Index stabs
5843 (defvar anything-c-source-info-stabs
5844 '((name . "Info index: stabs")
5845 (info-index . "stabs")))
5846 ;; (anything 'anything-c-source-info-stabs)
5848 ;; Info Index cvsbook
5849 (defvar anything-c-source-info-cvsbook
5850 '((name . "Info index: cvsbook")
5851 (info-index . "cvsbook")))
5852 ;; (anything 'anything-c-source-info-cvsbook)
5854 ;; Info Index cvs
5855 (defvar anything-c-source-info-cvs
5856 '((name . "Info index: cvs")
5857 (info-index . "cvs")))
5858 ;; (anything 'anything-c-source-info-cvs)
5860 ;; Info Index bison
5861 (defvar anything-c-source-info-bison
5862 '((name . "Info index: bison")
5863 (info-index . "bison")))
5864 ;; (anything 'anything-c-source-info-bison)
5866 ;; Info Index id-utils
5867 (defvar anything-c-source-info-id-utils
5868 '((name . "Info index: id-utils")
5869 (info-index . "id-utils")))
5870 ;; (anything 'anything-c-source-info-id-utils)
5872 ;; Info Index global
5873 (defvar anything-c-source-info-global
5874 '((name . "Info index: global")
5875 (info-index . "global")))
5876 ;; (anything 'anything-c-source-info-global)
5879 ;;; Man and woman UI
5882 (defvar anything-c-man-pages nil
5883 "All man pages on system.
5884 Will be calculated the first time you invoke anything with this
5885 source.")
5887 (defun anything-c-man-default-action (candidate)
5888 "Default action for jumping to a woman or man page from anything."
5889 (let ((wfiles (woman-file-name-all-completions candidate)))
5890 (condition-case err
5891 (if (> (length wfiles) 1)
5892 (woman-find-file
5893 (anything-comp-read
5894 "ManFile: " wfiles :must-match t))
5895 (woman candidate))
5896 ;; If woman is unable to format correctly
5897 ;; use man instead.
5898 (error (kill-buffer) ; Kill woman buffer.
5899 (let ((Man-notify-method 'meek))
5900 (Man-getpage-in-background candidate))))))
5902 (defvar anything-c-source-man-pages
5903 `((name . "Manual Pages")
5904 (candidates . (lambda ()
5905 (if anything-c-man-pages
5906 anything-c-man-pages
5907 ;; XEmacs doesn't have a woman :)
5908 (setq anything-c-man-pages
5909 (ignore-errors
5910 (require 'woman)
5911 (woman-file-name "")
5912 (sort (mapcar 'car woman-topic-all-completions)
5913 'string-lessp))))))
5914 (action ("Show with Woman" . anything-c-man-default-action))
5915 ;; Woman does not work OS X
5916 ;; http://xahlee.org/emacs/modernization_man_page.html
5917 (action-transformer . (lambda (actions candidate)
5918 (if (eq system-type 'darwin)
5919 '(("Show with Man" . man))
5920 actions)))
5921 (requires-pattern . 2)))
5922 ;; (anything 'anything-c-source-man-pages)
5925 ;;;; <Command>
5926 ;;; Anything M-x - Enhanced M-x UI
5929 ;; Another replacement of `M-x' that act exactly like the
5930 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5931 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5932 ;; anything invocation.
5933 ;; Documentation of commands available without quitting,
5934 ;; Show keybindings of commands.
5935 ;; Show history.
5936 (defvar anything-M-x-input-history nil)
5938 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5939 "Return alist of MODE-MAP."
5940 (loop for key being the key-seqs of mode-map using (key-bindings com)
5941 for str-key = (key-description key)
5942 for ismenu = (string-match "<menu-bar>" str-key)
5943 unless ismenu collect (cons str-key com)))
5945 (defun anything-get-mode-map-from-mode (mode)
5946 "Guess the mode-map name according to MODE.
5947 Some modes don't use conventional mode-map name
5948 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5949 Return nil if no mode-map found."
5950 (loop
5951 ;; Start with a conventional mode-map name.
5952 with mode-map = (intern-soft (format "%s-map" mode))
5953 with mode-string = (symbol-name mode)
5954 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5955 while (not mode-map)
5956 for count downfrom (length mode-name)
5957 ;; Return when no result after parsing entire string.
5958 when (eq count 0) return nil
5959 for sub-name = (substring mode-name 0 count)
5960 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5961 finally return mode-map))
5963 (defun anything-M-x-current-mode-map-alist ()
5964 "Return mode-map alist of current `major-mode'."
5965 (let ((map (anything-get-mode-map-from-mode major-mode)))
5966 (when (and map (boundp map))
5967 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5970 (defun anything-M-x-transformer (candidates sources)
5971 "filtered-candidate-transformer to show bindings in emacs commands.
5972 Show global bindings and local bindings according to current `major-mode'."
5973 (with-anything-current-buffer
5974 (loop
5975 with local-map = (anything-M-x-current-mode-map-alist)
5976 for cand in candidates
5977 for local-key = (car (rassq cand local-map))
5978 for key = (substitute-command-keys (format "\\[%s]" cand))
5979 collect
5980 (cons (cond ((and (string-match "^M-x" key) local-key)
5981 (format "%s (%s)"
5982 cand (propertize
5983 local-key
5984 'face 'anything-M-x-key-face)))
5985 ((string-match "^M-x" key) cand)
5986 (t (format "%s (%s)"
5987 cand (propertize
5989 'face 'anything-M-x-key-face))))
5990 cand) into ls
5991 finally return
5992 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5995 ;;; Complex command history
5998 (defvar anything-c-source-complex-command-history
5999 '((name . "Complex Command History")
6000 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
6001 (type . sexp)))
6002 ;; (anything 'anything-c-source-complex-command-history)
6004 ;;; M-x history (not related to `anything-M-x')
6007 (defvar anything-c-source-extended-command-history
6008 '((name . "Emacs Commands History")
6009 (candidates
6010 . (lambda ()
6011 (anything-fast-remove-dups extended-command-history :test 'equal)))
6012 (type . command)))
6013 ;; (anything 'anything-c-source-extended-command-history)
6015 ;;; Emacs commands (Basic source for emacs commands)
6018 (defvar anything-c-source-emacs-commands
6019 '((name . "Emacs Commands")
6020 (candidates . (lambda ()
6021 (let (commands)
6022 (mapatoms (lambda (a)
6023 (if (commandp a)
6024 (push (symbol-name a)
6025 commands))))
6026 (sort commands 'string-lessp))))
6027 (type . command)
6028 (requires-pattern . 2))
6029 "Source for completing and invoking Emacs commands.
6030 A command is a function with interactive spec that can
6031 be invoked with `M-x'.
6033 To get non-interactive functions listed, use
6034 `anything-c-source-emacs-functions'.")
6035 ;; (anything 'anything-c-source-emacs-commands)
6038 ;;;; <Function>
6039 ;;; Emacs functions
6042 (defvar anything-c-source-emacs-functions
6043 '((name . "Emacs Functions")
6044 (candidates . (lambda ()
6045 (let (commands)
6046 (mapatoms (lambda (a)
6047 (if (functionp a)
6048 (push (symbol-name a) commands))))
6049 (sort commands 'string-lessp))))
6050 (type . function)
6051 (requires-pattern . 2))
6052 "Source for completing Emacs functions.")
6053 ;; (anything 'anything-c-source-emacs-functions)
6055 ;;; With abbrev expansion
6056 ;;; Similar to my exec-abbrev-cmd.el
6057 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6058 (defvar anything-c-function-abbrev-regexp nil
6059 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6060 Regexp built from the current `anything-pattern' interpreting it
6061 as abbreviation.
6062 Only for internal use.")
6064 (defun anything-c-match-function-by-abbrev (candidate)
6065 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6067 Abbreviations are made by taking the first character from each
6068 word in the function's name, e.g. \"bb\" is an abbrev for
6069 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6070 (string-match anything-c-function-abbrev-regexp candidate))
6072 (defvar anything-c-source-emacs-functions-with-abbrevs
6073 (append anything-c-source-emacs-functions
6074 '((match anything-c-match-function-by-abbrev
6075 anything-c-string-match))
6076 '((init
6077 . (lambda ()
6078 (defadvice anything-update
6079 (before anything-c-update-function-abbrev-regexp activate)
6080 (let ((char-list (append anything-pattern nil))
6081 (str "^"))
6082 (dolist (c char-list)
6083 (setq str (concat str (list c) "[^-]*-")))
6084 (setq str (concat (substring str 0 (1- (length str))) "$"))
6085 (setq anything-c-function-abbrev-regexp str))))))))
6086 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6088 (defvar anything-c-source-advice
6089 '((name . "Function Advice")
6090 (candidates . anything-c-advice-candidates)
6091 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6092 (persistent-action . anything-c-advice-persistent-action)
6093 (multiline)
6094 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6095 ;; (anything 'anything-c-source-advice)
6096 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6097 ;; (testadvice)
6099 (defun anything-c-advice-candidates ()
6100 (require 'advice)
6101 (loop for (fname) in ad-advised-functions
6102 for function = (intern fname)
6103 append
6104 (loop for class in ad-advice-classes append
6105 (loop for advice in (ad-get-advice-info-field function class)
6106 for enabled = (ad-advice-enabled advice)
6107 collect
6108 (cons (format
6109 "%s %s %s"
6110 (if enabled "Enabled " "Disabled")
6111 (propertize fname 'face 'font-lock-function-name-face)
6112 (ad-make-single-advice-docstring advice class nil))
6113 (list function class advice))))))
6115 (defun anything-c-advice-persistent-action (func-class-advice)
6116 (if current-prefix-arg
6117 (anything-c-advice-toggle func-class-advice)
6118 (describe-function (car func-class-advice))))
6120 (defun anything-c-advice-toggle (func-class-advice)
6121 (destructuring-bind (function class advice) func-class-advice
6122 (cond ((ad-advice-enabled advice)
6123 (ad-advice-set-enabled advice nil)
6124 (message "Disabled"))
6125 (t ;disabled
6126 (ad-advice-set-enabled advice t)
6127 (message "Enabled")))
6128 (ad-activate function)
6129 (and anything-in-persistent-action
6130 (anything-c-advice-update-current-display-string))))
6132 (defun anything-c-advice-update-current-display-string ()
6133 (anything-edit-current-selection
6134 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6135 ((looking-at "Enabled") "Disabled")))
6136 realvalue)
6137 (when newword
6138 (delete-region (point) (progn (forward-word 1) (point)))
6139 (insert newword)))))
6142 ;;;; <Variable>
6143 ;;; Emacs variables
6146 (defvar anything-c-source-emacs-variables
6147 '((name . "Emacs Variables")
6148 (candidates . (lambda ()
6149 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6150 (type . variable)
6151 (requires-pattern . 2))
6152 "Source for completing Emacs variables.")
6153 ;; (anything 'anything-c-source-emacs-variables)
6156 ;;; LaCarte
6157 (defvar anything-c-source-lacarte
6158 '((name . "Lacarte")
6159 (init . (lambda () (require 'lacarte )))
6160 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6161 (candidate-number-limit . 9999)
6162 (action . anything-c-call-interactively))
6163 "Needs lacarte.el.
6165 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6166 ;; (anything 'anything-c-source-lacarte)
6169 ;;; Bookmarks
6172 ;; Bind some faces for bookmarks.
6173 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6174 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6175 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6177 (eval-when-compile (require 'bookmark))
6178 (defvar anything-c-source-bookmarks
6179 '((name . "Bookmarks")
6180 (init . (lambda ()
6181 (require 'bookmark)))
6182 (candidates . bookmark-all-names)
6183 (type . bookmark))
6184 "See (info \"(emacs)Bookmarks\").")
6185 ;; (anything 'anything-c-source-bookmarks)
6187 ;;; bookmark-set
6188 (defvar anything-c-source-bookmark-set
6189 '((name . "Set Bookmark")
6190 (dummy)
6191 (action . bookmark-set))
6192 "See (info \"(emacs)Bookmarks\").")
6193 ;; (anything 'anything-c-source-bookmark-set)
6195 ;;; Visible Bookmarks
6196 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6199 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6200 (defvar anything-c-source-bm
6201 '((name . "Visible Bookmarks")
6202 (init . anything-c-bm-init)
6203 (candidates-in-buffer)
6204 (type . line))
6205 "Needs bm.el.
6207 http://www.nongnu.org/bm/")
6209 (defun anything-c-bm-init ()
6210 "Init function for `anything-c-source-bm'."
6211 (when (require 'bm nil t)
6212 (with-no-warnings
6213 (let ((bookmarks (bm-lists))
6214 (buf (anything-candidate-buffer 'global)))
6215 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6216 '< :key 'overlay-start))
6217 (let ((start (overlay-start bm))
6218 (end (overlay-end bm))
6219 (annotation (or (overlay-get bm 'annotation) "")))
6220 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6221 (let ((str (format "%5d: [%s]: %s\n"
6222 (line-number-at-pos start)
6223 annotation
6224 (buffer-substring start (1- end)))))
6225 (with-current-buffer buf (insert str))))))))))
6227 ;;; Special bookmarks
6228 (defvar anything-c-source-bookmarks-ssh
6229 '((name . "Bookmarks-ssh")
6230 (init . (lambda ()
6231 (require 'bookmark)))
6232 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6233 (type . bookmark))
6234 "See (info \"(emacs)Bookmarks\").")
6235 ;; (anything 'anything-c-source-bookmarks-ssh)
6237 (defvar anything-c-source-bookmarks-su
6238 '((name . "Bookmarks-root")
6239 (init . (lambda ()
6240 (require 'bookmark)))
6241 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6242 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6244 (type . bookmark))
6245 "See (info \"(emacs)Bookmarks\").")
6246 ;; (anything 'anything-c-source-bookmarks-su)
6248 (defvar anything-c-source-bookmarks-local
6249 '((name . "Bookmarks-Local")
6250 (init . (lambda ()
6251 (require 'bookmark)))
6252 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6253 (filtered-candidate-transformer
6254 anything-c-adaptive-sort
6255 anything-c-highlight-bookmark)
6256 (type . bookmark))
6257 "See (info \"(emacs)Bookmarks\").")
6258 ;; (anything 'anything-c-source-bookmarks-local)
6260 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6261 (let* ((lis-all (bookmark-all-names))
6262 (lis-loc (cond (local (loop for i in lis-all
6263 unless (string-match "^(ssh)\\|^(su)" i)
6264 collect i))
6265 (su (loop for i in lis-all
6266 when (string-match "^(su)" i)
6267 collect i))
6268 (sudo (loop for i in lis-all
6269 when (string-match "^(sudo)" i)
6270 collect i))
6271 (ssh (loop for i in lis-all
6272 when (string-match "^(ssh)" i)
6273 collect i)))))
6274 (sort lis-loc 'string-lessp)))
6276 (defun anything-c-bookmark-root-logged-p ()
6277 (catch 'break
6278 (dolist (i (mapcar #'buffer-name (buffer-list)))
6279 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6280 (throw 'break t)))))
6282 (defun anything-c-highlight-bookmark-su (files source)
6283 (if (anything-c-bookmark-root-logged-p)
6284 (anything-c-highlight-bookmark files source)
6285 (anything-c-highlight-not-logged files source)))
6287 (defun anything-c-highlight-not-logged (files source)
6288 (loop for i in files
6289 collect (propertize i 'face anything-c-bookmarks-face3)))
6291 (defun anything-c-highlight-bookmark (bookmarks source)
6292 "Used as `candidate-transformer' to colorize bookmarks.
6293 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6294 (loop for i in bookmarks
6295 for isfile = (bookmark-get-filename i)
6296 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6297 (bmkext-get-buffer-name i))
6298 for handlerp = (and (fboundp 'bookmark-get-handler)
6299 (bookmark-get-handler i))
6300 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6301 (bmkext-w3m-bookmark-p i))
6302 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6303 (bmkext-gnus-bookmark-p i))
6304 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6305 (bmkext-man-bookmark-p i))
6306 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6307 (bmkext-woman-bookmark-p i))
6308 for handlerp = (bookmark-get-handler i)
6309 for isannotation = (bookmark-get-annotation i)
6310 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6311 for isinfo = (eq handlerp 'Info-bookmark-jump)
6312 ;; Add a * if bookmark have annotation
6313 if (and isannotation (not (string-equal isannotation "")))
6314 do (setq i (concat "*" i))
6315 collect (cond (;; info buffers
6316 isinfo
6317 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6318 (;; w3m buffers
6319 isw3m
6320 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6321 (;; gnus buffers
6322 isgnus
6323 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6324 (;; Man Woman
6325 (or iswoman isman)
6326 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6327 (;; Addressbook
6328 isabook
6329 (propertize i 'face '((:foreground "Tomato"))))
6330 (;; directories
6331 (and isfile (file-directory-p isfile))
6332 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6333 (;; regular files
6335 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6339 ;;; Sources to filter bookmark-extensions bookmarks.
6342 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6343 ;; If you want to enable google-maps in addressbook you will need
6344 ;; Julien Danjou google-maps-el package available here:
6345 ;; http://julien.danjou.info/google-maps-el.html
6347 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6348 "Return a filtered `bookmark-alist' sorted alphabetically."
6349 (loop
6350 with alist = (if args
6351 (apply #'(lambda (x) (funcall fn x)) args)
6352 (funcall fn))
6353 for i in alist
6354 for b = (car i)
6355 collect b into sa
6356 finally return (sort sa 'string-lessp)))
6358 ;;; Addressbook.
6361 (defvar anything-c-source-bmkext-addressbook
6362 '((name . "Bookmark Addressbook")
6363 (init . (lambda ()
6364 (require 'bookmark-extensions)
6365 (bookmark-maybe-load-default-file)))
6366 (candidates . anything-c-bmkext-addressbook-setup-alist)
6367 (persistent-action
6368 . (lambda (candidate)
6369 (let ((bmk (anything-bookmark-get-bookmark-from-name
6370 candidate)))
6371 (bookmark--jump-via bmk 'pop-to-buffer))))
6372 (persistent-help . "Show contact - Prefix with C-u to append")
6373 (filtered-candidate-transformer
6374 anything-c-adaptive-sort
6375 anything-c-highlight-bookmark)
6376 (action . (("Show Contact(s)"
6377 . (lambda (candidate)
6378 (let* ((contacts (anything-marked-candidates))
6379 (current-prefix-arg (or anything-current-prefix-arg
6380 (> (length contacts) 1))))
6381 (bookmark-jump
6382 (anything-bookmark-get-bookmark-from-name (car contacts)))
6383 (anything-aif (cdr contacts)
6384 (loop for bmk in it do
6385 (bookmark-jump
6386 (anything-bookmark-get-bookmark-from-name bmk)))))))
6387 ("Send Mail"
6388 . (lambda (candidate)
6389 (let* ((contacts (anything-marked-candidates))
6390 (bmk (anything-bookmark-get-bookmark-from-name
6391 (car contacts)))
6392 (append (message-buffers)))
6393 (if append
6394 (addressbook-set-mail-buffer1 bmk 'append)
6395 (addressbook-set-mail-buffer1 bmk))
6396 (setq contacts (cdr contacts))
6397 (when contacts
6398 (loop for bmk in contacts do
6399 (addressbook-set-mail-buffer1 bmk 'append))))))
6400 ("Edit Bookmark"
6401 . (lambda (candidate)
6402 (let ((bmk (anything-bookmark-get-bookmark-from-name
6403 candidate)))
6404 (addressbook-bookmark-edit
6405 (assoc bmk bookmark-alist)))))
6406 ("Insert Email at point"
6407 . (lambda (candidate)
6408 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6409 candidate))
6410 (mlist (split-string
6411 (assoc-default
6412 'email (assoc bmk bookmark-alist))
6413 ", ")))
6414 (insert
6415 (if (> (length mlist) 1)
6416 (anything-comp-read
6417 "Insert Mail Address: " mlist :must-match t)
6418 (car mlist))))))
6419 ("Show annotation"
6420 . (lambda (candidate)
6421 (let ((bmk (anything-bookmark-get-bookmark-from-name
6422 candidate)))
6423 (bookmark-show-annotation bmk))))
6424 ("Edit annotation"
6425 . (lambda (candidate)
6426 (let ((bmk (anything-bookmark-get-bookmark-from-name
6427 candidate)))
6428 (bookmark-edit-annotation bmk))))
6429 ("Show Google map"
6430 . (lambda (candidate)
6431 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6432 candidate))
6433 (full-bmk (assoc bmk bookmark-alist)))
6434 (addressbook-google-map full-bmk))))))))
6437 (defun anything-c-bmkext-addressbook-setup-alist ()
6438 "Specialized filter function for bookmarks w3m."
6439 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6441 ;; W3m bookmarks from bookmark-extensions.
6442 (defvar anything-c-source-bookmark-w3m
6443 '((name . "Bookmark W3m")
6444 (init . (lambda ()
6445 (require 'bookmark-extensions)
6446 (bookmark-maybe-load-default-file)))
6447 (candidates . anything-c-bookmark-w3m-setup-alist)
6448 (filtered-candidate-transformer
6449 anything-c-adaptive-sort
6450 anything-c-highlight-bookmark)
6451 (type . bookmark)))
6452 ;; (anything 'anything-c-source-bookmark-w3m)
6454 (defun anything-c-bookmark-w3m-setup-alist ()
6455 "Specialized filter function for bookmarks w3m."
6456 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6458 ;; Images
6459 (defvar anything-c-source-bookmark-images
6460 '((name . "Bookmark Images")
6461 (init . (lambda ()
6462 (require 'bookmark-extensions)
6463 (bookmark-maybe-load-default-file)))
6464 (candidates . anything-c-bookmark-images-setup-alist)
6465 (filtered-candidate-transformer
6466 anything-c-adaptive-sort
6467 anything-c-highlight-bookmark)
6468 (type . bookmark)))
6469 ;; (anything 'anything-c-source-bookmark-images)
6471 (defun anything-c-bookmark-images-setup-alist ()
6472 "Specialized filter function for images bookmarks."
6473 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6475 ;; Woman Man
6476 (defvar anything-c-source-bookmark-man
6477 '((name . "Bookmark Woman&Man")
6478 (init . (lambda ()
6479 (require 'bookmark-extensions)
6480 (bookmark-maybe-load-default-file)))
6481 (candidates . anything-c-bookmark-man-setup-alist)
6482 (filtered-candidate-transformer
6483 anything-c-adaptive-sort
6484 anything-c-highlight-bookmark)
6485 (type . bookmark)))
6486 ;; (anything 'anything-c-source-bookmark-man)
6488 (defun anything-c-bookmark-man-setup-alist ()
6489 "Specialized filter function for bookmarks w3m."
6490 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6491 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6493 ;; Gnus
6494 (defvar anything-c-source-bookmark-gnus
6495 '((name . "Bookmark Gnus")
6496 (init . (lambda ()
6497 (require 'bookmark-extensions)
6498 (bookmark-maybe-load-default-file)))
6499 (candidates . anything-c-bookmark-gnus-setup-alist)
6500 (filtered-candidate-transformer
6501 anything-c-adaptive-sort
6502 anything-c-highlight-bookmark)
6503 (type . bookmark)))
6504 ;; (anything 'anything-c-source-bookmark-gnus)
6506 (defun anything-c-bookmark-gnus-setup-alist ()
6507 "Specialized filter function for bookmarks gnus."
6508 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6510 ;; Info
6511 (defvar anything-c-source-bookmark-info
6512 '((name . "Bookmark Info")
6513 (init . (lambda ()
6514 (require 'bookmark-extensions)
6515 (bookmark-maybe-load-default-file)))
6516 (candidates . anything-c-bookmark-info-setup-alist)
6517 (filtered-candidate-transformer
6518 anything-c-adaptive-sort
6519 anything-c-highlight-bookmark)
6520 (type . bookmark)))
6521 ;; (anything 'anything-c-source-bookmark-info)
6523 (defun anything-c-bookmark-info-setup-alist ()
6524 "Specialized filter function for bookmarks info."
6525 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6527 ;; Local Files&directories
6528 (defvar anything-c-source-bookmark-files&dirs
6529 '((name . "Bookmark Files&Directories")
6530 (init . (lambda ()
6531 (require 'bookmark-extensions)
6532 (bookmark-maybe-load-default-file)))
6533 (candidates . anything-c-bookmark-local-files-setup-alist)
6534 (filtered-candidate-transformer
6535 anything-c-adaptive-sort
6536 anything-c-highlight-bookmark)
6537 (type . bookmark)))
6538 ;; (anything 'anything-c-source-bookmark-files&dirs)
6540 (defun anything-c-bookmark-local-files-setup-alist ()
6541 "Specialized filter function for bookmarks locals files."
6542 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6544 ;; Su Files&directories
6545 (defvar anything-c-source-bookmark-su-files&dirs
6546 '((name . "Bookmark Root-Files&Directories")
6547 (init . (lambda ()
6548 (require 'bookmark-extensions)
6549 (bookmark-maybe-load-default-file)))
6550 (candidates . anything-c-bookmark-su-files-setup-alist)
6551 (filtered-candidate-transformer
6552 anything-c-adaptive-sort
6553 anything-c-highlight-bookmark-su)
6554 (type . bookmark)))
6555 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6557 (defun anything-c-bookmark-su-files-setup-alist ()
6558 "Specialized filter function for bookmarks su/sudo files."
6559 (declare (special bmkext-su-or-sudo-regexp))
6560 (loop
6561 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6562 for i in l
6563 for isfile = (bookmark-get-filename i)
6564 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6565 (save-match-data
6566 (string-match tramp-file-name-regexp isfile)))
6567 for issu = (and istramp
6568 (string-match bmkext-su-or-sudo-regexp isfile))
6569 if issu
6570 collect i))
6572 ;; Ssh Files&directories
6573 (defvar anything-c-source-bookmark-ssh-files&dirs
6574 '((name . "Bookmark Ssh-Files&Directories")
6575 (init . (lambda ()
6576 (require 'bookmark-extensions)
6577 (bookmark-maybe-load-default-file)))
6578 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6579 (filtered-candidate-transformer . anything-c-adaptive-sort)
6580 (type . bookmark)))
6581 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6583 (defun anything-c-bookmark-ssh-files-setup-alist ()
6584 "Specialized filter function for bookmarks ssh files."
6585 (loop
6586 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6587 for i in l
6588 for isfile = (bookmark-get-filename i)
6589 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6590 (save-match-data
6591 (string-match tramp-file-name-regexp isfile)))
6592 for isssh = (and istramp
6593 (string-match "/ssh:" isfile))
6594 if isssh
6595 collect i))
6599 ;;; Firefox bookmarks
6602 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6603 ;; (only for firefox versions >=3)
6604 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6605 ;; to true:
6606 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6607 ;; You should have now:
6608 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6610 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6611 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6613 (defun anything-get-firefox-user-init-dir ()
6614 "Guess the default Firefox user directory name."
6615 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6616 (moz-user-dir
6617 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6618 (goto-char (point-min))
6619 (prog1
6620 (when (search-forward "Path=" nil t)
6621 (buffer-substring-no-properties (point) (point-at-eol)))
6622 (kill-buffer)))))
6623 (file-name-as-directory (concat moz-dir moz-user-dir))))
6625 (defun anything-guess-firefox-bookmark-file ()
6626 "Return the path of the Firefox bookmarks file."
6627 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6629 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6630 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6631 (let (bookmarks-alist url title)
6632 (with-temp-buffer
6633 (insert-file-contents file)
6634 (goto-char (point-min))
6635 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6636 (forward-line 0)
6637 (when (re-search-forward url-regexp nil t)
6638 (setq url (match-string 0)))
6639 (when (re-search-forward bmk-regexp nil t)
6640 (setq title (match-string 1)))
6641 (push (cons title url) bookmarks-alist)
6642 (forward-line)))
6643 (nreverse bookmarks-alist)))
6645 (defvar anything-c-firefox-bookmarks-alist nil)
6646 (defvar anything-c-source-firefox-bookmarks
6647 '((name . "Firefox Bookmarks")
6648 (init . (lambda ()
6649 (setq anything-c-firefox-bookmarks-alist
6650 (anything-html-bookmarks-to-alist
6651 (anything-guess-firefox-bookmark-file)
6652 anything-firefox-bookmark-url-regexp
6653 anything-firefox-bookmarks-regexp))))
6654 (candidates . (lambda ()
6655 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6656 (filtered-candidate-transformer
6657 anything-c-adaptive-sort
6658 anything-c-highlight-firefox-bookmarks)
6659 (action . (("Browse Url Firefox"
6660 . (lambda (candidate)
6661 (browse-url-firefox
6662 (anything-c-firefox-bookmarks-get-value candidate))))
6663 ("Browse Url w3m"
6664 . (lambda (candidate)
6665 (w3m-browse-url
6666 (anything-c-firefox-bookmarks-get-value candidate))))
6667 ("Copy Url"
6668 . (lambda (elm)
6669 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6671 ;; (anything 'anything-c-source-firefox-bookmarks)
6673 (defun anything-c-firefox-bookmarks-get-value (elm)
6674 (assoc-default elm anything-c-firefox-bookmarks-alist))
6676 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6677 (loop for i in bookmarks
6678 collect (propertize
6679 i 'face '((:foreground "YellowGreen"))
6680 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6684 ;;; W3m bookmark - anything interface.
6687 ;; Some users have the emacs-w3m library in load-path
6688 ;; without having the w3m executable :-;
6689 ;; So check if w3m program is present before trying to load
6690 ;; emacs-w3m.
6691 (eval-when-compile
6692 (when (executable-find "w3m")
6693 (require 'w3m-bookmark nil t)))
6695 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6696 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6697 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6698 (defvar anything-c-w3m-bookmarks-alist nil)
6699 (defvar anything-c-source-w3m-bookmarks
6700 '((name . "W3m Bookmarks")
6701 (init . (lambda ()
6702 (setq anything-c-w3m-bookmarks-alist
6703 (anything-html-bookmarks-to-alist
6704 w3m-bookmark-file
6705 anything-w3m-bookmark-url-regexp
6706 anything-w3m-bookmarks-regexp))))
6707 (candidates . (lambda ()
6708 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6709 (filtered-candidate-transformer
6710 anything-c-adaptive-sort
6711 anything-c-highlight-w3m-bookmarks)
6712 (action . (("Browse Url"
6713 . (lambda (candidate)
6714 (anything-c-w3m-browse-bookmark candidate)))
6715 ("Copy Url"
6716 . (lambda (elm)
6717 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6718 ("Browse Url Firefox"
6719 . (lambda (candidate)
6720 (anything-c-w3m-browse-bookmark candidate t)))
6721 ("Delete Bookmark"
6722 . (lambda (candidate)
6723 (anything-c-w3m-delete-bookmark candidate)))
6724 ("Rename Bookmark"
6725 . (lambda (candidate)
6726 (anything-c-w3m-rename-bookmark candidate)))))
6727 (persistent-action . (lambda (candidate)
6728 (if current-prefix-arg
6729 (anything-c-w3m-browse-bookmark candidate t)
6730 (anything-c-w3m-browse-bookmark candidate nil t))))
6731 (persistent-help . "Open URL with emacs-w3m in new tab / \
6732 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6733 "Needs w3m and emacs-w3m.
6735 http://w3m.sourceforge.net/
6736 http://emacs-w3m.namazu.org/")
6738 ;; (anything 'anything-c-source-w3m-bookmarks)
6740 (defun anything-c-w3m-bookmarks-get-value (elm)
6741 (replace-regexp-in-string
6742 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6744 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6745 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6746 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6747 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6749 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6750 (loop for i in bookmarks
6751 collect (propertize
6752 i 'face 'anything-w3m-bookmarks-face
6753 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6756 (defun anything-c-w3m-delete-bookmark (elm)
6757 "Delete w3m bookmark from `w3m-bookmark-file'."
6758 (with-current-buffer
6759 (find-file-literally w3m-bookmark-file)
6760 (goto-char (point-min))
6761 (when (re-search-forward elm nil t)
6762 (beginning-of-line)
6763 (delete-region (point)
6764 (line-end-position))
6765 (delete-blank-lines))
6766 (save-buffer)
6767 (kill-buffer)))
6769 (defun anything-c-w3m-rename-bookmark (elm)
6770 "Rename w3m bookmark in `w3m-bookmark-file'."
6771 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6772 (new-title (read-string "NewTitle: " old-title)))
6773 (with-current-buffer
6774 (find-file-literally w3m-bookmark-file)
6775 (goto-char (point-min))
6776 (when (re-search-forward (concat elm "<") nil t)
6777 (goto-char (1- (point)))
6778 (delete-char (- (length old-title)))
6779 (insert new-title))
6780 (save-buffer)
6781 (kill-buffer))))
6784 ;;;; <Library>
6785 ;;; Elisp library scan
6788 (defvar anything-c-source-elisp-library-scan
6789 '((name . "Elisp libraries (Scan)")
6790 (init . (anything-c-elisp-library-scan-init))
6791 (candidates-in-buffer)
6792 (action ("Find library"
6793 . (lambda (candidate) (find-file (find-library-name candidate))))
6794 ("Find library other window"
6795 . (lambda (candidate)
6796 (find-file-other-window (find-library-name candidate))))
6797 ("Load library"
6798 . (lambda (candidate) (load-library candidate))))))
6799 ;; (anything 'anything-c-source-elisp-library-scan)
6801 (defun anything-c-elisp-library-scan-init ()
6802 "Init anything buffer status."
6803 (let ((anything-buffer (anything-candidate-buffer 'global))
6804 (library-list (anything-c-elisp-library-scan-list)))
6805 (with-current-buffer anything-buffer
6806 (dolist (library library-list)
6807 (insert (format "%s\n" library))))))
6809 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6810 "Do completion for file names passed to `locate-file'.
6811 DIRS is directory to search path.
6812 STRING is string to match."
6813 ;; Use `load-path' as path when ignore `dirs'.
6814 (or dirs (setq dirs load-path))
6815 ;; Init with blank when ignore `string'.
6816 (or string (setq string ""))
6817 ;; Get library list.
6818 (let ((string-dir (file-name-directory string))
6819 ;; File regexp that suffix match `load-file-rep-suffixes'.
6820 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6821 name
6822 names)
6823 (dolist (dir dirs)
6824 (unless dir
6825 (setq dir default-directory))
6826 (if string-dir
6827 (setq dir (expand-file-name string-dir dir)))
6828 (when (file-directory-p dir)
6829 (dolist (file (file-name-all-completions
6830 (file-name-nondirectory string) dir))
6831 ;; Suffixes match `load-file-rep-suffixes'.
6832 (setq name (if string-dir (concat string-dir file) file))
6833 (if (string-match match-regexp name)
6834 (add-to-list 'names name)))))
6835 names))
6838 ;;;; <Programming>
6842 ;;; Imenu
6845 (defvar anything-c-imenu-delimiter " / ")
6847 (defvar anything-c-imenu-index-filter nil)
6848 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6850 (defvar anything-c-cached-imenu-alist nil)
6851 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6853 (defvar anything-c-cached-imenu-candidates nil)
6854 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6856 (defvar anything-c-cached-imenu-tick nil)
6857 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6859 (eval-when-compile (require 'imenu))
6860 (setq imenu-auto-rescan t)
6862 (defun anything-imenu-create-candidates (entry)
6863 "Create candidates with ENTRY."
6864 (if (listp (cdr entry))
6865 (mapcan
6866 (lambda (sub)
6867 (if (consp (cdr sub))
6868 (mapcar
6869 (lambda (subentry)
6870 (concat (car entry) anything-c-imenu-delimiter subentry))
6871 (anything-imenu-create-candidates sub))
6872 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6873 (cdr entry))
6874 (list entry)))
6876 (defvar anything-c-source-imenu
6877 '((name . "Imenu")
6878 (init . (lambda () (require 'imenu)))
6879 (candidates . anything-c-imenu-candidates)
6880 (persistent-action . (lambda (elm)
6881 (anything-c-imenu-default-action elm)
6882 (unless (fboundp 'semantic-imenu-tag-overlay)
6883 (anything-match-line-color-current-line))))
6884 (persistent-help . "Show this entry")
6885 (action . anything-c-imenu-default-action))
6886 "See (info \"(emacs)Imenu\")")
6888 ;; (anything 'anything-c-source-imenu)
6890 (defun anything-c-imenu-candidates ()
6891 (with-anything-current-buffer
6892 (let ((tick (buffer-modified-tick)))
6893 (if (eq anything-c-cached-imenu-tick tick)
6894 anything-c-cached-imenu-candidates
6895 (setq imenu--index-alist nil)
6896 (setq anything-c-cached-imenu-tick tick
6897 anything-c-cached-imenu-candidates
6898 (ignore-errors
6899 (mapcan
6900 'anything-imenu-create-candidates
6901 (setq anything-c-cached-imenu-alist
6902 (let ((index (imenu--make-index-alist)))
6903 (if anything-c-imenu-index-filter
6904 (funcall anything-c-imenu-index-filter index)
6905 index))))))
6906 (setq anything-c-cached-imenu-candidates
6907 (mapcar #'(lambda (x)
6908 (if (stringp x)
6910 (car x)))
6911 anything-c-cached-imenu-candidates))))))
6913 (setq imenu-default-goto-function 'imenu-default-goto-function)
6914 (defun anything-c-imenu-default-action (elm)
6915 "The default action for `anything-c-source-imenu'."
6916 (let ((path (split-string elm anything-c-imenu-delimiter))
6917 (alist anything-c-cached-imenu-alist))
6918 (dolist (elm path)
6919 (setq alist (assoc elm alist)))
6920 (imenu alist)))
6924 ;;; Ctags
6927 (defvar anything-c-ctags-modes
6928 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6929 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6930 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6932 (defun anything-c-source-ctags-init ()
6933 (when (and buffer-file-name
6934 (memq major-mode anything-c-ctags-modes)
6935 (anything-current-buffer-is-modified))
6936 (with-current-buffer (anything-candidate-buffer 'local)
6937 (call-process-shell-command
6938 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6939 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6940 anything-buffer-file-name)
6941 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6942 nil (current-buffer))
6943 (goto-char (point-min))
6944 (forward-line 2)
6945 (delete-region (point-min) (point))
6946 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6947 for lineno-start = (point)
6948 for lineno = (buffer-substring
6949 lineno-start
6950 (1- (search-forward "," (point-at-eol) t)))
6952 (beginning-of-line)
6953 (insert (format "%5s:" lineno))
6954 (search-forward "\177" (point-at-eol) t)
6955 (delete-region (1- (point)) (point-at-eol))
6956 (forward-line 1)))))
6958 (defvar anything-c-source-ctags
6959 '((name . "Exuberant ctags")
6960 (init . anything-c-source-ctags-init)
6961 (candidates-in-buffer)
6962 (adjust)
6963 (type . line))
6964 "Needs Exuberant Ctags.
6966 http://ctags.sourceforge.net/")
6967 ;; (anything 'anything-c-source-ctags)
6970 ;;; Etags
6973 ;; anything-etags.el is deprecated, if this file is found,
6974 ;; warn user at compile time.
6975 (eval-when-compile
6976 (when (locate-library "anything-etags.el")
6977 (display-warning
6978 '(anything-config)
6979 "You are using obsolete library `anything-etags.el' and should remove it."
6980 :warning)))
6982 (defvar anything-c-etags-tag-file-dir nil
6983 "Etags file directory.")
6984 (defvar anything-c-etags-mtime-alist nil
6985 "Store the last modification time of etags files here.")
6986 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6987 "Cache content of etags files used here for faster access.")
6989 (defun anything-c-etags-get-tag-file (&optional directory)
6990 "Return the path of etags file if found."
6991 ;; Get tag file from `default-directory' or upper directory.
6992 (let ((current-dir (anything-c-etags-find-tag-file-directory
6993 (or directory default-directory))))
6994 ;; Return nil if not find tag file.
6995 (when current-dir
6996 ;; Set tag file directory.
6997 (setq anything-c-etags-tag-file-dir current-dir)
6998 (expand-file-name anything-c-etags-tag-file-name current-dir))))
7000 (defun anything-c-etags-find-tag-file-directory (current-dir)
7001 "Try to find the directory containing tag file.
7002 If not found in CURRENT-DIR search in upper directory."
7003 (flet ((file-exists? (dir)
7004 (let ((tag-path (expand-file-name
7005 anything-c-etags-tag-file-name dir)))
7006 (and (stringp tag-path)
7007 (file-exists-p tag-path)
7008 (file-readable-p tag-path)))))
7009 (loop with count = 0
7010 until (file-exists? current-dir)
7011 ;; Return nil if outside the value of
7012 ;; `anything-c-etags-tag-file-search-limit'.
7013 if (= count anything-c-etags-tag-file-search-limit)
7014 do (return nil)
7015 ;; Or search upper directories.
7016 else
7017 do (incf count)
7018 (setq current-dir (expand-file-name (concat current-dir "../")))
7019 finally return current-dir)))
7021 (defun anything-c-source-etags-header-name (x)
7022 "Create header name for this anything etags session."
7023 (concat "Etags in "
7024 (with-anything-current-buffer
7025 (anything-c-etags-get-tag-file))))
7027 (defmacro anything-c-etags-create-buffer (file)
7028 "Create the `anything-buffer' based on contents of etags tag FILE."
7029 `(let* ((tag-fname ,file)
7031 (split (with-current-buffer (find-file-noselect tag-fname)
7032 (prog1
7033 (split-string (buffer-string) "\n" 'omit-nulls)
7034 (setq max (line-number-at-pos (point-max)))
7035 (kill-buffer))))
7036 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7037 (loop
7038 with fname
7039 with cand
7040 for i in split for count from 0
7041 for elm = (unless (string-match "^\x0c" i)
7042 (anything-aif (string-match "\177" i)
7043 (substring i 0 it)
7045 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7046 (setq fname (match-string 1 elm)))
7047 (elm (setq cand (concat fname ": " elm)))
7048 (t (setq cand nil)))
7049 when cand do (progn
7050 (insert (concat cand "\n"))
7051 (progress-reporter-update progress-reporter count)))))
7053 (defun anything-c-etags-init ()
7054 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7055 If no entry in cache, create one."
7056 (let ((tagfile (anything-c-etags-get-tag-file)))
7057 (when tagfile
7058 (with-current-buffer (anything-candidate-buffer 'global)
7059 (anything-aif (gethash tagfile anything-c-etags-cache)
7060 ;; An entry is present in cache, insert it.
7061 (insert it)
7062 ;; No entry, create a new buffer using content of tag file (slower).
7063 (anything-c-etags-create-buffer tagfile)
7064 ;; Store content of buffer in cache.
7065 (puthash tagfile (buffer-string) anything-c-etags-cache)
7066 ;; Store or set the last modification of tag file.
7067 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7068 ;; If an entry exists modify it.
7069 (setcdr it (anything-c-etags-mtime tagfile))
7070 ;; No entry create a new one.
7071 (add-to-list 'anything-c-etags-mtime-alist
7072 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7074 (defvar anything-c-source-etags-select
7075 '((name . "Etags")
7076 (header-name . anything-c-source-etags-header-name)
7077 (init . anything-c-etags-init)
7078 (candidates-in-buffer)
7079 (search . (anything-c-etags-search-fn))
7080 (mode-line . anything-etags-mode-line-string)
7081 (action . anything-c-etags-default-action)
7082 (persistent-action . (lambda (candidate)
7083 (anything-c-etags-default-action candidate)
7084 (anything-match-line-color-current-line))))
7085 "Anything source for Etags.")
7087 (defun anything-c-etags-search-fn (pattern)
7088 "Search function for `anything-c-source-etags-select'."
7089 (re-search-forward
7090 (if anything-c-etags-use-regexp-search
7091 (format anything-c-etags-search-regexp pattern)
7092 pattern)
7093 nil t))
7095 (defun anything-c-etags-default-action (candidate)
7096 "Anything default action to jump to an etags entry."
7097 (let* ((split (split-string candidate ": "))
7098 (fname (expand-file-name
7099 (car split) anything-c-etags-tag-file-dir))
7100 (elm (cadr split)))
7101 (find-file fname)
7102 (goto-char (point-min))
7103 (search-forward elm nil t)
7104 (goto-char (match-beginning 0))))
7106 (defun anything-c-etags-mtime (file)
7107 "Last modification time of etags tag FILE."
7108 (cadr (nth 5 (file-attributes file))))
7110 (defun anything-c-etags-file-modified-p (file)
7111 "Check if tag FILE have been modified in this session.
7112 If FILE is nil return nil."
7113 (let ((last-modif (and file
7114 (assoc-default file anything-c-etags-mtime-alist))))
7115 (and last-modif
7116 (/= last-modif (anything-c-etags-mtime file)))))
7120 ;;; Semantic
7123 (defvar anything-semantic-candidates nil)
7125 (defun anything-semantic-construct-candidates (tags depth)
7126 (when (require 'semantic nil t)
7127 (apply
7128 'append
7129 (mapcar
7130 (lambda (tag)
7131 (if (listp tag)
7132 (let ((type (semantic-tag-type tag))
7133 (class (semantic-tag-class tag)))
7134 (if (or (and (stringp type)
7135 (or (string= type "class")
7136 (string= type "namespace")))
7137 (eq class 'function)
7138 (eq class 'variable))
7139 (cons (cons (concat (make-string (* depth 2) ?\s)
7140 (semantic-format-tag-summarize tag nil t))
7141 tag)
7142 (anything-semantic-construct-candidates
7143 (semantic-tag-components tag) (1+ depth)))))))
7144 tags))))
7146 (defun anything-semantic-default-action (candidate)
7147 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7148 (semantic-go-to-tag tag)))
7150 (defvar anything-c-source-semantic
7151 '((name . "Semantic Tags")
7152 (init . (lambda ()
7153 (setq anything-semantic-candidates
7154 (ignore-errors (anything-semantic-construct-candidates
7155 (semantic-fetch-tags) 0)))))
7156 (candidates . (lambda ()
7157 (if anything-semantic-candidates
7158 (mapcar 'car anything-semantic-candidates))))
7159 (persistent-action . (lambda (elm)
7160 (anything-semantic-default-action elm)
7161 (anything-match-line-color-current-line)))
7162 (persistent-help . "Show this entry")
7163 (action . anything-semantic-default-action)
7164 "Needs semantic in CEDET.
7166 http://cedet.sourceforge.net/semantic.shtml
7167 http://cedet.sourceforge.net/"))
7169 ;; (anything 'anything-c-source-semantic)
7172 ;;; Anything interface of `simple-call-tree.el'.
7174 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7176 ;; Function is called by
7177 (defvar anything-c-source-simple-call-tree-functions-callers
7178 '((name . "Function is called by")
7179 (init . anything-c-simple-call-tree-functions-callers-init)
7180 (multiline)
7181 (candidates . anything-c-simple-call-tree-candidates)
7182 (persistent-action . anything-c-simple-call-tree-persistent-action)
7183 (persistent-help . "Show function definitions by rotation")
7184 (action ("Find definition selected by persistent-action" .
7185 anything-c-simple-call-tree-find-definition)))
7186 "Needs simple-call-tree.el.
7187 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7189 (defvar anything-c-simple-call-tree-tick nil)
7190 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7191 (defun anything-c-simple-call-tree-analyze-maybe ()
7192 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7193 (simple-call-tree-analyze)
7194 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7196 (defun anything-c-simple-call-tree-init-base (function message)
7197 (require 'simple-call-tree)
7198 (with-no-warnings
7199 (when (anything-current-buffer-is-modified)
7200 (anything-c-simple-call-tree-analyze-maybe)
7201 (let ((list (funcall function simple-call-tree-alist)))
7202 (with-current-buffer (anything-candidate-buffer 'local)
7203 (dolist (entry list)
7204 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7205 (insert (car entry) message
7206 (if (string= funcs " ")
7207 " no functions."
7208 funcs)
7209 "\n\n"))))))))
7211 (defun anything-c-simple-call-tree-functions-callers-init ()
7212 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7213 " is called by\n"))
7215 (defun anything-c-simple-call-tree-candidates ()
7216 (with-current-buffer (anything-candidate-buffer)
7217 (split-string (buffer-string) "\n\n")))
7219 (defvar anything-c-simple-call-tree-related-functions nil)
7220 (defvar anything-c-simple-call-tree-function-index 0)
7221 (defun anything-c-simple-call-tree-persistent-action (candidate)
7222 (unless (eq last-command 'anything-execute-persistent-action)
7223 (setq anything-c-simple-call-tree-related-functions
7224 (delete "no functions."
7225 (split-string
7226 (replace-regexp-in-string " \\| is called by\\| calls "
7227 "" candidate)
7228 "\n")))
7229 (setq anything-c-simple-call-tree-function-index -1))
7230 (incf anything-c-simple-call-tree-function-index)
7231 (anything-c-simple-call-tree-find-definition candidate))
7233 (defun anything-c-simple-call-tree-find-definition (candidate)
7234 (find-function
7235 (intern
7236 (nth (mod anything-c-simple-call-tree-function-index
7237 (length anything-c-simple-call-tree-related-functions))
7238 anything-c-simple-call-tree-related-functions))))
7240 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7242 ;;; Function calls
7243 (defvar anything-c-source-simple-call-tree-callers-functions
7244 '((name . "Function calls")
7245 (init . anything-c-simple-call-tree-callers-functions-init)
7246 (multiline)
7247 (candidates . anything-c-simple-call-tree-candidates)
7248 (persistent-action . anything-c-simple-call-tree-persistent-action)
7249 (persistent-help . "Show function definitions by rotation")
7250 (action ("Find definition selected by persistent-action" .
7251 anything-c-simple-call-tree-find-definition)))
7252 "Needs simple-call-tree.el.
7253 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7255 (defun anything-c-simple-call-tree-callers-functions-init ()
7256 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7258 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7262 ;;; Anything UI of auto-document.el
7264 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7266 ;; Commands/Options with doc
7267 (defvar anything-c-auto-document-data nil)
7268 (make-variable-buffer-local 'anything-c-auto-document-data)
7269 (defvar anything-c-source-commands-and-options-in-file
7270 '((name . "Commands/Options in file")
7271 (header-name
7272 . (lambda (x) (format "Commands/Options in %s"
7273 (buffer-local-value 'buffer-file-name
7274 anything-current-buffer))))
7275 (candidates . anything-command-and-options-candidates)
7276 (multiline)
7277 (action . imenu))
7278 "List Commands and Options with doc. It needs auto-document.el .
7280 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7282 (eval-when-compile (require 'auto-document nil t))
7283 (defun anything-command-and-options-candidates ()
7284 (with-anything-current-buffer
7285 (when (and (require 'auto-document nil t)
7286 (eq major-mode 'emacs-lisp-mode)
7287 (or (anything-current-buffer-is-modified)
7288 (not anything-c-auto-document-data)))
7289 (or imenu--index-alist (imenu--make-index-alist t))
7290 (setq anything-c-auto-document-data
7291 (destructuring-bind (commands options)
7292 (adoc-construct anything-current-buffer)
7293 (append
7294 (loop for (command . doc) in commands
7295 for cmdname = (symbol-name command)
7296 collect
7297 (cons
7298 (format "Command: %s\n %s"
7299 (propertize cmdname 'face font-lock-function-name-face)
7300 (adoc-first-line doc))
7301 (assoc cmdname imenu--index-alist)))
7302 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7303 for (option doc default) in options
7304 for optname = (symbol-name option)
7305 collect
7306 (cons
7307 (format "Option: %s\n %s\n default = %s"
7308 (propertize optname 'face font-lock-variable-name-face)
7309 (adoc-first-line doc)
7310 (adoc-prin1-to-string default))
7311 (assoc optname
7312 var-alist)))))))
7313 anything-c-auto-document-data))
7315 ;; (anything 'anything-c-source-commands-and-options-in-file)
7318 ;;;; <Color and Face>
7321 ;;; Customize Face
7324 (defvar anything-c-source-customize-face
7325 '((name . "Customize Face")
7326 (init . (lambda ()
7327 (unless (anything-candidate-buffer)
7328 (save-selected-window
7329 (list-faces-display))
7330 (anything-candidate-buffer (get-buffer "*Faces*")))))
7331 (candidates-in-buffer)
7332 (get-line . buffer-substring)
7333 (action . (lambda (line)
7334 (customize-face (intern (car (split-string line))))))
7335 (requires-pattern . 3))
7336 "See (info \"(emacs)Faces\")")
7337 ;; (anything 'anything-c-source-customize-face)
7339 ;;; Colors browser
7342 (defvar anything-c-source-colors
7343 '((name . "Colors")
7344 (init . (lambda () (unless (anything-candidate-buffer)
7345 (save-selected-window
7346 (list-colors-display))
7347 (anything-candidate-buffer (get-buffer "*Colors*")))))
7348 (candidates-in-buffer)
7349 (get-line . buffer-substring)
7350 (action
7351 ("Copy Name" . (lambda (candidate)
7352 (kill-new (anything-c-colors-get-name candidate))))
7353 ("Copy RGB" . (lambda (candidate)
7354 (kill-new (anything-c-colors-get-rgb candidate))))
7355 ("Insert Name" . (lambda (candidate)
7356 (with-anything-current-buffer
7357 (insert (anything-c-colors-get-name candidate)))))
7358 ("Insert RGB" . (lambda (candidate)
7359 (with-anything-current-buffer
7360 (insert (anything-c-colors-get-rgb candidate))))))))
7361 ;; (anything 'anything-c-source-colors)
7363 (defun anything-c-colors-get-name (candidate)
7364 "Get color name."
7365 (replace-regexp-in-string
7366 " " ""
7367 (with-temp-buffer
7368 (insert (capitalize candidate))
7369 (goto-char (point-min))
7370 (search-forward-regexp "\\s-\\{2,\\}")
7371 (delete-region (point) (point-max))
7372 (buffer-string))))
7374 (defun anything-c-colors-get-rgb (candidate)
7375 "Get color RGB."
7376 (replace-regexp-in-string
7377 " " ""
7378 (with-temp-buffer
7379 (insert (capitalize candidate))
7380 (goto-char (point-max))
7381 (search-backward-regexp "\\s-\\{2,\\}")
7382 (delete-region (point) (point-min))
7383 (buffer-string))))
7386 ;;;; <Search Engine>
7387 ;;; Tracker desktop search
7388 (defvar anything-c-source-tracker-search
7389 '((name . "Tracker Search")
7390 (candidates . (lambda ()
7391 (start-process "tracker-search-process" nil
7392 "tracker-search"
7393 anything-pattern)))
7394 (type . file)
7395 (requires-pattern . 3)
7396 (delayed))
7397 "Source for retrieving files matching the current input pattern
7398 with the tracker desktop search.")
7399 ;; (anything 'anything-c-source-tracker-search)
7401 ;;; Spotlight (MacOS X desktop search)
7402 (defvar anything-c-source-mac-spotlight
7403 '((name . "mdfind")
7404 (candidates
7405 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7406 (type . file)
7407 (requires-pattern . 3)
7408 (delayed))
7409 "Source for retrieving files via Spotlight's command line
7410 utility mdfind.")
7411 ;; (anything 'anything-c-source-mac-spotlight)
7413 ;;; Picklist
7414 (defvar anything-c-source-picklist
7415 '((name . "Picklist")
7416 (candidates . (lambda () (mapcar 'car picklist-list)))
7417 (type . file)))
7418 ;; (anything 'anything-c-source-picklist)
7422 ;;; Kill ring
7425 (defvar anything-c-source-kill-ring
7426 '((name . "Kill Ring")
7427 (init . (lambda () (anything-attrset 'last-command last-command)))
7428 (candidates . anything-c-kill-ring-candidates)
7429 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7430 (action . anything-c-kill-ring-action)
7431 (last-command)
7432 (migemo)
7433 (multiline))
7434 "Source for browse and insert contents of kill-ring.")
7436 (defun anything-c-kill-ring-candidates ()
7437 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7438 unless (or (< (length kill) anything-kill-ring-threshold)
7439 (string-match "^[\\s\\t]+$" kill))
7440 collect kill))
7442 (defun anything-c-kill-ring-transformer (candidates source)
7443 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7444 (loop for i in candidates
7445 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7446 if (and anything-c-kill-ring-max-lines-number
7447 (> nlines anything-c-kill-ring-max-lines-number))
7448 collect (cons
7449 (with-temp-buffer
7450 (insert i)
7451 (goto-char (point-min))
7452 (concat
7453 (buffer-substring
7454 (point-min)
7455 (save-excursion
7456 (forward-line anything-c-kill-ring-max-lines-number)
7457 (point)))
7458 "[...]")) i)
7459 else collect i))
7461 (defun anything-c-kill-ring-action (str)
7462 "Insert STR in `kill-ring' and set STR to the head.
7463 If this action is executed just after `yank',
7464 replace with STR as yanked string."
7465 (setq kill-ring (delete str kill-ring))
7466 (if (not (eq (anything-attr 'last-command) 'yank))
7467 (insert-for-yank str)
7468 ;; from `yank-pop'
7469 (let ((inhibit-read-only t)
7470 (before (< (point) (mark t))))
7471 (if before
7472 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7473 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7474 (setq yank-undo-function nil)
7475 (set-marker (mark-marker) (point) (current-buffer))
7476 (insert-for-yank str)
7477 ;; Set the window start back where it was in the yank command,
7478 ;; if possible.
7479 (set-window-start (selected-window) yank-window-start t)
7480 (if before
7481 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7482 ;; It is cleaner to avoid activation, even though the command
7483 ;; loop would deactivate the mark because we inserted text.
7484 (goto-char (prog1 (mark t)
7485 (set-marker (mark-marker) (point) (current-buffer)))))))
7486 (kill-new str))
7488 ;; (anything 'anything-c-source-kill-ring)
7491 ;;;; <Mark ring>
7492 ;; DO NOT include these sources in `anything-sources' use
7493 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7494 ;; `anything-all-mark-rings' instead.
7496 (defun anything-c-source-mark-ring-candidates ()
7497 (flet ((get-marks (pos)
7498 (save-excursion
7499 (goto-char pos)
7500 (beginning-of-line)
7501 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7502 (when (string= "" line)
7503 (setq line "<EMPTY LINE>"))
7504 (format "%7d: %s" (line-number-at-pos) line)))))
7505 (with-anything-current-buffer
7506 (loop
7507 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7508 with recip = nil
7509 for i in marks
7510 for m = (get-marks i)
7511 unless (member m recip)
7512 collect m into recip
7513 finally return recip))))
7515 (defvar anything-mark-ring-cache nil)
7516 (defvar anything-c-source-mark-ring
7517 '((name . "mark-ring")
7518 (init . (lambda ()
7519 (setq anything-mark-ring-cache
7520 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7521 (candidates . (lambda ()
7522 (anything-aif anything-mark-ring-cache
7523 it)))
7524 (action . (("Goto line"
7525 . (lambda (candidate)
7526 (anything-goto-line (string-to-number candidate))))))
7527 (persistent-action . (lambda (candidate)
7528 (anything-goto-line (string-to-number candidate))
7529 (anything-match-line-color-current-line)))
7530 (persistent-help . "Show this line")))
7532 ;; (anything 'anything-c-source-mark-ring)
7534 ;;; Global-mark-ring
7535 (defvar anything-c-source-global-mark-ring
7536 '((name . "global-mark-ring")
7537 (candidates . anything-c-source-global-mark-ring-candidates)
7538 (action . (("Goto line"
7539 . (lambda (candidate)
7540 (let ((items (split-string candidate ":")))
7541 (anything-c-switch-to-buffer (second items))
7542 (anything-goto-line (string-to-number (car items))))))))
7543 (persistent-action . (lambda (candidate)
7544 (let ((items (split-string candidate ":")))
7545 (anything-c-switch-to-buffer (second items))
7546 (anything-goto-line (string-to-number (car items)))
7547 (anything-match-line-color-current-line))))
7548 (persistent-help . "Show this line")))
7550 (defun anything-c-source-global-mark-ring-candidates ()
7551 (flet ((buf-fn (m)
7552 (with-current-buffer (marker-buffer m)
7553 (goto-char m)
7554 (beginning-of-line)
7555 (let (line)
7556 (if (string= "" line)
7557 (setq line "<EMPTY LINE>")
7558 (setq line (car (split-string (thing-at-point 'line)
7559 "[\n\r]"))))
7560 (format "%7d:%s: %s"
7561 (line-number-at-pos) (marker-buffer m) line)))))
7562 (loop
7563 with marks = global-mark-ring
7564 with recip = nil
7565 for i in marks
7566 for gm = (unless (or (string-match
7567 "^ " (format "%s" (marker-buffer i)))
7568 (null (marker-buffer i)))
7569 (buf-fn i))
7570 when (and gm (not (member gm recip)))
7571 collect gm into recip
7572 finally return recip)))
7574 ;; (anything 'anything-c-source-global-mark-ring)
7577 ;;;; <Register>
7578 ;;; Insert from register
7579 (defvar anything-c-source-register
7580 '((name . "Registers")
7581 (candidates . anything-c-register-candidates)
7582 (action-transformer . anything-c-register-action-transformer)
7583 (multiline)
7584 (action))
7585 "See (info \"(emacs)Registers\")")
7587 (defun anything-c-register-candidates ()
7588 "Collecting register contents and appropriate commands."
7589 (loop for (char . val) in register-alist
7590 for key = (single-key-description char)
7591 for string-actions =
7592 (cond
7593 ((numberp val)
7594 (list (int-to-string val)
7595 'insert-register
7596 'increment-register))
7597 ((markerp val)
7598 (let ((buf (marker-buffer val)))
7599 (if (null buf)
7600 (list "a marker in no buffer")
7601 (list (concat
7602 "a buffer position:"
7603 (buffer-name buf)
7604 ", position "
7605 (int-to-string (marker-position val)))
7606 'jump-to-register
7607 'insert-register))))
7608 ((and (consp val) (window-configuration-p (car val)))
7609 (list "window configuration."
7610 'jump-to-register))
7611 ((and (consp val) (frame-configuration-p (car val)))
7612 (list "frame configuration."
7613 'jump-to-register))
7614 ((and (consp val) (eq (car val) 'file))
7615 (list (concat "file:"
7616 (prin1-to-string (cdr val))
7617 ".")
7618 'jump-to-register))
7619 ((and (consp val) (eq (car val) 'file-query))
7620 (list (concat "file:a file-query reference: file "
7621 (car (cdr val))
7622 ", position "
7623 (int-to-string (car (cdr (cdr val))))
7624 ".")
7625 'jump-to-register))
7626 ((consp val)
7627 (let ((lines (format "%4d" (length val))))
7628 (list (format "%s: %s\n" lines
7629 (truncate-string-to-width
7630 (mapconcat 'identity (list (car val))
7631 ;; (mapconcat (lambda (y) y) val
7632 "^J") (- (window-width) 15)))
7633 'insert-register)))
7634 ((stringp val)
7635 (list ;; without properties
7636 (substring-no-properties val)
7637 'insert-register
7638 'append-to-register
7639 'prepend-to-register))
7641 "GARBAGE!"))
7642 collect (cons (format "register %3s: %s" key (car string-actions))
7643 (cons char (cdr string-actions)))))
7645 (defun anything-c-register-action-transformer (actions register-and-functions)
7646 "Decide actions by the contents of register."
7647 (loop with func-actions =
7648 '((insert-register
7649 "Insert Register" .
7650 (lambda (c) (insert-register (car c))))
7651 (jump-to-register
7652 "Jump to Register" .
7653 (lambda (c) (jump-to-register (car c))))
7654 (append-to-register
7655 "Append Region to Register" .
7656 (lambda (c) (append-to-register
7657 (car c) (region-beginning) (region-end))))
7658 (prepend-to-register
7659 "Prepend Region to Register" .
7660 (lambda (c) (prepend-to-register
7661 (car c) (region-beginning) (region-end))))
7662 (increment-register
7663 "Increment Prefix Arg to Register" .
7664 (lambda (c) (increment-register
7665 anything-current-prefix-arg (car c)))))
7666 for func in (cdr register-and-functions)
7667 for cell = (assq func func-actions)
7668 when cell
7669 collect (cdr cell)))
7671 ;; (anything 'anything-c-source-register)
7674 ;;; Latex completion
7675 (defun anything-c-latex-math-candidates ()
7676 "Collect candidates for latex math completion."
7677 (declare (special LaTeX-math-menu))
7678 (loop for i in (cddr LaTeX-math-menu)
7679 for elm = (loop for s in i when (vectorp s)
7680 collect (cons (aref s 0) (aref s 1)))
7681 append elm))
7683 (defvar anything-c-source-latex-math
7684 '((name . "Latex Math Menu")
7685 (init . (lambda ()
7686 (with-anything-current-buffer
7687 (LaTeX-math-mode 1))))
7688 (candidate-number-limit . 9999)
7689 (candidates . anything-c-latex-math-candidates)
7690 (action . (lambda (candidate)
7691 (call-interactively candidate)))))
7694 ;;;; <Headline Extraction>
7695 (defvar anything-c-source-fixme
7696 '((name . "TODO/FIXME/DRY comments")
7697 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7698 (adjust)
7699 (recenter))
7700 "Show TODO/FIXME/DRY comments in current file.")
7701 ;; (anything 'anything-c-source-fixme)
7703 (defvar anything-c-source-rd-headline
7704 '((name . "RD HeadLine")
7705 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7706 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7707 (migemo)
7708 (subexp . 1))
7709 "Show RD headlines.
7711 RD is Ruby's POD.
7712 http://en.wikipedia.org/wiki/Ruby_Document_format")
7713 ;; (anything 'anything-c-source-rd-headline)
7715 (defvar anything-c-source-oddmuse-headline
7716 '((name . "Oddmuse HeadLine")
7717 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7718 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7719 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7720 (migemo)
7721 (subexp . 1))
7722 "Show Oddmuse headlines, such as EmacsWiki.")
7723 ;; (anything 'anything-c-source-oddmuse-headline)
7725 (defvar anything-c-source-emacs-source-defun
7726 '((name . "Emacs Source DEFUN")
7727 (headline . "DEFUN\\|DEFVAR")
7728 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7729 (or buffer-file-name ""))))
7730 "Show DEFUN/DEFVAR in Emacs C source file.")
7731 ;; (anything 'anything-c-source-emacs-source-defun)
7733 (defvar anything-c-source-emacs-lisp-expectations
7734 '((name . "Emacs Lisp Expectations")
7735 (headline . "(desc[ ]\\|(expectations")
7736 (condition . (eq major-mode 'emacs-lisp-mode)))
7737 "Show descriptions (desc) in Emacs Lisp Expectations.
7739 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7740 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7742 (defvar anything-c-source-emacs-lisp-toplevels
7743 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7744 (headline . "^(\\|(@\\*\\|^;;;;")
7745 (get-line . buffer-substring)
7746 (condition . (eq major-mode 'emacs-lisp-mode))
7747 (adjust))
7748 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7749 linkd.el is optional because linkd stars are extracted by regexp.
7750 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7751 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7754 ;;; Anything yaoddmuse
7756 ;; Be sure to have yaoddmuse.el installed
7757 ;; install-elisp may be required if you want to install elisp file from here.
7758 (defvar anything-yaoddmuse-use-cache-file nil)
7759 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7760 (defvar anything-c-yaoddmuse-ew-cache nil)
7762 (defun anything-yaoddmuse-get-candidates ()
7763 (declare (special yaoddmuse-pages-hash))
7764 (if anything-yaoddmuse-use-cache-file
7765 (ignore-errors
7766 (unless anything-c-yaoddmuse-ew-cache
7767 (load anything-c-yaoddmuse-cache-file)
7768 (setq anything-c-yaoddmuse-ew-cache
7769 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7770 anything-c-yaoddmuse-ew-cache)
7771 (yaoddmuse-update-pagename t)
7772 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7774 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7775 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7776 (candidates . anything-yaoddmuse-get-candidates)
7777 (action . (("Edit page" . (lambda (candidate)
7778 (yaoddmuse-edit "EmacsWiki" candidate)))
7779 ("Browse page"
7780 . (lambda (candidate)
7781 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7782 ("Browse page other window"
7783 . (lambda (candidate)
7784 (if (one-window-p)
7785 (split-window-vertically))
7786 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7787 ("Browse diff"
7788 . (lambda (candidate)
7789 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7790 ("Copy URL"
7791 . (lambda (candidate)
7792 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7793 (message "Have copy page %s's URL to yank." candidate)))
7794 ("Create page"
7795 . (lambda (candidate)
7796 (yaoddmuse-edit "EmacsWiki" anything-input)))
7797 ("Update cache"
7798 . (lambda (candidate)
7799 (if anything-yaoddmuse-use-cache-file
7800 (progn
7801 (anything-yaoddmuse-cache-pages t)
7802 (setq anything-c-yaoddmuse-ew-cache
7803 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7804 (yaoddmuse-update-pagename))))))
7805 (action-transformer anything-c-yaoddmuse-action-transformer))
7806 "Needs yaoddmuse.el.
7808 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7810 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7812 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7813 '((name . "Yaoddmuse Post library (EmacsWiki)")
7814 (init . (anything-yaoddmuse-init))
7815 (candidates-in-buffer)
7816 (action . (("Post library and Browse"
7817 . (lambda (candidate)
7818 (yaoddmuse-post-file
7819 (find-library-name candidate)
7820 "EmacsWiki"
7821 (file-name-nondirectory (find-library-name candidate))
7822 nil t)))
7823 ("Post library"
7824 . (lambda (candidate)
7825 (yaoddmuse-post-file
7826 (find-library-name candidate)
7827 "EmacsWiki"
7828 (file-name-nondirectory
7829 (find-library-name candidate))))))))
7830 "Needs yaoddmuse.el.
7832 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7834 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7836 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7837 "Allow the use of `install-elisp' only on elisp files."
7838 (if (string-match "\.el$" candidate)
7839 (append actions '(("Install Elisp"
7840 . (lambda (elm)
7841 (install-elisp-from-emacswiki elm)))))
7842 actions))
7844 ;;;###autoload
7845 (defun anything-yaoddmuse-cache-pages (&optional load)
7846 "Fetch the list of files on emacswiki and create cache file.
7847 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7848 (interactive)
7849 (declare (special yaoddmuse-pages-hash))
7850 (yaoddmuse-update-pagename)
7851 (save-excursion
7852 (find-file anything-c-yaoddmuse-cache-file)
7853 (erase-buffer)
7854 (insert "(puthash \"EmacsWiki\" '(")
7855 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7857 (insert (concat "(\"" (car i) "\") ")))
7858 (insert ") yaoddmuse-pages-hash)\n")
7859 (save-buffer)
7860 (kill-buffer (current-buffer))
7861 (when (or current-prefix-arg
7862 load)
7863 (load anything-c-yaoddmuse-cache-file))))
7865 (defun anything-yaoddmuse-init ()
7866 "Init anything buffer status."
7867 (let ((anything-buffer (anything-candidate-buffer 'global))
7868 (library-list (yaoddmuse-get-library-list)))
7869 (with-current-buffer anything-buffer
7870 ;; Insert library name.
7871 (dolist (library library-list)
7872 (insert (format "%s\n" library)))
7873 ;; Sort lines.
7874 (sort-lines nil (point-min) (point-max)))))
7877 ;;; Eev anchors
7878 (defvar anything-c-source-eev-anchor
7879 '((name . "Anchors")
7880 (candidates
7881 . (lambda ()
7882 (ignore-errors
7883 (with-anything-current-buffer
7884 (loop initially (goto-char (point-min))
7885 while (re-search-forward
7886 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7887 for anchor = (match-string-no-properties 1)
7888 collect (cons (format "%5d:%s"
7889 (line-number-at-pos (match-beginning 0))
7890 (format ee-anchor-format anchor))
7891 anchor))))))
7892 (persistent-action . (lambda (item)
7893 (ee-to item)
7894 (anything-match-line-color-current-line)))
7895 (persistent-help . "Show this entry")
7896 (action . (("Goto link" . ee-to)))))
7897 ;; (anything 'anything-c-source-eev-anchor)
7900 ;;; Org headlines
7903 (defvar anything-c-source-org-headline
7904 `((name . "Org HeadLine")
7905 (headline
7906 ,@(mapcar
7907 (lambda (num)
7908 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7909 num))
7910 (number-sequence 1 8)))
7911 (condition . (eq major-mode 'org-mode))
7912 (migemo)
7913 (subexp . 1)
7914 (persistent-action . (lambda (elm)
7915 (anything-c-action-line-goto elm)
7916 (org-cycle)))
7917 (action-transformer
7918 . (lambda (actions candidate)
7919 '(("Go to Line" . anything-c-action-line-goto)
7920 ("Refile to this Headline" . anything-c-org-headline-refile)
7921 ("Insert Link to This Headline"
7922 . anything-c-org-headline-insert-link-to-headline)))))
7923 "Show Org headlines.
7924 org-mode is very very much extended text-mode/outline-mode.
7926 See (find-library \"org.el\")
7927 See http://orgmode.org for the latest version.")
7928 ;; (anything 'anything-c-source-org-headline)
7930 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7931 (insert
7932 (save-excursion
7933 (anything-goto-line (car lineno-and-content))
7934 (and (looking-at org-complex-heading-regexp)
7935 (org-make-link-string (concat "*" (match-string 4)))))))
7937 (defun anything-c-org-headline-refile (lineno-and-content)
7938 "Refile current org entry to LINENO-AND-CONTENT."
7939 (with-anything-current-buffer
7940 (org-cut-subtree)
7941 (anything-goto-line (car lineno-and-content))
7942 (org-end-of-subtree t t)
7943 (let ((org-yank-adjusted-subtrees t))
7944 (org-yank))))
7947 ;;; Org keywords
7950 (defvar anything-c-source-org-keywords
7951 '((name . "Org Keywords")
7952 (init . anything-c-org-keywords-init)
7953 (candidates . anything-c-org-keywords-candidates)
7954 (action . anything-c-org-keywords-insert)
7955 (persistent-action . anything-c-org-keywords-show-help)
7956 (persistent-help . "Show an example and info page to describe this keyword.")
7957 (keywords-examples)
7958 (keywords)))
7959 ;; (anything 'anything-c-source-org-keywords)
7961 (defvar anything-c-org-keywords-info-location
7962 '(("#+TITLE:" . "(org)Export options")
7963 ("#+AUTHOR:" . "(org)Export options")
7964 ("#+DATE:" . "(org)Export options")
7965 ("#+EMAIL:" . "(org)Export options")
7966 ("#+DESCRIPTION:" . "(org)Export options")
7967 ("#+KEYWORDS:" . "(org)Export options")
7968 ("#+LANGUAGE:" . "(org)Export options")
7969 ("#+TEXT:" . "(org)Export options")
7970 ("#+TEXT:" . "(org)Export options")
7971 ("#+OPTIONS:" . "(org)Export options")
7972 ("#+BIND:" . "(org)Export options")
7973 ("#+LINK_UP:" . "(org)Export options")
7974 ("#+LINK_HOME:" . "(org)Export options")
7975 ("#+LATEX_HEADER:" . "(org)Export options")
7976 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7977 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7978 ("#+INFOJS_OPT" . "(org)Javascript support")
7979 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7980 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7981 ("#+ORGTBL" . "(org)Radio tables")
7982 ("#+HTML:" . "(org)Quoting HTML tags")
7983 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7984 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7985 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7986 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7987 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7988 ("#+BEGIN_SRC" . "(org)Literal examples")
7989 ("#+CAPTION" . "(org)Tables in HTML export")
7990 ("#+LABEL" . "(org)Tables in LaTeX export")
7991 ("#+ATTR_HTML" . "(org)Links")
7992 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7994 (defun anything-c-org-keywords-init ()
7995 (unless (anything-attr 'keywords-examples)
7996 (require 'org)
7997 (anything-attrset 'keywords-examples
7998 (append
7999 (mapcar
8000 (lambda (x)
8001 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8002 (cons (match-string 2 x) (match-string 1 x)))
8003 (org-split-string (org-get-current-options) "\n"))
8004 (mapcar 'list org-additional-option-like-keywords)))
8005 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
8007 (defun anything-c-org-keywords-candidates ()
8008 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
8009 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
8010 (anything-attr 'keywords)))
8012 (defun anything-c-org-keywords-insert (keyword)
8013 (cond ((and (string-match "BEGIN" keyword)
8014 (anything-region-active-p))
8015 (let ((beg (region-beginning))
8016 (end (region-end)))
8017 (goto-char end)
8018 (insert "\n#+" (replace-regexp-in-string
8019 "BEGIN" "END" keyword) "\n")
8020 (goto-char beg)
8021 (insert "#+" keyword " ")
8022 (save-excursion (insert "\n"))))
8023 ((string-match "BEGIN" keyword)
8024 (insert "#+" keyword " ")
8025 (save-excursion
8026 (insert "\n#+" (replace-regexp-in-string
8027 "BEGIN" "END" keyword) "\n")))
8028 (t (insert "#+" keyword " "))))
8030 (defun anything-c-org-keywords-show-help (keyword)
8031 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
8032 "(org)In-buffer settings"))
8033 (search-forward (concat "#+" keyword) nil t)
8034 (anything-persistent-highlight-point)
8035 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8039 ;;; bbdb
8042 (defvar bbdb-records)
8043 (defvar bbdb-buffer-name)
8045 (defun anything-c-bbdb-candidates ()
8046 "Return a list of all names in the bbdb database. The format
8047 is \"Firstname Lastname\"."
8048 (mapcar (lambda (bbdb-record)
8049 (replace-regexp-in-string
8050 "\\s-+$" ""
8051 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8052 (bbdb-records)))
8054 (defun anything-c-bbdb-create-contact (actions candidate)
8055 "Action transformer that returns only an entry to add the
8056 current `anything-pattern' as new contact. All other actions are
8057 removed."
8058 (if (string= candidate "*Add to contacts*")
8059 '(("Add to contacts" . (lambda (actions)
8060 (bbdb-create-internal
8061 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8062 (read-from-minibuffer "Company: ")
8063 (read-from-minibuffer "Email: ")
8066 (read-from-minibuffer "Note: ")))))
8067 actions))
8069 (defun anything-c-bbdb-get-record (candidate)
8070 "Return record that match CANDIDATE."
8071 (bbdb candidate nil)
8072 (set-buffer "*BBDB*")
8073 (bbdb-current-record))
8075 (defvar anything-c-bbdb-name nil
8076 "Only for internal use.")
8078 (defvar anything-c-source-bbdb
8079 '((name . "BBDB")
8080 (candidates . anything-c-bbdb-candidates)
8081 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8082 ("View person's data" . anything-c-bbdb-view-person-action))
8083 (filtered-candidate-transformer . (lambda (candidates source)
8084 (setq anything-c-bbdb-name anything-pattern)
8085 (if (not candidates)
8086 (list "*Add to contacts*")
8087 candidates)))
8088 (action-transformer . (lambda (actions candidate)
8089 (anything-c-bbdb-create-contact actions candidate))))
8090 "Needs BBDB.
8092 http://bbdb.sourceforge.net/")
8093 ;; (anything 'anything-c-source-bbdb)
8095 (defun anything-c-bbdb-view-person-action (candidate)
8096 "View BBDB data of single CANDIDATE or marked candidates."
8097 (anything-aif (anything-marked-candidates)
8098 (let ((bbdb-append-records (length it)))
8099 (dolist (i it)
8100 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8101 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8103 (defun anything-c-bbdb-collect-mail-addresses ()
8104 "Return a list of all mail addresses of records in bbdb buffer."
8105 (with-current-buffer bbdb-buffer-name
8106 (loop for i in bbdb-records
8107 if (bbdb-record-net (car i))
8108 collect (bbdb-dwim-net-address (car i)))))
8110 (defun anything-c-bbdb-compose-mail (candidate)
8111 "Compose a mail with all records of bbdb buffer."
8112 (anything-c-bbdb-view-person-action candidate)
8113 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8114 (address-str (mapconcat 'identity address-list ",\n ")))
8115 (compose-mail address-str)))
8118 ;;; Evaluation Result
8121 ;; Internal
8122 (defvar anything-eldoc-active-minibuffers-list nil)
8123 (defvar anything-eval-expression-input-history nil)
8125 (defvar anything-c-source-evaluation-result
8126 '((name . "Evaluation Result")
8127 (disable-shortcuts)
8128 (dummy)
8129 (multiline)
8130 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8131 (filtered-candidate-transformer . (lambda (candidates source)
8132 (list
8133 (condition-case nil
8134 (with-anything-current-buffer
8135 (pp-to-string
8136 (eval (read anything-pattern))))
8137 (error "Error")))))
8138 (action . (("Copy result to kill-ring" . (lambda (candidate)
8139 (with-current-buffer anything-buffer
8140 (let ((end (save-excursion
8141 (goto-char (point-max))
8142 (search-backward "\n")
8143 (point))))
8144 (kill-region (point) end)))))
8145 ("copy sexp to kill-ring" . (lambda (candidate)
8146 (kill-new anything-input)))))))
8147 ;; (anything 'anything-c-source-evaluation-result)
8149 (defun anything-eval-new-line-and-indent ()
8150 (interactive)
8151 (newline) (lisp-indent-line))
8153 (defun anything-eldoc-store-minibuffer ()
8154 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8155 (with-selected-window (minibuffer-window)
8156 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8158 (defun anything-eldoc-show-in-eval ()
8159 "Return eldoc in mode-line for current minibuffer input."
8160 (let ((buf (with-selected-window (minibuffer-window)
8161 (buffer-name))))
8162 (when (member buf anything-eldoc-active-minibuffers-list)
8163 (let* ((str-all (with-current-buffer buf
8164 (minibuffer-completion-contents)))
8165 (sym (when str-all
8166 (with-temp-buffer
8167 (insert str-all)
8168 (goto-char (point-max))
8169 (unless (looking-back ")\\|\"") (forward-char -1))
8170 (eldoc-current-symbol))))
8171 (info-fn (eldoc-fnsym-in-current-sexp))
8172 (doc (or (eldoc-get-var-docstring sym)
8173 (eldoc-get-fnsym-args-string
8174 (car info-fn) (cadr info-fn)))))
8175 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8177 (defun anything-c-show-info-in-mode-line (str)
8178 "Display string STR in mode-line."
8179 (save-selected-window
8180 (with-current-buffer anything-buffer
8181 (let ((mode-line-format (concat " " str)))
8182 (force-mode-line-update)
8183 (sit-for anything-c-show-info-in-mode-line-delay))
8184 (force-mode-line-update))))
8186 ;;; Calculation Result
8189 (defvar anything-c-source-calculation-result
8190 '((name . "Calculation Result")
8191 (dummy)
8192 (filtered-candidate-transformer . (lambda (candidates source)
8193 (list
8194 (condition-case nil
8195 (calc-eval anything-pattern)
8196 (error "error")))))
8197 (action ("Copy result to kill-ring" . kill-new))))
8198 ;; (anything 'anything-c-source-calculation-result)
8201 ;;; Google Suggestions
8204 ;; Internal
8205 (defvar anything-ggs-max-length-real-flag 0)
8206 (defvar anything-ggs-max-length-num-flag 0)
8208 (defun anything-c-google-suggest-fetch (input)
8209 "Fetch suggestions for INPUT from XML buffer.
8210 Return an alist with elements like (data . number_results)."
8211 (setq anything-ggs-max-length-real-flag 0
8212 anything-ggs-max-length-num-flag 0)
8213 (let ((request (concat anything-c-google-suggest-url
8214 (url-hexify-string input))))
8215 (flet ((fetch ()
8216 (loop
8217 with result-alist = (xml-get-children
8218 (car (xml-parse-region
8219 (point-min) (point-max)))
8220 'CompleteSuggestion)
8221 for i in result-alist
8222 for data = (cdr (caadr (assoc 'suggestion i)))
8223 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8224 for lqueries = (length (anything-c-ggs-set-number-result
8225 nqueries))
8226 for ldata = (length data)
8228 (progn
8229 (when (> ldata anything-ggs-max-length-real-flag)
8230 (setq anything-ggs-max-length-real-flag ldata))
8231 (when (> lqueries anything-ggs-max-length-num-flag)
8232 (setq anything-ggs-max-length-num-flag lqueries)))
8233 collect (cons data nqueries) into cont
8234 finally return cont)))
8235 (if anything-google-suggest-use-curl-p
8236 (with-temp-buffer
8237 (call-process "curl" nil t nil request)
8238 (fetch))
8239 (with-current-buffer
8240 (url-retrieve-synchronously request)
8241 (fetch))))))
8243 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8244 "Set candidates with result and number of google results found."
8245 (let ((suggestions
8246 (loop with suggested-results = (anything-c-google-suggest-fetch
8247 (or (and request-prefix
8248 (concat request-prefix " " anything-pattern))
8249 anything-pattern))
8250 for (real . numresult) in suggested-results
8251 ;; Prepare number of results with ","
8252 for fnumresult = (anything-c-ggs-set-number-result numresult)
8253 ;; Calculate number of spaces to add before fnumresult
8254 ;; if it is smaller than longest result
8255 ;; `anything-ggs-max-length-num-flag'.
8256 ;; e.g 1,234,567
8257 ;; 345,678
8258 ;; To be sure it is aligned properly.
8259 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8260 (- anything-ggs-max-length-num-flag (length fnumresult))
8262 ;; Add now the spaces before fnumresult.
8263 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8264 for interval = (- anything-ggs-max-length-real-flag (length real))
8265 for spaces = (make-string (+ 2 interval) ? )
8266 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8267 collect (cons display real))))
8268 (if (loop for (disp . dat) in suggestions
8269 thereis (equal dat anything-pattern))
8270 suggestions
8271 ;; if there is no suggestion exactly matching the input then
8272 ;; prepend a Search on Google item to the list
8273 (append
8274 suggestions
8275 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8276 anything-input))))))
8278 (defun anything-c-ggs-set-number-result (num)
8279 (if num
8280 (progn
8281 (and (numberp num) (setq num (number-to-string num)))
8282 (loop for i in (reverse (split-string num "" t))
8283 for count from 1
8284 append (list i) into C
8285 when (= count 3)
8286 append (list ",") into C
8287 and do (setq count 0)
8288 finally return
8289 (replace-regexp-in-string
8290 "^," "" (mapconcat 'identity (reverse C) ""))))
8291 "?"))
8293 (defvar anything-c-google-suggest-default-browser-function nil
8294 "*The browse url function you prefer to use with google suggest.
8295 When nil, use the first browser function available
8296 See `anything-browse-url-default-browser-alist'.")
8298 (defun anything-c-google-suggest-action (candidate)
8299 "Default action to jump to a google suggested candidate."
8300 (let ((arg (concat anything-c-google-suggest-search-url
8301 (url-hexify-string candidate))))
8302 (anything-aif anything-c-google-suggest-default-browser-function
8303 (funcall it arg)
8304 (anything-c-browse-url arg))))
8306 (defvar anything-c-google-suggest-default-function
8307 'anything-c-google-suggest-set-candidates
8308 "Default function to use in anything google suggest.")
8310 (defvar anything-c-source-google-suggest
8311 '((name . "Google Suggest")
8312 (candidates . (lambda ()
8313 (funcall anything-c-google-suggest-default-function)))
8314 (action . (("Google Search" . anything-c-google-suggest-action)))
8315 (volatile)
8316 (requires-pattern . 3)
8317 (delayed)))
8319 (defun anything-c-google-suggest-emacs-lisp ()
8320 "Try to emacs lisp complete with google suggestions."
8321 (anything-c-google-suggest-set-candidates "emacs lisp"))
8323 ;; (anything 'anything-c-source-google-suggest)
8325 ;;; Yahoo suggestions
8328 (defun anything-c-yahoo-suggest-fetch (input)
8329 "Fetch Yahoo suggestions for INPUT from XML buffer.
8330 Return an alist with elements like (data . number_results)."
8331 (let ((request (concat anything-c-yahoo-suggest-url
8332 (url-hexify-string input))))
8333 (flet ((fetch ()
8334 (loop
8335 with result-alist = (xml-get-children
8336 (car (xml-parse-region (point-min) (point-max)))
8337 'Result)
8338 for i in result-alist
8339 collect (caddr i))))
8340 (with-current-buffer
8341 (url-retrieve-synchronously request)
8342 (fetch)))))
8344 (defun anything-c-yahoo-suggest-set-candidates ()
8345 "Set candidates with Yahoo results found."
8346 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8347 (or suggestions
8348 (append
8349 suggestions
8350 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8351 anything-input))))))
8353 (defun anything-c-yahoo-suggest-action (candidate)
8354 "Default action to jump to a Yahoo suggested candidate."
8355 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8356 (url-hexify-string candidate))))
8358 (defvar anything-c-source-yahoo-suggest
8359 '((name . "Yahoo Suggest")
8360 (candidates . anything-c-yahoo-suggest-set-candidates)
8361 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8362 (volatile)
8363 (requires-pattern . 3)
8364 (delayed)))
8366 ;; (anything 'anything-c-source-yahoo-suggest)
8369 ;;; Web browser functions.
8372 (require 'browse-url)
8373 ;; If default setting of `w3m-command' is not
8374 ;; what you want you and you modify it, you will have to reeval
8375 ;; also `anything-browse-url-default-browser-alist'.
8376 (defvar w3m-command "/usr/bin/w3m")
8377 (defvar anything-c-home-url "http://www.google.fr"
8378 "*Default url to use as home url.")
8380 (defvar ac-browse-url-chromium-program "chromium-browser")
8381 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8382 (defvar anything-browse-url-default-browser-alist
8383 `((,w3m-command . w3m-browse-url)
8384 (,browse-url-firefox-program . browse-url-firefox)
8385 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8386 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8387 (,browse-url-kde-program . browse-url-kde)
8388 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8389 (,browse-url-mozilla-program . browse-url-mozilla)
8390 (,browse-url-galeon-program . browse-url-galeon)
8391 (,browse-url-netscape-program . browse-url-netscape)
8392 (,browse-url-mosaic-program . browse-url-mosaic)
8393 (,browse-url-xterm-program . browse-url-text-xterm))
8394 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8396 (defun* anything-c-generic-browser (url name &rest args)
8397 "Browse URL with NAME browser."
8398 (let ((proc (concat name " " url)))
8399 (message "Starting %s..." name)
8400 (apply 'start-process proc nil name
8401 (append args (list url)))
8402 (set-process-sentinel
8403 (get-process proc)
8404 #'(lambda (process event)
8405 (when (string= event "finished\n")
8406 (message "%s process %s" process event))))))
8408 (defun ac-browse-url-chromium (url)
8409 "Browse URL with google chrome browser."
8410 (interactive "sURL: ")
8411 (anything-c-generic-browser
8412 url ac-browse-url-chromium-program))
8414 (defun ac-browse-url-uzbl (url &optional ignore)
8415 "Browse URL with uzbl browser."
8416 (interactive "sURL: ")
8417 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8419 (defun anything-browse-url-default-browser (url &rest args)
8420 "Find the first available browser and ask it to load URL."
8421 (let ((default-browser-fn
8422 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8423 thereis (and exe (executable-find exe) fn))))
8424 (if default-browser-fn
8425 (apply default-browser-fn url args)
8426 (error "No usable browser found"))))
8428 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8429 "Default command to browse URL."
8430 (if browse-url-browser-function
8431 (browse-url url)
8432 (anything-browse-url-default-browser url)))
8435 ;;; Surfraw
8437 ;; Need external program surfraw.
8438 ;; <http://surfraw.alioth.debian.org/>
8440 (defvar anything-surfraw-default-browser-function nil
8441 "*The browse url function you prefer to use with surfraw.
8442 When nil, fallback to `browse-url-browser-function'.")
8444 ;; Internal
8445 (defvar anything-surfraw-engines-history nil)
8446 (defvar anything-surfraw-input-history nil)
8448 (defun anything-c-build-elvi-list ()
8449 "Return list of all engines and descriptions handled by surfraw."
8450 (cdr
8451 (with-temp-buffer
8452 (call-process "surfraw" nil t nil
8453 "-elvi")
8454 (split-string (buffer-string) "\n"))))
8457 ;;; Emms
8460 (defun anything-emms-stream-edit-bookmark (elm)
8461 "Change the information of current emms-stream bookmark from anything."
8462 (declare (special emms-stream-list))
8463 (let* ((cur-buf anything-current-buffer)
8464 (bookmark (assoc elm emms-stream-list))
8465 (name (read-from-minibuffer "Description: "
8466 (nth 0 bookmark)))
8467 (url (read-from-minibuffer "URL: "
8468 (nth 1 bookmark)))
8469 (fd (read-from-minibuffer "Feed Descriptor: "
8470 (int-to-string (nth 2 bookmark))))
8471 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8472 (format "%s" (car (last bookmark))))))
8473 (save-excursion
8474 (emms-streams)
8475 (when (re-search-forward (concat "^" name) nil t)
8476 (beginning-of-line)
8477 (emms-stream-delete-bookmark)
8478 (emms-stream-add-bookmark name url (string-to-number fd) type)
8479 (emms-stream-save-bookmarks-file)
8480 (emms-stream-quit)
8481 (anything-c-switch-to-buffer cur-buf)))))
8483 (defun anything-emms-stream-delete-bookmark (elm)
8484 "Delete an emms-stream bookmark from anything."
8485 (let* ((cur-buf anything-current-buffer)
8486 (bookmark (assoc elm emms-stream-list))
8487 (name (nth 0 bookmark)))
8488 (save-excursion
8489 (emms-streams)
8490 (when (re-search-forward (concat "^" name) nil t)
8491 (beginning-of-line)
8492 (emms-stream-delete-bookmark)
8493 (emms-stream-save-bookmarks-file)
8494 (emms-stream-quit)
8495 (anything-c-switch-to-buffer cur-buf)))))
8497 (defvar anything-c-source-emms-streams
8498 '((name . "Emms Streams")
8499 (init . (lambda ()
8500 (emms-stream-init)))
8501 (candidates . (lambda ()
8502 (declare (special emms-stream-list))
8503 (mapcar 'car emms-stream-list)))
8504 (action . (("Play" . (lambda (elm)
8505 (declare (special emms-stream-list))
8506 (let* ((stream (assoc elm emms-stream-list))
8507 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8508 (url (second stream)))
8509 (funcall fn url))))
8510 ("Delete" . anything-emms-stream-delete-bookmark)
8511 ("Edit" . anything-emms-stream-edit-bookmark)))
8512 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8513 ;; (anything 'anything-c-source-emms-streams)
8515 ;; Don't forget to set `emms-source-file-default-directory'
8516 (defvar anything-c-source-emms-dired
8517 '((name . "Music Directory")
8518 (candidates . (lambda ()
8519 (cddr (directory-files emms-source-file-default-directory))))
8520 (action .
8521 (("Play Directory" . (lambda (item)
8522 (emms-play-directory
8523 (expand-file-name
8524 item
8525 emms-source-file-default-directory))))
8526 ("Open dired in file's directory" . (lambda (item)
8527 (anything-c-open-dired
8528 (expand-file-name
8529 item
8530 emms-source-file-default-directory))))))
8531 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8532 ;; (anything 'anything-c-source-emms-dired)
8535 (defun anything-c-emms-files-modifier (candidates source)
8536 (let ((current-playlist (with-current-emms-playlist
8537 (loop
8538 with cur-list = (emms-playlist-tracks-in-region
8539 (point-min) (point-max))
8540 for i in cur-list
8541 collect (assoc-default 'name i)))))
8542 (loop for i in candidates
8543 if (member (cdr i) current-playlist)
8544 collect (cons (propertize (car i)
8545 'face 'anything-emms-playlist)
8546 (cdr i)) into lis
8547 else collect i into lis
8548 finally return lis)))
8550 (defun anything-c-emms-play-current-playlist ()
8551 "Play current playlist."
8552 (with-current-emms-playlist
8553 (emms-playlist-first)
8554 (emms-playlist-mode-play-smart)))
8556 (defvar anything-c-source-emms-files
8557 '((name . "Emms files")
8558 (candidates . (lambda ()
8559 (loop for v being the hash-values in emms-cache-db
8560 for name = (assoc-default 'name v)
8561 for artist = (or (assoc-default 'info-artist v) "unknown")
8562 for genre = (or (assoc-default 'info-genre v) "unknown")
8563 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8564 for song = (or (assoc-default 'info-title v) "unknown")
8565 for info = (concat artist " - " genre " - " tracknum ": " song)
8566 unless (string-match "^http:" name) collect (cons info name))))
8567 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8568 (action . (("Play file" . emms-play-file)
8569 ("Add to Playlist and play (C-u clear current)"
8570 . (lambda (candidate)
8571 (when anything-current-prefix-arg
8572 (emms-playlist-current-clear))
8573 (emms-playlist-new)
8574 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8575 (unless emms-player-playing-p
8576 (anything-c-emms-play-current-playlist))))))))
8578 ;; (anything 'anything-c-source-emms-files)
8581 ;;; Jabber Contacts (jabber.el)
8582 (defun anything-c-jabber-online-contacts ()
8583 "List online Jabber contacts."
8584 (with-no-warnings
8585 (let (jids)
8586 (dolist (item (jabber-concat-rosters) jids)
8587 (when (get item 'connected)
8588 (push (if (get item 'name)
8589 (cons (get item 'name) item)
8590 (cons (symbol-name item) item)) jids))))))
8592 (defvar anything-c-source-jabber-contacts
8593 '((name . "Jabber Contacts")
8594 (init . (lambda () (require 'jabber)))
8595 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8596 (action . (lambda (x)
8597 (jabber-chat-with
8598 (jabber-read-account)
8599 (symbol-name
8600 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8601 ;; (anything 'anything-c-source-jabber-contacts)
8605 ;;; Call source.
8606 (defvar anything-source-select-buffer "*anything source select*")
8607 (defvar anything-c-source-call-source
8608 `((name . "Call anything source")
8609 (candidate-number-limit)
8610 (candidates
8611 . (lambda ()
8612 (loop for vname in (all-completions "anything-c-source-" obarray)
8613 for var = (intern vname)
8614 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8615 if name collect
8616 (cons (format "%s `%s'"
8617 name (propertize vname 'face 'font-lock-variable-name-face))
8618 var))))
8619 (action
8620 . (("Invoke anything with selected source"
8622 (lambda (candidate)
8623 (setq anything-candidate-number-limit 9999)
8624 (anything candidate nil nil nil nil
8625 anything-source-select-buffer)))
8626 ("Describe variable" . describe-variable)
8627 ("Find variable" . find-variable)))
8628 (persistent-action . describe-variable)
8629 (persistent-help . "Show description of this source")))
8630 ;; (anything 'anything-c-source-call-source)
8632 (defun anything-call-source-from-anything ()
8633 "Call anything source within `anything' session."
8634 (interactive)
8635 (setq anything-input-idle-delay 0)
8636 (anything-set-sources '(anything-c-source-call-source)))
8638 ;;; Execute Preconfigured anything.
8639 (defvar anything-c-source-anything-commands
8640 '((name . "Preconfigured Anything")
8641 (candidates . anything-c-anything-commands-candidates)
8642 (type . command)
8643 (candidate-number-limit)))
8644 ;; (anything 'anything-c-source-anything-commands)
8646 (defun anything-c-anything-commands-candidates ()
8647 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8648 collect (cons (if (where-is-internal cmd nil t)
8649 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8650 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8651 cmd)))
8654 ;;; Occur
8657 (defun anything-c-occur-init ()
8658 "Create the initial anything occur buffer.
8659 If region is active use region as buffer contents
8660 instead of whole buffer."
8661 (with-current-buffer (anything-candidate-buffer 'global)
8662 (erase-buffer)
8663 (let ((buf-contents
8664 (with-anything-current-buffer
8665 (if (anything-region-active-p)
8666 (buffer-substring (region-beginning) (region-end))
8667 (buffer-substring (point-min) (point-max))))))
8668 (insert buf-contents))))
8670 (defun anything-c-occur-get-line (s e)
8671 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8673 (defun anything-c-occur-query-replace-regexp (candidate)
8674 "Query replace regexp starting from CANDIDATE.
8675 If region is active ignore CANDIDATE and replace only in region.
8676 With a prefix arg replace only matches surrounded by word boundaries,
8677 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8678 (let ((regexp anything-input))
8679 (unless (anything-region-active-p)
8680 (anything-c-action-line-goto candidate))
8681 (apply 'query-replace-regexp
8682 (anything-c-query-replace-args regexp))))
8684 (defvar anything-c-source-occur
8685 '((name . "Occur")
8686 (init . anything-c-occur-init)
8687 (candidates-in-buffer)
8688 (migemo)
8689 (get-line . anything-c-occur-get-line)
8690 (display-to-real . anything-c-display-to-real-line)
8691 (action . (("Go to Line" . anything-c-action-line-goto)
8692 ("Query replace regexp (C-u Not inside word.)"
8693 . anything-c-occur-query-replace-regexp)))
8694 (recenter)
8695 (requires-pattern . 1)
8696 (delayed)
8697 (volatile)))
8698 ;; (anything 'anything-c-source-occur)
8701 ;;; Anything browse code.
8702 (defun anything-c-browse-code-get-line (beg end)
8703 "Select line if it match the regexp corresponding to current `major-mode'.
8704 Line is parsed for BEG position to END position."
8705 (let ((str-line (buffer-substring beg end))
8706 (regexp (assoc-default major-mode
8707 anything-c-browse-code-regexp-alist))
8708 (num-line (if (string= anything-pattern "") beg (1- beg))))
8709 (when (and regexp (string-match regexp str-line))
8710 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8713 (defvar anything-c-source-browse-code
8714 '((name . "Browse code")
8715 (init . (lambda ()
8716 (anything-candidate-buffer anything-current-buffer)
8717 (with-anything-current-buffer
8718 (jit-lock-fontify-now))))
8719 (candidate-number-limit . 9999)
8720 (candidates-in-buffer)
8721 (get-line . anything-c-browse-code-get-line)
8722 (type . line)
8723 (recenter)))
8726 ;; Do many actions for input
8727 (defvar anything-c-source-create
8728 '((name . "Create")
8729 (dummy)
8730 (action)
8731 (action-transformer . anything-create--actions))
8732 "Do many create actions from `anything-pattern'.
8733 See also `anything-create--actions'.")
8734 ;; (anything 'anything-c-source-create)
8736 (defun anything-create-from-anything ()
8737 "Run `anything-create' from `anything' as a fallback."
8738 (interactive)
8739 (anything-run-after-quit 'anything-create nil anything-pattern))
8741 (defun anything-create--actions (&rest ignored)
8742 "Default actions for `anything-create' / `anything-c-source-create'."
8743 (remove-if-not
8744 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8745 (append anything-create--actions-private
8746 '(("find-file" . find-file)
8747 ("find-file other window" . find-file-other-window)
8748 ("New buffer" . anything-c-switch-to-buffer)
8749 ("New buffer other window" . switch-to-buffer-other-window)
8750 ("Bookmark Set" . bookmark-set)
8751 ("Set Register" .
8752 (lambda (x) (set-register (read-char "Register: ") x)))
8753 ("Insert Linkd star" . linkd-insert-star)
8754 ("Insert Linkd Tag" . linkd-insert-tag)
8755 ("Insert Linkd Link" . linkd-insert-link)
8756 ("Insert Linkd Lisp" . linkd-insert-lisp)
8757 ("Insert Linkd Wiki" . linkd-insert-wiki)
8758 ("Google Search" . google)))))
8761 ;; Minibuffer History
8764 (defvar anything-c-source-minibuffer-history
8765 '((name . "Minibuffer History")
8766 (header-name . (lambda (name)
8767 (format "%s (%s)" name minibuffer-history-variable)))
8768 (candidates
8769 . (lambda ()
8770 (let ((history (loop for i in
8771 (symbol-value minibuffer-history-variable)
8772 unless (string= "" i) collect i)))
8773 (if (consp (car history))
8774 (mapcar 'prin1-to-string history)
8775 history))))
8776 (migemo)
8777 (action . insert)))
8778 ;; (anything 'anything-c-source-minibuffer-history)
8781 ;;; Elscreen
8784 (defvar anything-c-source-elscreen
8785 '((name . "Elscreen")
8786 (candidates
8787 . (lambda ()
8788 (if (cdr (elscreen-get-screen-to-name-alist))
8789 (sort
8790 (loop for sname in (elscreen-get-screen-to-name-alist)
8791 append (list (format "[%d] %s" (car sname) (cdr sname))))
8792 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8793 (action
8794 . (("Change Screen" .
8795 (lambda (candidate)
8796 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8797 ("Kill Screen(s)" .
8798 (lambda (candidate)
8799 (dolist (i (anything-marked-candidates))
8800 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8801 (elscreen-kill))))
8802 ("Only Screen" .
8803 (lambda (candidate)
8804 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8805 (elscreen-kill-others)))))))
8806 ;; (anything 'anything-c-source-elscreen)
8809 ;;;; <System>
8811 ;;; Top (process)
8812 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8813 "Top command (batch mode). %s is replaced with `frame-width'.")
8814 (defvar anything-c-source-top
8815 '((name . "Top (Press C-c C-u to refresh)")
8816 (init . anything-c-top-init)
8817 (candidates-in-buffer)
8818 (display-to-real . anything-c-top-display-to-real)
8819 (persistent-action . anything-c-top-sh-persistent-action)
8820 (persistent-help . "SIGTERM")
8821 (action
8822 ("kill (TERM)" . (lambda (pid)
8823 (anything-c-top-sh (format "kill -TERM %s" pid))))
8824 ("kill (KILL)" . (lambda (pid)
8825 (anything-c-top-sh (format "kill -KILL %s" pid))))
8826 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8827 ;; (anything 'anything-c-source-top)
8829 (defun anything-c-top-sh (cmd)
8830 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8832 (defun anything-c-top-sh-persistent-action (pid)
8833 (delete-other-windows)
8834 (anything-c-top-sh (format "kill -TERM %s" pid))
8835 (anything-force-update))
8837 (defun anything-c-top-init ()
8838 (with-current-buffer (anything-candidate-buffer 'global)
8839 (call-process-shell-command
8840 (format anything-c-top-command
8841 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8842 nil (current-buffer))))
8844 (defun anything-c-top-display-to-real (line)
8845 (car (split-string line)))
8847 ;;; Timers
8848 (defvar anything-c-source-absolute-time-timers
8849 '((name . "Absolute Time Timers")
8850 (candidates . timer-list)
8851 (type . timer)))
8852 ;; (anything 'anything-c-source-absolute-time-timers)
8854 (defvar anything-c-source-idle-time-timers
8855 '((name . "Idle Time Timers")
8856 (candidates . timer-idle-list)
8857 (type . timer)))
8858 ;; (anything 'anything-c-source-idle-time-timers)
8860 (defun anything-c-timer-real-to-display (timer)
8861 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8862 (append timer nil) ;use `append' to convert vector->list
8863 (format "%s repeat=%5S %s(%s)"
8864 (let ((time (list t1 t2 t3)))
8865 (if idle-delay
8866 (format-time-string "idle-for=%5s" time)
8867 (format-time-string "%m/%d %T" time)))
8868 repeat-delay
8869 func
8870 (mapconcat 'prin1-to-string args " "))))
8872 ;;; X RandR resolution change
8873 ;;; FIXME I do not care multi-display.
8874 (defvar anything-c-xrandr-output "VGA")
8875 (defvar anything-c-xrandr-screen "0")
8876 (defvar anything-c-source-xrandr-change-resolution
8877 '((name . "Change Resolution")
8878 (candidates
8879 . (lambda ()
8880 (with-temp-buffer
8881 (call-process "xrandr" nil (current-buffer) nil
8882 "--screen" anything-c-xrandr-screen "-q")
8883 (goto-char 1)
8884 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8885 collect (match-string 1)))))
8886 (action
8887 ("Change Resolution" . (lambda (mode)
8888 (call-process "xrandr" nil nil nil
8889 "--screen" anything-c-xrandr-screen
8890 "--output" anything-c-xrandr-output
8891 "--mode" mode))))))
8892 ;; (anything 'anything-c-source-xrandr-change-resolution)
8894 ;;; Xfont selection
8897 (defun anything-c-persistent-xfont-action (elm)
8898 "Show current font temporarily"
8899 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8900 (default-font elm))
8901 (unwind-protect
8902 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8903 (set-frame-font current-font))))
8905 (defvar anything-c-xfonts-cache nil)
8906 (defvar anything-c-source-xfonts
8907 '((name . "X Fonts")
8908 (init . (lambda ()
8909 (unless anything-c-xfonts-cache
8910 (setq anything-c-xfonts-cache
8911 (x-list-fonts "*")))))
8912 (candidates . anything-c-xfonts-cache)
8913 (action . (("Copy to kill ring" . (lambda (elm)
8914 (kill-new elm)))
8915 ("Set Font" . (lambda (elm)
8916 (kill-new elm)
8917 (set-frame-font elm 'keep-size)
8918 (message "New font have been copied to kill ring")))))
8919 (persistent-action . anything-c-persistent-xfont-action)
8920 (persistent-help . "Switch to this font temporarily")))
8921 ;; (anything 'anything-c-source-xfonts)
8923 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8926 (defvar anything-c-ucs-max-len 0)
8927 (defun anything-c-calculate-ucs-max-len ()
8928 "Calculate the length of longest `ucs-names' candidate."
8929 (loop with count = 0
8930 for (n . v) in (ucs-names)
8931 for len = (length n)
8932 if (> len count)
8933 do (setq count len)
8934 finally return count))
8936 (defun anything-c-ucs-init ()
8937 "Initialize an anything buffer with ucs symbols.
8938 Only math* symbols are collected."
8939 (unless (> anything-c-ucs-max-len 0)
8940 (setq anything-c-ucs-max-len
8941 (anything-c-calculate-ucs-max-len)))
8942 (with-current-buffer (anything-candidate-buffer
8943 (get-buffer-create "*anything ucs*"))
8944 ;; `ucs-names' fn will not run again, data is cached in
8945 ;; var `ucs-names'.
8946 (loop for (n . v) in (ucs-names)
8947 for len = (length n)
8948 for diff = (+ (- anything-c-ucs-max-len len) 2)
8949 unless (string= "" n)
8950 do (progn (insert (concat
8951 n ":"
8952 (make-string
8953 diff ? )))
8954 (ucs-insert v)
8955 (insert "\n")))))
8957 (defun anything-c-ucs-forward-char (candidate)
8958 (with-anything-current-buffer
8959 (forward-char 1)))
8961 (defun anything-c-ucs-backward-char (candidate)
8962 (with-anything-current-buffer
8963 (forward-char -1)))
8965 (defun anything-c-ucs-delete-backward (candidate)
8966 (with-anything-current-buffer
8967 (delete-char -1)))
8969 (defun anything-c-ucs-insert-char (candidate)
8970 (with-anything-current-buffer
8971 (insert
8972 (replace-regexp-in-string
8973 " " ""
8974 (cadr (split-string candidate ":"))))))
8976 (defun anything-c-ucs-persistent-insert ()
8977 (interactive)
8978 (anything-attrset 'action-insert 'anything-c-ucs-insert-char)
8979 (anything-execute-persistent-action 'action-insert))
8981 (defun anything-c-ucs-persistent-forward ()
8982 (interactive)
8983 (anything-attrset 'action-forward 'anything-c-ucs-forward-char)
8984 (anything-execute-persistent-action 'action-forward))
8986 (defun anything-c-ucs-persistent-backward ()
8987 (interactive)
8988 (anything-attrset 'action-back 'anything-c-ucs-backward-char)
8989 (anything-execute-persistent-action 'action-back))
8991 (defun anything-c-ucs-persistent-delete ()
8992 (interactive)
8993 (anything-attrset 'action-delete 'anything-c-ucs-delete-backward)
8994 (anything-execute-persistent-action 'action-delete))
8996 (defvar anything-c-source-ucs
8997 '((name . "Ucs names")
8998 (init . anything-c-ucs-init)
8999 (candidate-number-limit . 9999)
9000 (candidates-in-buffer)
9001 (mode-line . anything-c-ucs-mode-line-string)
9002 (action . (("Insert" . anything-c-ucs-insert-char)
9003 ("Forward char" . anything-c-ucs-forward-char)
9004 ("Backward char" . anything-c-ucs-backward-char)
9005 ("Delete char backward" . anything-c-ucs-delete-backward))))
9006 "Source for collecting `ucs-names' math symbols.")
9009 ;;; Emacs process
9012 (defvar anything-c-source-emacs-process
9013 '((name . "Emacs Process")
9014 (candidates . (lambda () (mapcar #'process-name (process-list))))
9015 (persistent-action . (lambda (elm)
9016 (delete-process (get-process elm))
9017 (anything-delete-current-selection)))
9018 (persistent-help . "Kill Process")
9019 (action ("Kill Process" . (lambda (elm)
9020 (delete-process (get-process elm)))))))
9021 ;; (anything 'anything-c-source-emacs-process)
9023 ;;; World time
9026 (defvar anything-c-source-time-world
9027 '((name . "Time World List")
9028 (init . (lambda ()
9029 (let ((anything-buffer (anything-candidate-buffer 'global)))
9030 (with-current-buffer anything-buffer
9031 (display-time-world-display display-time-world-list)))))
9032 (candidates-in-buffer)))
9036 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9039 (defvar anything-c-source-apt
9040 '((name . "APT")
9041 (init . anything-c-apt-init)
9042 (candidates-in-buffer)
9043 (candidate-transformer anything-c-apt-candidate-transformer)
9044 (display-to-real . anything-c-apt-display-to-real)
9045 (requires-pattern . 2)
9046 (update . anything-c-apt-refresh)
9047 (action
9048 ("Show package description" . anything-c-apt-cache-show)
9049 ("Install package" . anything-c-apt-install)
9050 ("Remove package" . anything-c-apt-uninstall)
9051 ("Purge package" . anything-c-apt-purge))
9052 (persistent-action . anything-c-apt-persistent-action)
9053 (persistent-help . "Show package description")))
9054 ;; (anything 'anything-c-source-apt)
9056 (defvar anything-c-apt-query "emacs")
9057 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9058 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9059 (defvar anything-c-apt-installed-packages nil)
9060 (defvar anything-c-apt-all-packages nil)
9061 (defvar anything-c-apt-input-history nil)
9063 (defun anything-c-apt-refresh ()
9064 "Refresh installed candidates list."
9065 (setq anything-c-apt-installed-packages nil)
9066 (setq anything-c-apt-all-packages nil))
9068 (defun anything-c-apt-persistent-action (candidate)
9069 "Persistent action for APT source."
9070 (anything-c-apt-cache-show candidate))
9072 (defun anything-c-apt-candidate-transformer (candidates)
9073 "Show installed candidates in a different color."
9074 (loop
9075 with all
9076 for cand in candidates
9077 for name = (anything-c-apt-display-to-real cand)
9078 if (member name anything-c-apt-installed-packages)
9079 collect (propertize cand 'face 'anything-apt-installed) into all
9080 else collect cand into all finally return all))
9082 (defun anything-c-apt-init ()
9083 "Initialize list of debian packages."
9084 (let ((query ""))
9085 (unless (and anything-c-apt-installed-packages
9086 anything-c-apt-all-packages)
9087 (message "Loading package list...")
9088 (setq anything-c-apt-installed-packages
9089 (with-temp-buffer
9090 (call-process-shell-command "dpkg --get-selections"
9091 nil (current-buffer))
9092 (loop for i in (split-string (buffer-string) "\n" t)
9093 collect (car (split-string i)))))
9094 (setq anything-c-apt-all-packages
9095 (with-current-buffer
9096 (anything-candidate-buffer
9097 (get-buffer-create (format "*anything-apt*")))
9098 (erase-buffer)
9099 (call-process-shell-command
9100 (format anything-c-apt-search-command query)
9101 nil (current-buffer))))
9102 (message "Loading package list done")
9103 (sit-for 0.5))))
9105 (defun anything-c-apt-display-to-real (line)
9106 "Return only name of a debian package.
9107 LINE is displayed like:
9108 package name - description."
9109 (car (split-string line " - ")))
9111 (defun anything-c-shell-command-if-needed (command)
9112 "Run shell command COMMAND to describe package.
9113 If a buffer named COMMAND already exists, just switch to it."
9114 (let ((buf (get-buffer command)))
9115 (anything-c-switch-to-buffer (get-buffer-create command))
9116 (unless buf (insert (shell-command-to-string command)))))
9118 (defun anything-c-apt-cache-show (package)
9119 "Show information on apt package PACKAGE."
9120 (anything-c-shell-command-if-needed
9121 (format anything-c-apt-show-command package)))
9123 (defun anything-c-apt-install (package)
9124 "Run 'apt-get install' shell command on PACKAGE."
9125 (anything-c-apt-generic-action :action 'install))
9127 (defun anything-c-apt-uninstall (package)
9128 "Run 'apt-get remove' shell command on PACKAGE."
9129 (anything-c-apt-generic-action :action 'uninstall))
9131 (defun anything-c-apt-purge (package)
9132 "Run 'apt-get purge' shell command on PACKAGE."
9133 (anything-c-apt-generic-action :action 'purge))
9135 (defun* anything-c-apt-generic-action (&key action)
9136 "Run 'apt-get ACTION'.
9137 Support install, remove and purge actions."
9138 (ansi-term (getenv "SHELL") "anything apt")
9139 (term-line-mode)
9140 (let ((command (case action
9141 ('install "sudo apt-get install ")
9142 ('uninstall "sudo apt-get remove ")
9143 ('purge "sudo apt-get purge ")
9144 (t (error "Unknow action"))))
9145 (beg (point))
9147 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9148 (anything-marked-candidates) " ")))
9149 (goto-char (point-max))
9150 (insert (concat command cand-list))
9151 (setq end (point))
9152 (if (y-or-n-p (format "%s package" (symbol-name action)))
9153 (progn
9154 (setq anything-c-external-commands-list nil)
9155 (setq anything-c-apt-installed-packages nil)
9156 (term-char-mode) (term-send-input))
9157 (delete-region beg end) (term-send-eof) (kill-buffer))))
9159 ;; (anything-c-apt-install "jed")
9162 ;;; Anything UI for gentoo portage.
9165 (defvar anything-c-gentoo-use-flags nil)
9166 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9167 (defvar anything-c-cache-gentoo nil)
9168 (defvar anything-c-cache-world nil)
9169 (defvar anything-c-source-gentoo
9170 '((name . "Portage sources")
9171 (init . (lambda ()
9172 (get-buffer-create anything-c-gentoo-buffer)
9173 (unless anything-c-cache-gentoo
9174 (anything-c-gentoo-setup-cache))
9175 (unless anything-c-cache-world
9176 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9177 (anything-c-gentoo-init-list)))
9178 (candidates-in-buffer)
9179 (match . identity)
9180 (candidate-transformer anything-c-highlight-world)
9181 (action . (("Show package" . (lambda (elm)
9182 (anything-c-gentoo-eshell-action elm "eix")))
9183 ("Show history" . (lambda (elm)
9184 (if (member elm anything-c-cache-world)
9185 (anything-c-gentoo-eshell-action elm "genlop -qe")
9186 (message "No infos on packages not yet installed"))))
9187 ("Copy in kill-ring" . kill-new)
9188 ("insert at point" . insert)
9189 ("Browse HomePage" . (lambda (elm)
9190 (let ((urls (anything-c-gentoo-get-url elm)))
9191 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9192 ("Show extra infos" . (lambda (elm)
9193 (if (member elm anything-c-cache-world)
9194 (anything-c-gentoo-eshell-action elm "genlop -qi")
9195 (message "No infos on packages not yet installed"))))
9196 ("Show use flags" . (lambda (elm)
9197 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9198 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9199 (font-lock-mode 1)))
9200 ("Run emerge pretend" . (lambda (elm)
9201 (anything-c-gentoo-eshell-action elm "emerge -p")))
9202 ("Emerge" . (lambda (elm)
9203 (anything-gentoo-install elm :action 'install)))
9204 ("Unmerge" . (lambda (elm)
9205 (anything-gentoo-install elm :action 'uninstall)))
9206 ("Show dependencies" . (lambda (elm)
9207 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9208 ("Show related files" . (lambda (elm)
9209 (anything-c-gentoo-default-action elm "equery" "files")))
9210 ("Refresh" . (lambda (elm)
9211 (anything-c-gentoo-setup-cache)
9212 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9214 ;; (anything 'anything-c-source-gentoo)
9216 (defun* anything-gentoo-install (candidate &key action)
9217 (setq anything-c-external-commands-list nil)
9218 (ansi-term (getenv "SHELL") "Gentoo emerge")
9219 (term-line-mode)
9220 (let ((command (case action
9221 ('install "sudo emerge -av ")
9222 ('uninstall "sudo emerge -avC ")
9223 (t (error "Unknow action"))))
9224 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9225 (beg (point)) end)
9226 (goto-char (point-max))
9227 (insert (concat command elms))
9228 (setq end (point))
9229 (term-char-mode) (term-send-input)))
9231 (defun anything-c-gentoo-default-action (elm command &rest args)
9232 "Gentoo default action that use `anything-c-gentoo-buffer'."
9233 (if (member elm anything-c-cache-world)
9234 (progn
9235 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9236 (erase-buffer)
9237 (let ((com-list (append args (list elm))))
9238 (apply #'call-process command nil t nil
9239 com-list)))
9240 (message "No infos on packages not yet installed")))
9242 (defvar anything-c-source-use-flags
9243 '((name . "Use Flags")
9244 (init . (lambda ()
9245 (unless anything-c-gentoo-use-flags
9246 (anything-c-gentoo-setup-use-flags-cache))
9247 (anything-c-gentoo-get-use)))
9248 (candidates-in-buffer)
9249 (match . identity)
9250 (candidate-transformer anything-c-highlight-local-use)
9251 (action . (("Description"
9252 . (lambda (elm)
9253 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9254 (erase-buffer)
9255 (apply #'call-process "euse" nil t nil
9256 `("-i"
9257 ,elm))
9258 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9259 (font-lock-mode 1)))
9260 ("Enable"
9261 . (lambda (elm)
9262 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9263 ("Disable"
9264 . (lambda (elm)
9265 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9266 ("Remove"
9267 . (lambda (elm)
9268 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9269 ("Show which dep use this flag"
9270 . (lambda (elm)
9271 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9272 (erase-buffer)
9273 (apply #'call-process "equery" nil t nil
9274 `("-C"
9276 ,elm))))))))
9279 ;; (anything 'anything-c-source-use-flags)
9281 (defun anything-c-gentoo-init-list ()
9282 "Initialize buffer with all packages in Portage."
9283 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9284 (buf (anything-candidate-buffer 'portage-buf)))
9285 (with-current-buffer buf
9286 (dolist (i anything-c-cache-gentoo)
9287 (insert (concat i "\n"))))))
9289 (defun anything-c-gentoo-setup-cache ()
9290 "Set up `anything-c-cache-gentoo'"
9291 (setq anything-c-cache-gentoo
9292 (split-string (with-temp-buffer
9293 (call-process "eix" nil t nil
9294 "--only-names")
9295 (buffer-string)))))
9297 (defun anything-c-gentoo-eshell-action (elm command)
9298 (when (get-buffer "*EShell Command Output*")
9299 (kill-buffer "*EShell Command Output*"))
9300 (message "Wait searching...")
9301 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9302 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9303 (progn
9304 (save-window-excursion
9305 (pop-to-buffer "*scratch*")
9306 (eshell-command (format "%s %s" command elm)))
9307 (pop-to-buffer "*EShell Command Output*"))
9308 (eshell-command (format "%s %s" command elm)))))
9310 (defun anything-c-gentoo-get-use ()
9311 "Initialize buffer with all use flags."
9312 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9313 (buf (anything-candidate-buffer 'use-buf)))
9314 (with-current-buffer buf
9315 (dolist (i anything-c-gentoo-use-flags)
9316 (insert (concat i "\n"))))))
9319 (defun anything-c-gentoo-setup-use-flags-cache ()
9320 "Setup `anything-c-gentoo-use-flags'"
9321 (setq anything-c-gentoo-use-flags
9322 (split-string (with-temp-buffer
9323 (call-process "eix" nil t nil
9324 "--print-all-useflags")
9325 (buffer-string)))))
9327 (defun anything-c-gentoo-get-url (elm)
9328 "Return a list of urls from eix output."
9329 (loop
9330 with url-list = (split-string
9331 (with-temp-buffer
9332 (call-process "eix" nil t nil
9333 elm "--format" "<homepage>\n")
9334 (buffer-string)))
9335 with all
9336 for i in url-list
9337 when (and (string-match "^http://.*" i)
9338 (not (member i all)))
9339 collect i into all
9340 finally return all))
9342 (defun anything-c-gentoo-get-world ()
9343 "Return list of all installed package on your system."
9344 (split-string (with-temp-buffer
9345 (call-process "qlist" nil t nil
9346 "-I")
9347 (buffer-string))))
9349 (defun anything-c-gentoo-get-local-use ()
9350 (split-string (with-temp-buffer
9351 (call-process "portageq" nil t nil
9352 "envvar"
9353 "USE")
9354 (buffer-string))))
9357 (defun anything-c-highlight-world (eix)
9358 "Highlight all installed package."
9359 (loop for i in eix
9360 if (member i anything-c-cache-world)
9361 collect (propertize i 'face 'anything-gentoo-match-face)
9362 else
9363 collect i))
9365 (defun anything-c-highlight-local-use (use-flags)
9366 (let ((local-uses (anything-c-gentoo-get-local-use)))
9367 (loop for i in use-flags
9368 if (member i local-uses)
9369 collect (propertize i 'face 'anything-gentoo-match-face)
9370 else
9371 collect i)))
9375 ;;; Anything ratpoison UI
9378 (defvar anything-c-source-ratpoison-commands
9379 '((name . "Ratpoison Commands")
9380 (init . anything-c-ratpoison-commands-init)
9381 (candidates-in-buffer)
9382 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9383 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9384 (candidate-number-limit)))
9385 ;; (anything 'anything-c-source-ratpoison-commands)
9387 (defun anything-c-ratpoison-commands-init ()
9388 (unless (anything-candidate-buffer)
9389 (with-current-buffer (anything-candidate-buffer 'global)
9390 ;; with ratpoison prefix key
9391 (save-excursion
9392 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9393 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9394 (replace-match "<ratpoison> \\1: \\2"))
9395 (goto-char (point-max))
9396 ;; direct binding
9397 (save-excursion
9398 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9399 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9400 (replace-match "\\1: \\2")))))
9402 (defun anything-c-ratpoison-commands-display-to-real (display)
9403 (and (string-match ": " display)
9404 (substring display (match-end 0))))
9406 (defun anything-c-ratpoison-commands-execute (candidate)
9407 (call-process "ratpoison" nil nil nil "-ic" candidate))
9411 ;;; Anything `completing-read' replacement
9414 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9415 "Convert COLLECTION to list removing elements that don't match TEST.
9416 See `anything-comp-read' about supported COLLECTION arguments.
9418 SORT-FN is a predicate to sort COLLECTION.
9420 ALISTP when non--nil will not use `all-completions' to collect
9421 candidates because it doesn't handle alists correctly for anything.
9422 i.e In `all-completions' the keys \(cars of elements\)
9423 are the possible completions. In anything we want to use the cdr instead
9424 like \(display . real\).
9428 \(setq A '((a . 1) (b . 2) (c . 3)))
9429 ==>((a . 1) (b . 2) (c . 3))
9430 \(anything-comp-read \"test: \" A :alistp nil
9431 :exec-when-only-one t
9432 :initial-input \"a\")
9433 ==>\"a\"
9434 \(anything-comp-read \"test: \" A :alistp t
9435 :exec-when-only-one t
9436 :initial-input \"1\")
9437 ==>\"1\"
9439 See docstring of `all-completions' for more info.
9441 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9442 (let ((cands
9443 (cond ((and (eq collection obarray) test)
9444 (all-completions "" collection test))
9445 ((and (vectorp collection) test)
9446 (loop for i across collection when (funcall test i) collect i))
9447 ((vectorp collection)
9448 (loop for i across collection collect i))
9449 ((and alistp test)
9450 (loop for i in collection when (funcall test i) collect i))
9451 ((and (symbolp collection) (boundp collection))
9452 (symbol-value collection))
9453 (alistp collection)
9454 ((and collection test)
9455 (all-completions "" collection test))
9456 (t (all-completions "" collection)))))
9457 (if sort-fn (sort cands sort-fn) cands)))
9459 (defun anything-cr-default-transformer (candidates source)
9460 "Default filter candidate function for `anything-comp-read'.
9461 Do nothing, just return candidate list unmodified."
9462 candidates)
9464 (defun* anything-comp-read (prompt collection
9465 &key
9466 test
9467 initial-input
9468 default
9469 preselect
9470 (buffer "*Anything Completions*")
9471 must-match
9472 (requires-pattern 0)
9473 (history nil)
9474 input-history
9475 (persistent-action nil)
9476 (persistent-help "DoNothing")
9477 (name "Anything Completions")
9478 candidates-in-buffer
9479 exec-when-only-one
9480 (volatile t)
9481 sort
9482 (fc-transformer 'anything-cr-default-transformer)
9483 (marked-candidates nil)
9484 (alistp t))
9485 "Read a string in the minibuffer, with anything completion.
9487 It is anything `completing-read' equivalent.
9489 - PROMPT is the prompt name to use.
9491 - COLLECTION can be a list, vector, obarray or hash-table.
9492 It can be also a function that receives three arguments:
9493 the values string, predicate and t. See `all-completions' for more details.
9495 Keys description:
9497 - TEST: A predicate called with one arg i.e candidate.
9499 - INITIAL-INPUT: Same as input arg in `anything'.
9501 - PRESELECT: See preselect arg of `anything'.
9503 - DEFAULT: This option is used only for compatibility with regular
9504 Emacs `completing-read'.
9506 - BUFFER: Name of anything-buffer.
9508 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9510 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9512 - HISTORY: A list containing specific history, default is nil.
9513 When it is non--nil, all elements of HISTORY are displayed in
9514 a special source before COLLECTION.
9516 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9517 stored there, if nil or not provided, `minibuffer-history'
9518 will be used instead.
9520 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9522 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9524 - NAME: The name related to this local source.
9526 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9527 to non--nil. (possibles values are t or nil).
9529 - VOLATILE: Use volatile attribute \(enabled by default\).
9531 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9533 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9535 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9537 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9539 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9540 `anything-candidates-in-buffer' which is much faster.
9541 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9543 Any prefix args passed during `anything-comp-read' invocation will be recorded
9544 in `anything-current-prefix-arg', otherwise if prefix args were given before
9545 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9546 That's mean you can pass prefix args before or after calling a command
9547 that use `anything-comp-read' See `anything-M-x' for example."
9548 (when (get-buffer anything-action-buffer)
9549 (kill-buffer anything-action-buffer))
9550 (flet ((action-fn (candidate)
9551 (if marked-candidates
9552 (anything-marked-candidates)
9553 (identity candidate))))
9554 ;; Assume completion have been already required,
9555 ;; so always use 'confirm.
9556 (when (eq must-match 'confirm-after-completion)
9557 (setq must-match 'confirm))
9558 (let* ((minibuffer-completion-confirm (unless (eq must-match t)
9559 must-match))
9560 (keymap (when must-match minibuffer-local-must-match-map))
9561 (anything-map (make-composed-keymap
9562 ;; Merge some anything bindings
9563 ;; that clash with minibuffer ones.
9564 (list '(keymap
9565 (7 . anything-keyboard-quit)
9566 (up . anything-previous-line)
9567 (down . anything-next-line))
9568 keymap)
9569 anything-map))
9570 (src-hist `((name . ,(format "%s History" name))
9571 (candidates
9572 . (lambda ()
9573 (let ((all (anything-comp-read-get-candidates
9574 history nil nil ,alistp)))
9575 (delete
9577 (anything-fast-remove-dups
9578 (if (and default (not (string= default "")))
9579 (delq nil (cons default
9580 (delete default all)))
9581 all)
9582 :test 'equal)))))
9583 (filtered-candidate-transformer
9584 . (lambda (candidates sources)
9585 (loop for i in candidates
9586 do (set-text-properties 0 (length i) nil i)
9587 collect i)))
9588 (persistent-action . ,persistent-action)
9589 (persistent-help . ,persistent-help)
9590 (action . ,'action-fn)))
9591 (src `((name . ,name)
9592 (candidates
9593 . (lambda ()
9594 (let ((cands (anything-comp-read-get-candidates
9595 collection test sort alistp)))
9596 (unless (or must-match (string= anything-pattern ""))
9597 (setq cands (append (list anything-pattern) cands)))
9598 (if (and default (not (string= default "")))
9599 (delq nil (cons default (delete default cands)))
9600 cands))))
9601 (filtered-candidate-transformer ,fc-transformer)
9602 (requires-pattern . ,requires-pattern)
9603 (persistent-action . ,persistent-action)
9604 (persistent-help . ,persistent-help)
9605 (action . ,'action-fn)))
9606 (src-1 `((name . ,name)
9607 (init
9608 . (lambda ()
9609 (let ((cands (anything-comp-read-get-candidates
9610 collection test sort alistp)))
9611 (unless (or must-match (string= anything-pattern ""))
9612 (setq cands (append (list anything-pattern) cands)))
9613 (with-current-buffer (anything-candidate-buffer 'global)
9614 (loop for i in
9615 (if (and default (not (string= default "")))
9616 (delq nil (cons default (delete default cands)))
9617 cands)
9618 do (insert (concat i "\n")))))))
9619 (candidates-in-buffer)
9620 (filtered-candidate-transformer ,fc-transformer)
9621 (requires-pattern . ,requires-pattern)
9622 (persistent-action . ,persistent-action)
9623 (persistent-help . ,persistent-help)
9624 (action . ,'action-fn)))
9625 (src-list (list src-hist
9626 (if candidates-in-buffer
9627 src-1
9628 (if volatile
9629 (append src '((volatile)))
9630 src))))
9631 (anything-execute-action-at-once-if-one exec-when-only-one))
9633 (anything
9634 :sources src-list
9635 :input initial-input
9636 :default default
9637 :preselect preselect
9638 :prompt prompt
9639 :resume 'noresume
9640 :history (and (symbolp input-history) input-history)
9641 :buffer buffer)
9642 (when (and (not (string= anything-pattern ""))
9643 (eq anything-exit-status 0)
9644 (eq must-match 'confirm))
9645 (identity anything-pattern))
9646 (unless (or (eq anything-exit-status 1) must-match)
9647 default)
9648 (keyboard-quit)))))
9650 ;; Generic completing-read
9652 ;; Support also function as collection.
9653 ;; e.g M-x man is supported.
9654 ;; Support hash-table and vectors as collection.
9655 ;; NOTE:
9656 ;; Some crap emacs functions may not be supported
9657 ;; like ffap-alternate-file (bad use of completing-read)
9658 ;; and maybe others.
9659 ;; Provide a mode `anything-completion-mode' which turn on
9660 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9662 (defvar anything-completion-mode-string " AC")
9664 (defvar anything-completion-mode-quit-message
9665 "Anything completion disabled")
9667 (defvar anything-completion-mode-start-message
9668 "Anything completion enabled")
9670 ;;; Specialized handlers
9673 (defun anything-completing-read-symbols
9674 (prompt collection test require-match init
9675 hist default inherit-input-method name buffer)
9676 "Specialized function for fast symbols completion in `ac-mode'."
9678 (anything
9679 :sources `((name . ,name)
9680 (init . (lambda ()
9681 (with-current-buffer (anything-candidate-buffer 'global)
9682 (goto-char (point-min))
9683 (when (and default (stringp default)
9684 ;; Some defaults args result as
9685 ;; (symbol-name nil) == "nil".
9686 ;; e.g debug-on-entry.
9687 (not (string= default "nil"))
9688 (not (string= default "")))
9689 (insert (concat default "\n")))
9690 (loop with all = (all-completions "" collection test)
9691 for sym in all
9692 unless (and default (eq sym default))
9693 do (insert (concat sym "\n"))))))
9694 (persistent-action . anything-lisp-completion-persistent-action)
9695 (persistent-help . "Show brief doc in mode-line")
9696 (candidates-in-buffer)
9697 (action . identity))
9698 :prompt prompt
9699 :buffer buffer
9700 :input init
9701 :history hist
9702 :resume 'noresume
9703 :default (or default ""))
9704 (keyboard-quit)))
9707 ;;; Generic completing read
9710 (defun anything-completing-read-default-1
9711 (prompt collection test require-match
9712 init hist default inherit-input-method
9713 name buffer &optional cands-in-buffer exec-when-only-one)
9714 "Call `anything-comp-read' with same args as `completing-read'.
9715 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9716 method which is faster.
9717 It should be used when candidate list don't need to rebuild dynamically."
9718 (let ((history (or (car-safe hist) hist)))
9719 (anything-comp-read
9720 prompt collection
9721 :test test
9722 :history history
9723 :input-history history
9724 :must-match require-match
9725 :alistp nil ; Be sure `all-completions' is used.
9726 :name name
9727 :candidates-in-buffer cands-in-buffer
9728 :exec-when-only-one exec-when-only-one
9729 :buffer buffer
9730 ;; If DEF is not provided, fallback to empty string
9731 ;; to avoid `thing-at-point' to be appended on top of list
9732 :default (or default "")
9733 :initial-input init)))
9735 (defun anything-completing-read-with-cands-in-buffer
9736 (prompt collection test require-match
9737 init hist default inherit-input-method
9738 name buffer)
9739 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9740 ;; Some commands like find-tag may use `read-file-name' from inside
9741 ;; the calculation of collection. in this case it clash with
9742 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9743 ;; So (re)calculate collection outside of main anything-session.
9744 (let ((cands (all-completions "" collection)))
9745 (anything-completing-read-default-1 prompt cands test require-match
9746 init hist default inherit-input-method
9747 name buffer t)))
9749 (defun* anything-completing-read-default
9750 (prompt collection &optional
9751 predicate require-match
9752 initial-input hist def
9753 inherit-input-method)
9754 "An anything replacement of `completing-read'.
9755 This function should be used only as a `completing-read-function'.
9757 Don't use it directly, use instead `anything-comp-read' in your programs.
9759 See documentation of `completing-read' and `all-completions' for details."
9760 (declare (special anything-completion-mode))
9761 (let* ((current-command this-command)
9762 (str-command (symbol-name current-command))
9763 (buf-name (format "*ac-mode-%s*" str-command))
9764 (entry (assq current-command
9765 anything-completing-read-handlers-alist))
9766 (def-com (cdr-safe entry))
9767 (str-defcom (and def-com (symbol-name def-com)))
9768 (def-args (list prompt collection predicate require-match
9769 initial-input hist def inherit-input-method))
9770 ;; Append the two extra args needed to set the buffer and source name
9771 ;; in anything specialized functions.
9772 (any-args (append def-args (list str-command buf-name)))
9773 anything-completion-mode-start-message ; Be quiet
9774 anything-completion-mode-quit-message
9775 (minibuffer-completion-table collection)
9776 (minibuffer-completion-predicate predicate)
9777 ;; Be sure this pesty *completion* buffer doesn't popup.
9778 (minibuffer-setup-hook (remove 'minibuffer-completion-help
9779 minibuffer-setup-hook)))
9780 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9781 (unless (or (not entry) def-com)
9782 ;; An entry in *read-handlers-alist exists but have
9783 ;; a nil value, so we exit from here, disable `ac-mode'
9784 ;; and run the command again with it original behavior.
9785 ;; `ac-mode' will be restored on exit.
9786 (return-from anything-completing-read-default
9787 (unwind-protect
9788 (progn
9789 (ac-mode -1)
9790 (apply completing-read-function def-args))
9791 (ac-mode 1))))
9792 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9793 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9794 (when (or (eq def-com 'completing-read)
9795 ;; All specialized functions are prefixed by "anything"
9796 (and (stringp str-defcom)
9797 (not (string-match "^anything" str-defcom))))
9798 (ac-mode -1))
9799 (unwind-protect
9800 (cond (;; An anything specialized function exists, run it.
9801 (and def-com anything-completion-mode)
9802 (apply def-com any-args))
9803 (;; Try to handle `ido-completing-read' everywhere.
9804 (and def-com (eq def-com 'ido-completing-read))
9805 (setcar (memq collection def-args)
9806 (all-completions "" collection predicate))
9807 (apply def-com def-args))
9808 (;; User set explicitely `completing-read' or something similar
9809 ;; in *read-handlers-alist, use this with exactly the same
9810 ;; args as in `completing-read'.
9811 ;; If we are here `anything-completion-mode' is now disabled.
9812 def-com
9813 (apply def-com def-args))
9814 (t ; Fall back to classic `anything-comp-read'.
9815 (anything-completing-read-default-1
9816 prompt collection predicate require-match
9817 initial-input hist def inherit-input-method
9818 str-command buf-name)))
9819 (ac-mode 1)
9820 ;; When exiting minibuffer, `this-command' is set to
9821 ;; `anything-exit-minibuffer', which is unwanted when starting
9822 ;; on another `completing-read', so restore `this-command' to
9823 ;; initial value when exiting.
9824 (setq this-command current-command))))
9826 (defun* anything-generic-read-file-name
9827 (prompt &optional dir default-filename mustmatch initial predicate)
9828 "An anything replacement of `read-file-name'."
9829 (declare (special anything-completion-mode))
9830 (let* ((default (and default-filename
9831 (if (listp default-filename)
9832 (car default-filename)
9833 default-filename)))
9834 (init (or default initial dir default-directory))
9835 (ini-input (and init (expand-file-name init)))
9836 (current-command this-command)
9837 (str-command (symbol-name current-command))
9838 (anything-file-completion-sources
9839 (cons str-command
9840 (remove str-command anything-file-completion-sources)))
9841 (buf-name (format "*ac-mode-%s*" str-command))
9842 (entry (assq current-command
9843 anything-completing-read-handlers-alist))
9844 (def-com (cdr-safe entry))
9845 (str-defcom (symbol-name def-com))
9846 (def-args (list prompt dir default-filename mustmatch initial predicate))
9847 ;; Append the two extra args needed to set the buffer and source name
9848 ;; in anything specialized functions.
9849 (any-args (append def-args (list str-command buf-name)))
9850 (ido-state ido-mode)
9851 anything-completion-mode-start-message ; Be quiet
9852 anything-completion-mode-quit-message ; Same here
9853 fname)
9854 ;; Some functions that normally call `completing-read' can switch
9855 ;; brutally to `read-file-name' (e.g find-tag), in this case
9856 ;; the anything specialized function will fail because it is build
9857 ;; for `completing-read', so set it to 'incompatible to be sure
9858 ;; we switch to `anything-c-read-file-name' and don't try to call it
9859 ;; with wrong number of args.
9860 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9861 (setq def-com 'incompatible))
9862 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9863 (unless (or (not entry) def-com)
9864 (return-from anything-generic-read-file-name
9865 (unwind-protect
9866 (progn
9867 (ac-mode -1)
9868 (apply read-file-name-function def-args))
9869 (ac-mode 1))))
9870 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9871 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9872 (when (or (eq def-com 'read-file-name)
9873 (eq def-com 'ido-read-file-name)
9874 (and (stringp str-defcom)
9875 (not (string-match "^anything" str-defcom))))
9876 (ac-mode -1))
9877 (unwind-protect
9878 (setq fname
9879 (cond (;; A specialized function exists, run it
9880 ;; with the two extra args specific to anything..
9881 (and def-com anything-completion-mode
9882 (not (eq def-com 'ido-read-file-name))
9883 (not (eq def-com 'incompatible)))
9884 (apply def-com any-args))
9885 (;; Def-com value is `ido-read-file-name'
9886 ;; run it with default args.
9887 (and def-com (eq def-com 'ido-read-file-name))
9888 (ido-mode 1)
9889 (apply def-com def-args))
9890 (;; Def-com value is `read-file-name'
9891 ;; run it with default args.
9892 (eq def-com 'read-file-name)
9893 (apply def-com def-args))
9894 (t ; Fall back to classic `anything-c-read-file-name'.
9895 (anything-c-read-file-name
9896 prompt
9897 :name str-command
9898 :buffer buf-name
9899 :initial-input (expand-file-name init dir)
9900 :alistp nil
9901 :test predicate))))
9902 (ac-mode 1)
9903 (ido-mode (if ido-state 1 -1))
9904 ;; Same comment as in `anything-completing-read-default'.
9905 (setq this-command current-command))
9906 (if (and mustmatch (not (file-exists-p fname)))
9907 (if (y-or-n-p "File does not exists, create buffer?")
9908 fname (error "Abort file does not exists"))
9909 fname)))
9911 ;;;###autoload
9912 (define-minor-mode anything-completion-mode
9913 "Toggle generic anything completion.
9915 All functions in Emacs that use `completing-read'
9916 or `read-file-name' and friends will use anything interface
9917 when this mode is turned on.
9918 However you can modify this behavior for functions of your choice
9919 with `anything-completing-read-handlers-alist'.
9921 Called with a positive arg, turn on unconditionally, with a
9922 negative arg turn off.
9923 You can turn it on with `ac-mode'.
9925 Some crap emacs functions may not be supported,
9926 e.g `ffap-alternate-file' and maybe others
9927 You can add such functions to `anything-completing-read-handlers-alist'
9928 with a nil value.
9930 Note: This mode will work only partially on Emacs23."
9931 :group 'anything
9932 :global t
9933 :lighter anything-completion-mode-string
9934 (declare (special completing-read-function))
9935 (if anything-completion-mode
9936 (progn
9937 (setq completing-read-function 'anything-completing-read-default
9938 read-file-name-function 'anything-generic-read-file-name)
9939 (message anything-completion-mode-start-message))
9940 (setq completing-read-function (and (fboundp 'completing-read-default)
9941 'completing-read-default)
9942 read-file-name-function (and (fboundp 'read-file-name-default)
9943 'read-file-name-default))
9944 (message anything-completion-mode-quit-message)))
9946 (defalias 'ac-mode 'anything-completion-mode)
9950 ;;; Eshell completion.
9952 ;; Enable like this in .emacs:
9954 ;; (add-hook 'eshell-mode-hook
9955 ;; #'(lambda ()
9956 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9958 (defvar anything-c-source-esh
9959 '((name . "Eshell completions")
9960 (init . (lambda ()
9961 (setq pcomplete-current-completions nil
9962 pcomplete-last-completion-raw nil)
9963 ;; Eshell-command add this hook in all minibuffers
9964 ;; Remove it for the anything one. (Fixed in Emacs24)
9965 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9966 (candidates . anything-esh-get-candidates)
9967 (action . anything-ec-insert))
9968 "Anything source for Eshell completion.")
9970 ;; Internal.
9971 (defvar anything-ec-target "")
9972 (defun anything-ec-insert (candidate)
9973 "Insert CANDIDATE at point.
9974 This is the same as `ac-insert', just inlined here for compatibility."
9975 (let ((pt (point)))
9976 (when (and anything-ec-target
9977 (search-backward anything-ec-target nil t)
9978 (string= (buffer-substring (point) pt) anything-ec-target))
9979 (delete-region (point) pt)))
9980 (insert candidate))
9982 (defun anything-esh-get-candidates ()
9983 "Get candidates for eshell completion using `pcomplete'."
9984 (catch 'pcompleted
9985 (let* ((pcomplete-stub)
9986 pcomplete-seen pcomplete-norm-func
9987 pcomplete-args pcomplete-last pcomplete-index
9988 (pcomplete-autolist pcomplete-autolist)
9989 (pcomplete-suffix-list pcomplete-suffix-list))
9990 (with-anything-current-buffer
9991 (loop
9992 with table = (pcomplete-completions)
9993 with entry = (condition-case nil
9994 ;; For Emacs24
9995 (try-completion anything-pattern (pcomplete-entries))
9996 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9997 (error
9999 (let ((fc (car (last (pcomplete-parse-arguments)))))
10000 ;; Check if last arg require fname completion.
10001 (and (file-name-directory fc) fc))))
10002 for i in (if (listp table) table ; Emacs23 or commands.
10003 (all-completions pcomplete-stub table)) ; Emacs24
10004 for file-cand = (and entry
10005 (if (file-remote-p i) i
10006 (expand-file-name i (file-name-directory entry))))
10007 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
10008 collect file-cand into ls
10009 else collect i into ls
10010 finally return
10011 (if (and entry (not (string= entry "")) (file-exists-p entry))
10012 (append (list (expand-file-name entry default-directory)) ls) ls))))))
10014 ;;; Eshell history.
10017 (defvar anything-c-source-eshell-history
10018 '((name . "Eshell history")
10019 (init . (lambda ()
10020 (let (eshell-hist-ignoredups)
10021 ;; Write the content's of ring to file.
10022 (eshell-write-history eshell-history-file-name t)
10023 (with-current-buffer (anything-candidate-buffer 'global)
10024 (insert-file-contents eshell-history-file-name)))
10025 ;; Same comment as in `anything-c-source-esh'
10026 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
10027 (candidates-in-buffer)
10028 (filtered-candidate-transformer . (lambda (candidates sources)
10029 (reverse candidates)))
10030 (candidate-number-limit . 9999)
10031 (action . (lambda (candidate)
10032 (eshell-kill-input)
10033 (insert candidate))))
10034 "Anything source for Eshell history.")
10037 ;;; Show completion - an alternative of anything-show-completion.el.
10039 ;; Provide show completion with macro `with-anything-show-completion'.
10042 ;; Called each time cursor move in anything-buffer.
10043 (defun anything-c-show-completion ()
10044 (with-anything-current-buffer
10045 (overlay-put anything-c-show-completion-overlay
10046 'display (anything-get-selection))))
10048 (defun anything-c-show-completion-init-overlay (beg end)
10049 (and anything-c-turn-on-show-completion
10050 (setq anything-c-show-completion-overlay (make-overlay beg end))
10051 (overlay-put anything-c-show-completion-overlay
10052 'face 'anything-lisp-show-completion)))
10054 (defmacro with-anything-show-completion (beg end &rest body)
10055 "Show anything candidate in an overlay at point.
10056 BEG and END are the beginning and end position of the current completion
10057 in `anything-current-buffer'.
10058 BODY is an anything call where we want to enable show completion.
10059 If `anything-c-turn-on-show-completion' is nil just do nothing."
10060 (declare (indent 2) (debug t))
10061 `(let ((anything-move-selection-after-hook
10062 (and anything-c-turn-on-show-completion
10063 (append (list 'anything-c-show-completion)
10064 anything-move-selection-after-hook))))
10065 (unwind-protect
10066 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10067 ,@body)
10068 (and anything-c-turn-on-show-completion
10069 (delete-overlay anything-c-show-completion-overlay)))))
10072 ;;; Lisp symbol completion.
10075 ;;;###autoload
10076 (defun anything-lisp-completion-at-point ()
10077 "Anything lisp symbol completion at point."
10078 (interactive)
10079 (let* ((data (lisp-completion-at-point))
10080 (beg (car data))
10081 (end (point)) ; 'cadr data' is wrong when no space after point.
10082 (plist (nthcdr 3 data))
10083 (pred (plist-get plist :predicate))
10084 (lgst-len 0)
10085 (target (and beg end (buffer-substring-no-properties beg end)))
10086 (candidates (all-completions target (nth 2 data) pred))
10087 (anything-quit-if-no-candidate t)
10088 (anything-execute-action-at-once-if-one t)
10089 (anything-match-plugin-enabled
10090 (member 'anything-compile-source--match-plugin
10091 anything-compile-source-functions)))
10092 (if candidates
10093 (with-anything-show-completion beg end
10094 ;; Overlay is initialized now in anything-current-buffer.
10095 (anything
10096 :sources
10097 '((name . "Lisp completion")
10098 (init . (lambda ()
10099 (with-current-buffer (anything-candidate-buffer 'global)
10100 (loop for sym in candidates
10101 for len = (length sym)
10102 when (> len lgst-len) do (setq lgst-len len)
10103 do (insert (concat sym "\n"))))))
10104 (candidates-in-buffer)
10105 (persistent-action . anything-lisp-completion-persistent-action)
10106 (persistent-help . "Show brief doc in mode-line")
10107 (filtered-candidate-transformer anything-lisp-completion-transformer)
10108 (action . (lambda (candidate)
10109 (delete-region beg end)
10110 (insert candidate))))
10111 :input (if anything-match-plugin-enabled (concat target " ") target)))
10112 (message "[No Match]"))))
10114 (defun anything-lisp-completion-persistent-action (candidate)
10115 (let ((cursor-in-echo-area t)
10116 mode-line-in-non-selected-windows)
10117 (anything-c-show-info-in-mode-line
10118 (propertize
10119 (anything-c-get-first-line-documentation
10120 (intern candidate))
10121 'face 'anything-lisp-completion-info))))
10123 (defun anything-lisp-completion-transformer (candidates source)
10124 "Anything candidates transformer for lisp completion."
10125 (declare (special lgst-len))
10126 (loop for c in candidates
10127 for sym = (intern c)
10128 for annot = (cond ((commandp sym) " (Com)")
10129 ((fboundp sym) " (Fun)")
10130 ((boundp sym) " (Var)")
10131 ((facep sym) " (Face)"))
10132 for spaces = (make-string (- lgst-len (length c)) ? )
10133 collect (cons (concat c spaces annot) c)))
10135 (defun anything-c-get-first-line-documentation (sym)
10136 "Return first line documentation of symbol SYM.
10137 If SYM is not documented, return \"Not documented\"."
10138 (let ((doc (cond ((fboundp sym)
10139 (documentation sym t))
10140 ((boundp sym)
10141 (documentation-property sym 'variable-documentation t))
10142 ((facep sym)
10143 (face-documentation sym))
10144 (t nil))))
10145 (if (and doc (not (string= doc ""))
10146 ;; `documentation' return "\n\n(args...)"
10147 ;; for CL-style functions.
10148 (not (string-match-p "^\n\n" doc)))
10149 (car (split-string doc "\n"))
10150 "Not documented")))
10152 ;;; File completion.
10154 ;; Complete file name at point.
10155 (defun anything-c-thing-before-point ()
10156 "Get symbol name before point.
10157 Borrowed from anything-complete.el, inlined here for compatibility."
10158 (save-excursion
10159 (let ((beg (point)))
10160 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10161 (when (re-search-backward
10162 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10163 (buffer-substring-no-properties beg (match-end 0))))))
10165 ;;;###autoload
10166 (defun anything-c-complete-file-name-at-point ()
10167 "Complete file name at point."
10168 (interactive)
10169 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10170 (end (point))
10171 (beg (- (point) (length init)))
10172 (anything-quit-if-no-candidate t)
10173 (anything-execute-action-at-once-if-one t)
10174 completion)
10175 (with-anything-show-completion beg end
10176 (setq completion (anything-c-read-file-name "FileName: "
10177 :initial-input init)))
10178 (anything-c-insert-file-name-completion-at-point completion)))
10180 ;; Internal
10181 (defvar anything-lisp-completion-counter 0)
10182 ;;;###autoload
10183 (defun anything-lisp-completion-at-point-or-indent (arg)
10184 "First call indent and second call complete lisp symbol.
10185 The second call should happen before `anything-lisp-completion-or-indent-delay',
10186 after this delay, next call will indent again.
10187 After completion, next call is always indent.
10188 See that like click and double mouse click.
10189 One hit indent, two quick hits maybe indent and complete."
10190 (interactive "P")
10191 ;; Be sure `indent-for-tab-command' will not try
10192 ;; to use `completion-at-point'.
10193 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10194 t tab-always-indent)))
10195 (incf anything-lisp-completion-counter)
10196 (unwind-protect
10197 (if (> anything-lisp-completion-counter 1)
10198 (anything-lisp-completion-or-file-name-at-point)
10199 (indent-for-tab-command arg))
10200 ;; After `anything-lisp-completion-or-indent-delay' seconds
10201 ;; reset to 0.
10202 (run-with-timer anything-lisp-completion-or-indent-delay nil
10203 #'(lambda ()
10204 (setq anything-lisp-completion-counter 0)))
10205 ;; Always reset to 0 at second hit.
10206 (when (eq anything-lisp-completion-counter 2)
10207 (setq anything-lisp-completion-counter 0)))))
10209 ;;;###autoload
10210 (defun anything-lisp-completion-or-file-name-at-point ()
10211 "Complete lisp symbol or filename at point.
10212 Filename completion happen if filename is started in
10213 or between double quotes."
10214 (interactive)
10215 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10216 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10217 (save-excursion (search-backward "\"" (point-at-bol) t)))
10218 (anything-c-complete-file-name-at-point)
10219 (anything-lisp-completion-at-point))))
10221 (defun anything-c-apropos-init (test default)
10222 "Init candidates buffer for `anything-c-apropos' sources."
10223 (with-current-buffer (anything-candidate-buffer 'global)
10224 (goto-char (point-min))
10225 (when (and default (stringp default)
10226 ;; Some defaults args result as
10227 ;; (symbol-name nil) == "nil".
10228 ;; e.g debug-on-entry.
10229 (not (string= default "nil"))
10230 (funcall test (intern default)))
10231 (insert (concat default "\n")))
10232 (loop with all = (all-completions "" obarray test)
10233 for sym in all
10234 unless (and default (eq sym default))
10235 do (insert (concat sym "\n")))))
10238 ;;; Run Externals commands within Emacs with anything completion
10241 (defvar anything-external-command-history nil)
10243 (defun anything-c-external-commands-list-1 (&optional sort)
10244 "Returns a list of all external commands the user can execute.
10245 If `anything-c-external-commands-list' is non-nil it will
10246 return its contents. Else it calculates all external commands
10247 and sets `anything-c-external-commands-list'."
10248 (if anything-c-external-commands-list
10249 anything-c-external-commands-list
10250 (setq anything-c-external-commands-list
10251 (loop
10252 with paths = (split-string (getenv "PATH") path-separator)
10253 with completions = ()
10254 for dir in paths
10255 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10256 for lsdir = (loop for i in (directory-files dir t)
10257 for bn = (file-name-nondirectory i)
10258 when (and (not (member bn completions))
10259 (not (file-directory-p i))
10260 (file-executable-p i))
10261 collect bn)
10262 append lsdir into completions
10263 finally return (if sort (sort completions 'string-lessp) completions)))))
10265 (defun anything-run-or-raise (exe &optional file)
10266 "Generic command that run asynchronously EXE.
10267 If EXE is already running just jump to his window if `anything-raise-command'
10268 is non--nil.
10269 When FILE argument is provided run EXE with FILE.
10270 In this case EXE must be provided as \"EXE %s\"."
10271 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10272 "%s" "" exe))))
10273 (proc (if file (concat real-com " " file) real-com)))
10274 (if (get-process proc)
10275 (if anything-raise-command
10276 (shell-command (format anything-raise-command real-com))
10277 (error "Error: %s is already running" real-com))
10278 (when (loop for i in anything-c-external-commands-list thereis real-com)
10279 (message "Starting %s..." real-com)
10280 (if file
10281 (start-process-shell-command
10282 proc nil (format exe (shell-quote-argument
10283 (if (eq system-type 'windows-nt)
10284 (anything-w32-prepare-filename file)
10285 file))))
10286 (start-process-shell-command proc nil real-com))
10287 (set-process-sentinel
10288 (get-process proc)
10289 #'(lambda (process event)
10290 (when (and (string= event "finished\n")
10291 anything-raise-command
10292 (not (anything-c-get-pid-from-process-name real-com)))
10293 (shell-command (format anything-raise-command "emacs")))
10294 (message "%s process...Finished." process))))
10295 (setq anything-c-external-commands-list
10296 (cons real-com
10297 (delete real-com anything-c-external-commands-list))))))
10301 ;;; Generic action functions
10304 (defun anything-c-file-buffers (filename)
10305 "Returns a list of buffer names corresponding to FILENAME."
10306 (let ((name (expand-file-name filename))
10307 (buf-list ()))
10308 (dolist (buf (buffer-list) buf-list)
10309 (let ((bfn (buffer-file-name buf)))
10310 (when (and bfn (string= name bfn))
10311 (push (buffer-name buf) buf-list))))))
10313 (defun anything-revert-buffer (candidate)
10314 (with-current-buffer candidate
10315 (when (or (buffer-modified-p)
10316 (not (verify-visited-file-modtime
10317 (get-buffer candidate))))
10318 (revert-buffer t t))))
10320 (defun anything-revert-marked-buffers (ignore)
10321 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10323 (defun anything-kill-marked-buffers (ignore)
10324 (mapc 'kill-buffer (anything-marked-candidates)))
10326 (defun anything-c-delete-file (file &optional error-if-dot-file-p)
10327 "Delete the given file after querying the user.
10328 Ask to kill buffers associated with that file, too."
10329 (when (and error-if-dot-file-p
10330 (anything-ff-dot-file-p file))
10331 (error "Error: Cannot operate on `.' or `..'"))
10332 (let ((buffers (anything-c-file-buffers file)))
10333 (if (< emacs-major-version 24)
10334 ;; `dired-delete-file' in Emacs versions < 24
10335 ;; doesn't support delete-by-moving-to-trash
10336 ;; so use `delete-directory' and `delete-file'
10337 ;; that handle it.
10338 (cond ((and (not (file-symlink-p file))
10339 (file-directory-p file)
10340 (directory-files file t dired-re-no-dot))
10341 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10342 (delete-directory file 'recursive)))
10343 ((and (not (file-symlink-p file))
10344 (file-directory-p file))
10345 (delete-directory file))
10346 (t (delete-file file)))
10347 (dired-delete-file
10348 file 'dired-recursive-deletes delete-by-moving-to-trash))
10349 (when buffers
10350 (dolist (buf buffers)
10351 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10352 (kill-buffer buf))))))
10354 (defun anything-get-mailcap-for-file (filename)
10355 "Get the command to use for FILENAME from mailcap files.
10356 The command is like <command %s> and is meant to use with `format'."
10357 (mailcap-parse-mailcaps)
10358 (let* ((ext (file-name-extension filename))
10359 (mime (when ext (mailcap-extension-to-mime ext)))
10360 (result (when mime (mailcap-mime-info mime))))
10361 ;; If elisp file have no associations in .mailcap
10362 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10363 (when (stringp result) result)))
10365 (defun anything-get-default-program-for-file (filename)
10366 "Try to find a default program to open FILENAME.
10367 Try first in `anything-c-external-programs-associations' and then in mailcap file
10368 if nothing found return nil."
10369 (let* ((ext (file-name-extension filename))
10370 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10371 (cond ((and def-prog (not (string= def-prog "")))
10372 (concat def-prog " %s"))
10373 ((and anything-c-default-external-file-browser
10374 (file-directory-p filename))
10375 (concat anything-c-default-external-file-browser " %s"))
10376 (t (anything-get-mailcap-for-file filename)))))
10378 (defun anything-c-open-file-externally (file)
10379 "Open FILE with an external program.
10380 Try to guess which program to use with `anything-get-default-program-for-file'.
10381 If not found or a prefix arg is given query the user which tool to use."
10382 (let* ((fname (expand-file-name file))
10383 (collection (anything-c-external-commands-list-1 'sort))
10384 (def-prog (anything-get-default-program-for-file fname))
10385 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10386 ;; Prefix arg or no default program.
10387 (prog1
10388 (anything-comp-read
10389 "Program: " collection
10390 :must-match t
10391 :name "Open file Externally"
10392 :history anything-external-command-history)
10393 ;; Always prompt to set this program as default.
10394 (setq def-prog nil))
10395 ;; No prefix arg or default program exists.
10396 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10397 (program (concat real-prog-name " %s")))
10398 (unless (or def-prog ; Association exists, no need to record it.
10399 ;; Don't try to record non--filenames associations (e.g urls).
10400 (not (file-exists-p fname)))
10401 (when
10402 (y-or-n-p
10403 (format
10404 "Do you want to make `%s' the default program for this kind of files? "
10405 real-prog-name))
10406 (anything-aif (assoc (file-name-extension fname)
10407 anything-c-external-programs-associations)
10408 (setq anything-c-external-programs-associations
10409 (delete it anything-c-external-programs-associations)))
10410 (push (cons (file-name-extension fname)
10411 (read-string
10412 "Program (Add args maybe and confirm): " real-prog-name))
10413 anything-c-external-programs-associations)
10414 (customize-save-variable 'anything-c-external-programs-associations
10415 anything-c-external-programs-associations)))
10416 (anything-run-or-raise program file)
10417 (setq anything-external-command-history
10418 (cons real-prog-name
10419 (delete real-prog-name
10420 (loop for i in anything-external-command-history
10421 when (executable-find i) collect i))))))
10423 (defun anything-c-find-file-or-marked (candidate)
10424 "Open file CANDIDATE or open anything marked files in background."
10425 (let ((marked (anything-marked-candidates))
10426 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10427 (find-file-wildcards nil))
10428 (if (> (length marked) 1)
10429 ;; Open all marked files in background and display
10430 ;; the first one.
10431 (progn (mapc 'find-file-noselect (cdr marked))
10432 (find-file (car marked)))
10433 (if (and (not (file-exists-p candidate))
10434 (and ffap-url-regexp
10435 (not (string-match ffap-url-regexp candidate)))
10436 (string-match "/$" candidate))
10437 ;; A a non--existing filename ending with /
10438 ;; Create a directory and jump to it.
10439 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10440 (let ((dirfname (directory-file-name candidate)))
10441 (if (file-exists-p dirfname)
10442 (error "Mkdir: Unable to create directory `%s': file exists."
10443 (anything-c-basename dirfname))
10444 (make-directory candidate 'parent)))
10445 (anything-find-files-1 candidate))
10446 ;; A non--existing filename NOT ending with / or
10447 ;; an existing filename, create or jump to it.
10448 (find-file-at-point (car marked))))))
10450 (defun anything-delete-marked-files (ignore)
10451 (let* ((files (anything-marked-candidates))
10452 (len (length files)))
10453 (if (not (y-or-n-p
10454 (format "Delete *%s File(s):\n%s"
10456 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10457 (message "(No deletions performed)")
10458 (dolist (i files)
10459 (set-text-properties 0 (length i) nil i)
10460 (anything-c-delete-file i anything-ff-signal-error-on-dot-files))
10461 (message "%s File(s) deleted" len))))
10463 (defun anything-ediff-marked-buffers (candidate &optional merge)
10464 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10465 With optional arg MERGE call `ediff-merge-buffers'."
10466 (let ((lg-lst (length (anything-marked-candidates)))
10467 buf1 buf2)
10468 (case lg-lst
10470 (error "Error:You have to mark at least 1 buffer"))
10472 (setq buf1 anything-current-buffer
10473 buf2 (first (anything-marked-candidates))))
10475 (setq buf1 (first (anything-marked-candidates))
10476 buf2 (second (anything-marked-candidates))))
10478 (error "Error:To much buffers marked!")))
10479 (if merge
10480 (ediff-merge-buffers buf1 buf2)
10481 (ediff-buffers buf1 buf2))))
10483 (defun anything-ediff-marked-buffers-merge (candidate)
10484 "Ediff merge `anything-current-buffer' with CANDIDATE.
10485 See `anything-ediff-marked-buffers'."
10486 (anything-ediff-marked-buffers candidate t))
10488 (defun anything-bookmark-get-bookmark-from-name (bmk)
10489 "Return bookmark name even if it is a bookmark with annotation.
10490 e.g prepended with *.
10491 Return nil if bmk is not a valid bookmark."
10492 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10493 (if (assoc bookmark bookmark-alist)
10494 bookmark
10495 (when (assoc bmk bookmark-alist)
10496 bmk))))
10498 (defun anything-delete-marked-bookmarks (ignore)
10499 "Delete this bookmark or all marked bookmarks."
10500 (dolist (i (anything-marked-candidates))
10501 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10502 'batch)))
10504 (defun anything-require-or-error (feature function)
10505 (or (require feature nil t)
10506 (error "Need %s to use `%s'." feature function)))
10508 (defun anything-find-buffer-on-elscreen (candidate)
10509 "Open buffer in new screen, if marked buffers open all in elscreens."
10510 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10511 (anything-aif (anything-marked-candidates)
10512 (dolist (i it)
10513 (let ((target-screen (elscreen-find-screen-by-buffer
10514 (get-buffer i) 'create)))
10515 (elscreen-goto target-screen)))
10516 (let ((target-screen (elscreen-find-screen-by-buffer
10517 (get-buffer candidate) 'create)))
10518 (elscreen-goto target-screen))))
10520 (defun anything-elscreen-find-file (file)
10521 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10522 (elscreen-find-file file))
10524 (defun anything-w32-prepare-filename (file)
10525 "Convert filename FILE to something usable by external w32 executables."
10526 (replace-regexp-in-string ; For UNC paths
10527 "/" "\\"
10528 (replace-regexp-in-string ; Strip cygdrive paths
10529 "/cygdrive/\\(.\\)" "\\1:"
10530 file nil nil) nil t))
10532 ;;;###autoload
10533 (defun anything-w32-shell-execute-open-file (file)
10534 (interactive "fOpen file:")
10535 (with-no-warnings
10536 (w32-shell-execute "open" (anything-w32-prepare-filename file))))
10538 (defun anything-c-open-file-with-default-tool (file)
10539 "Open FILE with the default tool on this platform."
10540 (if (eq system-type 'windows-nt)
10541 (anything-w32-shell-execute-open-file file)
10542 (start-process "anything-c-open-file-with-default-tool"
10544 (cond ((eq system-type 'gnu/linux)
10545 "xdg-open")
10546 ((or (eq system-type 'darwin) ;; Mac OS X
10547 (eq system-type 'macos)) ;; Mac OS 9
10548 "open"))
10549 file)))
10551 (defun anything-c-open-dired (file)
10552 "Opens a dired buffer in FILE's directory. If FILE is a
10553 directory, open this directory."
10554 (if (file-directory-p file)
10555 (dired file)
10556 (dired (file-name-directory file))
10557 (dired-goto-file file)))
10559 (defun anything-c-display-to-real-line (candidate)
10560 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10561 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10562 (error "Line number not found")))
10564 (defun anything-c-action-line-goto (lineno-and-content)
10565 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10566 (append lineno-and-content
10567 (list (if (and (anything-attr-defined 'target-file)
10568 (not anything-in-persistent-action))
10569 'find-file-other-window
10570 'find-file)))))
10572 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10573 (apply #'anything-goto-file-line
10574 (if (stringp file-line-content)
10575 ;; Case: filtered-candidate-transformer is skipped
10576 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10577 file-line-content)))
10579 (require 'compile)
10580 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10581 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10583 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10584 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10585 (let ((filename (match-string 1 candidate))
10586 (lineno (match-string 2 candidate))
10587 (content (match-string 3 candidate)))
10588 (cons (format "%s:%s\n %s"
10589 (propertize filename 'face compilation-info-face)
10590 (propertize lineno 'face compilation-line-face)
10591 content)
10592 (list (expand-file-name
10593 filename
10594 (or (anything-interpret-value (anything-attr 'default-directory))
10595 (and (anything-candidate-buffer)
10596 (buffer-local-value
10597 'default-directory (anything-candidate-buffer)))))
10598 (string-to-number lineno) content)))))
10600 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10601 (anything-aif (anything-attr 'before-jump-hook)
10602 (funcall it))
10603 (when file (funcall find-file-function file))
10604 (if (anything-attr-defined 'adjust)
10605 (anything-c-goto-line-with-adjustment lineno content)
10606 (anything-goto-line lineno))
10607 (unless (anything-attr-defined 'recenter)
10608 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10609 (anything-aif (anything-attr 'after-jump-hook)
10610 (funcall it))
10611 (when anything-in-persistent-action
10612 (anything-match-line-color-current-line)))
10614 (defun anything-find-file-as-root (candidate)
10615 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10617 (defun anything-find-many-files (ignore)
10618 (mapc 'find-file (anything-marked-candidates)))
10620 ;; borrowed from etags.el
10621 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10622 (defun anything-c-goto-line-with-adjustment (line line-content)
10623 (let ((startpos)
10624 offset found pat)
10625 ;; This constant is 1/2 the initial search window.
10626 ;; There is no sense in making it too small,
10627 ;; since just going around the loop once probably
10628 ;; costs about as much as searching 2000 chars.
10629 (setq offset 1000
10630 found nil
10631 pat (concat (if (eq selective-display t)
10632 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10633 (regexp-quote line-content)))
10634 ;; If no char pos was given, try the given line number.
10635 (setq startpos (progn (anything-goto-line line) (point)))
10636 (or startpos (setq startpos (point-min)))
10637 ;; First see if the tag is right at the specified location.
10638 (goto-char startpos)
10639 (setq found (looking-at pat))
10640 (while (and (not found)
10641 (progn
10642 (goto-char (- startpos offset))
10643 (not (bobp))))
10644 (setq found
10645 (re-search-forward pat (+ startpos offset) t)
10646 offset (* 3 offset))) ; expand search window
10647 (or found
10648 (re-search-forward pat nil t)
10649 (error "not found")))
10650 ;; Position point at the right place
10651 ;; if the search string matched an extra Ctrl-m at the beginning.
10652 (and (eq selective-display t)
10653 (looking-at "\^m")
10654 (forward-char 1))
10655 (beginning-of-line))
10657 (anything-document-attribute 'default-directory "type . file-line"
10658 "`default-directory' to interpret file.")
10659 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10660 "Function to call before jumping to the target location.")
10661 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10662 "Function to call after jumping to the target location.")
10663 (anything-document-attribute 'adjust "type . file-line"
10664 "Search around line matching line contents.")
10665 (anything-document-attribute 'recenter "type . file-line / line"
10666 "`recenter' after jumping.")
10667 (anything-document-attribute 'target-file "type . line"
10668 "Goto line of target-file.")
10670 ;;;###autoload
10671 (defun anything-c-call-interactively (cmd-or-name)
10672 "Execute CMD-OR-NAME as Emacs command.
10673 It is added to `extended-command-history'.
10674 `anything-current-prefix-arg' is used as the command's prefix argument."
10675 (setq extended-command-history
10676 (cons (anything-c-stringify cmd-or-name)
10677 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10678 (let ((current-prefix-arg anything-current-prefix-arg)
10679 (cmd (anything-c-symbolify cmd-or-name)))
10680 (if (stringp (symbol-function cmd))
10681 (execute-kbd-macro (symbol-function cmd))
10682 (setq this-command cmd)
10683 (call-interactively cmd))))
10685 ;;;###autoload
10686 (defun anything-c-set-variable (var)
10687 "Set value to VAR interactively."
10688 (interactive)
10689 (let ((sym (anything-c-symbolify var)))
10690 (set sym (eval-minibuffer (format "Set %s: " var)
10691 (prin1-to-string (symbol-value sym))))))
10692 ;; (setq hh 12)
10693 ;; (anything-c-set-variable 'hh)
10697 ;;; Persistent Action Helpers
10700 (defvar anything-match-line-overlay-face nil)
10701 (defvar anything-match-line-overlay nil)
10703 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10704 "Highlight and underline current position"
10705 (let ((args (list (or start (line-beginning-position))
10706 (or end (1+ (line-end-position)))
10707 buf)))
10708 (if (not anything-match-line-overlay)
10709 (setq anything-match-line-overlay (apply 'make-overlay args))
10710 (apply 'move-overlay anything-match-line-overlay args)))
10711 (overlay-put anything-match-line-overlay
10712 'face (or face anything-match-line-overlay-face))
10713 (when rec
10714 (goto-char start)
10715 (recenter)))
10717 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10720 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10722 (defun anything-match-line-cleanup ()
10723 (when anything-match-line-overlay
10724 (delete-overlay anything-match-line-overlay)
10725 (setq anything-match-line-overlay nil)))
10727 (defun anything-match-line-update ()
10728 (when anything-match-line-overlay
10729 (delete-overlay anything-match-line-overlay)
10730 (anything-match-line-color-current-line)))
10732 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10733 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10736 ;;; Actions Transformers
10739 ;;; Files
10740 (defun anything-c-transform-file-load-el (actions candidate)
10741 "Add action to load the file CANDIDATE if it is an emacs lisp
10742 file. Else return ACTIONS unmodified."
10743 (if (member (file-name-extension candidate) '("el" "elc"))
10744 (append actions '(("Load Emacs Lisp File" . load-file)))
10745 actions))
10747 (defun anything-c-transform-file-browse-url (actions candidate)
10748 "Add an action to browse the file CANDIDATE if it in a html
10749 file or URL. Else return ACTIONS unmodified."
10750 (let ((browse-action '("Browse with Browser" . browse-url)))
10751 (cond ((string-match "^http\\|^ftp" candidate)
10752 (cons browse-action actions))
10753 ((string-match "\\.html?$" candidate)
10754 (append actions (list browse-action)))
10755 (t actions))))
10757 ;;; Function
10758 (defun anything-c-transform-function-call-interactively (actions candidate)
10759 "Add an action to call the function CANDIDATE interactively if
10760 it is a command. Else return ACTIONS unmodified."
10761 (if (commandp (intern-soft candidate))
10762 (append actions '(("Call Interactively"
10764 anything-c-call-interactively)))
10765 actions))
10767 ;;;; S-Expressions
10768 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10769 "If CANDIDATE's `car' is a command, then add an action to
10770 evaluate it and put it onto the `command-history'."
10771 (if (commandp (car (read candidate)))
10772 ;; Make it first entry
10773 (cons '("Eval and put onto command-history" .
10774 (lambda (sexp)
10775 (let ((sym (read sexp)))
10776 (eval sym)
10777 (setq command-history
10778 (cons sym command-history)))))
10779 actions)
10780 actions))
10783 ;;; Candidate Transformers
10786 ;;; Buffers
10787 (defun anything-c-skip-boring-buffers (buffers)
10788 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10790 (defun anything-c-skip-current-buffer (buffers)
10791 (if anything-allow-skipping-current-buffer
10792 (remove (buffer-name anything-current-buffer) buffers)
10793 buffers))
10795 (defun anything-c-shadow-boring-buffers (buffers)
10796 "Buffers matching `anything-c-boring-buffer-regexp' will be
10797 displayed with the `file-name-shadow' face if available."
10798 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10800 (defvar anything-c-buffer-display-string-functions
10801 '(anything-c-buffer-display-string--compilation
10802 anything-c-buffer-display-string--shell
10803 anything-c-buffer-display-string--eshell)
10804 "Functions to setup display string for buffer.
10806 Function has one argument, buffer name.
10807 If it returns string, use it.
10808 If it returns nil, display buffer name.
10809 See `anything-c-buffer-display-string--compilation' for example.")
10811 (defun anything-c-transform-buffer-display-string (buffers)
10812 "Setup display string for buffer candidates
10813 using `anything-c-buffer-display-string-functions'."
10814 (loop for buf in buffers
10815 if (consp buf)
10816 collect buf
10817 else
10818 for disp = (progn (set-buffer buf)
10819 (run-hook-with-args-until-success
10820 'anything-c-buffer-display-string-functions buf))
10821 collect (if disp (cons disp buf) buf)))
10823 (defun anything-c-buffer-display-string--compilation (buf)
10824 (anything-aif (car compilation-arguments)
10825 (format "%s: %s [%s]" buf it default-directory)))
10827 (defun anything-c-buffer-display-string--eshell (buf)
10828 (declare (special eshell-history-ring))
10829 (when (eq major-mode 'eshell-mode)
10830 (format "%s: %s [%s]" buf
10831 (ignore-errors (ring-ref eshell-history-ring 0))
10832 default-directory)))
10834 (defun anything-c-buffer-display-string--shell (buf)
10835 (when (eq major-mode 'shell-mode)
10836 (format "%s: %s [%s]" buf
10837 (ignore-errors (ring-ref comint-input-ring 0))
10838 default-directory)))
10840 ;;; Files
10841 (defun anything-c-shadow-boring-files (files)
10842 "Files matching `anything-c-boring-file-regexp' will be
10843 displayed with the `file-name-shadow' face if available."
10844 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10846 (defun anything-c-skip-boring-files (files)
10847 "Files matching `anything-c-boring-file-regexp' will be skipped."
10848 (anything-c-skip-entries files anything-c-boring-file-regexp))
10849 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10851 (defun anything-c-skip-current-file (files)
10852 "Current file will be skipped."
10853 (remove (buffer-file-name anything-current-buffer) files))
10855 (defun anything-c-w32-pathname-transformer (args)
10856 "Change undesirable features of windows pathnames to ones more acceptable to
10857 other candidate transformers."
10858 (if (eq system-type 'windows-nt)
10859 (mapcar (lambda (x)
10860 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10861 (mapcar (lambda (y)
10862 (replace-regexp-in-string "\\\\" "/" y)) args))
10863 args))
10865 (defun anything-c-shorten-home-path (files)
10866 "Replaces /home/user with ~."
10867 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10868 (getenv "HOME"))))
10869 (mapcar (lambda (file)
10870 (if (and (stringp file) (string-match home file))
10871 (cons (replace-match "~" nil nil file) file)
10872 file))
10873 files)))
10875 ;;; Functions
10876 (defun anything-c-mark-interactive-functions (functions)
10877 "Mark interactive functions (commands) with (i) after the function name."
10878 (let (list)
10879 (loop for function in functions
10880 do (push (cons (concat function
10881 (when (commandp (intern-soft function)) " (i)"))
10882 function)
10883 list)
10884 finally (return (nreverse list)))))
10887 ;;; Adaptive Sorting of Candidates
10890 ;; Internal
10891 (defvar anything-c-adaptive-done nil
10892 "nil if history information is not yet stored for the current
10893 selection.")
10895 (defvar anything-c-adaptive-history nil
10896 "Contains the stored history information.
10897 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10899 ;; Should run at beginning of `anything-initial-setup'.
10900 (add-hook 'anything-before-initialize-hook #'(lambda ()
10901 (when anything-c-use-adaptative-sorting
10902 (setq anything-c-adaptive-done nil))))
10904 ;; Should run at beginning of `anything-exit-minibuffer'.
10905 (add-hook 'anything-before-action-hook #'(lambda ()
10906 (when anything-c-use-adaptative-sorting
10907 (anything-c-adaptive-store-selection))))
10909 ;; Should run at beginning of `anything-select-action'.
10910 (add-hook 'anything-select-action-hook #'(lambda ()
10911 (when anything-c-use-adaptative-sorting
10912 (anything-c-adaptive-store-selection))))
10914 (defun anything-c-source-use-adaptative-p (&optional source-name)
10915 "Return current source only if it use adaptative history, nil otherwise."
10916 (when anything-c-use-adaptative-sorting
10917 (let* ((source (or source-name (anything-get-current-source)))
10918 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10919 (assoc (assoc-default 'type source)
10920 anything-type-attributes))
10921 (assoc-default 'candidate-transformer
10922 (assoc (assoc-default 'type source)
10923 anything-type-attributes))
10924 (assoc-default 'filtered-candidate-transformer source)
10925 (assoc-default 'candidate-transformer source))))
10926 (if (listp adapt-source)
10927 (when (member 'anything-c-adaptive-sort adapt-source) source)
10928 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10930 (defun anything-c-adaptive-store-selection ()
10931 "Store history information for the selected candidate."
10932 (unless anything-c-adaptive-done
10933 (setq anything-c-adaptive-done t)
10934 (let ((source (anything-c-source-use-adaptative-p)))
10935 (when source
10936 (let* ((source-name (or (assoc-default 'type source)
10937 (assoc-default 'name source)))
10938 (source-info (or (assoc source-name anything-c-adaptive-history)
10939 (progn
10940 (push (list source-name) anything-c-adaptive-history)
10941 (car anything-c-adaptive-history))))
10942 (selection (anything-get-selection))
10943 (selection-info (progn
10944 (setcdr source-info
10945 (cons
10946 (let ((found (assoc selection (cdr source-info))))
10947 (if (not found)
10948 ;; new entry
10949 (list selection)
10951 ;; move entry to the beginning of the
10952 ;; list, so that it doesn't get
10953 ;; trimmed when the history is
10954 ;; truncated
10955 (setcdr source-info
10956 (delete found (cdr source-info)))
10957 found))
10958 (cdr source-info)))
10959 (cadr source-info)))
10960 (pattern-info (progn
10961 (setcdr selection-info
10962 (cons
10963 (let ((found (assoc anything-pattern (cdr selection-info))))
10964 (if (not found)
10965 ;; new entry
10966 (cons anything-pattern 0)
10968 ;; move entry to the beginning of the
10969 ;; list, so if two patterns used the
10970 ;; same number of times then the one
10971 ;; used last appears first in the list
10972 (setcdr selection-info
10973 (delete found (cdr selection-info)))
10974 found))
10975 (cdr selection-info)))
10976 (cadr selection-info))))
10978 ;; increase usage count
10979 (setcdr pattern-info (1+ (cdr pattern-info)))
10981 ;; truncate history if needed
10982 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10983 (setcdr selection-info
10984 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10986 (defun anything-c-adaptative-maybe-load-history ()
10987 (when (and anything-c-use-adaptative-sorting
10988 (file-readable-p anything-c-adaptive-history-file))
10989 (load-file anything-c-adaptive-history-file)))
10991 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10992 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10994 (defun anything-c-adaptive-save-history (&optional arg)
10995 "Save history information to file given by `anything-c-adaptive-history-file'."
10996 (interactive "p")
10997 (when anything-c-use-adaptative-sorting
10998 (with-temp-buffer
10999 (insert
11000 ";; -*- mode: emacs-lisp -*-\n"
11001 ";; History entries used for anything adaptive display.\n")
11002 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
11003 (current-buffer))
11004 (insert ?\n)
11005 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11006 (unless arg 'quiet)))))
11008 (defun anything-c-adaptive-sort (candidates source)
11009 "Sort the CANDIDATES for SOURCE by usage frequency.
11010 This is a filtered candidate transformer you can use for the
11011 attribute `filtered-candidate-transformer' of a source in
11012 `anything-sources' or a type in `anything-type-attributes'."
11013 (let* ((source-name (or (assoc-default 'type source)
11014 (assoc-default 'name source)))
11015 (source-info (assoc source-name anything-c-adaptive-history)))
11016 (if source-info
11017 (let ((usage
11018 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11019 ;; pairs
11020 (mapcar (lambda (candidate-info)
11021 (let ((count 0))
11022 (dolist (pattern-info (cdr candidate-info))
11023 (if (not (equal (car pattern-info)
11024 anything-pattern))
11025 (incf count (cdr pattern-info))
11027 ;; if current pattern is equal to the previously
11028 ;; used one then this candidate has priority
11029 ;; (that's why its count is boosted by 10000) and
11030 ;; it only has to compete with other candidates
11031 ;; which were also selected with the same pattern
11032 (setq count (+ 10000 (cdr pattern-info)))
11033 (return)))
11034 (cons (car candidate-info) count)))
11035 (cdr source-info)))
11036 sorted)
11037 (if (and usage (consp usage))
11038 ;; sort the list in descending order, so candidates with highest
11039 ;; priorty come first
11040 (progn
11041 (setq usage (sort usage (lambda (first second)
11042 (> (cdr first) (cdr second)))))
11044 ;; put those candidates first which have the highest usage count
11045 (dolist (info usage)
11046 (when (member* (car info) candidates
11047 :test 'anything-c-adaptive-compare)
11048 (push (car info) sorted)
11049 (setq candidates (remove* (car info) candidates
11050 :test 'anything-c-adaptive-compare))))
11052 ;; and append the rest
11053 (append (reverse sorted) candidates nil))
11054 (message "Your `%s' is maybe corrupted or too old, \
11055 you should reinitialize it with `anything-c-reset-adaptative-history'"
11056 anything-c-adaptive-history-file)
11057 (sit-for 1)
11058 candidates))
11059 ;; if there is no information stored for this source then do nothing
11060 candidates)))
11062 ;;;###autoload
11063 (defun anything-c-reset-adaptative-history ()
11064 "Delete all `anything-c-adaptive-history' and his file.
11065 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11066 (interactive)
11067 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11068 (setq anything-c-adaptive-history nil)
11069 (delete-file anything-c-adaptive-history-file)))
11071 (defun anything-c-adaptive-compare (x y)
11072 "Compare candidates X and Y taking into account that the
11073 candidate can be in (DISPLAY . REAL) format."
11074 (equal (if (listp x)
11075 (cdr x)
11077 (if (listp y)
11078 (cdr y)
11079 y)))
11083 ;;; Outliner
11086 (defvar anything-outline-goto-near-line-flag t)
11087 (defvar anything-outline-using nil)
11088 (defun anything-after-update-hook--outline ()
11089 (if (and (eq anything-outline-using t)
11090 (eq anything-outline-goto-near-line-flag t))
11091 (anything-outline-goto-near-line)))
11092 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11094 (defun anything-outline-goto-near-line ()
11095 (with-anything-window
11096 ;; TODO need consideration whether to update position by every input.
11097 (when t ; (equal anything-pattern "")
11098 (anything-goto-line 2)
11099 (let ((lineno (with-anything-current-buffer
11100 (line-number-at-pos (car anything-current-position)))))
11101 (block exit
11102 (while (<= (progn (skip-chars-forward " ")
11103 (or (number-at-point) lineno))
11104 lineno)
11105 (forward-line 1)
11106 (when (eobp)
11107 (forward-line -1)
11108 (return-from exit))))
11109 (forward-line -1)
11110 (and (bobp) (forward-line 1))
11111 (and (anything-pos-header-line-p) (forward-line -2))
11112 (anything-mark-current-line)))))
11116 ;;; Plug-in
11119 ;; Plug-in: info-index
11120 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11121 (let (result)
11122 (unless (anything-candidate-buffer)
11123 (save-window-excursion
11124 (info file)
11125 (let (Info-history
11126 (tobuf (anything-candidate-buffer 'global))
11127 (infobuf (current-buffer))
11128 s e)
11129 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11130 (Info-goto-node node)
11131 (goto-char (point-min))
11132 (while (search-forward "\n* " nil t)
11133 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11134 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11135 (setq s (point-at-bol)
11136 e (point-at-eol))
11137 (with-current-buffer tobuf
11138 (insert-buffer-substring infobuf s e)
11139 (insert "\n"))))))))))
11141 (defun anything-c-info-goto (node-line)
11142 (Info-goto-node (car node-line))
11143 (anything-goto-line (cdr node-line)))
11145 (defun anything-c-info-display-to-real (line)
11146 (and (string-match
11147 ;; This regexp is stolen from Info-apropos-matches
11148 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11149 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11150 (string-to-number (or (match-string 3 line) "1")))))
11152 (defun anything-c-make-info-source (source file)
11153 `(,@source
11154 (name . ,(concat "Info Index: " file))
11155 (info-file . ,file)
11156 (init . anything-c-info-init)
11157 (display-to-real . anything-c-info-display-to-real)
11158 (get-line . buffer-substring)
11159 (candidates-in-buffer)
11160 (action ("Goto node" . anything-c-info-goto))))
11162 (defun anything-compile-source--info-index (source)
11163 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11164 (anything-c-make-info-source source it)
11165 source))
11166 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11168 (anything-document-attribute 'info-index "info-index plugin"
11169 "Create a source of info index very easily.
11171 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11173 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11174 "Index nodes of info file.
11176 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11177 Some info files are missing index specification.
11179 ex. See `anything-c-source-info-screen'.")
11181 ;; Plug-in: candidates-file
11182 (defun anything-compile-source--candidates-file (source)
11183 (if (assoc-default 'candidates-file source)
11184 `((init anything-p-candidats-file-init
11185 ,@(let ((orig-init (assoc-default 'init source)))
11186 (cond ((null orig-init) nil)
11187 ((functionp orig-init) (list orig-init))
11188 (t orig-init))))
11189 (candidates-in-buffer)
11190 ,@source)
11191 source))
11192 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11194 (defun anything-p-candidats-file-init ()
11195 (destructuring-bind (file &optional updating)
11196 (anything-mklist (anything-attr 'candidates-file))
11197 (setq file (anything-interpret-value file))
11198 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11199 (when updating
11200 (buffer-disable-undo)
11201 (font-lock-mode -1)
11202 (auto-revert-mode 1)))))
11204 (anything-document-attribute 'candidates-file "candidates-file plugin"
11205 "Use a file as the candidates buffer.
11207 1st argument is a filename, string or function name or variable name.
11208 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11210 ;; Plug-in: headline
11211 (defun anything-compile-source--anything-headline (source)
11212 (if (assoc-default 'headline source)
11213 (append '((init . anything-headline-init)
11214 (get-line . buffer-substring)
11215 (type . line))
11216 source
11217 '((candidates-in-buffer)
11218 (persistent-help . "Show this line")))
11219 source))
11220 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11222 (defun anything-headline-init ()
11223 (when (and (anything-current-buffer-is-modified)
11224 (with-anything-current-buffer
11225 (eval (or (anything-attr 'condition) t))))
11226 (anything-headline-make-candidate-buffer
11227 (anything-interpret-value (anything-attr 'headline))
11228 (anything-interpret-value (anything-attr 'subexp)))))
11230 (anything-document-attribute 'headline "Headline plug-in"
11231 "Regexp string for anything-headline to scan.")
11232 (anything-document-attribute 'condition "Headline plug-in"
11233 "A sexp representing the condition to use anything-headline.")
11234 (anything-document-attribute 'subexp "Headline plug-in"
11235 "Display (match-string-no-properties subexp).")
11237 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11238 ;; of regexps.
11240 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11241 ;; 2. Sort this list by start-of-match.
11242 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11244 ;; It's quite brilliantly written.
11248 (defun anything-headline-get-candidates (regexp subexp)
11249 (with-anything-current-buffer
11250 (save-excursion
11251 (goto-char (point-min))
11252 (if (functionp regexp) (setq regexp (funcall regexp)))
11253 (let (hierarchy curhead)
11254 (flet ((matched ()
11255 (if (numberp subexp)
11256 (cons (match-string-no-properties subexp) (match-beginning subexp))
11257 (cons (buffer-substring (point-at-bol) (point-at-eol))
11258 (point-at-bol))))
11259 (hierarchies (headlines)
11260 (1+ (loop for (_ . hierarchy) in headlines
11261 maximize hierarchy)))
11262 (vector-0-n (v n)
11263 (loop for i from 0 to hierarchy
11264 collecting (aref curhead i)))
11265 (arrange (headlines)
11266 (unless (null headlines) ; FIX headlines empty bug!
11267 (loop with curhead = (make-vector (hierarchies headlines) "")
11268 for ((str . pt) . hierarchy) in headlines
11269 do (aset curhead hierarchy str)
11270 collecting
11271 (cons
11272 (format "H%d:%s" (1+ hierarchy)
11273 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11274 pt)))))
11275 (if (listp regexp)
11276 (arrange
11277 (sort
11278 (loop for re in regexp
11279 for hierarchy from 0
11280 do (goto-char (point-min))
11281 appending
11282 (loop
11283 while (re-search-forward re nil t)
11284 collect (cons (matched) hierarchy)))
11285 (lambda (a b) (> (cdar b) (cdar a)))))
11286 (loop while (re-search-forward regexp nil t)
11287 collect (matched))))))))
11290 (defun anything-headline-make-candidate-buffer (regexp subexp)
11291 (with-current-buffer (anything-candidate-buffer 'local)
11292 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11293 do (insert
11294 (format "%5d:%s\n"
11295 (with-anything-current-buffer
11296 (line-number-at-pos pos))
11297 content)))))
11299 (defun anything-headline-goto-position (pos recenter)
11300 (goto-char pos)
11301 (unless recenter
11302 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11305 ;; Plug-in: persistent-help
11306 (defun anything-compile-source--persistent-help (source)
11307 (append source '((header-line . anything-persistent-help-string))))
11308 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11310 (defun anything-persistent-help-string ()
11311 (substitute-command-keys
11312 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11313 (or (anything-interpret-value (anything-attr 'persistent-help))
11314 (anything-aif (or (assoc-default 'persistent-action
11315 (anything-get-current-source))
11316 (assoc-default 'action
11317 (anything-get-current-source)))
11318 (cond ((symbolp it) (symbol-name it))
11319 ((listp it) (or (ignore-errors (caar it)) ""))))
11321 " (keeping session)")))
11323 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11324 "A string to explain persistent-action of this source.
11325 It also accepts a function or a variable name.")
11327 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11329 ;; Plug-in: Type customize
11330 (defun anything-c-uniq-list (lst)
11331 "Like `remove-duplicates' in CL.
11332 But cut deeper duplicates and test by `equal'. "
11333 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11334 (defvar anything-additional-type-attributes nil)
11335 (defun anything-c-arrange-type-attribute (type spec)
11336 "Override type attributes by `define-anything-type-attribute'.
11338 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11340 Example: Set `play-sound-file' as default action
11341 (anything-c-arrange-type-attribute 'file
11342 '((action (\"Play sound\" . play-sound-file)
11343 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11346 (add-to-list 'anything-additional-type-attributes
11347 (cons type
11348 (loop with typeattr = (assoc-default type anything-type-attributes)
11349 for (attr . value) in spec
11350 if (listp value)
11351 collect (cons attr
11352 (anything-c-uniq-list
11353 (loop for v in value
11354 if (eq v 'REST)
11355 append (assoc-default attr typeattr)
11356 else
11357 collect v)))
11358 else
11359 collect (cons attr value)))))
11360 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11362 (defun anything-compile-source--type-customize (source)
11363 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11364 (append it source)
11365 source))
11366 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11368 ;; Plug-in: default-action
11369 (defun anything-compile-source--default-action (source)
11370 (anything-aif (assoc-default 'default-action source)
11371 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11372 source)
11373 source))
11374 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11375 (anything-document-attribute 'default-action "default-action plug-in"
11376 "Default action.")
11379 ;;; Toggle anything-match-plugin
11382 (defvar anything-mp-initial-highlight-delay nil)
11384 ;;;###autoload
11385 (defun anything-c-toggle-match-plugin ()
11386 "Toggle anything-match-plugin."
11387 (interactive)
11388 (let ((anything-match-plugin-enabled
11389 (member 'anything-compile-source--match-plugin
11390 anything-compile-source-functions)))
11391 (flet ((disable-match-plugin ()
11392 (setq anything-compile-source-functions
11393 (delq 'anything-compile-source--match-plugin
11394 anything-compile-source-functions))
11395 (setq anything-mp-initial-highlight-delay
11396 anything-mp-highlight-delay)
11397 (setq anything-mp-highlight-delay nil))
11398 (enable-match-plugin ()
11399 (require 'anything-match-plugin)
11400 (unless anything-mp-initial-highlight-delay
11401 (setq anything-mp-initial-highlight-delay
11402 anything-mp-highlight-delay))
11403 (setq anything-compile-source-functions
11404 (cons 'anything-compile-source--match-plugin
11405 anything-compile-source-functions))
11406 (unless anything-mp-highlight-delay
11407 (setq anything-mp-highlight-delay
11408 anything-mp-initial-highlight-delay))))
11409 (if anything-match-plugin-enabled
11410 (when (y-or-n-p "Really disable match-plugin? ")
11411 (disable-match-plugin)
11412 (message "Anything-match-plugin disabled"))
11413 (when (y-or-n-p "Really enable match-plugin? ")
11414 (enable-match-plugin)
11415 (message "Anything-match-plugin enabled"))))))
11419 ;;; Type Attributes
11422 (define-anything-type-attribute 'buffer
11423 `((action
11424 ("Switch to buffer" . anything-c-switch-to-buffer)
11425 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11426 ("Switch to buffer other window" . switch-to-buffer-other-window)
11427 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11428 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11429 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11430 ("Query replace" . anything-c-buffer-query-replace)
11431 ("View buffer" . view-buffer)
11432 ("Display buffer" . display-buffer)
11433 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11434 ("Revert buffer(s)" . anything-revert-marked-buffers)
11435 ("Insert buffer" . insert-buffer)
11436 ("Kill buffer(s)" . anything-kill-marked-buffers)
11437 ("Diff with file" . diff-buffer-with-file)
11438 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11439 ("Ediff Merge marked buffers" . (lambda (candidate)
11440 (anything-ediff-marked-buffers candidate t))))
11441 (persistent-help . "Show this buffer")
11442 (candidate-transformer anything-c-skip-current-buffer
11443 anything-c-skip-boring-buffers
11444 anything-c-transform-buffer-display-string))
11445 "Buffer or buffer name.")
11447 (define-anything-type-attribute 'file
11448 `((action
11449 ("Find file" . anything-find-many-files)
11450 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11451 ("Find file as root" . anything-find-file-as-root)
11452 ("Find file other window" . find-file-other-window)
11453 ("Find file other frame" . find-file-other-frame)
11454 ("Open dired in file's directory" . anything-c-open-dired)
11455 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11456 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11457 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11458 ("Checksum File" . anything-ff-checksum)
11459 ("Ediff File" . anything-find-files-ediff-files)
11460 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11461 ("View file" . view-file)
11462 ("Insert file" . insert-file)
11463 ("Delete file(s)" . anything-delete-marked-files)
11464 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11465 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11466 ("Find file in hex dump" . hexl-find-file))
11467 (persistent-help . "Show this file")
11468 (action-transformer anything-c-transform-file-load-el
11469 anything-c-transform-file-browse-url)
11470 (candidate-transformer anything-c-w32-pathname-transformer
11471 anything-c-skip-current-file
11472 anything-c-skip-boring-files
11473 anything-c-shorten-home-path))
11474 "File name.")
11476 (let ((actions '(("Describe command" . describe-function)
11477 ("Add command to kill ring" . anything-c-kill-new)
11478 ("Go to command's definition" . find-function)
11479 ("Debug on entry" . debug-on-entry)
11480 ("Cancel debug on entry" . cancel-debug-on-entry)
11481 ("Trace function" . trace-function)
11482 ("Trace function (background)" . trace-function-background)
11483 ("Untrace function" . untrace-function))))
11484 (define-anything-type-attribute 'command
11485 `((action ("Call interactively" . anything-c-call-interactively)
11486 ,@actions)
11487 ;; Sort commands according to their usage count.
11488 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11489 (coerce . anything-c-symbolify)
11490 (persistent-action . describe-function))
11491 "Command. (string or symbol)")
11493 (define-anything-type-attribute 'function
11494 `((action . ,actions)
11495 (action-transformer anything-c-transform-function-call-interactively)
11496 (candidate-transformer anything-c-mark-interactive-functions)
11497 (coerce . anything-c-symbolify))
11498 "Function. (string or symbol)"))
11500 (define-anything-type-attribute 'variable
11501 '((action ("Describe variable" . describe-variable)
11502 ("Add variable to kill ring" . anything-c-kill-new)
11503 ("Go to variable's definition" . find-variable)
11504 ("Set variable" . anything-c-set-variable))
11505 (coerce . anything-c-symbolify))
11506 "Variable.")
11508 (define-anything-type-attribute 'sexp
11509 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11510 ("Add s-expression to kill ring" . kill-new))
11511 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11512 "String representing S-Expressions.")
11514 (define-anything-type-attribute 'bookmark
11515 `((coerce . anything-bookmark-get-bookmark-from-name)
11516 (action
11517 ("Jump to bookmark" . (lambda (bookmark)
11518 (let ((current-prefix-arg anything-current-prefix-arg))
11519 (bookmark-jump bookmark))
11520 (anything-update)))
11521 ("Jump to BM other window" . (lambda (bookmark)
11522 (bookmark-jump-other-window bookmark)
11523 (anything-update)))
11524 ("Bookmark edit annotation" . bookmark-edit-annotation)
11525 ("Bookmark show annotation" . bookmark-show-annotation)
11526 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11527 ,@(and (locate-library "bookmark-extensions")
11528 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11529 ("Rename bookmark" . bookmark-rename)
11530 ("Relocate bookmark" . bookmark-relocate)))
11531 "Bookmark name.")
11533 (define-anything-type-attribute 'line
11534 '((display-to-real . anything-c-display-to-real-line)
11535 (action ("Go to Line" . anything-c-action-line-goto)))
11536 "LINENO:CONTENT string, eg. \" 16:foo\".
11538 Optional `target-file' attribute is a name of target file.
11540 Optional `before-jump-hook' attribute is a function with no
11541 arguments which is called before jumping to position.
11543 Optional `after-jump-hook' attribute is a function with no
11544 arguments which is called after jumping to position.
11546 If `adjust' attribute is specified, searches the line whose
11547 content is CONTENT near the LINENO.
11549 If `recenter' attribute is specified, the line is displayed at
11550 the center of window, otherwise at the top of window.
11553 (define-anything-type-attribute 'file-line
11554 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11555 (multiline)
11556 (action ("Go to" . anything-c-action-file-line-goto)))
11557 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11559 Optional `default-directory' attribute is a default-directory
11560 FILENAME is interpreted.
11562 Optional `before-jump-hook' attribute is a function with no
11563 arguments which is called before jumping to position.
11565 Optional `after-jump-hook' attribute is a function with no
11566 arguments which is called after jumping to position.
11568 If `adjust' attribute is specified, searches the line whose
11569 content is CONTENT near the LINENO.
11571 If `recenter' attribute is specified, the line is displayed at
11572 the center of window, otherwise at the top of window.
11575 (define-anything-type-attribute 'timer
11576 '((real-to-display . anything-c-timer-real-to-display)
11577 (action ("Cancel Timer" . cancel-timer)
11578 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11579 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11580 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11581 (persistent-help . "Describe Function"))
11582 "Timer.")
11585 ;;; Default `anything-sources'
11586 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11587 ;; tend to invoke M-x anything directly. So I offer default setting.
11588 (setq anything-sources
11589 '(anything-c-source-buffers-list
11590 anything-c-source-recentf
11591 anything-c-source-files-in-current-dir+))
11594 ;;; Preconfigured Anything
11597 ;;;###autoload
11598 (defun anything-mini ()
11599 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11600 (interactive)
11601 (anything-other-buffer '(anything-c-source-buffers-list
11602 anything-c-source-recentf
11603 anything-c-source-buffer-not-found)
11604 "*anything mini*"))
11605 ;;;###autoload
11606 (defun anything-for-files ()
11607 "Preconfigured `anything' for opening files.
11608 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11609 (interactive)
11610 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11612 ;;;###autoload
11613 (defun anything-recentf ()
11614 "Preconfigured `anything' for `recentf'."
11615 (interactive)
11616 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11618 ;;;###autoload
11619 (defun anything-info-at-point (arg)
11620 "Preconfigured `anything' for searching info at point.
11621 With a prefix-arg insert symbol at point."
11622 (interactive "P")
11623 (let ((anything-c-google-suggest-default-function
11624 'anything-c-google-suggest-emacs-lisp))
11625 (anything :sources '(anything-c-source-info-elisp
11626 anything-c-source-info-cl
11627 anything-c-source-info-pages
11628 anything-c-source-google-suggest)
11629 :input (and arg (thing-at-point 'symbol))
11630 :buffer "*anything info*")))
11632 ;;;###autoload
11633 (defun anything-info-emacs ()
11634 "Preconfigured anything for Emacs manual index."
11635 (interactive)
11636 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11638 ;;;###autoload
11639 (defun anything-show-kill-ring ()
11640 "Preconfigured `anything' for `kill-ring'.
11641 It is drop-in replacement of `yank-pop'.
11642 You may bind this command to M-y.
11643 First call open the kill-ring browser, next calls move to next line."
11644 (interactive)
11645 (let ((buf "*anything kill-ring*"))
11646 (if (get-buffer-window buf)
11647 (with-anything-window
11648 (if (eq (overlay-end anything-selection-overlay) (point-max))
11649 (anything-beginning-of-buffer)
11650 (anything-next-line)))
11651 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11653 ;;;###autoload
11654 (defun anything-minibuffer-history ()
11655 "Preconfigured `anything' for `minibuffer-history'."
11656 (interactive)
11657 (let ((enable-recursive-minibuffers t))
11658 (anything-other-buffer 'anything-c-source-minibuffer-history
11659 "*anything minibuffer-history*")))
11661 ;;;###autoload
11662 (defun anything-gentoo ()
11663 "Preconfigured `anything' for gentoo linux."
11664 (interactive)
11665 (anything-other-buffer '(anything-c-source-gentoo
11666 anything-c-source-use-flags)
11667 "*anything gentoo*"))
11669 ;;;###autoload
11670 (defun anything-imenu ()
11671 "Preconfigured `anything' for `imenu'."
11672 (interactive)
11673 (anything :sources 'anything-c-source-imenu
11674 :buffer "*anything imenu*"))
11676 ;;;###autoload
11677 (defun anything-google-suggest ()
11678 "Preconfigured `anything' for google search with google suggest."
11679 (interactive)
11680 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11682 ;;;###autoload
11683 (defun anything-yahoo-suggest ()
11684 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11685 (interactive)
11686 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11688 ;;; Converted from anything-show-*-only
11689 ;;;###autoload
11690 (defun anything-for-buffers ()
11691 "Preconfigured `anything' for buffer."
11692 (interactive)
11693 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11695 ;;;###autoload
11696 (defun anything-buffers-list ()
11697 "Enhanced preconfigured `anything' for buffer."
11698 (interactive)
11699 (anything :sources '(anything-c-source-buffers-list
11700 anything-c-source-buffer-not-found)
11701 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11702 (defalias 'anything-buffers+ 'anything-buffer-list)
11703 ;;;###autoload
11704 (defun anything-bbdb ()
11705 "Preconfigured `anything' for BBDB.
11707 Needs BBDB.
11709 http://bbdb.sourceforge.net/"
11710 (interactive)
11711 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11713 ;;;###autoload
11714 (defun anything-locate (arg)
11715 "Preconfigured `anything' for Locate.
11716 Note: you can add locate options after entering pattern.
11717 See 'man locate' for valid options.
11719 You can specify a specific database with prefix argument ARG \(C-u\).
11720 Many databases can be used: navigate and mark them.
11721 See also `anything-locate-with-db'.
11723 To create a user specific db, use
11724 \"updatedb -l 0 -o db_path -U directory\".
11725 Where db_path is a filename matched by
11726 `anything-locate-db-file-regexp'."
11727 (interactive "P")
11728 (anything-locate-1 arg))
11730 ;;;###autoload
11731 (defun anything-w3m-bookmarks ()
11732 "Preconfigured `anything' for w3m bookmark.
11734 Needs w3m and emacs-w3m.
11736 http://w3m.sourceforge.net/
11737 http://emacs-w3m.namazu.org/"
11738 (interactive)
11739 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11740 "*anything w3m bookmarks*"))
11742 ;;;###autoload
11743 (defun anything-firefox-bookmarks ()
11744 "Preconfigured `anything' for firefox bookmark.
11745 You will have to enable html bookmarks in firefox:
11746 open about:config in firefox and double click on this line to enable value \
11747 to true:
11749 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11751 You should have now:
11753 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11755 After closing firefox, you will be able to browse you bookmarks.
11757 (interactive)
11758 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11759 "*Anything Firefox*"))
11761 ;;;###autoload
11762 (defun anything-colors ()
11763 "Preconfigured `anything' for color."
11764 (interactive)
11765 (anything-other-buffer
11766 '(anything-c-source-colors anything-c-source-customize-face)
11767 "*anything colors*"))
11769 ;;;###autoload
11770 (defun anything-bookmarks ()
11771 "Preconfigured `anything' for bookmarks."
11772 (interactive)
11773 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11775 ;;;###autoload
11776 (defun anything-c-pp-bookmarks ()
11777 "Preconfigured `anything' for bookmarks (pretty-printed)."
11778 (interactive)
11779 (anything-other-buffer '(anything-c-source-bookmarks-local
11780 anything-c-source-bookmarks-su
11781 anything-c-source-bookmarks-ssh)
11782 "*anything pp bookmarks*"))
11784 ;;;###autoload
11785 (defun anything-c-insert-latex-math ()
11786 "Preconfigured anything for latex math symbols completion."
11787 (interactive)
11788 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11790 ;;;###autoload
11791 (defun anything-register ()
11792 "Preconfigured `anything' for Emacs registers."
11793 (interactive)
11794 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11796 ;;;###autoload
11797 (defun anything-man-woman ()
11798 "Preconfigured `anything' for Man and Woman pages."
11799 (interactive)
11800 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11802 ;;;###autoload
11803 (defun anything-org-keywords ()
11804 "Preconfigured `anything' for org keywords."
11805 (interactive)
11806 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11808 ;;;###autoload
11809 (defun anything-emms ()
11810 "Preconfigured `anything' for emms sources."
11811 (interactive)
11812 (anything :sources '(anything-c-source-emms-streams
11813 anything-c-source-emms-files
11814 anything-c-source-emms-dired)
11815 :buffer "*Anything Emms*"))
11817 ;;;###autoload
11818 (defun anything-eev-anchors ()
11819 "Preconfigured `anything' for eev anchors."
11820 (interactive)
11821 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11823 ;;;###autoload
11824 (defun anything-bm-list ()
11825 "Preconfigured `anything' for visible bookmarks.
11827 Needs bm.el
11829 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11830 (interactive)
11831 (let ((anything-outline-using t))
11832 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11834 ;;;###autoload
11835 (defun anything-timers ()
11836 "Preconfigured `anything' for timers."
11837 (interactive)
11838 (anything-other-buffer '(anything-c-source-absolute-time-timers
11839 anything-c-source-idle-time-timers)
11840 "*anything timers*"))
11842 ;;;###autoload
11843 (defun anything-list-emacs-process ()
11844 "Preconfigured `anything' for emacs process."
11845 (interactive)
11846 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11848 ;;;###autoload
11849 (defun anything-occur ()
11850 "Preconfigured Anything for Occur source.
11851 If region is active, search only in region,
11852 otherwise search in whole buffer."
11853 (interactive)
11854 (let ((anything-compile-source-functions
11855 ;; rule out anything-match-plugin because the input is one regexp.
11856 (delq 'anything-compile-source--match-plugin
11857 (copy-sequence anything-compile-source-functions))))
11858 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11860 ;;;###autoload
11861 (defun anything-browse-code ()
11862 "Preconfigured anything to browse code."
11863 (interactive)
11864 (anything :sources 'anything-c-source-browse-code
11865 :buffer "*anything browse code*"
11866 :default (thing-at-point 'symbol)))
11868 ;;;###autoload
11869 (defun anything-org-headlines ()
11870 "Preconfigured anything to show org headlines."
11871 (interactive)
11872 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11874 ;;;###autoload
11875 (defun anything-info-gnus ()
11876 "Preconfigured anything to browse Gnus Manual."
11877 (interactive)
11878 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11880 ;;;###autoload
11881 (defun anything-regexp ()
11882 "Preconfigured anything to build regexps.
11883 `query-replace-regexp' can be run from there against found regexp."
11884 (interactive)
11885 (save-restriction
11886 (let ((anything-compile-source-functions
11887 ;; rule out anything-match-plugin because the input is one regexp.
11888 (delq 'anything-compile-source--match-plugin
11889 (copy-sequence anything-compile-source-functions))))
11890 (when (and (anything-region-active-p)
11891 ;; Don't narrow to region if buffer is already narrowed.
11892 (not (anything-current-buffer-narrowed-p)))
11893 (narrow-to-region (region-beginning) (region-end)))
11894 (anything :sources anything-c-source-regexp
11895 :buffer "*anything regexp*"
11896 :prompt "Regexp: "
11897 :history 'anything-build-regexp-history))))
11899 ;;;###autoload
11900 (defun anything-c-copy-files-async ()
11901 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11902 (interactive)
11903 (let* ((flist (anything-c-read-file-name
11904 "Copy File async: "
11905 :marked-candidates t))
11906 (dest (anything-c-read-file-name
11907 "Copy File async To: "
11908 :preselect (car flist)
11909 :initial-input (car anything-ff-history)
11910 :history (anything-find-files-history :comp-read nil))))
11911 (anything-c-copy-async-with-log flist dest)))
11913 ;;;###autoload
11914 (defun anything-find-files (arg)
11915 "Preconfigured `anything' for anything implementation of `find-file'.
11916 Called with a prefix arg show history if some.
11917 Don't call it from programs, use `anything-find-files-1' instead.
11918 This is the starting point for nearly all actions you can do on files."
11919 (interactive "P")
11920 (let ((any-input (if (and arg anything-ff-history)
11921 (anything-find-files-history)
11922 (anything-find-files-initial-input)))
11923 (presel (buffer-file-name (current-buffer))))
11924 (when (and (eq major-mode 'org-agenda-mode)
11925 org-directory
11926 (not any-input))
11927 (setq any-input (expand-file-name org-directory)))
11928 (set-text-properties 0 (length any-input) nil any-input)
11929 (if any-input
11930 (anything-find-files-1 any-input)
11931 (setq any-input (expand-file-name (anything-c-current-directory)))
11932 (anything-find-files-1
11933 any-input (if anything-ff-transformer-show-only-basename
11934 (and presel (anything-c-basename presel))
11935 presel)))))
11937 ;;;###autoload
11938 (defun anything-write-file ()
11939 "Preconfigured `anything' providing completion for `write-file'."
11940 (interactive)
11941 (let ((anything-mp-highlight-delay nil))
11942 (anything :sources 'anything-c-source-write-file
11943 :input (expand-file-name default-directory)
11944 :prompt "Write buffer to file: "
11945 :buffer "*Anything write file*")))
11947 ;;;###autoload
11948 (defun anything-insert-file ()
11949 "Preconfigured `anything' providing completion for `insert-file'."
11950 (interactive)
11951 (let ((anything-mp-highlight-delay nil))
11952 (anything :sources 'anything-c-source-insert-file
11953 :input (expand-file-name default-directory)
11954 :prompt "Insert file: "
11955 :buffer "*Anything insert file*")))
11957 ;;;###autoload
11958 (defun anything-dired-rename-file ()
11959 "Preconfigured `anything' to rename files from dired."
11960 (interactive)
11961 (anything-dired-do-action-on-file :action 'rename))
11963 ;;;###autoload
11964 (defun anything-dired-copy-file ()
11965 "Preconfigured `anything' to copy files from dired."
11966 (interactive)
11967 (anything-dired-do-action-on-file :action 'copy))
11969 ;;;###autoload
11970 (defun anything-dired-symlink-file ()
11971 "Preconfigured `anything' to symlink files from dired."
11972 (interactive)
11973 (anything-dired-do-action-on-file :action 'symlink))
11975 ;;;###autoload
11976 (defun anything-dired-hardlink-file ()
11977 "Preconfigured `anything' to hardlink files from dired."
11978 (interactive)
11979 (anything-dired-do-action-on-file :action 'hardlink))
11981 ;;;###autoload
11982 (defun anything-do-grep ()
11983 "Preconfigured anything for grep.
11984 Contrarily to Emacs `grep' no default directory is given, but
11985 the full path of candidates in ONLY.
11986 That allow to grep different files not only in `default-directory' but anywhere
11987 by marking them (C-<SPACE>). If one or more directory is selected
11988 grep will search in all files of these directories.
11989 You can use also wildcard in the base name of candidate.
11990 If a prefix arg is given use the -r option of grep.
11991 The prefix arg can be passed before or after start.
11992 See also `anything-do-grep-1'."
11993 (interactive)
11994 (let ((only (anything-c-read-file-name
11995 "Search in file(s): "
11996 :marked-candidates t
11997 :preselect (or (dired-get-filename nil t)
11998 (buffer-file-name (current-buffer)))))
11999 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
12000 (anything-do-grep-1 only prefarg)))
12002 ;;;###autoload
12003 (defun anything-do-zgrep (candidate)
12004 "Preconfigured anything for zgrep."
12005 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
12006 (ls (anything-c-read-file-name
12007 "Search in file(s): "
12008 :marked-candidates t
12009 :preselect (or (dired-get-filename nil t)
12010 (buffer-file-name (current-buffer))))))
12011 (anything-ff-zgrep-1 ls prefarg)))
12013 (defun anything-c-etags-select (arg)
12014 "Preconfigured anything for etags.
12015 Called with one prefix arg use symbol at point as initial input.
12016 Called with two prefix arg reinitialize cache.
12017 If tag file have been modified reinitialize cache."
12018 (interactive "P")
12019 (let ((tag (anything-c-etags-get-tag-file))
12020 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
12021 (anything-quit-if-no-candidate t)
12022 (anything-execute-action-at-once-if-one t)
12023 (anything-compile-source-functions
12024 (if anything-c-etags-use-regexp-search
12025 ;; rule out anything-match-plugin because the input is one regexp.
12026 (delq 'anything-compile-source--match-plugin
12027 (copy-sequence anything-compile-source-functions))
12028 anything-compile-source-functions)))
12029 (when (or (equal arg '(16))
12030 (and anything-c-etags-mtime-alist
12031 (anything-c-etags-file-modified-p tag)))
12032 (remhash tag anything-c-etags-cache))
12033 (if (and tag (file-exists-p tag))
12034 (anything :sources 'anything-c-source-etags-select
12035 :keymap anything-c-etags-map
12036 :input init
12037 :buffer "*anything etags*")
12038 (message "Error: No tag file found, please create one with etags shell command."))))
12040 ;;;###autoload
12041 (defun anything-filelist ()
12042 "Preconfigured `anything' to open files instantly.
12044 See `anything-c-filelist-file-name' docstring for usage."
12045 (interactive)
12046 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
12048 ;;;###autoload
12049 (defun anything-filelist+ ()
12050 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
12052 This is a replacement for `anything-for-files'.
12053 See `anything-c-filelist-file-name' docstring for usage."
12054 (interactive)
12055 (anything-other-buffer
12056 '(anything-c-source-ffap-line
12057 anything-c-source-ffap-guesser
12058 anything-c-source-buffers-list
12059 anything-c-source-recentf
12060 anything-c-source-bookmarks
12061 anything-c-source-file-cache
12062 anything-c-source-filelist)
12063 "*anything file list*"))
12065 ;;;###autoload
12066 (defun anything-M-x ()
12067 "Preconfigured `anything' for Emacs commands.
12068 It is `anything' replacement of regular `M-x' `execute-extended-command'."
12069 (interactive)
12070 (let* (in-help
12071 help-cand
12072 special-display-buffer-names
12073 special-display-regexps
12074 anything-persistent-action-use-special-display
12075 (history (loop with hist
12076 for i in extended-command-history
12077 for com = (intern i)
12078 when (fboundp com)
12079 collect i into hist finally return hist)))
12080 (flet ((pers-help (candidate)
12081 (let ((hbuf (get-buffer (help-buffer))))
12082 (if (and in-help (string= candidate help-cand))
12083 (progn
12084 ;; When M-x is started from a help buffer,
12085 ;; Don't kill it as it is anything-current-buffer.
12086 (unless (equal hbuf anything-current-buffer)
12087 (kill-buffer hbuf))
12088 (setq in-help nil))
12089 ;; Be sure anything-current-buffer
12090 ;; have not a dedicated window.
12091 (set-window-dedicated-p
12092 (get-buffer-window anything-current-buffer) nil)
12093 (describe-function (intern candidate))
12094 (message nil) ; Erase the new stupid message Type "q"[...]
12095 (setq in-help t))
12096 (setq help-cand candidate))))
12097 (let* ((command
12099 (anything
12100 :sources
12101 `(((name . "Emacs Commands history")
12102 (candidates . ,history)
12103 (filtered-candidate-transformer
12104 . (lambda (candidates sources)
12105 (loop for i in candidates
12106 do (set-text-properties 0 (length i) nil i)
12107 collect i)))
12108 (persistent-action . pers-help)
12109 (persistent-help . "Describe this command")
12110 (action . identity))
12111 ((name . "Emacs Commands")
12112 (init
12113 . (lambda ()
12114 (with-current-buffer (anything-candidate-buffer 'global)
12115 (goto-char (point-min))
12116 (loop for sym in
12117 (all-completions "" obarray 'commandp)
12118 do (insert (concat sym "\n"))))))
12119 (persistent-action . pers-help)
12120 (persistent-help . "Describe this command")
12121 (filtered-candidate-transformer . anything-M-x-transformer)
12122 (candidates-in-buffer)
12123 (action . identity)))
12124 :resume 'noresume
12125 :prompt "M-x "
12126 :history 'anything-M-x-input-history
12127 :buffer "*anything M-x*")
12128 (keyboard-quit)))
12129 (sym-com (intern command)))
12130 (unless current-prefix-arg
12131 (setq current-prefix-arg anything-current-prefix-arg))
12132 ;; Avoid having `this-command' set to *exit-minibuffer.
12133 (setq this-command sym-com)
12134 (call-interactively sym-com)
12135 (setq extended-command-history
12136 (cons command (delete command history)))))))
12138 ;;;###autoload
12139 (defun anything-manage-advice ()
12140 "Preconfigured `anything' to disable/enable function advices."
12141 (interactive)
12142 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12144 ;;;###autoload
12145 (defun anything-bookmark-ext ()
12146 "Preconfigured `anything' for bookmark-extensions sources.
12147 Needs bookmark-ext.el:
12148 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12149 Contain also `anything-c-source-google-suggest'."
12150 (interactive)
12151 (anything
12152 :sources
12153 '(anything-c-source-bookmark-files&dirs
12154 anything-c-source-bookmark-w3m
12155 anything-c-source-google-suggest
12156 anything-c-source-bmkext-addressbook
12157 anything-c-source-bookmark-gnus
12158 anything-c-source-bookmark-info
12159 anything-c-source-bookmark-man
12160 anything-c-source-bookmark-images
12161 anything-c-source-bookmark-su-files&dirs
12162 anything-c-source-bookmark-ssh-files&dirs)
12163 :prompt "SearchBookmark: "
12164 :buffer "*anything bmkext*"))
12166 ;;;###autoload
12167 (defun anything-simple-call-tree ()
12168 "Preconfigured `anything' for simple-call-tree. List function relationships.
12170 Needs simple-call-tree.el.
12171 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12172 (interactive)
12173 (anything-other-buffer
12174 '(anything-c-source-simple-call-tree-functions-callers
12175 anything-c-source-simple-call-tree-callers-functions)
12176 "*anything simple-call-tree*"))
12178 ;;;###autoload
12179 (defun anything-mark-ring ()
12180 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12181 (interactive)
12182 (anything :sources 'anything-c-source-mark-ring))
12184 ;;;###autoload
12185 (defun anything-global-mark-ring ()
12186 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12187 (interactive)
12188 (anything :sources 'anything-c-source-global-mark-ring))
12190 ;;;###autoload
12191 (defun anything-all-mark-rings ()
12192 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12193 `anything-c-source-mark-ring'."
12194 (interactive)
12195 (anything :sources '(anything-c-source-mark-ring
12196 anything-c-source-global-mark-ring)))
12198 ;;;###autoload
12199 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12200 "Preconfigured `anything' to edit or view EmacsWiki page.
12202 Needs yaoddmuse.el.
12204 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12205 (interactive)
12206 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12208 ;;;###autoload
12209 (defun anything-yaoddmuse-emacswiki-post-library ()
12210 "Preconfigured `anything' to post library to EmacsWiki.
12212 Needs yaoddmuse.el.
12214 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12215 (interactive)
12216 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12218 ;;;###autoload
12219 (defun anything-eval-expression (arg)
12220 "Preconfigured anything for `anything-c-source-evaluation-result'."
12221 (interactive "P")
12222 (anything :sources 'anything-c-source-evaluation-result
12223 :input (when arg (thing-at-point 'sexp))
12224 :buffer "*anything eval*"
12225 :history 'anything-eval-expression-input-history
12226 :keymap anything-eval-expression-map))
12228 ;;;###autoload
12229 (defun anything-eval-expression-with-eldoc ()
12230 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12231 (interactive)
12232 (declare (special eldoc-idle-delay))
12233 (let ((timer (run-with-idle-timer eldoc-idle-delay
12234 'repeat 'anything-eldoc-show-in-eval))
12235 (minibuffer-completing-symbol t) ; Enable lisp completion.
12236 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12237 (unwind-protect
12238 (minibuffer-with-setup-hook
12239 'anything-eldoc-store-minibuffer
12240 (call-interactively 'anything-eval-expression))
12241 (and timer (cancel-timer timer))
12242 (setq anything-eldoc-active-minibuffers-list
12243 (cdr anything-eldoc-active-minibuffers-list)))))
12245 ;;;###autoload
12246 (defun anything-calcul-expression ()
12247 "Preconfigured anything for `anything-c-source-calculation-result'."
12248 (interactive)
12249 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12251 ;;;###autoload
12252 (defun anything-surfraw (pattern engine)
12253 "Preconfigured `anything' to search PATTERN with search ENGINE."
12254 (interactive (list (read-string "SearchFor: "
12255 nil 'anything-surfraw-input-history)
12256 (anything-comp-read
12257 "Engine: "
12258 (anything-c-build-elvi-list)
12259 :must-match t
12260 :name "Surfraw Search Engines"
12261 :history anything-surfraw-engines-history)))
12262 (let* ((engine-nodesc (car (split-string engine)))
12263 (url (with-temp-buffer
12264 (apply 'call-process "surfraw" nil t nil
12265 ;;JAVE
12266 (append (list engine-nodesc "-p") (split-string pattern)))
12267 (replace-regexp-in-string
12268 "\n" "" (buffer-string))))
12269 (browse-url-browser-function (or anything-surfraw-default-browser-function
12270 browse-url-browser-function)))
12271 (if (string= engine-nodesc "W")
12272 (anything-c-browse-url)
12273 (anything-c-browse-url url)
12274 (setq anything-surfraw-engines-history
12275 (cons engine (delete engine anything-surfraw-engines-history))))))
12277 ;;;###autoload
12278 (defun anything-call-source ()
12279 "Preconfigured `anything' to call anything source."
12280 (interactive)
12281 (anything :sources 'anything-c-source-call-source
12282 :buffer anything-source-select-buffer))
12284 ;;;###autoload
12285 (defun anything-execute-anything-command ()
12286 "Preconfigured `anything' to execute preconfigured `anything'."
12287 (interactive)
12288 (anything-other-buffer 'anything-c-source-anything-commands
12289 "*anything commands*"))
12291 ;;;###autoload
12292 (defun anything-create (&optional string initial-input)
12293 "Preconfigured `anything' to do many create actions from STRING.
12294 See also `anything-create--actions'."
12295 (interactive)
12296 (setq string (or string (read-string "Create Anything: " initial-input)))
12297 (anything :sources '(((name . "Anything Create")
12298 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12299 (candidates . anything-create--actions)
12300 (candidate-number-limit)
12301 (action . (lambda (func) (funcall func string)))))))
12303 ;;;###autoload
12304 (defun anything-top ()
12305 "Preconfigured `anything' for top command."
12306 (interactive)
12307 (let ((anything-samewindow t)
12308 (anything-enable-shortcuts)
12309 (anything-display-function 'anything-default-display-buffer)
12310 (anything-candidate-number-limit 9999))
12311 (save-window-excursion
12312 (delete-other-windows)
12313 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12315 ;;;###autoload
12316 (defun anything-select-xfont ()
12317 "Preconfigured `anything' to select Xfont."
12318 (interactive)
12319 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12321 ;;;###autoload
12322 (defun anything-world-time ()
12323 "Preconfigured `anything' to show world time."
12324 (interactive)
12325 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12327 ;;;###autoload
12328 (defun anything-apt (arg)
12329 "Preconfigured `anything' : frontend of APT package manager.
12330 With a prefix arg reload cache."
12331 (interactive "P")
12332 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12333 (when arg (anything-c-apt-refresh))
12334 (anything :sources 'anything-c-source-apt
12335 :prompt "Search Package: "
12336 :input query
12337 :history 'anything-c-apt-input-history)))
12339 ;;;###autoload
12340 (defun anything-esh-pcomplete ()
12341 "Preconfigured anything to provide anything completion in eshell."
12342 (interactive)
12343 (let* ((anything-quit-if-no-candidate t)
12344 (anything-execute-action-at-once-if-one t)
12345 (target (thing-at-point 'symbol))
12346 (end (point))
12347 (beg (or (and target (- end (length target)))
12348 ;; Nothing at point.
12349 (progn (insert " ") (point)))))
12350 (setq anything-ec-target (or target " "))
12351 (with-anything-show-completion beg end
12352 (anything :sources 'anything-c-source-esh
12353 :input (anything-ff-set-pattern ; Handle tramp filenames.
12354 (car (last (ignore-errors ; Needed in lisp symbols completion.
12355 (pcomplete-parse-arguments)))))))))
12357 ;;;###autoload
12358 (defun anything-eshell-history ()
12359 "Preconfigured anything for eshell history."
12360 (interactive)
12361 (let* ((end (point))
12362 (beg (save-excursion (eshell-bol) (point)))
12363 flag-empty)
12364 (when (eq beg end)
12365 (insert " ")
12366 (setq flag-empty t)
12367 (setq end (point)))
12368 (unwind-protect
12369 (with-anything-show-completion beg end
12370 (anything :sources 'anything-c-source-eshell-history
12371 :buffer "*Eshell history*"))
12372 (when (and flag-empty
12373 (looking-back " "))
12374 (delete-char -1)))))
12376 ;;;###autoload
12377 (defun anything-c-run-external-command (program)
12378 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12379 If program is already running exit with error.
12380 You can set your own list of commands with
12381 `anything-c-external-commands-list'."
12382 (interactive (list
12383 (anything-comp-read
12384 "RunProgram: "
12385 (anything-c-external-commands-list-1 'sort)
12386 :must-match t
12387 :name "External Commands"
12388 :history anything-external-command-history)))
12389 (anything-run-or-raise program)
12390 (setq anything-external-command-history
12391 (cons program (delete program
12392 (loop for i in anything-external-command-history
12393 when (executable-find i) collect i)))))
12395 ;;;###autoload
12396 (defun anything-ratpoison-commands ()
12397 "Preconfigured `anything' to execute ratpoison commands."
12398 (interactive)
12399 (anything-other-buffer 'anything-c-source-ratpoison-commands
12400 "*anything ratpoison commands*"))
12402 ;;;###autoload
12403 (defun anything-ucs ()
12404 "Preconfigured anything for `ucs-names' math symbols."
12405 (interactive)
12406 (anything :sources 'anything-c-source-ucs
12407 :keymap anything-c-ucs-map))
12409 ;;;###autoload
12410 (defun anything-c-apropos ()
12411 "Preconfigured anything to describe commands, functions, variables and faces."
12412 (interactive)
12413 (let ((default (thing-at-point 'symbol)))
12414 (anything :sources
12415 `(((name . "Commands")
12416 (init . (lambda ()
12417 (anything-c-apropos-init 'commandp ,default)))
12418 (persistent-action . anything-lisp-completion-persistent-action)
12419 (persistent-help . "Show brief doc in mode-line")
12420 (candidates-in-buffer)
12421 (action . (lambda (candidate)
12422 (describe-function (intern candidate)))))
12423 ((name . "Functions")
12424 (init . (lambda ()
12425 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12426 (not (commandp x))))
12427 ,default)))
12428 (persistent-action . anything-lisp-completion-persistent-action)
12429 (persistent-help . "Show brief doc in mode-line")
12430 (candidates-in-buffer)
12431 (action . (lambda (candidate)
12432 (describe-function (intern candidate)))))
12433 ((name . "Variables")
12434 (init . (lambda ()
12435 (anything-c-apropos-init 'boundp ,default)))
12436 (persistent-action . anything-lisp-completion-persistent-action)
12437 (persistent-help . "Show brief doc in mode-line")
12438 (candidates-in-buffer)
12439 (action . (lambda (candidate)
12440 (describe-variable (intern candidate)))))
12441 ((name . "Faces")
12442 (init . (lambda ()
12443 (anything-c-apropos-init 'facep ,default)))
12444 (persistent-action . anything-lisp-completion-persistent-action)
12445 (persistent-help . "Show brief doc in mode-line")
12446 (candidates-in-buffer)
12447 (filtered-candidate-transformer . (lambda (candidates source)
12448 (loop for c in candidates
12449 collect (propertize c 'face (intern c)))))
12450 (action . (lambda (candidate)
12451 (describe-face (intern candidate)))))
12452 ((name . "Anything attributes")
12453 (candidates . (lambda ()
12454 (mapcar 'symbol-name anything-additional-attributes)))
12455 (action . (lambda (candidate)
12456 (with-output-to-temp-buffer "*Help*"
12457 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12460 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12463 (provide 'anything-config)
12465 ;;; Local Variables:
12466 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12467 ;;; End:
12469 ;; How to save (DO NOT REMOVE!!)
12470 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12471 ;;; anything-config.el ends here
12473 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12474 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12475 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12476 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12477 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12478 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12479 ;;; LocalWords: dotimes Thierry online vname
12480 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12481 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12482 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12483 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12484 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12485 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12486 ;;; LocalWords: startpos noselect dont desc