* anything-config.el (anything-c-read-file-name): Partial fix require-match handling...
[anything-config.git] / anything-config.el
blobe04dc68dea073740098b58de7ab233b2fee638ed
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 (&optional require-match)
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 (unless require-match (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 must-match
4633 (marked-candidates nil)
4634 (alistp t)
4635 (persistent-action 'anything-find-files-persistent-action)
4636 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4637 "Anything `read-file-name' emulation.
4638 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4639 (when (get-buffer anything-action-buffer)
4640 (kill-buffer anything-action-buffer))
4642 ;; Assume completion have been already required,
4643 ;; so always use 'confirm.
4644 (when (eq must-match 'confirm-after-completion)
4645 (setq must-match 'confirm))
4647 (flet ((action-fn (candidate)
4648 (if marked-candidates
4649 (anything-marked-candidates)
4650 (identity candidate))))
4652 (let* ((anything-mp-highlight-delay nil)
4653 ;; Be sure we don't erase the underlying minibuffer if some.
4654 (anything-ff-auto-update-initial-value
4655 (not (minibuffer-window-active-p (minibuffer-window))))
4656 anything-same-window
4657 (hist (and history (anything-comp-read-get-candidates
4658 history nil nil alistp)))
4659 (minibuffer-completion-table nil)
4660 (minibuffer-completing-file-name t)
4661 (minibuffer-completion-predicate (or test 'file-exists-p))
4662 (minibuffer-completion-confirm (unless (eq must-match t)
4663 must-match))
4664 (keymap (when must-match minibuffer-local-must-match-map))
4665 (anything-map (make-composed-keymap
4666 ;; Merge some anything bindings
4667 ;; that clash with minibuffer ones.
4668 (list '(keymap
4669 (7 . anything-keyboard-quit)
4670 (up . anything-previous-line)
4671 (down . anything-next-line))
4672 keymap)
4673 anything-c-read-file-map)))
4675 (or (anything
4676 :sources
4677 `(((name . ,(format "%s History" name))
4678 (header-name . (lambda (name)
4679 (concat name anything-c-find-files-doc-header)))
4680 (disable-shortcuts)
4681 (mode-line . anything-read-file-name-mode-line-string)
4682 (candidates . hist)
4683 (persistent-action . ,persistent-action)
4684 (persistent-help . ,persistent-help)
4685 (action . ,'action-fn))
4686 ((name . ,name)
4687 (header-name . (lambda (name)
4688 (concat name anything-c-find-files-doc-header)))
4689 (init . (lambda ()
4690 (setq anything-ff-auto-update-flag
4691 anything-ff-auto-update-initial-value)))
4692 ;; It is needed for filenames with capital letters
4693 (disable-shortcuts)
4694 (mode-line . anything-read-file-name-mode-line-string)
4695 (candidates . (lambda ()
4696 (let ((seq (anything-find-files-get-candidates must-match)))
4697 (setq minibuffer-completion-table
4698 (all-completions "" seq test)))))
4699 (filtered-candidate-transformer anything-c-find-files-transformer)
4700 (persistent-action . ,persistent-action)
4701 (candidate-number-limit . 9999)
4702 (toggle-auto-update . anything-ff-toggle-auto-update)
4703 (persistent-help . ,persistent-help)
4704 (volatile)
4705 (action . ,'action-fn)))
4706 :input initial-input
4707 :prompt prompt
4708 :resume 'noresume
4709 :buffer buffer
4710 :preselect preselect)
4711 (when (and (not (string= anything-pattern ""))
4712 (eq anything-exit-status 0)
4713 (eq must-match 'confirm))
4714 (identity anything-pattern))
4715 (keyboard-quit)))))
4718 ;;; File Cache
4719 (defvar anything-c-file-cache-initialized-p nil)
4721 (defvar anything-c-file-cache-files nil)
4723 (defvar anything-c-source-file-cache
4724 '((name . "File Cache")
4725 (init
4726 . (lambda ()
4727 (require 'filecache nil t)
4728 (unless anything-c-file-cache-initialized-p
4729 (setq anything-c-file-cache-files
4730 (loop for item in file-cache-alist append
4731 (destructuring-bind (base &rest dirs) item
4732 (loop for dir in dirs collect
4733 (concat dir base)))))
4734 (defadvice file-cache-add-file (after file-cache-list activate)
4735 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4736 (setq anything-c-file-cache-initialized-p t))))
4737 (candidates . anything-c-file-cache-files)
4738 (match anything-c-match-on-basename)
4739 (type . file)))
4740 ;; (anything 'anything-c-source-file-cache)
4743 ;;; Locate
4746 ;; NOTE for WINDOZE users:
4747 ;; You have to install Everything with his command line interface here:
4748 ;; http://www.voidtools.com/download.php
4750 (defun anything-locate-1 (&optional localdb init)
4751 "Generic function to run Locate.
4752 if LOCALDB is non--nil search and use a local locate db file.
4753 INIT is a string to use as initial input in prompt.
4754 See `anything-locate-with-db' and `anything-locate'."
4755 (anything-locate-with-db
4756 (and localdb
4757 (anything-c-read-file-name
4758 "LocateDBFiles: "
4759 :marked-candidates t
4760 :preselect anything-locate-db-file-regexp
4761 :test #'(lambda (x)
4762 (if anything-locate-db-file-regexp
4763 ;; Select only locate db files and directories
4764 ;; to allow navigation.
4765 (or (string-match
4766 anything-locate-db-file-regexp x)
4767 (file-directory-p x))
4768 x))))
4769 init))
4770 ;; (anything-locate-1 t)
4772 (defun anything-locate-with-db (&optional db initial-input)
4773 "Run locate -d DB.
4774 If DB is not given or nil use locate without -d option.
4775 Argument DB can be given as a string or list of db files.
4776 Argument INITIAL-INPUT is a string to use as initial-input.
4777 See also `anything-locate'."
4778 (when (and db (stringp db)) (setq db (list db)))
4779 (let ((anything-c-locate-command
4780 (if db
4781 (replace-regexp-in-string
4782 "locate"
4783 (format "locate -d %s"
4784 (mapconcat 'identity
4785 ;; Remove eventually
4786 ;; marked directories by error.
4787 (loop for i in db
4788 unless (file-directory-p i)
4789 collect i) ":"))
4790 anything-c-locate-command)
4791 anything-c-locate-command)))
4792 (anything :sources 'anything-c-source-locate
4793 :buffer "*anything locate*"
4794 :input initial-input
4795 :keymap anything-generic-files-map)))
4796 ;; (anything-locate-with-db "~/locate.db")
4798 (defun anything-c-locate-init ()
4799 "Initialize async locate process for `anything-c-source-locate'."
4800 (setq mode-line-format
4801 '(" " mode-line-buffer-identification " "
4802 (line-number-mode "%l") " "
4803 (:eval (propertize "(Locate Process Running) "
4804 'face '((:foreground "red"))))))
4805 (unless anything-c-locate-command
4806 (setq anything-c-locate-command
4807 (case system-type
4808 ('gnu/linux "locate -i -r %s")
4809 ('berkeley-unix "locate -i %s")
4810 ('windows-nt "es -i -r %s")
4811 (t "locate %s"))))
4812 (prog1
4813 (start-process-shell-command "locate-process" nil
4814 (format anything-c-locate-command
4815 anything-pattern))
4816 (set-process-sentinel (get-process "locate-process")
4817 #'(lambda (process event)
4818 (when (string= event "finished\n")
4819 (with-anything-window
4820 (force-mode-line-update nil)
4821 (anything-update-move-first-line)))))))
4823 (defvar anything-c-source-locate
4824 '((name . "Locate")
4825 (candidates . anything-c-locate-init)
4826 (type . file)
4827 (requires-pattern . 3)
4828 (candidate-number-limit . 9999)
4829 (mode-line . anything-generic-file-mode-line-string)
4830 (delayed))
4831 "Find files matching the current input pattern with locate.")
4832 ;; (anything 'anything-c-source-locate)
4834 (defun anything-c-locate-read-file-name (prompt &optional init)
4835 "Search a file with locate and return it's filename.
4836 Use argument PROMPT and INIT for `anything' arguments
4837 prompt and input."
4838 (anything :sources
4839 '((name . "Locate")
4840 (candidates . anything-c-locate-init)
4841 (action . identity)
4842 (requires-pattern . 3)
4843 (candidate-number-limit . 9999)
4844 (mode-line . anything-generic-file-mode-line-string)
4845 (delayed))
4846 :prompt prompt
4847 :input init
4848 :buffer "*anything locate rfn*"))
4852 ;;; Anything Incremental Grep.
4855 ;; Allow to grep incrementally with anything interface.
4856 ;; It allow also to Grep files recursively without using 'find' shell command.
4857 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4858 (defvar anything-c-grep-default-command
4859 "grep -d skip %e -niH -e %p %f"
4860 "Default grep format command for `anything-do-grep-1'.
4861 Where:
4862 '%e' format spec is for --exclude or --include grep options.
4863 '%p' format spec is for pattern.
4864 '%f' format spec is for filenames.")
4866 (defvar anything-c-grep-default-recurse-command
4867 "grep -d recurse %e -niH -e %p %f"
4868 "Default recursive grep format command for `anything-do-grep-1'.
4869 See `anything-c-grep-default-command' for format specs.")
4871 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4873 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4875 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4877 (defvar anything-c-grep-debug-command-line nil
4878 "Turn on anything grep command-line debugging when non--nil.")
4880 (defvar anything-c-zgrep-recurse-flag nil)
4882 (defvar anything-c-grep-history nil)
4884 (defvar anything-c-grep-max-length-history 100
4885 "*Max number of elements to save in `anything-c-grep-history'.")
4887 (defun anything-c-grep-prepare-candidates (candidates)
4888 "Prepare filenames and directories CANDIDATES for grep command line."
4889 ;; If one or more candidate is a directory, search in all files
4890 ;; of this candidate (e.g /home/user/directory/*).
4891 ;; If r option is enabled search also in subdidrectories.
4892 ;; We need here to expand wildcards to support crap windows filenames
4893 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4894 (if anything-c-zgrep-recurse-flag
4895 (mapconcat 'shell-quote-argument candidates " ")
4896 (loop for i in candidates append
4897 (cond ( ;; Candidate is a directory and we use recursion.
4898 (and (file-directory-p i)
4899 (anything-c-grep-recurse-p))
4900 (list (expand-file-name i)))
4901 ;; Candidate is a directory, search in all files.
4902 ((file-directory-p i)
4903 (file-expand-wildcards
4904 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4905 ;; Candidate is a file or wildcard and we use recursion, use the
4906 ;; current directory instead of candidate.
4907 ((and (or (file-exists-p i) (string-match "\*" i))
4908 (anything-c-grep-recurse-p))
4909 (list (expand-file-name
4910 (directory-file-name ; Needed for windoze.
4911 (file-name-directory (directory-file-name i))))))
4912 ;; Candidate use wildcard.
4913 ((string-match "^\*" (anything-c-basename i))
4914 (file-expand-wildcards i t))
4915 ;; Else should be one or more file.
4916 (t (list i))) into all-files
4917 finally return
4918 (mapconcat 'shell-quote-argument all-files " "))))
4920 (defun anything-c-grep-recurse-p ()
4921 "Check if `anything-do-grep-1' have switched to recursive."
4922 (let ((args (replace-regexp-in-string
4923 "grep" "" anything-c-grep-default-command)))
4924 (string-match-p "r\\|recurse" args)))
4926 (defun anything-c-grep-init (only-files &optional include zgrep)
4927 "Start an asynchronous grep process in ONLY-FILES list."
4928 (let* ((fnargs (anything-c-grep-prepare-candidates
4929 (if (file-remote-p anything-ff-default-directory)
4930 (mapcar #'(lambda (x)
4931 (file-remote-p x 'localname))
4932 only-files)
4933 only-files)))
4934 (ignored-files (mapconcat
4935 #'(lambda (x)
4936 (concat "--exclude=" (shell-quote-argument x)))
4937 grep-find-ignored-files " "))
4938 (ignored-dirs (mapconcat
4939 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4940 #'(lambda (x)
4941 (concat "--exclude-dir=" (shell-quote-argument x)))
4942 grep-find-ignored-directories " "))
4943 (exclude (if (anything-c-grep-recurse-p)
4944 (concat (or include ignored-files) " " ignored-dirs)
4945 ignored-files))
4946 (cmd-line (format-spec
4947 anything-c-grep-default-command
4948 (delq nil
4949 (list (unless zgrep (cons ?e exclude))
4950 (cons ?p (shell-quote-argument anything-pattern))
4951 (cons ?f fnargs))))))
4952 (when anything-c-grep-debug-command-line
4953 (with-current-buffer (get-buffer-create "*any grep debug*")
4954 (goto-char (point-max))
4955 (insert (concat ">>> " cmd-line "\n\n"))))
4956 (setq mode-line-format
4957 '(" " mode-line-buffer-identification " "
4958 (line-number-mode "%l") " "
4959 (:eval (when (get-process "grep-process")
4960 (propertize "[Grep Process Running] "
4961 'face 'anything-grep-running)))))
4962 (force-mode-line-update nil)
4963 (prog1
4964 (let ((default-directory anything-ff-default-directory))
4965 (start-file-process-shell-command "grep-process" nil cmd-line))
4966 (message nil)
4967 (set-process-sentinel
4968 (get-process "grep-process")
4969 #'(lambda (process event)
4970 (when (string= event "finished\n")
4971 (with-anything-window
4972 (anything-update-move-first-line)
4973 (setq mode-line-format
4974 '(" " mode-line-buffer-identification " "
4975 (line-number-mode "%l") " "
4976 (:eval (propertize
4977 (format "[Grep Process Finished - (%s results)] "
4978 (let ((nlines (1- (count-lines
4979 (point-min)
4980 (point-max)))))
4981 (if (> nlines 0) nlines 0)))
4982 'face 'anything-grep-finish))))
4983 (force-mode-line-update nil))))))))
4985 (defun anything-c-grep-action (candidate &optional where mark)
4986 "Define a default action for `anything-do-grep' on CANDIDATE.
4987 WHERE can be one of other-window, elscreen, other-frame."
4988 (let* ((split (anything-c-grep-split-line candidate))
4989 (lineno (string-to-number (nth 1 split)))
4990 (loc-fname (car split))
4991 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4992 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4993 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4994 (fname (if tramp-host
4995 (concat tramp-prefix loc-fname) loc-fname)))
4996 (case where
4997 (other-window (find-file-other-window fname))
4998 (elscreen (anything-elscreen-find-file fname))
4999 (other-frame (find-file-other-frame fname))
5000 (t (find-file fname)))
5001 (anything-goto-line lineno)
5002 (when mark
5003 (set-marker (mark-marker) (point))
5004 (push-mark (point) 'nomsg))
5005 ;; Save history
5006 (unless (or anything-in-persistent-action
5007 (string= anything-pattern ""))
5008 (setq anything-c-grep-history
5009 (cons anything-pattern
5010 (delete anything-pattern anything-c-grep-history)))
5011 (when (> (length anything-c-grep-history)
5012 anything-c-grep-max-length-history)
5013 (setq anything-c-grep-history
5014 (delete (car (last anything-c-grep-history))
5015 anything-c-grep-history))))))
5017 (defun anything-c-grep-other-window (candidate)
5018 "Jump to result in other window from anything grep."
5019 (anything-c-grep-action candidate 'other-window))
5021 (defun anything-c-grep-other-frame (candidate)
5022 "Jump to result in other frame from anything grep."
5023 (anything-c-grep-action candidate 'other-frame))
5025 (defun anything-c-grep-jump-elscreen (candidate)
5026 "Jump to result in elscreen from anything grep."
5027 (anything-c-grep-action candidate 'elscreen))
5029 (defun anything-c-grep-save-results (candidate)
5030 "Save anything grep result in a `grep-mode' buffer."
5031 (let ((buf "*grep*")
5032 new-buf)
5033 (when (get-buffer buf)
5034 (setq new-buf (read-string "GrepBufferName: " buf))
5035 (loop for b in (anything-c-buffer-list)
5036 when (and (string= new-buf b)
5037 (not (y-or-n-p
5038 (format "Buffer `%s' already exists overwrite? "
5039 new-buf))))
5040 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
5041 (setq buf new-buf))
5042 (with-current-buffer (get-buffer-create buf)
5043 (let ((inhibit-read-only t))
5044 (erase-buffer)
5045 (insert "-*- mode: grep -*-\n\n"
5046 (format "Grep Results for `%s':\n\n" anything-pattern))
5047 (save-excursion
5048 (insert (with-current-buffer anything-buffer
5049 (forward-line 1)
5050 (buffer-substring (point) (point-max))))
5051 (grep-mode))))
5052 (message "Anything Grep Results saved in `%s' buffer" buf)))
5054 (defun anything-c-grep-persistent-action (candidate)
5055 "Persistent action for `anything-do-grep'.
5056 With a prefix arg record CANDIDATE in `mark-ring'."
5057 (if current-prefix-arg
5058 (anything-c-grep-action candidate nil 'mark)
5059 (anything-c-grep-action candidate))
5060 (anything-match-line-color-current-line))
5062 (defun anything-c-grep-guess-extensions (files)
5063 "Try to guess file extensions in FILES list when using grep recurse.
5064 These extensions will be added to command line with --include arg of grep."
5065 (loop
5066 with glob-list = nil
5067 with lst = (if (file-directory-p (car files))
5068 (directory-files
5069 (car files) nil
5070 directory-files-no-dot-files-regexp)
5071 files)
5072 for i in lst
5073 for ext = (file-name-extension i t)
5074 for glob = (and ext (not (string= ext ""))
5075 (concat "*" ext))
5076 unless (or (not glob)
5077 (member glob glob-list)
5078 (member glob grep-find-ignored-files))
5079 collect glob into glob-list
5080 finally return glob-list))
5082 (defun anything-do-grep-1 (only &optional recurse zgrep)
5083 "Launch grep with a list of ONLY files.
5084 When RECURSE is given use -r option of grep and prompt user
5085 to set the --include args of grep.
5086 You can give more than one arg separated by space.
5087 e.g *.el *.py *.tex.
5088 If it's empty --exclude `grep-find-ignored-files' is used instead."
5089 (let* ((anything-compile-source-functions
5090 ;; rule out anything-match-plugin because the input is one regexp.
5091 (delq 'anything-compile-source--match-plugin
5092 (copy-sequence anything-compile-source-functions)))
5093 (exts (anything-c-grep-guess-extensions only))
5094 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5095 (include-files (and recurse (not zgrep)
5096 (read-string "OnlyExt(*.[ext]): "
5097 globs)))
5098 ;; Set `minibuffer-history' AFTER includes-files
5099 ;; to avoid storing wild-cards here.
5100 (minibuffer-history anything-c-grep-history)
5101 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5102 (recurse anything-c-grep-default-recurse-command)
5103 (zgrep anything-c-default-zgrep-command)
5104 (t anything-c-grep-default-command)))
5105 ;; Disable match-plugin and use here own highlighting.
5106 (anything-mp-highlight-delay nil))
5107 (when include-files
5108 (setq include-files
5109 (and (not (string= include-files ""))
5110 (mapconcat #'(lambda (x)
5111 (concat "--include=" (shell-quote-argument x)))
5112 (split-string include-files) " "))))
5113 ;; When called as action from an other source e.g *-find-files
5114 ;; we have to kill action buffer.
5115 (when (get-buffer anything-action-buffer)
5116 (kill-buffer anything-action-buffer))
5117 ;; `anything-find-files' haven't already started,
5118 ;; give a default value to `anything-ff-default-directory'.
5119 (setq anything-ff-default-directory (or anything-ff-default-directory
5120 default-directory))
5121 (anything
5122 :sources
5123 `(((name . "Grep (C-c ? Help)")
5124 (candidates
5125 . (lambda ()
5126 (funcall anything-c-grep-default-function only include-files zgrep)))
5127 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5128 (candidate-number-limit . 9999)
5129 (mode-line . anything-grep-mode-line-string)
5130 (action . ,(delq
5132 `(("Find File" . anything-c-grep-action)
5133 ("Find file other frame" . anything-c-grep-other-frame)
5134 ,(and (locate-library "elscreen")
5135 '("Find file in Elscreen"
5136 . anything-c-grep-jump-elscreen))
5137 ("Save results in grep buffer" . anything-c-grep-save-results)
5138 ("Find file other window" . anything-c-grep-other-window))))
5139 (persistent-action . anything-c-grep-persistent-action)
5140 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5141 (requires-pattern . 3)
5142 (delayed)))
5143 :keymap anything-c-grep-map
5144 :buffer "*anything grep*")))
5146 (defun anything-ff-zgrep-1 (flist recursive)
5147 (unwind-protect
5148 (let* ((def-dir (or anything-ff-default-directory
5149 default-directory))
5150 (only (if recursive
5151 (or (gethash def-dir anything-c-rzgrep-cache)
5152 (puthash
5153 def-dir
5154 (anything-c-walk-directory
5155 def-dir
5156 :directories nil
5157 :path 'full
5158 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5159 anything-c-rzgrep-cache))
5160 flist)))
5161 (when recursive (setq anything-c-zgrep-recurse-flag t))
5162 (anything-do-grep-1 only recursive 'zgrep))
5163 (setq anything-c-zgrep-recurse-flag nil)))
5165 (defun anything-c-grep-split-line (line)
5166 "Split a grep output line."
5167 (let (beg fname lineno str)
5168 ;; Don't print until grep line is valid.
5169 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5170 (with-temp-buffer
5171 (insert line)
5172 (goto-char (point-min))
5173 (setq beg (point))
5174 (forward-char 2)
5175 (re-search-forward ":" nil t)
5176 (setq fname (buffer-substring-no-properties beg (1- (point))))
5177 (setq beg (point))
5178 (re-search-forward ":" nil t)
5179 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5180 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5181 (list fname lineno str))))
5183 (defun anything-c-grep-cand-transformer (candidates sources)
5184 "Filtered candidate transformer function for `anything-do-grep'."
5185 (loop for i in candidates
5186 for split = (and i (anything-c-grep-split-line i))
5187 for fname = (car split)
5188 for lineno = (nth 1 split)
5189 for str = (nth 2 split)
5190 when (and fname lineno str)
5191 collect
5192 (cons (concat (propertize (file-name-nondirectory fname)
5193 'face 'anything-grep-file
5194 'help-echo fname) ":"
5195 (propertize lineno 'face 'anything-grep-lineno) ":"
5196 (anything-c-grep-highlight-match str))
5197 i)))
5199 (defun anything-c-grep-highlight-match (str)
5200 "Highlight in string STR all occurences matching `anything-pattern'."
5201 (condition-case nil
5202 (with-temp-buffer
5203 (insert str)
5204 (goto-char (point-min))
5205 (while (and (re-search-forward anything-pattern nil t)
5206 (> (- (match-end 0) (match-beginning 0)) 0))
5207 (add-text-properties
5208 (match-beginning 0) (match-end 0)
5209 '(face anything-grep-match)))
5210 (buffer-string))
5211 (error nil)))
5213 ;; Go to next or precedent file (common to etags and grep).
5214 (defun anything-c-goto-next-or-prec-file (n)
5215 "Go to next or precedent candidate file in anything grep/etags buffers.
5216 If N is positive go forward otherwise go backward."
5217 (with-anything-window
5218 (let* ((current-line-list (split-string
5219 (buffer-substring
5220 (point-at-bol)
5221 (point-at-eol)) ":"))
5222 (current-fname (nth 0 current-line-list))
5223 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5224 (catch 'break
5225 (while (not (funcall fn-b-o-f))
5226 (forward-line n) ; Go forward or backward depending of n value.
5227 (unless (search-forward current-fname (point-at-eol) t)
5228 (anything-mark-current-line)
5229 (throw 'break nil))))
5230 (cond ((and (eq n 1) (eobp))
5231 (re-search-backward ".")
5232 (forward-line 0)
5233 (anything-mark-current-line))
5234 ((and (< n 1) (bobp))
5235 (forward-line 1)
5236 (anything-mark-current-line))))))
5238 ;;;###autoload
5239 (defun anything-c-goto-precedent-file ()
5240 "Go to precedent file in anything grep/etags buffers."
5241 (interactive)
5242 (anything-c-goto-next-or-prec-file -1))
5244 ;;;###autoload
5245 (defun anything-c-goto-next-file ()
5246 "Go to precedent file in anything grep/etags buffers."
5247 (interactive)
5248 (anything-c-goto-next-or-prec-file 1))
5250 ;;;###autoload
5251 (defun anything-c-grep-run-persistent-action ()
5252 "Run grep persistent action from `anything-do-grep-1'."
5253 (interactive)
5254 (anything-attrset 'jump-persistent 'anything-c-grep-persistent-action)
5255 (anything-execute-persistent-action 'jump-persistent))
5257 ;;;###autoload
5258 (defun anything-c-grep-run-default-action ()
5259 "Run grep default action from `anything-do-grep-1'."
5260 (interactive)
5261 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5263 ;;;###autoload
5264 (defun anything-c-grep-run-other-window-action ()
5265 "Run grep goto other window action from `anything-do-grep-1'."
5266 (interactive)
5267 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5269 ;;;###autoload
5270 (defun anything-c-grep-run-save-buffer ()
5271 "Run grep save results action from `anything-do-grep-1'."
5272 (interactive)
5273 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5275 ;; Grep buffers
5276 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5277 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5278 If one of selected buffers is not a file--buffer,
5279 it is ignored and grep will run on all others file--buffers.
5280 If only one candidate is selected and it is not a file--buffer,
5281 switch to this buffer and run `anything-occur'.
5282 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5283 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5284 (cands (if prefarg
5285 (buffer-list)
5286 (anything-marked-candidates)))
5287 (win-conf (current-window-configuration))
5288 ;; Non--fname buffers are ignored.
5289 (bufs (loop for buf in cands
5290 for fname = (buffer-file-name (get-buffer buf))
5291 when fname
5292 collect (expand-file-name fname))))
5293 (if bufs
5294 (if zgrep
5295 (anything-do-grep-1 bufs nil 'zgrep)
5296 (anything-do-grep-1 bufs))
5297 ;; bufs is empty, thats mean we have only CANDIDATE
5298 ;; and it is not a buffer-filename, fallback to occur.
5299 (anything-c-switch-to-buffer candidate)
5300 (when (get-buffer anything-action-buffer)
5301 (kill-buffer anything-action-buffer))
5302 (anything-occur)
5303 (when (eq anything-exit-status 1)
5304 (set-window-configuration win-conf)))))
5306 (defun anything-c-grep-buffers (candidate)
5307 "Action to grep buffers."
5308 (anything-c-grep-buffers-1 candidate))
5310 (defun anything-c-zgrep-buffers (candidate)
5311 "Action to zgrep buffers."
5312 (anything-c-grep-buffers-1 candidate 'zgrep))
5315 ;;; Anything interface for pdfgrep
5316 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5317 ;; and a pdf-reader (e.g xpdf) are needed.
5319 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5320 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5321 (defvar anything-c-pdfgrep-debug-command-line nil)
5323 (defun anything-c-pdfgrep-init (only-files)
5324 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5325 (let* ((fnargs (anything-c-grep-prepare-candidates
5326 (if (file-remote-p anything-ff-default-directory)
5327 (mapcar #'(lambda (x)
5328 (file-remote-p x 'localname))
5329 only-files)
5330 only-files)))
5331 (cmd-line (format anything-c-pdfgrep-default-command
5332 anything-pattern
5333 fnargs)))
5334 (when anything-c-pdfgrep-debug-command-line
5335 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5336 (goto-char (point-max))
5337 (insert (concat ">>> " cmd-line "\n\n"))))
5338 (setq mode-line-format
5339 '(" " mode-line-buffer-identification " "
5340 (line-number-mode "%l") " "
5341 (:eval (propertize "(Pdfgrep Process Running) "
5342 'face '((:foreground "red"))))))
5343 (prog1
5344 (let ((default-directory anything-ff-default-directory))
5345 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5346 (message nil)
5347 (set-process-sentinel
5348 (get-process "pdfgrep-process")
5349 #'(lambda (process event)
5350 (when (string= event "finished\n")
5351 (with-anything-window
5352 (anything-update-move-first-line))
5353 (force-mode-line-update nil)))))))
5356 (defun anything-do-pdfgrep-1 (only)
5357 "Launch pdfgrep with a list of ONLY files."
5358 (unless (executable-find "pdfgrep")
5359 (error "Error: No such program `pdfgrep'."))
5360 (let* ((anything-compile-source-functions
5361 ;; rule out anything-match-plugin because the input is one regexp.
5362 (delq 'anything-compile-source--match-plugin
5363 (copy-sequence anything-compile-source-functions)))
5364 ;; Disable match-plugin and use here own highlighting.
5365 (anything-mp-highlight-delay nil))
5366 ;; When called as action from an other source e.g *-find-files
5367 ;; we have to kill action buffer.
5368 (when (get-buffer anything-action-buffer)
5369 (kill-buffer anything-action-buffer))
5370 ;; If `anything-find-files' haven't already started,
5371 ;; give a default value to `anything-ff-default-directory'.
5372 (setq anything-ff-default-directory (or anything-ff-default-directory
5373 default-directory))
5374 (anything
5375 :sources
5376 `(((name . "PdfGrep")
5377 (candidates
5378 . (lambda ()
5379 (funcall anything-c-pdfgrep-default-function only)))
5380 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5381 (candidate-number-limit . 9999)
5382 (mode-line . anything-pdfgrep-mode-line-string)
5383 (action . anything-c-pdfgrep-action)
5384 (persistent-help . "Jump to PDF Page")
5385 (requires-pattern . 3)
5386 (delayed)))
5387 :keymap anything-c-pdfgrep-map
5388 :buffer "*anything grep*")))
5391 (defun anything-c-pdfgrep-action (candidate)
5392 (let* ((split (anything-c-grep-split-line candidate))
5393 (pageno (nth 1 split))
5394 (fname (car split)))
5395 (start-file-process-shell-command
5396 "pdf-reader" nil
5397 (format-spec anything-c-pdfgrep-default-read-command
5398 (list (cons ?f fname) (cons ?p pageno))))))
5400 (defun anything-do-pdfgrep ()
5401 (interactive)
5402 (let ((only (anything-c-read-file-name
5403 "Search in file(s): "
5404 :marked-candidates t
5405 :test #'(lambda (file)
5406 (or (string= (file-name-extension file) "pdf")
5407 (string= (file-name-extension file) "PDF")
5408 (file-directory-p file)))
5409 :preselect (or (dired-get-filename nil t)
5410 (buffer-file-name (current-buffer)))))
5411 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5412 (anything-do-pdfgrep-1 only)))
5415 ;; Yank text at point.
5418 ;; Internal
5419 (defvar anything-yank-point nil)
5421 ;;;###autoload
5422 (defun anything-yank-text-at-point ()
5423 "Yank text at point in minibuffer."
5424 (interactive)
5425 (let (input)
5426 (flet ((insert-in-minibuffer (word)
5427 (with-selected-window (minibuffer-window)
5428 (let ((str anything-pattern))
5429 (delete-minibuffer-contents)
5430 (set-text-properties 0 (length word) nil word)
5431 (insert (concat str word))))))
5432 (with-anything-current-buffer
5433 ;; Start to initial point if C-w have never been hit.
5434 (unless anything-yank-point (setq anything-yank-point (point)))
5435 (and anything-yank-point (goto-char anything-yank-point))
5436 (forward-word 1)
5437 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5438 (setq anything-yank-point (point))) ; End of last forward-word
5439 (insert-in-minibuffer input))))
5441 (defun anything-reset-yank-point ()
5442 (setq anything-yank-point nil))
5444 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5445 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5448 ;;; Recentf files
5451 (defvar anything-c-source-recentf
5452 '((name . "Recentf")
5453 (init . (lambda ()
5454 (require 'recentf)
5455 (or recentf-mode (recentf-mode 1))))
5456 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5457 (candidates . recentf-list)
5458 (match anything-c-match-on-basename)
5459 (type . file))
5460 "See (info \"(emacs)File Conveniences\").
5461 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5462 ;; (anything 'anything-c-source-recentf)
5464 ;;; ffap
5465 (eval-when-compile (require 'ffap))
5466 (defvar anything-c-source-ffap-guesser
5467 '((name . "File at point")
5468 (init . (lambda () (require 'ffap)))
5469 (candidates . (lambda ()
5470 (anything-aif
5471 (with-anything-current-buffer
5472 (ffap-guesser))
5473 (list it))))
5474 (type . file)))
5475 ;; (anything 'anything-c-source-ffap-guesser)
5477 ;;; ffap with line number
5478 (defun anything-c-ffap-file-line-at-point ()
5479 "Get (FILENAME . LINENO) at point."
5480 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5481 (save-excursion
5482 (beginning-of-line)
5483 (when (and (search-forward it nil t)
5484 (looking-at ":\\([0-9]+\\)"))
5485 (cons it (string-to-number (match-string 1)))))))
5487 (defvar anything-c-ffap-line-location nil
5488 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5489 It is cleared after jumping line.")
5491 (defun anything-c-ffap-line-candidates ()
5492 (with-anything-current-buffer
5493 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5494 (when anything-c-ffap-line-location
5495 (destructuring-bind (file . line) anything-c-ffap-line-location
5496 (list (cons (format "%s (line %d)" file line) file)))))
5498 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5499 (defun anything-c-ffap-line-goto-line ()
5500 (when (car anything-c-ffap-line-location)
5501 (unwind-protect
5502 (ignore-errors
5503 (with-selected-window
5504 (get-buffer-window
5505 (get-file-buffer (car anything-c-ffap-line-location)))
5506 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5507 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5508 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5510 (defvar anything-c-source-ffap-line
5511 '((name . "File/Lineno at point")
5512 (init . (lambda () (require 'ffap)))
5513 (candidates . anything-c-ffap-line-candidates)
5514 (type . file)))
5515 ;; (anything 'anything-c-source-ffap-line)
5517 ;;; list of files gleaned from every dired buffer
5518 (defun anything-c-files-in-all-dired-candidates ()
5519 (save-excursion
5520 (mapcan
5521 (lambda (dir)
5522 (cond ((listp dir) ;filelist
5523 dir)
5524 ((equal "" (file-name-nondirectory dir)) ;dir
5525 (directory-files dir t))
5526 (t ;wildcard
5527 (file-expand-wildcards dir t))))
5528 (delq nil
5529 (mapcar (lambda (buf)
5530 (set-buffer buf)
5531 (when (eq major-mode 'dired-mode)
5532 (if (consp dired-directory)
5533 (cdr dired-directory) ;filelist
5534 dired-directory))) ;dir or wildcard
5535 (buffer-list))))))
5536 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5538 (defvar anything-c-source-files-in-all-dired
5539 '((name . "Files in all dired buffer.")
5540 (candidates . anything-c-files-in-all-dired-candidates)
5541 (type . file)))
5542 ;; (anything 'anything-c-source-files-in-all-dired)
5544 (defvar anything-c-source-filelist
5545 '((name . "FileList")
5546 (grep-candidates . anything-c-filelist-file-name)
5547 (candidate-number-limit . 200)
5548 (requires-pattern . 4)
5549 (type . file))
5550 "Source to find files instantly.
5551 See `anything-c-filelist-file-name' docstring for usage.")
5554 ;;;; <info>
5555 ;;; Info pages
5556 (defvar anything-c-info-pages nil
5557 "All info pages on system.
5558 Will be calculated the first time you invoke anything with this
5559 source.")
5561 (defun anything-c-info-pages-init ()
5562 "Collect candidates for initial Info node Top."
5563 (if anything-c-info-pages
5564 anything-c-info-pages
5565 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5566 topics)
5567 (require 'info)
5568 (with-temp-buffer
5569 (Info-find-node "dir" "top")
5570 (goto-char (point-min))
5571 (while (re-search-forward info-topic-regexp nil t)
5572 (push (match-string-no-properties 1) topics))
5573 (kill-buffer))
5574 (setq anything-c-info-pages topics))))
5576 (defvar anything-c-source-info-pages
5577 `((name . "Info Pages")
5578 (init . anything-c-info-pages-init)
5579 (candidates . anything-c-info-pages)
5580 (action . (("Show with Info" .(lambda (node-str)
5581 (info (replace-regexp-in-string
5582 "^[^:]+: " "" node-str))))))
5583 (requires-pattern . 2)))
5584 ;; (anything 'anything-c-source-info-pages)
5587 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5588 (defun anything-c-describe-attributes (anything-attribute)
5589 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5590 Same as `anything-describe-anything-attribute' but with anything completion."
5591 (interactive (list (intern
5592 (anything-comp-read
5593 "Describe anything attribute: "
5594 (mapcar 'symbol-name anything-additional-attributes)
5595 :must-match t
5596 :persistent-action
5597 #'(lambda (candidate)
5598 (with-output-to-temp-buffer "*Help*"
5599 (princ (get (intern candidate) 'anything-attrdoc))))))))
5600 (with-output-to-temp-buffer "*Help*"
5601 (princ (get anything-attribute 'anything-attrdoc))))
5604 ;;; Use info-index plug-in.
5607 ;; Note that `name' attribute is not needed since
5608 ;; `anything-c-insert-summary' have been removed.
5609 ;; Info Elisp
5610 (defvar anything-c-source-info-elisp
5611 '((name . "Info index: elisp")
5612 (info-index . "elisp")))
5613 ;; (anything 'anything-c-source-info-elisp)
5615 ;; Info-Common-Lisp
5616 (defvar anything-c-source-info-cl
5617 '((name . "Info index: cl")
5618 (info-index . "cl")))
5619 ;; (anything 'anything-c-source-info-cl)
5621 ;; Info Index org
5622 (defvar anything-c-source-info-org
5623 '((name . "Info index: org")
5624 (info-index . "org")))
5625 ;; (anything 'anything-c-source-info-org)
5627 ;; Info Index gnus
5628 (defvar anything-c-source-info-gnus
5629 '((name . "Info index: Gnus")
5630 (info-index . "gnus")))
5632 ;; Info Index ratpoison
5633 (defvar anything-c-source-info-ratpoison
5634 '((name . "Info index: ratpoison")
5635 (info-index . "ratpoison")))
5636 ;; (anything 'anything-c-source-info-ratpoison)
5638 ;; Info Index zsh
5639 (defvar anything-c-source-info-zsh
5640 '((name . "Info index: zsh")
5641 (info-index . "zsh")))
5642 ;; (anything 'anything-c-source-info-zsh)
5644 ;; Info Index bash
5645 (defvar anything-c-source-info-bash
5646 '((name . "Info index: bash")
5647 (info-index . "bash")))
5648 ;; (anything 'anything-c-source-info-bash)
5650 ;; Info Index coreutils
5651 (defvar anything-c-source-info-coreutils
5652 '((name . "Info index: coreutils")
5653 (info-index . "coreutils")))
5654 ;; (anything 'anything-c-source-info-coreutils)
5656 ;; Info Index fileutils
5657 (defvar anything-c-source-info-fileutils
5658 '((name . "Info index: fileutils")
5659 (info-index . "fileutils")))
5660 ;; (anything 'anything-c-source-info-fileutils)
5662 ;; Info Index find
5663 (defvar anything-c-source-info-find
5664 '((name . "Info index: find")
5665 (info-index . "find")))
5666 ;; (anything 'anything-c-source-info-find)
5668 ;; Info Index sh-utils
5669 (defvar anything-c-source-info-sh-utils
5670 '((name . "Info index: sh-utils")
5671 (info-index . "sh-utils")))
5672 ;; (anything 'anything-c-source-info-sh-utils)
5674 ;; Info Index textutils
5675 (defvar anything-c-source-info-textutils
5676 '((name . "Info index: textutils")
5677 (info-index . "textutils")))
5678 ;; (anything 'anything-c-source-info-textutils)
5680 ;; Info Index libc
5681 (defvar anything-c-source-info-libc
5682 '((name . "Info index: libc")
5683 (info-index . "libc")))
5684 ;; (anything 'anything-c-source-info-libc)
5686 ;; Info Index make
5687 (defvar anything-c-source-info-make
5688 '((name . "Info index: make")
5689 (info-index . "make")))
5690 ;; (anything 'anything-c-source-info-make)
5692 ;; Info Index automake
5693 (defvar anything-c-source-info-automake
5694 '((name . "Info index: automake")
5695 (info-index . "automake")))
5696 ;; (anything 'anything-c-source-info-automake)
5698 ;; Info Index autoconf
5699 (defvar anything-c-source-info-autoconf
5700 '((name . "Info index: autoconf")
5701 (info-index . "autoconf")))
5702 ;; (anything 'anything-c-source-info-autoconf)
5704 ;; Info Index emacs-lisp-intro
5705 (defvar anything-c-source-info-emacs-lisp-intro
5706 '((name . "Info index: emacs-lisp-intro")
5707 (info-index . "emacs-lisp-intro")))
5708 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5710 ;; Info Index emacs
5711 (defvar anything-c-source-info-emacs
5712 '((name . "Info index: emacs")
5713 (info-index . "emacs")))
5714 ;; (anything 'anything-c-source-info-emacs)
5716 ;; Info Index elib
5717 (defvar anything-c-source-info-elib
5718 '((name . "Info index: elib")
5719 (info-index . "elib")))
5720 ;; (anything 'anything-c-source-info-elib)
5722 ;; Info Index eieio
5723 (defvar anything-c-source-info-eieio
5724 '((name . "Info index: eieio")
5725 (info-index . "eieio")))
5726 ;; (anything 'anything-c-source-info-eieio)
5728 ;; Info Index gauche-refe
5729 (defvar anything-c-source-info-gauche-refe
5730 '((name . "Info index: gauche")
5731 (info-index . "gauche-refe")))
5732 ;; (anything 'anything-c-source-info-gauche-refe)
5734 ;; Info Index guile
5735 (defvar anything-c-source-info-guile
5736 '((name . "Info index: guile")
5737 (info-index . "guile")))
5738 ;; (anything 'anything-c-source-info-guile)
5740 ;; Info Index guile-tut
5741 (defvar anything-c-source-info-guile-tut
5742 '((name . "Info index: guile-tut")
5743 (info-index . "guile-tut")))
5744 ;; (anything 'anything-c-source-info-guile-tut)
5746 ;; Info Index goops
5747 (defvar anything-c-source-info-goops
5748 '((name . "Info index: goops")
5749 (info-index . "goops")))
5750 ;; (anything 'anything-c-source-info-goops)
5752 ;; Info Index screen
5753 (defvar anything-c-source-info-screen
5754 '((name . "Info index: screen")
5755 (info-index . "screen")
5756 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5757 ;; (anything 'anything-c-source-info-screen)
5759 ;; Info Index latex
5760 (defvar anything-c-source-info-latex
5761 '((name . "Info index: latex")
5762 (info-index . "latex")))
5763 ;; (anything 'anything-c-source-info-latex)
5765 ;; Info Index gawk
5766 (defvar anything-c-source-info-gawk
5767 '((name . "Info index: gawk")
5768 (info-index . "gawk")))
5769 ;; (anything 'anything-c-source-info-gawk)
5771 ;; Info Index sed
5772 (defvar anything-c-source-info-sed
5773 '((name . "Info index: sed")
5774 (info-index . "sed")))
5775 ;; (anything 'anything-c-source-info-sed)
5777 ;; Info Index m4
5778 (defvar anything-c-source-info-m4
5779 '((name . "Info index: m4")
5780 (info-index . "m4")))
5781 ;; (anything 'anything-c-source-info-m4)
5783 ;; Info Index wget
5784 (defvar anything-c-source-info-wget
5785 '((name . "Info index: wget")
5786 (info-index . "wget")))
5787 ;; (anything 'anything-c-source-info-wget)
5789 ;; Info Index binutils
5790 (defvar anything-c-source-info-binutils
5791 '((name . "Info index: binutils")
5792 (info-index . "binutils")))
5793 ;; (anything 'anything-c-source-info-binutils)
5795 ;; Info Index as
5796 (defvar anything-c-source-info-as
5797 '((name . "Info index: as")
5798 (info-index . "as")))
5799 ;; (anything 'anything-c-source-info-as)
5801 ;; Info Index bfd
5802 (defvar anything-c-source-info-bfd
5803 '((name . "Info index: bfd")
5804 (info-index . "bfd")))
5805 ;; (anything 'anything-c-source-info-bfd)
5807 ;; Info Index gprof
5808 (defvar anything-c-source-info-gprof
5809 '((name . "Info index: gprof")
5810 (info-index . "gprof")))
5811 ;; (anything 'anything-c-source-info-gprof)
5813 ;; Info Index ld
5814 (defvar anything-c-source-info-ld
5815 '((name . "Info index: ld")
5816 (info-index . "ld")))
5817 ;; (anything 'anything-c-source-info-ld)
5819 ;; Info Index diff
5820 (defvar anything-c-source-info-diff
5821 '((name . "Info index: diff")
5822 (info-index . "diff")))
5823 ;; (anything 'anything-c-source-info-diff)
5825 ;; Info Index flex
5826 (defvar anything-c-source-info-flex
5827 '((name . "Info index: flex")
5828 (info-index . "flex")))
5829 ;; (anything 'anything-c-source-info-flex)
5831 ;; Info Index grep
5832 (defvar anything-c-source-info-grep
5833 '((name . "Info index: grep")
5834 (info-index . "grep")))
5835 ;; (anything 'anything-c-source-info-grep)
5837 ;; Info Index gzip
5838 (defvar anything-c-source-info-gzip
5839 '((name . "Info index: gzip")
5840 (info-index . "gzip")))
5841 ;; (anything 'anything-c-source-info-gzip)
5843 ;; Info Index libtool
5844 (defvar anything-c-source-info-libtool
5845 '((name . "Info index: libtool")
5846 (info-index . "libtool")))
5847 ;; (anything 'anything-c-source-info-libtool)
5849 ;; Info Index texinfo
5850 (defvar anything-c-source-info-texinfo
5851 '((name . "Info index: texinfo")
5852 (info-index . "texinfo")))
5853 ;; (anything 'anything-c-source-info-texinfo)
5855 ;; Info Index info
5856 (defvar anything-c-source-info-info
5857 '((name . "Info index: info")
5858 (info-index . "info")))
5859 ;; (anything 'anything-c-source-info-info)
5861 ;; Info Index gdb
5862 (defvar anything-c-source-info-gdb
5863 '((name . "Info index: gdb")
5864 (info-index . "gdb")))
5865 ;; (anything 'anything-c-source-info-gdb)
5867 ;; Info Index stabs
5868 (defvar anything-c-source-info-stabs
5869 '((name . "Info index: stabs")
5870 (info-index . "stabs")))
5871 ;; (anything 'anything-c-source-info-stabs)
5873 ;; Info Index cvsbook
5874 (defvar anything-c-source-info-cvsbook
5875 '((name . "Info index: cvsbook")
5876 (info-index . "cvsbook")))
5877 ;; (anything 'anything-c-source-info-cvsbook)
5879 ;; Info Index cvs
5880 (defvar anything-c-source-info-cvs
5881 '((name . "Info index: cvs")
5882 (info-index . "cvs")))
5883 ;; (anything 'anything-c-source-info-cvs)
5885 ;; Info Index bison
5886 (defvar anything-c-source-info-bison
5887 '((name . "Info index: bison")
5888 (info-index . "bison")))
5889 ;; (anything 'anything-c-source-info-bison)
5891 ;; Info Index id-utils
5892 (defvar anything-c-source-info-id-utils
5893 '((name . "Info index: id-utils")
5894 (info-index . "id-utils")))
5895 ;; (anything 'anything-c-source-info-id-utils)
5897 ;; Info Index global
5898 (defvar anything-c-source-info-global
5899 '((name . "Info index: global")
5900 (info-index . "global")))
5901 ;; (anything 'anything-c-source-info-global)
5904 ;;; Man and woman UI
5907 (defvar anything-c-man-pages nil
5908 "All man pages on system.
5909 Will be calculated the first time you invoke anything with this
5910 source.")
5912 (defun anything-c-man-default-action (candidate)
5913 "Default action for jumping to a woman or man page from anything."
5914 (let ((wfiles (woman-file-name-all-completions candidate)))
5915 (condition-case err
5916 (if (> (length wfiles) 1)
5917 (woman-find-file
5918 (anything-comp-read
5919 "ManFile: " wfiles :must-match t))
5920 (woman candidate))
5921 ;; If woman is unable to format correctly
5922 ;; use man instead.
5923 (error (kill-buffer) ; Kill woman buffer.
5924 (let ((Man-notify-method 'meek))
5925 (Man-getpage-in-background candidate))))))
5927 (defvar anything-c-source-man-pages
5928 `((name . "Manual Pages")
5929 (candidates . (lambda ()
5930 (if anything-c-man-pages
5931 anything-c-man-pages
5932 ;; XEmacs doesn't have a woman :)
5933 (setq anything-c-man-pages
5934 (ignore-errors
5935 (require 'woman)
5936 (woman-file-name "")
5937 (sort (mapcar 'car woman-topic-all-completions)
5938 'string-lessp))))))
5939 (action ("Show with Woman" . anything-c-man-default-action))
5940 ;; Woman does not work OS X
5941 ;; http://xahlee.org/emacs/modernization_man_page.html
5942 (action-transformer . (lambda (actions candidate)
5943 (if (eq system-type 'darwin)
5944 '(("Show with Man" . man))
5945 actions)))
5946 (requires-pattern . 2)))
5947 ;; (anything 'anything-c-source-man-pages)
5950 ;;;; <Command>
5951 ;;; Anything M-x - Enhanced M-x UI
5954 ;; Another replacement of `M-x' that act exactly like the
5955 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5956 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5957 ;; anything invocation.
5958 ;; Documentation of commands available without quitting,
5959 ;; Show keybindings of commands.
5960 ;; Show history.
5961 (defvar anything-M-x-input-history nil)
5963 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5964 "Return alist of MODE-MAP."
5965 (loop for key being the key-seqs of mode-map using (key-bindings com)
5966 for str-key = (key-description key)
5967 for ismenu = (string-match "<menu-bar>" str-key)
5968 unless ismenu collect (cons str-key com)))
5970 (defun anything-get-mode-map-from-mode (mode)
5971 "Guess the mode-map name according to MODE.
5972 Some modes don't use conventional mode-map name
5973 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5974 Return nil if no mode-map found."
5975 (loop
5976 ;; Start with a conventional mode-map name.
5977 with mode-map = (intern-soft (format "%s-map" mode))
5978 with mode-string = (symbol-name mode)
5979 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5980 while (not mode-map)
5981 for count downfrom (length mode-name)
5982 ;; Return when no result after parsing entire string.
5983 when (eq count 0) return nil
5984 for sub-name = (substring mode-name 0 count)
5985 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5986 finally return mode-map))
5988 (defun anything-M-x-current-mode-map-alist ()
5989 "Return mode-map alist of current `major-mode'."
5990 (let ((map (anything-get-mode-map-from-mode major-mode)))
5991 (when (and map (boundp map))
5992 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5995 (defun anything-M-x-transformer (candidates sources)
5996 "filtered-candidate-transformer to show bindings in emacs commands.
5997 Show global bindings and local bindings according to current `major-mode'."
5998 (with-anything-current-buffer
5999 (loop
6000 with local-map = (anything-M-x-current-mode-map-alist)
6001 for cand in candidates
6002 for local-key = (car (rassq cand local-map))
6003 for key = (substitute-command-keys (format "\\[%s]" cand))
6004 collect
6005 (cons (cond ((and (string-match "^M-x" key) local-key)
6006 (format "%s (%s)"
6007 cand (propertize
6008 local-key
6009 'face 'anything-M-x-key-face)))
6010 ((string-match "^M-x" key) cand)
6011 (t (format "%s (%s)"
6012 cand (propertize
6014 'face 'anything-M-x-key-face))))
6015 cand) into ls
6016 finally return
6017 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
6020 ;;; Complex command history
6023 (defvar anything-c-source-complex-command-history
6024 '((name . "Complex Command History")
6025 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
6026 (type . sexp)))
6027 ;; (anything 'anything-c-source-complex-command-history)
6029 ;;; M-x history (not related to `anything-M-x')
6032 (defvar anything-c-source-extended-command-history
6033 '((name . "Emacs Commands History")
6034 (candidates
6035 . (lambda ()
6036 (anything-fast-remove-dups extended-command-history :test 'equal)))
6037 (type . command)))
6038 ;; (anything 'anything-c-source-extended-command-history)
6040 ;;; Emacs commands (Basic source for emacs commands)
6043 (defvar anything-c-source-emacs-commands
6044 '((name . "Emacs Commands")
6045 (candidates . (lambda ()
6046 (let (commands)
6047 (mapatoms (lambda (a)
6048 (if (commandp a)
6049 (push (symbol-name a)
6050 commands))))
6051 (sort commands 'string-lessp))))
6052 (type . command)
6053 (requires-pattern . 2))
6054 "Source for completing and invoking Emacs commands.
6055 A command is a function with interactive spec that can
6056 be invoked with `M-x'.
6058 To get non-interactive functions listed, use
6059 `anything-c-source-emacs-functions'.")
6060 ;; (anything 'anything-c-source-emacs-commands)
6063 ;;;; <Function>
6064 ;;; Emacs functions
6067 (defvar anything-c-source-emacs-functions
6068 '((name . "Emacs Functions")
6069 (candidates . (lambda ()
6070 (let (commands)
6071 (mapatoms (lambda (a)
6072 (if (functionp a)
6073 (push (symbol-name a) commands))))
6074 (sort commands 'string-lessp))))
6075 (type . function)
6076 (requires-pattern . 2))
6077 "Source for completing Emacs functions.")
6078 ;; (anything 'anything-c-source-emacs-functions)
6080 ;;; With abbrev expansion
6081 ;;; Similar to my exec-abbrev-cmd.el
6082 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6083 (defvar anything-c-function-abbrev-regexp nil
6084 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6085 Regexp built from the current `anything-pattern' interpreting it
6086 as abbreviation.
6087 Only for internal use.")
6089 (defun anything-c-match-function-by-abbrev (candidate)
6090 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6092 Abbreviations are made by taking the first character from each
6093 word in the function's name, e.g. \"bb\" is an abbrev for
6094 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6095 (string-match anything-c-function-abbrev-regexp candidate))
6097 (defvar anything-c-source-emacs-functions-with-abbrevs
6098 (append anything-c-source-emacs-functions
6099 '((match anything-c-match-function-by-abbrev
6100 anything-c-string-match))
6101 '((init
6102 . (lambda ()
6103 (defadvice anything-update
6104 (before anything-c-update-function-abbrev-regexp activate)
6105 (let ((char-list (append anything-pattern nil))
6106 (str "^"))
6107 (dolist (c char-list)
6108 (setq str (concat str (list c) "[^-]*-")))
6109 (setq str (concat (substring str 0 (1- (length str))) "$"))
6110 (setq anything-c-function-abbrev-regexp str))))))))
6111 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6113 (defvar anything-c-source-advice
6114 '((name . "Function Advice")
6115 (candidates . anything-c-advice-candidates)
6116 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6117 (persistent-action . anything-c-advice-persistent-action)
6118 (multiline)
6119 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6120 ;; (anything 'anything-c-source-advice)
6121 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6122 ;; (testadvice)
6124 (defun anything-c-advice-candidates ()
6125 (require 'advice)
6126 (loop for (fname) in ad-advised-functions
6127 for function = (intern fname)
6128 append
6129 (loop for class in ad-advice-classes append
6130 (loop for advice in (ad-get-advice-info-field function class)
6131 for enabled = (ad-advice-enabled advice)
6132 collect
6133 (cons (format
6134 "%s %s %s"
6135 (if enabled "Enabled " "Disabled")
6136 (propertize fname 'face 'font-lock-function-name-face)
6137 (ad-make-single-advice-docstring advice class nil))
6138 (list function class advice))))))
6140 (defun anything-c-advice-persistent-action (func-class-advice)
6141 (if current-prefix-arg
6142 (anything-c-advice-toggle func-class-advice)
6143 (describe-function (car func-class-advice))))
6145 (defun anything-c-advice-toggle (func-class-advice)
6146 (destructuring-bind (function class advice) func-class-advice
6147 (cond ((ad-advice-enabled advice)
6148 (ad-advice-set-enabled advice nil)
6149 (message "Disabled"))
6150 (t ;disabled
6151 (ad-advice-set-enabled advice t)
6152 (message "Enabled")))
6153 (ad-activate function)
6154 (and anything-in-persistent-action
6155 (anything-c-advice-update-current-display-string))))
6157 (defun anything-c-advice-update-current-display-string ()
6158 (anything-edit-current-selection
6159 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6160 ((looking-at "Enabled") "Disabled")))
6161 realvalue)
6162 (when newword
6163 (delete-region (point) (progn (forward-word 1) (point)))
6164 (insert newword)))))
6167 ;;;; <Variable>
6168 ;;; Emacs variables
6171 (defvar anything-c-source-emacs-variables
6172 '((name . "Emacs Variables")
6173 (candidates . (lambda ()
6174 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6175 (type . variable)
6176 (requires-pattern . 2))
6177 "Source for completing Emacs variables.")
6178 ;; (anything 'anything-c-source-emacs-variables)
6181 ;;; LaCarte
6182 (defvar anything-c-source-lacarte
6183 '((name . "Lacarte")
6184 (init . (lambda () (require 'lacarte )))
6185 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6186 (candidate-number-limit . 9999)
6187 (action . anything-c-call-interactively))
6188 "Needs lacarte.el.
6190 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6191 ;; (anything 'anything-c-source-lacarte)
6194 ;;; Bookmarks
6197 ;; Bind some faces for bookmarks.
6198 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6199 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6200 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6202 (eval-when-compile (require 'bookmark))
6203 (defvar anything-c-source-bookmarks
6204 '((name . "Bookmarks")
6205 (init . (lambda ()
6206 (require 'bookmark)))
6207 (candidates . bookmark-all-names)
6208 (type . bookmark))
6209 "See (info \"(emacs)Bookmarks\").")
6210 ;; (anything 'anything-c-source-bookmarks)
6212 ;;; bookmark-set
6213 (defvar anything-c-source-bookmark-set
6214 '((name . "Set Bookmark")
6215 (dummy)
6216 (action . bookmark-set))
6217 "See (info \"(emacs)Bookmarks\").")
6218 ;; (anything 'anything-c-source-bookmark-set)
6220 ;;; Visible Bookmarks
6221 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6224 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6225 (defvar anything-c-source-bm
6226 '((name . "Visible Bookmarks")
6227 (init . anything-c-bm-init)
6228 (candidates-in-buffer)
6229 (type . line))
6230 "Needs bm.el.
6232 http://www.nongnu.org/bm/")
6234 (defun anything-c-bm-init ()
6235 "Init function for `anything-c-source-bm'."
6236 (when (require 'bm nil t)
6237 (with-no-warnings
6238 (let ((bookmarks (bm-lists))
6239 (buf (anything-candidate-buffer 'global)))
6240 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6241 '< :key 'overlay-start))
6242 (let ((start (overlay-start bm))
6243 (end (overlay-end bm))
6244 (annotation (or (overlay-get bm 'annotation) "")))
6245 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6246 (let ((str (format "%5d: [%s]: %s\n"
6247 (line-number-at-pos start)
6248 annotation
6249 (buffer-substring start (1- end)))))
6250 (with-current-buffer buf (insert str))))))))))
6252 ;;; Special bookmarks
6253 (defvar anything-c-source-bookmarks-ssh
6254 '((name . "Bookmarks-ssh")
6255 (init . (lambda ()
6256 (require 'bookmark)))
6257 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6258 (type . bookmark))
6259 "See (info \"(emacs)Bookmarks\").")
6260 ;; (anything 'anything-c-source-bookmarks-ssh)
6262 (defvar anything-c-source-bookmarks-su
6263 '((name . "Bookmarks-root")
6264 (init . (lambda ()
6265 (require 'bookmark)))
6266 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6267 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6269 (type . bookmark))
6270 "See (info \"(emacs)Bookmarks\").")
6271 ;; (anything 'anything-c-source-bookmarks-su)
6273 (defvar anything-c-source-bookmarks-local
6274 '((name . "Bookmarks-Local")
6275 (init . (lambda ()
6276 (require 'bookmark)))
6277 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6278 (filtered-candidate-transformer
6279 anything-c-adaptive-sort
6280 anything-c-highlight-bookmark)
6281 (type . bookmark))
6282 "See (info \"(emacs)Bookmarks\").")
6283 ;; (anything 'anything-c-source-bookmarks-local)
6285 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6286 (let* ((lis-all (bookmark-all-names))
6287 (lis-loc (cond (local (loop for i in lis-all
6288 unless (string-match "^(ssh)\\|^(su)" i)
6289 collect i))
6290 (su (loop for i in lis-all
6291 when (string-match "^(su)" i)
6292 collect i))
6293 (sudo (loop for i in lis-all
6294 when (string-match "^(sudo)" i)
6295 collect i))
6296 (ssh (loop for i in lis-all
6297 when (string-match "^(ssh)" i)
6298 collect i)))))
6299 (sort lis-loc 'string-lessp)))
6301 (defun anything-c-bookmark-root-logged-p ()
6302 (catch 'break
6303 (dolist (i (mapcar #'buffer-name (buffer-list)))
6304 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6305 (throw 'break t)))))
6307 (defun anything-c-highlight-bookmark-su (files source)
6308 (if (anything-c-bookmark-root-logged-p)
6309 (anything-c-highlight-bookmark files source)
6310 (anything-c-highlight-not-logged files source)))
6312 (defun anything-c-highlight-not-logged (files source)
6313 (loop for i in files
6314 collect (propertize i 'face anything-c-bookmarks-face3)))
6316 (defun anything-c-highlight-bookmark (bookmarks source)
6317 "Used as `candidate-transformer' to colorize bookmarks.
6318 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6319 (loop for i in bookmarks
6320 for isfile = (bookmark-get-filename i)
6321 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6322 (bmkext-get-buffer-name i))
6323 for handlerp = (and (fboundp 'bookmark-get-handler)
6324 (bookmark-get-handler i))
6325 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6326 (bmkext-w3m-bookmark-p i))
6327 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6328 (bmkext-gnus-bookmark-p i))
6329 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6330 (bmkext-man-bookmark-p i))
6331 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6332 (bmkext-woman-bookmark-p i))
6333 for handlerp = (bookmark-get-handler i)
6334 for isannotation = (bookmark-get-annotation i)
6335 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6336 for isinfo = (eq handlerp 'Info-bookmark-jump)
6337 ;; Add a * if bookmark have annotation
6338 if (and isannotation (not (string-equal isannotation "")))
6339 do (setq i (concat "*" i))
6340 collect (cond (;; info buffers
6341 isinfo
6342 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6343 (;; w3m buffers
6344 isw3m
6345 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6346 (;; gnus buffers
6347 isgnus
6348 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6349 (;; Man Woman
6350 (or iswoman isman)
6351 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6352 (;; Addressbook
6353 isabook
6354 (propertize i 'face '((:foreground "Tomato"))))
6355 (;; directories
6356 (and isfile (file-directory-p isfile))
6357 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6358 (;; regular files
6360 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6364 ;;; Sources to filter bookmark-extensions bookmarks.
6367 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6368 ;; If you want to enable google-maps in addressbook you will need
6369 ;; Julien Danjou google-maps-el package available here:
6370 ;; http://julien.danjou.info/google-maps-el.html
6372 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6373 "Return a filtered `bookmark-alist' sorted alphabetically."
6374 (loop
6375 with alist = (if args
6376 (apply #'(lambda (x) (funcall fn x)) args)
6377 (funcall fn))
6378 for i in alist
6379 for b = (car i)
6380 collect b into sa
6381 finally return (sort sa 'string-lessp)))
6383 ;;; Addressbook.
6386 (defvar anything-c-source-bmkext-addressbook
6387 '((name . "Bookmark Addressbook")
6388 (init . (lambda ()
6389 (require 'bookmark-extensions)
6390 (bookmark-maybe-load-default-file)))
6391 (candidates . anything-c-bmkext-addressbook-setup-alist)
6392 (persistent-action
6393 . (lambda (candidate)
6394 (let ((bmk (anything-bookmark-get-bookmark-from-name
6395 candidate)))
6396 (bookmark--jump-via bmk 'pop-to-buffer))))
6397 (persistent-help . "Show contact - Prefix with C-u to append")
6398 (filtered-candidate-transformer
6399 anything-c-adaptive-sort
6400 anything-c-highlight-bookmark)
6401 (action . (("Show Contact(s)"
6402 . (lambda (candidate)
6403 (let* ((contacts (anything-marked-candidates))
6404 (current-prefix-arg (or anything-current-prefix-arg
6405 (> (length contacts) 1))))
6406 (bookmark-jump
6407 (anything-bookmark-get-bookmark-from-name (car contacts)))
6408 (anything-aif (cdr contacts)
6409 (loop for bmk in it do
6410 (bookmark-jump
6411 (anything-bookmark-get-bookmark-from-name bmk)))))))
6412 ("Send Mail"
6413 . (lambda (candidate)
6414 (let* ((contacts (anything-marked-candidates))
6415 (bmk (anything-bookmark-get-bookmark-from-name
6416 (car contacts)))
6417 (append (message-buffers)))
6418 (if append
6419 (addressbook-set-mail-buffer1 bmk 'append)
6420 (addressbook-set-mail-buffer1 bmk))
6421 (setq contacts (cdr contacts))
6422 (when contacts
6423 (loop for bmk in contacts do
6424 (addressbook-set-mail-buffer1 bmk 'append))))))
6425 ("Edit Bookmark"
6426 . (lambda (candidate)
6427 (let ((bmk (anything-bookmark-get-bookmark-from-name
6428 candidate)))
6429 (addressbook-bookmark-edit
6430 (assoc bmk bookmark-alist)))))
6431 ("Insert Email at point"
6432 . (lambda (candidate)
6433 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6434 candidate))
6435 (mlist (split-string
6436 (assoc-default
6437 'email (assoc bmk bookmark-alist))
6438 ", ")))
6439 (insert
6440 (if (> (length mlist) 1)
6441 (anything-comp-read
6442 "Insert Mail Address: " mlist :must-match t)
6443 (car mlist))))))
6444 ("Show annotation"
6445 . (lambda (candidate)
6446 (let ((bmk (anything-bookmark-get-bookmark-from-name
6447 candidate)))
6448 (bookmark-show-annotation bmk))))
6449 ("Edit annotation"
6450 . (lambda (candidate)
6451 (let ((bmk (anything-bookmark-get-bookmark-from-name
6452 candidate)))
6453 (bookmark-edit-annotation bmk))))
6454 ("Show Google map"
6455 . (lambda (candidate)
6456 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6457 candidate))
6458 (full-bmk (assoc bmk bookmark-alist)))
6459 (addressbook-google-map full-bmk))))))))
6462 (defun anything-c-bmkext-addressbook-setup-alist ()
6463 "Specialized filter function for bookmarks w3m."
6464 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6466 ;; W3m bookmarks from bookmark-extensions.
6467 (defvar anything-c-source-bookmark-w3m
6468 '((name . "Bookmark W3m")
6469 (init . (lambda ()
6470 (require 'bookmark-extensions)
6471 (bookmark-maybe-load-default-file)))
6472 (candidates . anything-c-bookmark-w3m-setup-alist)
6473 (filtered-candidate-transformer
6474 anything-c-adaptive-sort
6475 anything-c-highlight-bookmark)
6476 (type . bookmark)))
6477 ;; (anything 'anything-c-source-bookmark-w3m)
6479 (defun anything-c-bookmark-w3m-setup-alist ()
6480 "Specialized filter function for bookmarks w3m."
6481 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6483 ;; Images
6484 (defvar anything-c-source-bookmark-images
6485 '((name . "Bookmark Images")
6486 (init . (lambda ()
6487 (require 'bookmark-extensions)
6488 (bookmark-maybe-load-default-file)))
6489 (candidates . anything-c-bookmark-images-setup-alist)
6490 (filtered-candidate-transformer
6491 anything-c-adaptive-sort
6492 anything-c-highlight-bookmark)
6493 (type . bookmark)))
6494 ;; (anything 'anything-c-source-bookmark-images)
6496 (defun anything-c-bookmark-images-setup-alist ()
6497 "Specialized filter function for images bookmarks."
6498 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6500 ;; Woman Man
6501 (defvar anything-c-source-bookmark-man
6502 '((name . "Bookmark Woman&Man")
6503 (init . (lambda ()
6504 (require 'bookmark-extensions)
6505 (bookmark-maybe-load-default-file)))
6506 (candidates . anything-c-bookmark-man-setup-alist)
6507 (filtered-candidate-transformer
6508 anything-c-adaptive-sort
6509 anything-c-highlight-bookmark)
6510 (type . bookmark)))
6511 ;; (anything 'anything-c-source-bookmark-man)
6513 (defun anything-c-bookmark-man-setup-alist ()
6514 "Specialized filter function for bookmarks w3m."
6515 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6516 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6518 ;; Gnus
6519 (defvar anything-c-source-bookmark-gnus
6520 '((name . "Bookmark Gnus")
6521 (init . (lambda ()
6522 (require 'bookmark-extensions)
6523 (bookmark-maybe-load-default-file)))
6524 (candidates . anything-c-bookmark-gnus-setup-alist)
6525 (filtered-candidate-transformer
6526 anything-c-adaptive-sort
6527 anything-c-highlight-bookmark)
6528 (type . bookmark)))
6529 ;; (anything 'anything-c-source-bookmark-gnus)
6531 (defun anything-c-bookmark-gnus-setup-alist ()
6532 "Specialized filter function for bookmarks gnus."
6533 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6535 ;; Info
6536 (defvar anything-c-source-bookmark-info
6537 '((name . "Bookmark Info")
6538 (init . (lambda ()
6539 (require 'bookmark-extensions)
6540 (bookmark-maybe-load-default-file)))
6541 (candidates . anything-c-bookmark-info-setup-alist)
6542 (filtered-candidate-transformer
6543 anything-c-adaptive-sort
6544 anything-c-highlight-bookmark)
6545 (type . bookmark)))
6546 ;; (anything 'anything-c-source-bookmark-info)
6548 (defun anything-c-bookmark-info-setup-alist ()
6549 "Specialized filter function for bookmarks info."
6550 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6552 ;; Local Files&directories
6553 (defvar anything-c-source-bookmark-files&dirs
6554 '((name . "Bookmark Files&Directories")
6555 (init . (lambda ()
6556 (require 'bookmark-extensions)
6557 (bookmark-maybe-load-default-file)))
6558 (candidates . anything-c-bookmark-local-files-setup-alist)
6559 (filtered-candidate-transformer
6560 anything-c-adaptive-sort
6561 anything-c-highlight-bookmark)
6562 (type . bookmark)))
6563 ;; (anything 'anything-c-source-bookmark-files&dirs)
6565 (defun anything-c-bookmark-local-files-setup-alist ()
6566 "Specialized filter function for bookmarks locals files."
6567 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6569 ;; Su Files&directories
6570 (defvar anything-c-source-bookmark-su-files&dirs
6571 '((name . "Bookmark Root-Files&Directories")
6572 (init . (lambda ()
6573 (require 'bookmark-extensions)
6574 (bookmark-maybe-load-default-file)))
6575 (candidates . anything-c-bookmark-su-files-setup-alist)
6576 (filtered-candidate-transformer
6577 anything-c-adaptive-sort
6578 anything-c-highlight-bookmark-su)
6579 (type . bookmark)))
6580 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6582 (defun anything-c-bookmark-su-files-setup-alist ()
6583 "Specialized filter function for bookmarks su/sudo files."
6584 (declare (special bmkext-su-or-sudo-regexp))
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 issu = (and istramp
6593 (string-match bmkext-su-or-sudo-regexp isfile))
6594 if issu
6595 collect i))
6597 ;; Ssh Files&directories
6598 (defvar anything-c-source-bookmark-ssh-files&dirs
6599 '((name . "Bookmark Ssh-Files&Directories")
6600 (init . (lambda ()
6601 (require 'bookmark-extensions)
6602 (bookmark-maybe-load-default-file)))
6603 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6604 (filtered-candidate-transformer . anything-c-adaptive-sort)
6605 (type . bookmark)))
6606 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6608 (defun anything-c-bookmark-ssh-files-setup-alist ()
6609 "Specialized filter function for bookmarks ssh files."
6610 (loop
6611 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6612 for i in l
6613 for isfile = (bookmark-get-filename i)
6614 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6615 (save-match-data
6616 (string-match tramp-file-name-regexp isfile)))
6617 for isssh = (and istramp
6618 (string-match "/ssh:" isfile))
6619 if isssh
6620 collect i))
6624 ;;; Firefox bookmarks
6627 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6628 ;; (only for firefox versions >=3)
6629 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6630 ;; to true:
6631 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6632 ;; You should have now:
6633 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6635 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6636 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6638 (defun anything-get-firefox-user-init-dir ()
6639 "Guess the default Firefox user directory name."
6640 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6641 (moz-user-dir
6642 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6643 (goto-char (point-min))
6644 (prog1
6645 (when (search-forward "Path=" nil t)
6646 (buffer-substring-no-properties (point) (point-at-eol)))
6647 (kill-buffer)))))
6648 (file-name-as-directory (concat moz-dir moz-user-dir))))
6650 (defun anything-guess-firefox-bookmark-file ()
6651 "Return the path of the Firefox bookmarks file."
6652 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6654 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6655 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6656 (let (bookmarks-alist url title)
6657 (with-temp-buffer
6658 (insert-file-contents file)
6659 (goto-char (point-min))
6660 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6661 (forward-line 0)
6662 (when (re-search-forward url-regexp nil t)
6663 (setq url (match-string 0)))
6664 (when (re-search-forward bmk-regexp nil t)
6665 (setq title (match-string 1)))
6666 (push (cons title url) bookmarks-alist)
6667 (forward-line)))
6668 (nreverse bookmarks-alist)))
6670 (defvar anything-c-firefox-bookmarks-alist nil)
6671 (defvar anything-c-source-firefox-bookmarks
6672 '((name . "Firefox Bookmarks")
6673 (init . (lambda ()
6674 (setq anything-c-firefox-bookmarks-alist
6675 (anything-html-bookmarks-to-alist
6676 (anything-guess-firefox-bookmark-file)
6677 anything-firefox-bookmark-url-regexp
6678 anything-firefox-bookmarks-regexp))))
6679 (candidates . (lambda ()
6680 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6681 (filtered-candidate-transformer
6682 anything-c-adaptive-sort
6683 anything-c-highlight-firefox-bookmarks)
6684 (action . (("Browse Url Firefox"
6685 . (lambda (candidate)
6686 (browse-url-firefox
6687 (anything-c-firefox-bookmarks-get-value candidate))))
6688 ("Browse Url w3m"
6689 . (lambda (candidate)
6690 (w3m-browse-url
6691 (anything-c-firefox-bookmarks-get-value candidate))))
6692 ("Copy Url"
6693 . (lambda (elm)
6694 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6696 ;; (anything 'anything-c-source-firefox-bookmarks)
6698 (defun anything-c-firefox-bookmarks-get-value (elm)
6699 (assoc-default elm anything-c-firefox-bookmarks-alist))
6701 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6702 (loop for i in bookmarks
6703 collect (propertize
6704 i 'face '((:foreground "YellowGreen"))
6705 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6709 ;;; W3m bookmark - anything interface.
6712 ;; Some users have the emacs-w3m library in load-path
6713 ;; without having the w3m executable :-;
6714 ;; So check if w3m program is present before trying to load
6715 ;; emacs-w3m.
6716 (eval-when-compile
6717 (when (executable-find "w3m")
6718 (require 'w3m-bookmark nil t)))
6720 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6721 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6722 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6723 (defvar anything-c-w3m-bookmarks-alist nil)
6724 (defvar anything-c-source-w3m-bookmarks
6725 '((name . "W3m Bookmarks")
6726 (init . (lambda ()
6727 (setq anything-c-w3m-bookmarks-alist
6728 (anything-html-bookmarks-to-alist
6729 w3m-bookmark-file
6730 anything-w3m-bookmark-url-regexp
6731 anything-w3m-bookmarks-regexp))))
6732 (candidates . (lambda ()
6733 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6734 (filtered-candidate-transformer
6735 anything-c-adaptive-sort
6736 anything-c-highlight-w3m-bookmarks)
6737 (action . (("Browse Url"
6738 . (lambda (candidate)
6739 (anything-c-w3m-browse-bookmark candidate)))
6740 ("Copy Url"
6741 . (lambda (elm)
6742 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6743 ("Browse Url Firefox"
6744 . (lambda (candidate)
6745 (anything-c-w3m-browse-bookmark candidate t)))
6746 ("Delete Bookmark"
6747 . (lambda (candidate)
6748 (anything-c-w3m-delete-bookmark candidate)))
6749 ("Rename Bookmark"
6750 . (lambda (candidate)
6751 (anything-c-w3m-rename-bookmark candidate)))))
6752 (persistent-action . (lambda (candidate)
6753 (if current-prefix-arg
6754 (anything-c-w3m-browse-bookmark candidate t)
6755 (anything-c-w3m-browse-bookmark candidate nil t))))
6756 (persistent-help . "Open URL with emacs-w3m in new tab / \
6757 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6758 "Needs w3m and emacs-w3m.
6760 http://w3m.sourceforge.net/
6761 http://emacs-w3m.namazu.org/")
6763 ;; (anything 'anything-c-source-w3m-bookmarks)
6765 (defun anything-c-w3m-bookmarks-get-value (elm)
6766 (replace-regexp-in-string
6767 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6769 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6770 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6771 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6772 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6774 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6775 (loop for i in bookmarks
6776 collect (propertize
6777 i 'face 'anything-w3m-bookmarks-face
6778 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6781 (defun anything-c-w3m-delete-bookmark (elm)
6782 "Delete w3m bookmark from `w3m-bookmark-file'."
6783 (with-current-buffer
6784 (find-file-literally w3m-bookmark-file)
6785 (goto-char (point-min))
6786 (when (re-search-forward elm nil t)
6787 (beginning-of-line)
6788 (delete-region (point)
6789 (line-end-position))
6790 (delete-blank-lines))
6791 (save-buffer)
6792 (kill-buffer)))
6794 (defun anything-c-w3m-rename-bookmark (elm)
6795 "Rename w3m bookmark in `w3m-bookmark-file'."
6796 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6797 (new-title (read-string "NewTitle: " old-title)))
6798 (with-current-buffer
6799 (find-file-literally w3m-bookmark-file)
6800 (goto-char (point-min))
6801 (when (re-search-forward (concat elm "<") nil t)
6802 (goto-char (1- (point)))
6803 (delete-char (- (length old-title)))
6804 (insert new-title))
6805 (save-buffer)
6806 (kill-buffer))))
6809 ;;;; <Library>
6810 ;;; Elisp library scan
6813 (defvar anything-c-source-elisp-library-scan
6814 '((name . "Elisp libraries (Scan)")
6815 (init . (anything-c-elisp-library-scan-init))
6816 (candidates-in-buffer)
6817 (action ("Find library"
6818 . (lambda (candidate) (find-file (find-library-name candidate))))
6819 ("Find library other window"
6820 . (lambda (candidate)
6821 (find-file-other-window (find-library-name candidate))))
6822 ("Load library"
6823 . (lambda (candidate) (load-library candidate))))))
6824 ;; (anything 'anything-c-source-elisp-library-scan)
6826 (defun anything-c-elisp-library-scan-init ()
6827 "Init anything buffer status."
6828 (let ((anything-buffer (anything-candidate-buffer 'global))
6829 (library-list (anything-c-elisp-library-scan-list)))
6830 (with-current-buffer anything-buffer
6831 (dolist (library library-list)
6832 (insert (format "%s\n" library))))))
6834 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6835 "Do completion for file names passed to `locate-file'.
6836 DIRS is directory to search path.
6837 STRING is string to match."
6838 ;; Use `load-path' as path when ignore `dirs'.
6839 (or dirs (setq dirs load-path))
6840 ;; Init with blank when ignore `string'.
6841 (or string (setq string ""))
6842 ;; Get library list.
6843 (let ((string-dir (file-name-directory string))
6844 ;; File regexp that suffix match `load-file-rep-suffixes'.
6845 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6846 name
6847 names)
6848 (dolist (dir dirs)
6849 (unless dir
6850 (setq dir default-directory))
6851 (if string-dir
6852 (setq dir (expand-file-name string-dir dir)))
6853 (when (file-directory-p dir)
6854 (dolist (file (file-name-all-completions
6855 (file-name-nondirectory string) dir))
6856 ;; Suffixes match `load-file-rep-suffixes'.
6857 (setq name (if string-dir (concat string-dir file) file))
6858 (if (string-match match-regexp name)
6859 (add-to-list 'names name)))))
6860 names))
6863 ;;;; <Programming>
6867 ;;; Imenu
6870 (defvar anything-c-imenu-delimiter " / ")
6872 (defvar anything-c-imenu-index-filter nil)
6873 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6875 (defvar anything-c-cached-imenu-alist nil)
6876 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6878 (defvar anything-c-cached-imenu-candidates nil)
6879 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6881 (defvar anything-c-cached-imenu-tick nil)
6882 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6884 (eval-when-compile (require 'imenu))
6885 (setq imenu-auto-rescan t)
6887 (defun anything-imenu-create-candidates (entry)
6888 "Create candidates with ENTRY."
6889 (if (listp (cdr entry))
6890 (mapcan
6891 (lambda (sub)
6892 (if (consp (cdr sub))
6893 (mapcar
6894 (lambda (subentry)
6895 (concat (car entry) anything-c-imenu-delimiter subentry))
6896 (anything-imenu-create-candidates sub))
6897 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6898 (cdr entry))
6899 (list entry)))
6901 (defvar anything-c-source-imenu
6902 '((name . "Imenu")
6903 (init . (lambda () (require 'imenu)))
6904 (candidates . anything-c-imenu-candidates)
6905 (persistent-action . (lambda (elm)
6906 (anything-c-imenu-default-action elm)
6907 (unless (fboundp 'semantic-imenu-tag-overlay)
6908 (anything-match-line-color-current-line))))
6909 (persistent-help . "Show this entry")
6910 (action . anything-c-imenu-default-action))
6911 "See (info \"(emacs)Imenu\")")
6913 ;; (anything 'anything-c-source-imenu)
6915 (defun anything-c-imenu-candidates ()
6916 (with-anything-current-buffer
6917 (let ((tick (buffer-modified-tick)))
6918 (if (eq anything-c-cached-imenu-tick tick)
6919 anything-c-cached-imenu-candidates
6920 (setq imenu--index-alist nil)
6921 (setq anything-c-cached-imenu-tick tick
6922 anything-c-cached-imenu-candidates
6923 (ignore-errors
6924 (mapcan
6925 'anything-imenu-create-candidates
6926 (setq anything-c-cached-imenu-alist
6927 (let ((index (imenu--make-index-alist)))
6928 (if anything-c-imenu-index-filter
6929 (funcall anything-c-imenu-index-filter index)
6930 index))))))
6931 (setq anything-c-cached-imenu-candidates
6932 (mapcar #'(lambda (x)
6933 (if (stringp x)
6935 (car x)))
6936 anything-c-cached-imenu-candidates))))))
6938 (setq imenu-default-goto-function 'imenu-default-goto-function)
6939 (defun anything-c-imenu-default-action (elm)
6940 "The default action for `anything-c-source-imenu'."
6941 (let ((path (split-string elm anything-c-imenu-delimiter))
6942 (alist anything-c-cached-imenu-alist))
6943 (dolist (elm path)
6944 (setq alist (assoc elm alist)))
6945 (imenu alist)))
6949 ;;; Ctags
6952 (defvar anything-c-ctags-modes
6953 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6954 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6955 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6957 (defun anything-c-source-ctags-init ()
6958 (when (and buffer-file-name
6959 (memq major-mode anything-c-ctags-modes)
6960 (anything-current-buffer-is-modified))
6961 (with-current-buffer (anything-candidate-buffer 'local)
6962 (call-process-shell-command
6963 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6964 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6965 anything-buffer-file-name)
6966 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6967 nil (current-buffer))
6968 (goto-char (point-min))
6969 (forward-line 2)
6970 (delete-region (point-min) (point))
6971 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6972 for lineno-start = (point)
6973 for lineno = (buffer-substring
6974 lineno-start
6975 (1- (search-forward "," (point-at-eol) t)))
6977 (beginning-of-line)
6978 (insert (format "%5s:" lineno))
6979 (search-forward "\177" (point-at-eol) t)
6980 (delete-region (1- (point)) (point-at-eol))
6981 (forward-line 1)))))
6983 (defvar anything-c-source-ctags
6984 '((name . "Exuberant ctags")
6985 (init . anything-c-source-ctags-init)
6986 (candidates-in-buffer)
6987 (adjust)
6988 (type . line))
6989 "Needs Exuberant Ctags.
6991 http://ctags.sourceforge.net/")
6992 ;; (anything 'anything-c-source-ctags)
6995 ;;; Etags
6998 ;; anything-etags.el is deprecated, if this file is found,
6999 ;; warn user at compile time.
7000 (eval-when-compile
7001 (when (locate-library "anything-etags.el")
7002 (display-warning
7003 '(anything-config)
7004 "You are using obsolete library `anything-etags.el' and should remove it."
7005 :warning)))
7007 (defvar anything-c-etags-tag-file-dir nil
7008 "Etags file directory.")
7009 (defvar anything-c-etags-mtime-alist nil
7010 "Store the last modification time of etags files here.")
7011 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
7012 "Cache content of etags files used here for faster access.")
7014 (defun anything-c-etags-get-tag-file (&optional directory)
7015 "Return the path of etags file if found."
7016 ;; Get tag file from `default-directory' or upper directory.
7017 (let ((current-dir (anything-c-etags-find-tag-file-directory
7018 (or directory default-directory))))
7019 ;; Return nil if not find tag file.
7020 (when current-dir
7021 ;; Set tag file directory.
7022 (setq anything-c-etags-tag-file-dir current-dir)
7023 (expand-file-name anything-c-etags-tag-file-name current-dir))))
7025 (defun anything-c-etags-find-tag-file-directory (current-dir)
7026 "Try to find the directory containing tag file.
7027 If not found in CURRENT-DIR search in upper directory."
7028 (flet ((file-exists? (dir)
7029 (let ((tag-path (expand-file-name
7030 anything-c-etags-tag-file-name dir)))
7031 (and (stringp tag-path)
7032 (file-exists-p tag-path)
7033 (file-readable-p tag-path)))))
7034 (loop with count = 0
7035 until (file-exists? current-dir)
7036 ;; Return nil if outside the value of
7037 ;; `anything-c-etags-tag-file-search-limit'.
7038 if (= count anything-c-etags-tag-file-search-limit)
7039 do (return nil)
7040 ;; Or search upper directories.
7041 else
7042 do (incf count)
7043 (setq current-dir (expand-file-name (concat current-dir "../")))
7044 finally return current-dir)))
7046 (defun anything-c-source-etags-header-name (x)
7047 "Create header name for this anything etags session."
7048 (concat "Etags in "
7049 (with-anything-current-buffer
7050 (anything-c-etags-get-tag-file))))
7052 (defmacro anything-c-etags-create-buffer (file)
7053 "Create the `anything-buffer' based on contents of etags tag FILE."
7054 `(let* ((tag-fname ,file)
7056 (split (with-current-buffer (find-file-noselect tag-fname)
7057 (prog1
7058 (split-string (buffer-string) "\n" 'omit-nulls)
7059 (setq max (line-number-at-pos (point-max)))
7060 (kill-buffer))))
7061 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7062 (loop
7063 with fname
7064 with cand
7065 for i in split for count from 0
7066 for elm = (unless (string-match "^\x0c" i)
7067 (anything-aif (string-match "\177" i)
7068 (substring i 0 it)
7070 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7071 (setq fname (match-string 1 elm)))
7072 (elm (setq cand (concat fname ": " elm)))
7073 (t (setq cand nil)))
7074 when cand do (progn
7075 (insert (concat cand "\n"))
7076 (progress-reporter-update progress-reporter count)))))
7078 (defun anything-c-etags-init ()
7079 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7080 If no entry in cache, create one."
7081 (let ((tagfile (anything-c-etags-get-tag-file)))
7082 (when tagfile
7083 (with-current-buffer (anything-candidate-buffer 'global)
7084 (anything-aif (gethash tagfile anything-c-etags-cache)
7085 ;; An entry is present in cache, insert it.
7086 (insert it)
7087 ;; No entry, create a new buffer using content of tag file (slower).
7088 (anything-c-etags-create-buffer tagfile)
7089 ;; Store content of buffer in cache.
7090 (puthash tagfile (buffer-string) anything-c-etags-cache)
7091 ;; Store or set the last modification of tag file.
7092 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7093 ;; If an entry exists modify it.
7094 (setcdr it (anything-c-etags-mtime tagfile))
7095 ;; No entry create a new one.
7096 (add-to-list 'anything-c-etags-mtime-alist
7097 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7099 (defvar anything-c-source-etags-select
7100 '((name . "Etags")
7101 (header-name . anything-c-source-etags-header-name)
7102 (init . anything-c-etags-init)
7103 (candidates-in-buffer)
7104 (search . (anything-c-etags-search-fn))
7105 (mode-line . anything-etags-mode-line-string)
7106 (action . anything-c-etags-default-action)
7107 (persistent-action . (lambda (candidate)
7108 (anything-c-etags-default-action candidate)
7109 (anything-match-line-color-current-line))))
7110 "Anything source for Etags.")
7112 (defun anything-c-etags-search-fn (pattern)
7113 "Search function for `anything-c-source-etags-select'."
7114 (re-search-forward
7115 (if anything-c-etags-use-regexp-search
7116 (format anything-c-etags-search-regexp pattern)
7117 pattern)
7118 nil t))
7120 (defun anything-c-etags-default-action (candidate)
7121 "Anything default action to jump to an etags entry."
7122 (let* ((split (split-string candidate ": "))
7123 (fname (expand-file-name
7124 (car split) anything-c-etags-tag-file-dir))
7125 (elm (cadr split)))
7126 (find-file fname)
7127 (goto-char (point-min))
7128 (search-forward elm nil t)
7129 (goto-char (match-beginning 0))))
7131 (defun anything-c-etags-mtime (file)
7132 "Last modification time of etags tag FILE."
7133 (cadr (nth 5 (file-attributes file))))
7135 (defun anything-c-etags-file-modified-p (file)
7136 "Check if tag FILE have been modified in this session.
7137 If FILE is nil return nil."
7138 (let ((last-modif (and file
7139 (assoc-default file anything-c-etags-mtime-alist))))
7140 (and last-modif
7141 (/= last-modif (anything-c-etags-mtime file)))))
7145 ;;; Semantic
7148 (defvar anything-semantic-candidates nil)
7150 (defun anything-semantic-construct-candidates (tags depth)
7151 (when (require 'semantic nil t)
7152 (apply
7153 'append
7154 (mapcar
7155 (lambda (tag)
7156 (if (listp tag)
7157 (let ((type (semantic-tag-type tag))
7158 (class (semantic-tag-class tag)))
7159 (if (or (and (stringp type)
7160 (or (string= type "class")
7161 (string= type "namespace")))
7162 (eq class 'function)
7163 (eq class 'variable))
7164 (cons (cons (concat (make-string (* depth 2) ?\s)
7165 (semantic-format-tag-summarize tag nil t))
7166 tag)
7167 (anything-semantic-construct-candidates
7168 (semantic-tag-components tag) (1+ depth)))))))
7169 tags))))
7171 (defun anything-semantic-default-action (candidate)
7172 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7173 (semantic-go-to-tag tag)))
7175 (defvar anything-c-source-semantic
7176 '((name . "Semantic Tags")
7177 (init . (lambda ()
7178 (setq anything-semantic-candidates
7179 (ignore-errors (anything-semantic-construct-candidates
7180 (semantic-fetch-tags) 0)))))
7181 (candidates . (lambda ()
7182 (if anything-semantic-candidates
7183 (mapcar 'car anything-semantic-candidates))))
7184 (persistent-action . (lambda (elm)
7185 (anything-semantic-default-action elm)
7186 (anything-match-line-color-current-line)))
7187 (persistent-help . "Show this entry")
7188 (action . anything-semantic-default-action)
7189 "Needs semantic in CEDET.
7191 http://cedet.sourceforge.net/semantic.shtml
7192 http://cedet.sourceforge.net/"))
7194 ;; (anything 'anything-c-source-semantic)
7197 ;;; Anything interface of `simple-call-tree.el'.
7199 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7201 ;; Function is called by
7202 (defvar anything-c-source-simple-call-tree-functions-callers
7203 '((name . "Function is called by")
7204 (init . anything-c-simple-call-tree-functions-callers-init)
7205 (multiline)
7206 (candidates . anything-c-simple-call-tree-candidates)
7207 (persistent-action . anything-c-simple-call-tree-persistent-action)
7208 (persistent-help . "Show function definitions by rotation")
7209 (action ("Find definition selected by persistent-action" .
7210 anything-c-simple-call-tree-find-definition)))
7211 "Needs simple-call-tree.el.
7212 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7214 (defvar anything-c-simple-call-tree-tick nil)
7215 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7216 (defun anything-c-simple-call-tree-analyze-maybe ()
7217 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7218 (simple-call-tree-analyze)
7219 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7221 (defun anything-c-simple-call-tree-init-base (function message)
7222 (require 'simple-call-tree)
7223 (with-no-warnings
7224 (when (anything-current-buffer-is-modified)
7225 (anything-c-simple-call-tree-analyze-maybe)
7226 (let ((list (funcall function simple-call-tree-alist)))
7227 (with-current-buffer (anything-candidate-buffer 'local)
7228 (dolist (entry list)
7229 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7230 (insert (car entry) message
7231 (if (string= funcs " ")
7232 " no functions."
7233 funcs)
7234 "\n\n"))))))))
7236 (defun anything-c-simple-call-tree-functions-callers-init ()
7237 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7238 " is called by\n"))
7240 (defun anything-c-simple-call-tree-candidates ()
7241 (with-current-buffer (anything-candidate-buffer)
7242 (split-string (buffer-string) "\n\n")))
7244 (defvar anything-c-simple-call-tree-related-functions nil)
7245 (defvar anything-c-simple-call-tree-function-index 0)
7246 (defun anything-c-simple-call-tree-persistent-action (candidate)
7247 (unless (eq last-command 'anything-execute-persistent-action)
7248 (setq anything-c-simple-call-tree-related-functions
7249 (delete "no functions."
7250 (split-string
7251 (replace-regexp-in-string " \\| is called by\\| calls "
7252 "" candidate)
7253 "\n")))
7254 (setq anything-c-simple-call-tree-function-index -1))
7255 (incf anything-c-simple-call-tree-function-index)
7256 (anything-c-simple-call-tree-find-definition candidate))
7258 (defun anything-c-simple-call-tree-find-definition (candidate)
7259 (find-function
7260 (intern
7261 (nth (mod anything-c-simple-call-tree-function-index
7262 (length anything-c-simple-call-tree-related-functions))
7263 anything-c-simple-call-tree-related-functions))))
7265 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7267 ;;; Function calls
7268 (defvar anything-c-source-simple-call-tree-callers-functions
7269 '((name . "Function calls")
7270 (init . anything-c-simple-call-tree-callers-functions-init)
7271 (multiline)
7272 (candidates . anything-c-simple-call-tree-candidates)
7273 (persistent-action . anything-c-simple-call-tree-persistent-action)
7274 (persistent-help . "Show function definitions by rotation")
7275 (action ("Find definition selected by persistent-action" .
7276 anything-c-simple-call-tree-find-definition)))
7277 "Needs simple-call-tree.el.
7278 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7280 (defun anything-c-simple-call-tree-callers-functions-init ()
7281 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7283 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7287 ;;; Anything UI of auto-document.el
7289 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7291 ;; Commands/Options with doc
7292 (defvar anything-c-auto-document-data nil)
7293 (make-variable-buffer-local 'anything-c-auto-document-data)
7294 (defvar anything-c-source-commands-and-options-in-file
7295 '((name . "Commands/Options in file")
7296 (header-name
7297 . (lambda (x) (format "Commands/Options in %s"
7298 (buffer-local-value 'buffer-file-name
7299 anything-current-buffer))))
7300 (candidates . anything-command-and-options-candidates)
7301 (multiline)
7302 (action . imenu))
7303 "List Commands and Options with doc. It needs auto-document.el .
7305 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7307 (eval-when-compile (require 'auto-document nil t))
7308 (defun anything-command-and-options-candidates ()
7309 (with-anything-current-buffer
7310 (when (and (require 'auto-document nil t)
7311 (eq major-mode 'emacs-lisp-mode)
7312 (or (anything-current-buffer-is-modified)
7313 (not anything-c-auto-document-data)))
7314 (or imenu--index-alist (imenu--make-index-alist t))
7315 (setq anything-c-auto-document-data
7316 (destructuring-bind (commands options)
7317 (adoc-construct anything-current-buffer)
7318 (append
7319 (loop for (command . doc) in commands
7320 for cmdname = (symbol-name command)
7321 collect
7322 (cons
7323 (format "Command: %s\n %s"
7324 (propertize cmdname 'face font-lock-function-name-face)
7325 (adoc-first-line doc))
7326 (assoc cmdname imenu--index-alist)))
7327 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7328 for (option doc default) in options
7329 for optname = (symbol-name option)
7330 collect
7331 (cons
7332 (format "Option: %s\n %s\n default = %s"
7333 (propertize optname 'face font-lock-variable-name-face)
7334 (adoc-first-line doc)
7335 (adoc-prin1-to-string default))
7336 (assoc optname
7337 var-alist)))))))
7338 anything-c-auto-document-data))
7340 ;; (anything 'anything-c-source-commands-and-options-in-file)
7343 ;;;; <Color and Face>
7346 ;;; Customize Face
7349 (defvar anything-c-source-customize-face
7350 '((name . "Customize Face")
7351 (init . (lambda ()
7352 (unless (anything-candidate-buffer)
7353 (save-selected-window
7354 (list-faces-display))
7355 (anything-candidate-buffer (get-buffer "*Faces*")))))
7356 (candidates-in-buffer)
7357 (get-line . buffer-substring)
7358 (action . (lambda (line)
7359 (customize-face (intern (car (split-string line))))))
7360 (requires-pattern . 3))
7361 "See (info \"(emacs)Faces\")")
7362 ;; (anything 'anything-c-source-customize-face)
7364 ;;; Colors browser
7367 (defvar anything-c-source-colors
7368 '((name . "Colors")
7369 (init . (lambda () (unless (anything-candidate-buffer)
7370 (save-selected-window
7371 (list-colors-display))
7372 (anything-candidate-buffer (get-buffer "*Colors*")))))
7373 (candidates-in-buffer)
7374 (get-line . buffer-substring)
7375 (action
7376 ("Copy Name" . (lambda (candidate)
7377 (kill-new (anything-c-colors-get-name candidate))))
7378 ("Copy RGB" . (lambda (candidate)
7379 (kill-new (anything-c-colors-get-rgb candidate))))
7380 ("Insert Name" . (lambda (candidate)
7381 (with-anything-current-buffer
7382 (insert (anything-c-colors-get-name candidate)))))
7383 ("Insert RGB" . (lambda (candidate)
7384 (with-anything-current-buffer
7385 (insert (anything-c-colors-get-rgb candidate))))))))
7386 ;; (anything 'anything-c-source-colors)
7388 (defun anything-c-colors-get-name (candidate)
7389 "Get color name."
7390 (replace-regexp-in-string
7391 " " ""
7392 (with-temp-buffer
7393 (insert (capitalize candidate))
7394 (goto-char (point-min))
7395 (search-forward-regexp "\\s-\\{2,\\}")
7396 (delete-region (point) (point-max))
7397 (buffer-string))))
7399 (defun anything-c-colors-get-rgb (candidate)
7400 "Get color RGB."
7401 (replace-regexp-in-string
7402 " " ""
7403 (with-temp-buffer
7404 (insert (capitalize candidate))
7405 (goto-char (point-max))
7406 (search-backward-regexp "\\s-\\{2,\\}")
7407 (delete-region (point) (point-min))
7408 (buffer-string))))
7411 ;;;; <Search Engine>
7412 ;;; Tracker desktop search
7413 (defvar anything-c-source-tracker-search
7414 '((name . "Tracker Search")
7415 (candidates . (lambda ()
7416 (start-process "tracker-search-process" nil
7417 "tracker-search"
7418 anything-pattern)))
7419 (type . file)
7420 (requires-pattern . 3)
7421 (delayed))
7422 "Source for retrieving files matching the current input pattern
7423 with the tracker desktop search.")
7424 ;; (anything 'anything-c-source-tracker-search)
7426 ;;; Spotlight (MacOS X desktop search)
7427 (defvar anything-c-source-mac-spotlight
7428 '((name . "mdfind")
7429 (candidates
7430 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7431 (type . file)
7432 (requires-pattern . 3)
7433 (delayed))
7434 "Source for retrieving files via Spotlight's command line
7435 utility mdfind.")
7436 ;; (anything 'anything-c-source-mac-spotlight)
7438 ;;; Picklist
7439 (defvar anything-c-source-picklist
7440 '((name . "Picklist")
7441 (candidates . (lambda () (mapcar 'car picklist-list)))
7442 (type . file)))
7443 ;; (anything 'anything-c-source-picklist)
7447 ;;; Kill ring
7450 (defvar anything-c-source-kill-ring
7451 '((name . "Kill Ring")
7452 (init . (lambda () (anything-attrset 'last-command last-command)))
7453 (candidates . anything-c-kill-ring-candidates)
7454 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7455 (action . anything-c-kill-ring-action)
7456 (last-command)
7457 (migemo)
7458 (multiline))
7459 "Source for browse and insert contents of kill-ring.")
7461 (defun anything-c-kill-ring-candidates ()
7462 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7463 unless (or (< (length kill) anything-kill-ring-threshold)
7464 (string-match "^[\\s\\t]+$" kill))
7465 collect kill))
7467 (defun anything-c-kill-ring-transformer (candidates source)
7468 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7469 (loop for i in candidates
7470 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7471 if (and anything-c-kill-ring-max-lines-number
7472 (> nlines anything-c-kill-ring-max-lines-number))
7473 collect (cons
7474 (with-temp-buffer
7475 (insert i)
7476 (goto-char (point-min))
7477 (concat
7478 (buffer-substring
7479 (point-min)
7480 (save-excursion
7481 (forward-line anything-c-kill-ring-max-lines-number)
7482 (point)))
7483 "[...]")) i)
7484 else collect i))
7486 (defun anything-c-kill-ring-action (str)
7487 "Insert STR in `kill-ring' and set STR to the head.
7488 If this action is executed just after `yank',
7489 replace with STR as yanked string."
7490 (setq kill-ring (delete str kill-ring))
7491 (if (not (eq (anything-attr 'last-command) 'yank))
7492 (insert-for-yank str)
7493 ;; from `yank-pop'
7494 (let ((inhibit-read-only t)
7495 (before (< (point) (mark t))))
7496 (if before
7497 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7498 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7499 (setq yank-undo-function nil)
7500 (set-marker (mark-marker) (point) (current-buffer))
7501 (insert-for-yank str)
7502 ;; Set the window start back where it was in the yank command,
7503 ;; if possible.
7504 (set-window-start (selected-window) yank-window-start t)
7505 (if before
7506 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7507 ;; It is cleaner to avoid activation, even though the command
7508 ;; loop would deactivate the mark because we inserted text.
7509 (goto-char (prog1 (mark t)
7510 (set-marker (mark-marker) (point) (current-buffer)))))))
7511 (kill-new str))
7513 ;; (anything 'anything-c-source-kill-ring)
7516 ;;;; <Mark ring>
7517 ;; DO NOT include these sources in `anything-sources' use
7518 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7519 ;; `anything-all-mark-rings' instead.
7521 (defun anything-c-source-mark-ring-candidates ()
7522 (flet ((get-marks (pos)
7523 (save-excursion
7524 (goto-char pos)
7525 (beginning-of-line)
7526 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7527 (when (string= "" line)
7528 (setq line "<EMPTY LINE>"))
7529 (format "%7d: %s" (line-number-at-pos) line)))))
7530 (with-anything-current-buffer
7531 (loop
7532 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7533 with recip = nil
7534 for i in marks
7535 for m = (get-marks i)
7536 unless (member m recip)
7537 collect m into recip
7538 finally return recip))))
7540 (defvar anything-mark-ring-cache nil)
7541 (defvar anything-c-source-mark-ring
7542 '((name . "mark-ring")
7543 (init . (lambda ()
7544 (setq anything-mark-ring-cache
7545 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7546 (candidates . (lambda ()
7547 (anything-aif anything-mark-ring-cache
7548 it)))
7549 (action . (("Goto line"
7550 . (lambda (candidate)
7551 (anything-goto-line (string-to-number candidate))))))
7552 (persistent-action . (lambda (candidate)
7553 (anything-goto-line (string-to-number candidate))
7554 (anything-match-line-color-current-line)))
7555 (persistent-help . "Show this line")))
7557 ;; (anything 'anything-c-source-mark-ring)
7559 ;;; Global-mark-ring
7560 (defvar anything-c-source-global-mark-ring
7561 '((name . "global-mark-ring")
7562 (candidates . anything-c-source-global-mark-ring-candidates)
7563 (action . (("Goto line"
7564 . (lambda (candidate)
7565 (let ((items (split-string candidate ":")))
7566 (anything-c-switch-to-buffer (second items))
7567 (anything-goto-line (string-to-number (car items))))))))
7568 (persistent-action . (lambda (candidate)
7569 (let ((items (split-string candidate ":")))
7570 (anything-c-switch-to-buffer (second items))
7571 (anything-goto-line (string-to-number (car items)))
7572 (anything-match-line-color-current-line))))
7573 (persistent-help . "Show this line")))
7575 (defun anything-c-source-global-mark-ring-candidates ()
7576 (flet ((buf-fn (m)
7577 (with-current-buffer (marker-buffer m)
7578 (goto-char m)
7579 (beginning-of-line)
7580 (let (line)
7581 (if (string= "" line)
7582 (setq line "<EMPTY LINE>")
7583 (setq line (car (split-string (thing-at-point 'line)
7584 "[\n\r]"))))
7585 (format "%7d:%s: %s"
7586 (line-number-at-pos) (marker-buffer m) line)))))
7587 (loop
7588 with marks = global-mark-ring
7589 with recip = nil
7590 for i in marks
7591 for gm = (unless (or (string-match
7592 "^ " (format "%s" (marker-buffer i)))
7593 (null (marker-buffer i)))
7594 (buf-fn i))
7595 when (and gm (not (member gm recip)))
7596 collect gm into recip
7597 finally return recip)))
7599 ;; (anything 'anything-c-source-global-mark-ring)
7602 ;;;; <Register>
7603 ;;; Insert from register
7604 (defvar anything-c-source-register
7605 '((name . "Registers")
7606 (candidates . anything-c-register-candidates)
7607 (action-transformer . anything-c-register-action-transformer)
7608 (multiline)
7609 (action))
7610 "See (info \"(emacs)Registers\")")
7612 (defun anything-c-register-candidates ()
7613 "Collecting register contents and appropriate commands."
7614 (loop for (char . val) in register-alist
7615 for key = (single-key-description char)
7616 for string-actions =
7617 (cond
7618 ((numberp val)
7619 (list (int-to-string val)
7620 'insert-register
7621 'increment-register))
7622 ((markerp val)
7623 (let ((buf (marker-buffer val)))
7624 (if (null buf)
7625 (list "a marker in no buffer")
7626 (list (concat
7627 "a buffer position:"
7628 (buffer-name buf)
7629 ", position "
7630 (int-to-string (marker-position val)))
7631 'jump-to-register
7632 'insert-register))))
7633 ((and (consp val) (window-configuration-p (car val)))
7634 (list "window configuration."
7635 'jump-to-register))
7636 ((and (consp val) (frame-configuration-p (car val)))
7637 (list "frame configuration."
7638 'jump-to-register))
7639 ((and (consp val) (eq (car val) 'file))
7640 (list (concat "file:"
7641 (prin1-to-string (cdr val))
7642 ".")
7643 'jump-to-register))
7644 ((and (consp val) (eq (car val) 'file-query))
7645 (list (concat "file:a file-query reference: file "
7646 (car (cdr val))
7647 ", position "
7648 (int-to-string (car (cdr (cdr val))))
7649 ".")
7650 'jump-to-register))
7651 ((consp val)
7652 (let ((lines (format "%4d" (length val))))
7653 (list (format "%s: %s\n" lines
7654 (truncate-string-to-width
7655 (mapconcat 'identity (list (car val))
7656 ;; (mapconcat (lambda (y) y) val
7657 "^J") (- (window-width) 15)))
7658 'insert-register)))
7659 ((stringp val)
7660 (list ;; without properties
7661 (substring-no-properties val)
7662 'insert-register
7663 'append-to-register
7664 'prepend-to-register))
7666 "GARBAGE!"))
7667 collect (cons (format "register %3s: %s" key (car string-actions))
7668 (cons char (cdr string-actions)))))
7670 (defun anything-c-register-action-transformer (actions register-and-functions)
7671 "Decide actions by the contents of register."
7672 (loop with func-actions =
7673 '((insert-register
7674 "Insert Register" .
7675 (lambda (c) (insert-register (car c))))
7676 (jump-to-register
7677 "Jump to Register" .
7678 (lambda (c) (jump-to-register (car c))))
7679 (append-to-register
7680 "Append Region to Register" .
7681 (lambda (c) (append-to-register
7682 (car c) (region-beginning) (region-end))))
7683 (prepend-to-register
7684 "Prepend Region to Register" .
7685 (lambda (c) (prepend-to-register
7686 (car c) (region-beginning) (region-end))))
7687 (increment-register
7688 "Increment Prefix Arg to Register" .
7689 (lambda (c) (increment-register
7690 anything-current-prefix-arg (car c)))))
7691 for func in (cdr register-and-functions)
7692 for cell = (assq func func-actions)
7693 when cell
7694 collect (cdr cell)))
7696 ;; (anything 'anything-c-source-register)
7699 ;;; Latex completion
7700 (defun anything-c-latex-math-candidates ()
7701 "Collect candidates for latex math completion."
7702 (declare (special LaTeX-math-menu))
7703 (loop for i in (cddr LaTeX-math-menu)
7704 for elm = (loop for s in i when (vectorp s)
7705 collect (cons (aref s 0) (aref s 1)))
7706 append elm))
7708 (defvar anything-c-source-latex-math
7709 '((name . "Latex Math Menu")
7710 (init . (lambda ()
7711 (with-anything-current-buffer
7712 (LaTeX-math-mode 1))))
7713 (candidate-number-limit . 9999)
7714 (candidates . anything-c-latex-math-candidates)
7715 (action . (lambda (candidate)
7716 (call-interactively candidate)))))
7719 ;;;; <Headline Extraction>
7720 (defvar anything-c-source-fixme
7721 '((name . "TODO/FIXME/DRY comments")
7722 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7723 (adjust)
7724 (recenter))
7725 "Show TODO/FIXME/DRY comments in current file.")
7726 ;; (anything 'anything-c-source-fixme)
7728 (defvar anything-c-source-rd-headline
7729 '((name . "RD HeadLine")
7730 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7731 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7732 (migemo)
7733 (subexp . 1))
7734 "Show RD headlines.
7736 RD is Ruby's POD.
7737 http://en.wikipedia.org/wiki/Ruby_Document_format")
7738 ;; (anything 'anything-c-source-rd-headline)
7740 (defvar anything-c-source-oddmuse-headline
7741 '((name . "Oddmuse HeadLine")
7742 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7743 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7744 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7745 (migemo)
7746 (subexp . 1))
7747 "Show Oddmuse headlines, such as EmacsWiki.")
7748 ;; (anything 'anything-c-source-oddmuse-headline)
7750 (defvar anything-c-source-emacs-source-defun
7751 '((name . "Emacs Source DEFUN")
7752 (headline . "DEFUN\\|DEFVAR")
7753 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7754 (or buffer-file-name ""))))
7755 "Show DEFUN/DEFVAR in Emacs C source file.")
7756 ;; (anything 'anything-c-source-emacs-source-defun)
7758 (defvar anything-c-source-emacs-lisp-expectations
7759 '((name . "Emacs Lisp Expectations")
7760 (headline . "(desc[ ]\\|(expectations")
7761 (condition . (eq major-mode 'emacs-lisp-mode)))
7762 "Show descriptions (desc) in Emacs Lisp Expectations.
7764 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7765 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7767 (defvar anything-c-source-emacs-lisp-toplevels
7768 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7769 (headline . "^(\\|(@\\*\\|^;;;;")
7770 (get-line . buffer-substring)
7771 (condition . (eq major-mode 'emacs-lisp-mode))
7772 (adjust))
7773 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7774 linkd.el is optional because linkd stars are extracted by regexp.
7775 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7776 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7779 ;;; Anything yaoddmuse
7781 ;; Be sure to have yaoddmuse.el installed
7782 ;; install-elisp may be required if you want to install elisp file from here.
7783 (defvar anything-yaoddmuse-use-cache-file nil)
7784 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7785 (defvar anything-c-yaoddmuse-ew-cache nil)
7787 (defun anything-yaoddmuse-get-candidates ()
7788 (declare (special yaoddmuse-pages-hash))
7789 (if anything-yaoddmuse-use-cache-file
7790 (ignore-errors
7791 (unless anything-c-yaoddmuse-ew-cache
7792 (load anything-c-yaoddmuse-cache-file)
7793 (setq anything-c-yaoddmuse-ew-cache
7794 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7795 anything-c-yaoddmuse-ew-cache)
7796 (yaoddmuse-update-pagename t)
7797 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7799 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7800 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7801 (candidates . anything-yaoddmuse-get-candidates)
7802 (action . (("Edit page" . (lambda (candidate)
7803 (yaoddmuse-edit "EmacsWiki" candidate)))
7804 ("Browse page"
7805 . (lambda (candidate)
7806 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7807 ("Browse page other window"
7808 . (lambda (candidate)
7809 (if (one-window-p)
7810 (split-window-vertically))
7811 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7812 ("Browse diff"
7813 . (lambda (candidate)
7814 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7815 ("Copy URL"
7816 . (lambda (candidate)
7817 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7818 (message "Have copy page %s's URL to yank." candidate)))
7819 ("Create page"
7820 . (lambda (candidate)
7821 (yaoddmuse-edit "EmacsWiki" anything-input)))
7822 ("Update cache"
7823 . (lambda (candidate)
7824 (if anything-yaoddmuse-use-cache-file
7825 (progn
7826 (anything-yaoddmuse-cache-pages t)
7827 (setq anything-c-yaoddmuse-ew-cache
7828 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7829 (yaoddmuse-update-pagename))))))
7830 (action-transformer anything-c-yaoddmuse-action-transformer))
7831 "Needs yaoddmuse.el.
7833 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7835 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7837 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7838 '((name . "Yaoddmuse Post library (EmacsWiki)")
7839 (init . (anything-yaoddmuse-init))
7840 (candidates-in-buffer)
7841 (action . (("Post library and Browse"
7842 . (lambda (candidate)
7843 (yaoddmuse-post-file
7844 (find-library-name candidate)
7845 "EmacsWiki"
7846 (file-name-nondirectory (find-library-name candidate))
7847 nil t)))
7848 ("Post library"
7849 . (lambda (candidate)
7850 (yaoddmuse-post-file
7851 (find-library-name candidate)
7852 "EmacsWiki"
7853 (file-name-nondirectory
7854 (find-library-name candidate))))))))
7855 "Needs yaoddmuse.el.
7857 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7859 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7861 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7862 "Allow the use of `install-elisp' only on elisp files."
7863 (if (string-match "\.el$" candidate)
7864 (append actions '(("Install Elisp"
7865 . (lambda (elm)
7866 (install-elisp-from-emacswiki elm)))))
7867 actions))
7869 ;;;###autoload
7870 (defun anything-yaoddmuse-cache-pages (&optional load)
7871 "Fetch the list of files on emacswiki and create cache file.
7872 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7873 (interactive)
7874 (declare (special yaoddmuse-pages-hash))
7875 (yaoddmuse-update-pagename)
7876 (save-excursion
7877 (find-file anything-c-yaoddmuse-cache-file)
7878 (erase-buffer)
7879 (insert "(puthash \"EmacsWiki\" '(")
7880 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7882 (insert (concat "(\"" (car i) "\") ")))
7883 (insert ") yaoddmuse-pages-hash)\n")
7884 (save-buffer)
7885 (kill-buffer (current-buffer))
7886 (when (or current-prefix-arg
7887 load)
7888 (load anything-c-yaoddmuse-cache-file))))
7890 (defun anything-yaoddmuse-init ()
7891 "Init anything buffer status."
7892 (let ((anything-buffer (anything-candidate-buffer 'global))
7893 (library-list (yaoddmuse-get-library-list)))
7894 (with-current-buffer anything-buffer
7895 ;; Insert library name.
7896 (dolist (library library-list)
7897 (insert (format "%s\n" library)))
7898 ;; Sort lines.
7899 (sort-lines nil (point-min) (point-max)))))
7902 ;;; Eev anchors
7903 (defvar anything-c-source-eev-anchor
7904 '((name . "Anchors")
7905 (candidates
7906 . (lambda ()
7907 (ignore-errors
7908 (with-anything-current-buffer
7909 (loop initially (goto-char (point-min))
7910 while (re-search-forward
7911 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7912 for anchor = (match-string-no-properties 1)
7913 collect (cons (format "%5d:%s"
7914 (line-number-at-pos (match-beginning 0))
7915 (format ee-anchor-format anchor))
7916 anchor))))))
7917 (persistent-action . (lambda (item)
7918 (ee-to item)
7919 (anything-match-line-color-current-line)))
7920 (persistent-help . "Show this entry")
7921 (action . (("Goto link" . ee-to)))))
7922 ;; (anything 'anything-c-source-eev-anchor)
7925 ;;; Org headlines
7928 (defvar anything-c-source-org-headline
7929 `((name . "Org HeadLine")
7930 (headline
7931 ,@(mapcar
7932 (lambda (num)
7933 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7934 num))
7935 (number-sequence 1 8)))
7936 (condition . (eq major-mode 'org-mode))
7937 (migemo)
7938 (subexp . 1)
7939 (persistent-action . (lambda (elm)
7940 (anything-c-action-line-goto elm)
7941 (org-cycle)))
7942 (action-transformer
7943 . (lambda (actions candidate)
7944 '(("Go to Line" . anything-c-action-line-goto)
7945 ("Refile to this Headline" . anything-c-org-headline-refile)
7946 ("Insert Link to This Headline"
7947 . anything-c-org-headline-insert-link-to-headline)))))
7948 "Show Org headlines.
7949 org-mode is very very much extended text-mode/outline-mode.
7951 See (find-library \"org.el\")
7952 See http://orgmode.org for the latest version.")
7953 ;; (anything 'anything-c-source-org-headline)
7955 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7956 (insert
7957 (save-excursion
7958 (anything-goto-line (car lineno-and-content))
7959 (and (looking-at org-complex-heading-regexp)
7960 (org-make-link-string (concat "*" (match-string 4)))))))
7962 (defun anything-c-org-headline-refile (lineno-and-content)
7963 "Refile current org entry to LINENO-AND-CONTENT."
7964 (with-anything-current-buffer
7965 (org-cut-subtree)
7966 (anything-goto-line (car lineno-and-content))
7967 (org-end-of-subtree t t)
7968 (let ((org-yank-adjusted-subtrees t))
7969 (org-yank))))
7972 ;;; Org keywords
7975 (defvar anything-c-source-org-keywords
7976 '((name . "Org Keywords")
7977 (init . anything-c-org-keywords-init)
7978 (candidates . anything-c-org-keywords-candidates)
7979 (action . anything-c-org-keywords-insert)
7980 (persistent-action . anything-c-org-keywords-show-help)
7981 (persistent-help . "Show an example and info page to describe this keyword.")
7982 (keywords-examples)
7983 (keywords)))
7984 ;; (anything 'anything-c-source-org-keywords)
7986 (defvar anything-c-org-keywords-info-location
7987 '(("#+TITLE:" . "(org)Export options")
7988 ("#+AUTHOR:" . "(org)Export options")
7989 ("#+DATE:" . "(org)Export options")
7990 ("#+EMAIL:" . "(org)Export options")
7991 ("#+DESCRIPTION:" . "(org)Export options")
7992 ("#+KEYWORDS:" . "(org)Export options")
7993 ("#+LANGUAGE:" . "(org)Export options")
7994 ("#+TEXT:" . "(org)Export options")
7995 ("#+TEXT:" . "(org)Export options")
7996 ("#+OPTIONS:" . "(org)Export options")
7997 ("#+BIND:" . "(org)Export options")
7998 ("#+LINK_UP:" . "(org)Export options")
7999 ("#+LINK_HOME:" . "(org)Export options")
8000 ("#+LATEX_HEADER:" . "(org)Export options")
8001 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
8002 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
8003 ("#+INFOJS_OPT" . "(org)Javascript support")
8004 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
8005 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
8006 ("#+ORGTBL" . "(org)Radio tables")
8007 ("#+HTML:" . "(org)Quoting HTML tags")
8008 ("#+LaTeX:" . "(org)Quoting LaTeX code")
8009 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
8010 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
8011 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
8012 ("#+BEGIN_VERSE" . "(org)Paragraphs")
8013 ("#+BEGIN_SRC" . "(org)Literal examples")
8014 ("#+CAPTION" . "(org)Tables in HTML export")
8015 ("#+LABEL" . "(org)Tables in LaTeX export")
8016 ("#+ATTR_HTML" . "(org)Links")
8017 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
8019 (defun anything-c-org-keywords-init ()
8020 (unless (anything-attr 'keywords-examples)
8021 (require 'org)
8022 (anything-attrset 'keywords-examples
8023 (append
8024 (mapcar
8025 (lambda (x)
8026 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8027 (cons (match-string 2 x) (match-string 1 x)))
8028 (org-split-string (org-get-current-options) "\n"))
8029 (mapcar 'list org-additional-option-like-keywords)))
8030 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
8032 (defun anything-c-org-keywords-candidates ()
8033 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
8034 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
8035 (anything-attr 'keywords)))
8037 (defun anything-c-org-keywords-insert (keyword)
8038 (cond ((and (string-match "BEGIN" keyword)
8039 (anything-region-active-p))
8040 (let ((beg (region-beginning))
8041 (end (region-end)))
8042 (goto-char end)
8043 (insert "\n#+" (replace-regexp-in-string
8044 "BEGIN" "END" keyword) "\n")
8045 (goto-char beg)
8046 (insert "#+" keyword " ")
8047 (save-excursion (insert "\n"))))
8048 ((string-match "BEGIN" keyword)
8049 (insert "#+" keyword " ")
8050 (save-excursion
8051 (insert "\n#+" (replace-regexp-in-string
8052 "BEGIN" "END" keyword) "\n")))
8053 (t (insert "#+" keyword " "))))
8055 (defun anything-c-org-keywords-show-help (keyword)
8056 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
8057 "(org)In-buffer settings"))
8058 (search-forward (concat "#+" keyword) nil t)
8059 (anything-persistent-highlight-point)
8060 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8064 ;;; bbdb
8067 (defvar bbdb-records)
8068 (defvar bbdb-buffer-name)
8070 (defun anything-c-bbdb-candidates ()
8071 "Return a list of all names in the bbdb database. The format
8072 is \"Firstname Lastname\"."
8073 (mapcar (lambda (bbdb-record)
8074 (replace-regexp-in-string
8075 "\\s-+$" ""
8076 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8077 (bbdb-records)))
8079 (defun anything-c-bbdb-create-contact (actions candidate)
8080 "Action transformer that returns only an entry to add the
8081 current `anything-pattern' as new contact. All other actions are
8082 removed."
8083 (if (string= candidate "*Add to contacts*")
8084 '(("Add to contacts" . (lambda (actions)
8085 (bbdb-create-internal
8086 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8087 (read-from-minibuffer "Company: ")
8088 (read-from-minibuffer "Email: ")
8091 (read-from-minibuffer "Note: ")))))
8092 actions))
8094 (defun anything-c-bbdb-get-record (candidate)
8095 "Return record that match CANDIDATE."
8096 (bbdb candidate nil)
8097 (set-buffer "*BBDB*")
8098 (bbdb-current-record))
8100 (defvar anything-c-bbdb-name nil
8101 "Only for internal use.")
8103 (defvar anything-c-source-bbdb
8104 '((name . "BBDB")
8105 (candidates . anything-c-bbdb-candidates)
8106 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8107 ("View person's data" . anything-c-bbdb-view-person-action))
8108 (filtered-candidate-transformer . (lambda (candidates source)
8109 (setq anything-c-bbdb-name anything-pattern)
8110 (if (not candidates)
8111 (list "*Add to contacts*")
8112 candidates)))
8113 (action-transformer . (lambda (actions candidate)
8114 (anything-c-bbdb-create-contact actions candidate))))
8115 "Needs BBDB.
8117 http://bbdb.sourceforge.net/")
8118 ;; (anything 'anything-c-source-bbdb)
8120 (defun anything-c-bbdb-view-person-action (candidate)
8121 "View BBDB data of single CANDIDATE or marked candidates."
8122 (anything-aif (anything-marked-candidates)
8123 (let ((bbdb-append-records (length it)))
8124 (dolist (i it)
8125 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8126 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8128 (defun anything-c-bbdb-collect-mail-addresses ()
8129 "Return a list of all mail addresses of records in bbdb buffer."
8130 (with-current-buffer bbdb-buffer-name
8131 (loop for i in bbdb-records
8132 if (bbdb-record-net (car i))
8133 collect (bbdb-dwim-net-address (car i)))))
8135 (defun anything-c-bbdb-compose-mail (candidate)
8136 "Compose a mail with all records of bbdb buffer."
8137 (anything-c-bbdb-view-person-action candidate)
8138 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8139 (address-str (mapconcat 'identity address-list ",\n ")))
8140 (compose-mail address-str)))
8143 ;;; Evaluation Result
8146 ;; Internal
8147 (defvar anything-eldoc-active-minibuffers-list nil)
8148 (defvar anything-eval-expression-input-history nil)
8150 (defvar anything-c-source-evaluation-result
8151 '((name . "Evaluation Result")
8152 (disable-shortcuts)
8153 (dummy)
8154 (multiline)
8155 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8156 (filtered-candidate-transformer . (lambda (candidates source)
8157 (list
8158 (condition-case nil
8159 (with-anything-current-buffer
8160 (pp-to-string
8161 (eval (read anything-pattern))))
8162 (error "Error")))))
8163 (action . (("Copy result to kill-ring" . (lambda (candidate)
8164 (with-current-buffer anything-buffer
8165 (let ((end (save-excursion
8166 (goto-char (point-max))
8167 (search-backward "\n")
8168 (point))))
8169 (kill-region (point) end)))))
8170 ("copy sexp to kill-ring" . (lambda (candidate)
8171 (kill-new anything-input)))))))
8172 ;; (anything 'anything-c-source-evaluation-result)
8174 (defun anything-eval-new-line-and-indent ()
8175 (interactive)
8176 (newline) (lisp-indent-line))
8178 (defun anything-eldoc-store-minibuffer ()
8179 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8180 (with-selected-window (minibuffer-window)
8181 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8183 (defun anything-eldoc-show-in-eval ()
8184 "Return eldoc in mode-line for current minibuffer input."
8185 (let ((buf (with-selected-window (minibuffer-window)
8186 (buffer-name))))
8187 (when (member buf anything-eldoc-active-minibuffers-list)
8188 (let* ((str-all (with-current-buffer buf
8189 (minibuffer-completion-contents)))
8190 (sym (when str-all
8191 (with-temp-buffer
8192 (insert str-all)
8193 (goto-char (point-max))
8194 (unless (looking-back ")\\|\"") (forward-char -1))
8195 (eldoc-current-symbol))))
8196 (info-fn (eldoc-fnsym-in-current-sexp))
8197 (doc (or (eldoc-get-var-docstring sym)
8198 (eldoc-get-fnsym-args-string
8199 (car info-fn) (cadr info-fn)))))
8200 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8202 (defun anything-c-show-info-in-mode-line (str)
8203 "Display string STR in mode-line."
8204 (save-selected-window
8205 (with-current-buffer anything-buffer
8206 (let ((mode-line-format (concat " " str)))
8207 (force-mode-line-update)
8208 (sit-for anything-c-show-info-in-mode-line-delay))
8209 (force-mode-line-update))))
8211 ;;; Calculation Result
8214 (defvar anything-c-source-calculation-result
8215 '((name . "Calculation Result")
8216 (dummy)
8217 (filtered-candidate-transformer . (lambda (candidates source)
8218 (list
8219 (condition-case nil
8220 (calc-eval anything-pattern)
8221 (error "error")))))
8222 (action ("Copy result to kill-ring" . kill-new))))
8223 ;; (anything 'anything-c-source-calculation-result)
8226 ;;; Google Suggestions
8229 ;; Internal
8230 (defvar anything-ggs-max-length-real-flag 0)
8231 (defvar anything-ggs-max-length-num-flag 0)
8233 (defun anything-c-google-suggest-fetch (input)
8234 "Fetch suggestions for INPUT from XML buffer.
8235 Return an alist with elements like (data . number_results)."
8236 (setq anything-ggs-max-length-real-flag 0
8237 anything-ggs-max-length-num-flag 0)
8238 (let ((request (concat anything-c-google-suggest-url
8239 (url-hexify-string input))))
8240 (flet ((fetch ()
8241 (loop
8242 with result-alist = (xml-get-children
8243 (car (xml-parse-region
8244 (point-min) (point-max)))
8245 'CompleteSuggestion)
8246 for i in result-alist
8247 for data = (cdr (caadr (assoc 'suggestion i)))
8248 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8249 for lqueries = (length (anything-c-ggs-set-number-result
8250 nqueries))
8251 for ldata = (length data)
8253 (progn
8254 (when (> ldata anything-ggs-max-length-real-flag)
8255 (setq anything-ggs-max-length-real-flag ldata))
8256 (when (> lqueries anything-ggs-max-length-num-flag)
8257 (setq anything-ggs-max-length-num-flag lqueries)))
8258 collect (cons data nqueries) into cont
8259 finally return cont)))
8260 (if anything-google-suggest-use-curl-p
8261 (with-temp-buffer
8262 (call-process "curl" nil t nil request)
8263 (fetch))
8264 (with-current-buffer
8265 (url-retrieve-synchronously request)
8266 (fetch))))))
8268 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8269 "Set candidates with result and number of google results found."
8270 (let ((suggestions
8271 (loop with suggested-results = (anything-c-google-suggest-fetch
8272 (or (and request-prefix
8273 (concat request-prefix " " anything-pattern))
8274 anything-pattern))
8275 for (real . numresult) in suggested-results
8276 ;; Prepare number of results with ","
8277 for fnumresult = (anything-c-ggs-set-number-result numresult)
8278 ;; Calculate number of spaces to add before fnumresult
8279 ;; if it is smaller than longest result
8280 ;; `anything-ggs-max-length-num-flag'.
8281 ;; e.g 1,234,567
8282 ;; 345,678
8283 ;; To be sure it is aligned properly.
8284 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8285 (- anything-ggs-max-length-num-flag (length fnumresult))
8287 ;; Add now the spaces before fnumresult.
8288 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8289 for interval = (- anything-ggs-max-length-real-flag (length real))
8290 for spaces = (make-string (+ 2 interval) ? )
8291 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8292 collect (cons display real))))
8293 (if (loop for (disp . dat) in suggestions
8294 thereis (equal dat anything-pattern))
8295 suggestions
8296 ;; if there is no suggestion exactly matching the input then
8297 ;; prepend a Search on Google item to the list
8298 (append
8299 suggestions
8300 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8301 anything-input))))))
8303 (defun anything-c-ggs-set-number-result (num)
8304 (if num
8305 (progn
8306 (and (numberp num) (setq num (number-to-string num)))
8307 (loop for i in (reverse (split-string num "" t))
8308 for count from 1
8309 append (list i) into C
8310 when (= count 3)
8311 append (list ",") into C
8312 and do (setq count 0)
8313 finally return
8314 (replace-regexp-in-string
8315 "^," "" (mapconcat 'identity (reverse C) ""))))
8316 "?"))
8318 (defvar anything-c-google-suggest-default-browser-function nil
8319 "*The browse url function you prefer to use with google suggest.
8320 When nil, use the first browser function available
8321 See `anything-browse-url-default-browser-alist'.")
8323 (defun anything-c-google-suggest-action (candidate)
8324 "Default action to jump to a google suggested candidate."
8325 (let ((arg (concat anything-c-google-suggest-search-url
8326 (url-hexify-string candidate))))
8327 (anything-aif anything-c-google-suggest-default-browser-function
8328 (funcall it arg)
8329 (anything-c-browse-url arg))))
8331 (defvar anything-c-google-suggest-default-function
8332 'anything-c-google-suggest-set-candidates
8333 "Default function to use in anything google suggest.")
8335 (defvar anything-c-source-google-suggest
8336 '((name . "Google Suggest")
8337 (candidates . (lambda ()
8338 (funcall anything-c-google-suggest-default-function)))
8339 (action . (("Google Search" . anything-c-google-suggest-action)))
8340 (volatile)
8341 (requires-pattern . 3)
8342 (delayed)))
8344 (defun anything-c-google-suggest-emacs-lisp ()
8345 "Try to emacs lisp complete with google suggestions."
8346 (anything-c-google-suggest-set-candidates "emacs lisp"))
8348 ;; (anything 'anything-c-source-google-suggest)
8350 ;;; Yahoo suggestions
8353 (defun anything-c-yahoo-suggest-fetch (input)
8354 "Fetch Yahoo suggestions for INPUT from XML buffer.
8355 Return an alist with elements like (data . number_results)."
8356 (let ((request (concat anything-c-yahoo-suggest-url
8357 (url-hexify-string input))))
8358 (flet ((fetch ()
8359 (loop
8360 with result-alist = (xml-get-children
8361 (car (xml-parse-region (point-min) (point-max)))
8362 'Result)
8363 for i in result-alist
8364 collect (caddr i))))
8365 (with-current-buffer
8366 (url-retrieve-synchronously request)
8367 (fetch)))))
8369 (defun anything-c-yahoo-suggest-set-candidates ()
8370 "Set candidates with Yahoo results found."
8371 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8372 (or suggestions
8373 (append
8374 suggestions
8375 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8376 anything-input))))))
8378 (defun anything-c-yahoo-suggest-action (candidate)
8379 "Default action to jump to a Yahoo suggested candidate."
8380 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8381 (url-hexify-string candidate))))
8383 (defvar anything-c-source-yahoo-suggest
8384 '((name . "Yahoo Suggest")
8385 (candidates . anything-c-yahoo-suggest-set-candidates)
8386 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8387 (volatile)
8388 (requires-pattern . 3)
8389 (delayed)))
8391 ;; (anything 'anything-c-source-yahoo-suggest)
8394 ;;; Web browser functions.
8397 (require 'browse-url)
8398 ;; If default setting of `w3m-command' is not
8399 ;; what you want you and you modify it, you will have to reeval
8400 ;; also `anything-browse-url-default-browser-alist'.
8401 (defvar w3m-command "/usr/bin/w3m")
8402 (defvar anything-c-home-url "http://www.google.fr"
8403 "*Default url to use as home url.")
8405 (defvar ac-browse-url-chromium-program "chromium-browser")
8406 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8407 (defvar anything-browse-url-default-browser-alist
8408 `((,w3m-command . w3m-browse-url)
8409 (,browse-url-firefox-program . browse-url-firefox)
8410 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8411 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8412 (,browse-url-kde-program . browse-url-kde)
8413 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8414 (,browse-url-mozilla-program . browse-url-mozilla)
8415 (,browse-url-galeon-program . browse-url-galeon)
8416 (,browse-url-netscape-program . browse-url-netscape)
8417 (,browse-url-mosaic-program . browse-url-mosaic)
8418 (,browse-url-xterm-program . browse-url-text-xterm))
8419 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8421 (defun* anything-c-generic-browser (url name &rest args)
8422 "Browse URL with NAME browser."
8423 (let ((proc (concat name " " url)))
8424 (message "Starting %s..." name)
8425 (apply 'start-process proc nil name
8426 (append args (list url)))
8427 (set-process-sentinel
8428 (get-process proc)
8429 #'(lambda (process event)
8430 (when (string= event "finished\n")
8431 (message "%s process %s" process event))))))
8433 (defun ac-browse-url-chromium (url)
8434 "Browse URL with google chrome browser."
8435 (interactive "sURL: ")
8436 (anything-c-generic-browser
8437 url ac-browse-url-chromium-program))
8439 (defun ac-browse-url-uzbl (url &optional ignore)
8440 "Browse URL with uzbl browser."
8441 (interactive "sURL: ")
8442 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8444 (defun anything-browse-url-default-browser (url &rest args)
8445 "Find the first available browser and ask it to load URL."
8446 (let ((default-browser-fn
8447 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8448 thereis (and exe (executable-find exe) fn))))
8449 (if default-browser-fn
8450 (apply default-browser-fn url args)
8451 (error "No usable browser found"))))
8453 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8454 "Default command to browse URL."
8455 (if browse-url-browser-function
8456 (browse-url url)
8457 (anything-browse-url-default-browser url)))
8460 ;;; Surfraw
8462 ;; Need external program surfraw.
8463 ;; <http://surfraw.alioth.debian.org/>
8465 (defvar anything-surfraw-default-browser-function nil
8466 "*The browse url function you prefer to use with surfraw.
8467 When nil, fallback to `browse-url-browser-function'.")
8469 ;; Internal
8470 (defvar anything-surfraw-engines-history nil)
8471 (defvar anything-surfraw-input-history nil)
8473 (defun anything-c-build-elvi-list ()
8474 "Return list of all engines and descriptions handled by surfraw."
8475 (cdr
8476 (with-temp-buffer
8477 (call-process "surfraw" nil t nil
8478 "-elvi")
8479 (split-string (buffer-string) "\n"))))
8482 ;;; Emms
8485 (defun anything-emms-stream-edit-bookmark (elm)
8486 "Change the information of current emms-stream bookmark from anything."
8487 (declare (special emms-stream-list))
8488 (let* ((cur-buf anything-current-buffer)
8489 (bookmark (assoc elm emms-stream-list))
8490 (name (read-from-minibuffer "Description: "
8491 (nth 0 bookmark)))
8492 (url (read-from-minibuffer "URL: "
8493 (nth 1 bookmark)))
8494 (fd (read-from-minibuffer "Feed Descriptor: "
8495 (int-to-string (nth 2 bookmark))))
8496 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8497 (format "%s" (car (last bookmark))))))
8498 (save-excursion
8499 (emms-streams)
8500 (when (re-search-forward (concat "^" name) nil t)
8501 (beginning-of-line)
8502 (emms-stream-delete-bookmark)
8503 (emms-stream-add-bookmark name url (string-to-number fd) type)
8504 (emms-stream-save-bookmarks-file)
8505 (emms-stream-quit)
8506 (anything-c-switch-to-buffer cur-buf)))))
8508 (defun anything-emms-stream-delete-bookmark (elm)
8509 "Delete an emms-stream bookmark from anything."
8510 (let* ((cur-buf anything-current-buffer)
8511 (bookmark (assoc elm emms-stream-list))
8512 (name (nth 0 bookmark)))
8513 (save-excursion
8514 (emms-streams)
8515 (when (re-search-forward (concat "^" name) nil t)
8516 (beginning-of-line)
8517 (emms-stream-delete-bookmark)
8518 (emms-stream-save-bookmarks-file)
8519 (emms-stream-quit)
8520 (anything-c-switch-to-buffer cur-buf)))))
8522 (defvar anything-c-source-emms-streams
8523 '((name . "Emms Streams")
8524 (init . (lambda ()
8525 (emms-stream-init)))
8526 (candidates . (lambda ()
8527 (declare (special emms-stream-list))
8528 (mapcar 'car emms-stream-list)))
8529 (action . (("Play" . (lambda (elm)
8530 (declare (special emms-stream-list))
8531 (let* ((stream (assoc elm emms-stream-list))
8532 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8533 (url (second stream)))
8534 (funcall fn url))))
8535 ("Delete" . anything-emms-stream-delete-bookmark)
8536 ("Edit" . anything-emms-stream-edit-bookmark)))
8537 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8538 ;; (anything 'anything-c-source-emms-streams)
8540 ;; Don't forget to set `emms-source-file-default-directory'
8541 (defvar anything-c-source-emms-dired
8542 '((name . "Music Directory")
8543 (candidates . (lambda ()
8544 (cddr (directory-files emms-source-file-default-directory))))
8545 (action .
8546 (("Play Directory" . (lambda (item)
8547 (emms-play-directory
8548 (expand-file-name
8549 item
8550 emms-source-file-default-directory))))
8551 ("Open dired in file's directory" . (lambda (item)
8552 (anything-c-open-dired
8553 (expand-file-name
8554 item
8555 emms-source-file-default-directory))))))
8556 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8557 ;; (anything 'anything-c-source-emms-dired)
8560 (defun anything-c-emms-files-modifier (candidates source)
8561 (let ((current-playlist (with-current-emms-playlist
8562 (loop
8563 with cur-list = (emms-playlist-tracks-in-region
8564 (point-min) (point-max))
8565 for i in cur-list
8566 collect (assoc-default 'name i)))))
8567 (loop for i in candidates
8568 if (member (cdr i) current-playlist)
8569 collect (cons (propertize (car i)
8570 'face 'anything-emms-playlist)
8571 (cdr i)) into lis
8572 else collect i into lis
8573 finally return lis)))
8575 (defun anything-c-emms-play-current-playlist ()
8576 "Play current playlist."
8577 (with-current-emms-playlist
8578 (emms-playlist-first)
8579 (emms-playlist-mode-play-smart)))
8581 (defvar anything-c-source-emms-files
8582 '((name . "Emms files")
8583 (candidates . (lambda ()
8584 (loop for v being the hash-values in emms-cache-db
8585 for name = (assoc-default 'name v)
8586 for artist = (or (assoc-default 'info-artist v) "unknown")
8587 for genre = (or (assoc-default 'info-genre v) "unknown")
8588 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8589 for song = (or (assoc-default 'info-title v) "unknown")
8590 for info = (concat artist " - " genre " - " tracknum ": " song)
8591 unless (string-match "^http:" name) collect (cons info name))))
8592 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8593 (action . (("Play file" . emms-play-file)
8594 ("Add to Playlist and play (C-u clear current)"
8595 . (lambda (candidate)
8596 (when anything-current-prefix-arg
8597 (emms-playlist-current-clear))
8598 (emms-playlist-new)
8599 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8600 (unless emms-player-playing-p
8601 (anything-c-emms-play-current-playlist))))))))
8603 ;; (anything 'anything-c-source-emms-files)
8606 ;;; Jabber Contacts (jabber.el)
8607 (defun anything-c-jabber-online-contacts ()
8608 "List online Jabber contacts."
8609 (with-no-warnings
8610 (let (jids)
8611 (dolist (item (jabber-concat-rosters) jids)
8612 (when (get item 'connected)
8613 (push (if (get item 'name)
8614 (cons (get item 'name) item)
8615 (cons (symbol-name item) item)) jids))))))
8617 (defvar anything-c-source-jabber-contacts
8618 '((name . "Jabber Contacts")
8619 (init . (lambda () (require 'jabber)))
8620 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8621 (action . (lambda (x)
8622 (jabber-chat-with
8623 (jabber-read-account)
8624 (symbol-name
8625 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8626 ;; (anything 'anything-c-source-jabber-contacts)
8630 ;;; Call source.
8631 (defvar anything-source-select-buffer "*anything source select*")
8632 (defvar anything-c-source-call-source
8633 `((name . "Call anything source")
8634 (candidate-number-limit)
8635 (candidates
8636 . (lambda ()
8637 (loop for vname in (all-completions "anything-c-source-" obarray)
8638 for var = (intern vname)
8639 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8640 if name collect
8641 (cons (format "%s `%s'"
8642 name (propertize vname 'face 'font-lock-variable-name-face))
8643 var))))
8644 (action
8645 . (("Invoke anything with selected source"
8647 (lambda (candidate)
8648 (setq anything-candidate-number-limit 9999)
8649 (anything candidate nil nil nil nil
8650 anything-source-select-buffer)))
8651 ("Describe variable" . describe-variable)
8652 ("Find variable" . find-variable)))
8653 (persistent-action . describe-variable)
8654 (persistent-help . "Show description of this source")))
8655 ;; (anything 'anything-c-source-call-source)
8657 (defun anything-call-source-from-anything ()
8658 "Call anything source within `anything' session."
8659 (interactive)
8660 (setq anything-input-idle-delay 0)
8661 (anything-set-sources '(anything-c-source-call-source)))
8663 ;;; Execute Preconfigured anything.
8664 (defvar anything-c-source-anything-commands
8665 '((name . "Preconfigured Anything")
8666 (candidates . anything-c-anything-commands-candidates)
8667 (type . command)
8668 (candidate-number-limit)))
8669 ;; (anything 'anything-c-source-anything-commands)
8671 (defun anything-c-anything-commands-candidates ()
8672 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8673 collect (cons (if (where-is-internal cmd nil t)
8674 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8675 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8676 cmd)))
8679 ;;; Occur
8682 (defun anything-c-occur-init ()
8683 "Create the initial anything occur buffer.
8684 If region is active use region as buffer contents
8685 instead of whole buffer."
8686 (with-current-buffer (anything-candidate-buffer 'global)
8687 (erase-buffer)
8688 (let ((buf-contents
8689 (with-anything-current-buffer
8690 (if (anything-region-active-p)
8691 (buffer-substring (region-beginning) (region-end))
8692 (buffer-substring (point-min) (point-max))))))
8693 (insert buf-contents))))
8695 (defun anything-c-occur-get-line (s e)
8696 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8698 (defun anything-c-occur-query-replace-regexp (candidate)
8699 "Query replace regexp starting from CANDIDATE.
8700 If region is active ignore CANDIDATE and replace only in region.
8701 With a prefix arg replace only matches surrounded by word boundaries,
8702 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8703 (let ((regexp anything-input))
8704 (unless (anything-region-active-p)
8705 (anything-c-action-line-goto candidate))
8706 (apply 'query-replace-regexp
8707 (anything-c-query-replace-args regexp))))
8709 (defvar anything-c-source-occur
8710 '((name . "Occur")
8711 (init . anything-c-occur-init)
8712 (candidates-in-buffer)
8713 (migemo)
8714 (get-line . anything-c-occur-get-line)
8715 (display-to-real . anything-c-display-to-real-line)
8716 (action . (("Go to Line" . anything-c-action-line-goto)
8717 ("Query replace regexp (C-u Not inside word.)"
8718 . anything-c-occur-query-replace-regexp)))
8719 (recenter)
8720 (requires-pattern . 1)
8721 (delayed)
8722 (volatile)))
8723 ;; (anything 'anything-c-source-occur)
8726 ;;; Anything browse code.
8727 (defun anything-c-browse-code-get-line (beg end)
8728 "Select line if it match the regexp corresponding to current `major-mode'.
8729 Line is parsed for BEG position to END position."
8730 (let ((str-line (buffer-substring beg end))
8731 (regexp (assoc-default major-mode
8732 anything-c-browse-code-regexp-alist))
8733 (num-line (if (string= anything-pattern "") beg (1- beg))))
8734 (when (and regexp (string-match regexp str-line))
8735 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8738 (defvar anything-c-source-browse-code
8739 '((name . "Browse code")
8740 (init . (lambda ()
8741 (anything-candidate-buffer anything-current-buffer)
8742 (with-anything-current-buffer
8743 (jit-lock-fontify-now))))
8744 (candidate-number-limit . 9999)
8745 (candidates-in-buffer)
8746 (get-line . anything-c-browse-code-get-line)
8747 (type . line)
8748 (recenter)))
8751 ;; Do many actions for input
8752 (defvar anything-c-source-create
8753 '((name . "Create")
8754 (dummy)
8755 (action)
8756 (action-transformer . anything-create--actions))
8757 "Do many create actions from `anything-pattern'.
8758 See also `anything-create--actions'.")
8759 ;; (anything 'anything-c-source-create)
8761 (defun anything-create-from-anything ()
8762 "Run `anything-create' from `anything' as a fallback."
8763 (interactive)
8764 (anything-run-after-quit 'anything-create nil anything-pattern))
8766 (defun anything-create--actions (&rest ignored)
8767 "Default actions for `anything-create' / `anything-c-source-create'."
8768 (remove-if-not
8769 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8770 (append anything-create--actions-private
8771 '(("find-file" . find-file)
8772 ("find-file other window" . find-file-other-window)
8773 ("New buffer" . anything-c-switch-to-buffer)
8774 ("New buffer other window" . switch-to-buffer-other-window)
8775 ("Bookmark Set" . bookmark-set)
8776 ("Set Register" .
8777 (lambda (x) (set-register (read-char "Register: ") x)))
8778 ("Insert Linkd star" . linkd-insert-star)
8779 ("Insert Linkd Tag" . linkd-insert-tag)
8780 ("Insert Linkd Link" . linkd-insert-link)
8781 ("Insert Linkd Lisp" . linkd-insert-lisp)
8782 ("Insert Linkd Wiki" . linkd-insert-wiki)
8783 ("Google Search" . google)))))
8786 ;; Minibuffer History
8789 (defvar anything-c-source-minibuffer-history
8790 '((name . "Minibuffer History")
8791 (header-name . (lambda (name)
8792 (format "%s (%s)" name minibuffer-history-variable)))
8793 (candidates
8794 . (lambda ()
8795 (let ((history (loop for i in
8796 (symbol-value minibuffer-history-variable)
8797 unless (string= "" i) collect i)))
8798 (if (consp (car history))
8799 (mapcar 'prin1-to-string history)
8800 history))))
8801 (migemo)
8802 (action . insert)))
8803 ;; (anything 'anything-c-source-minibuffer-history)
8806 ;;; Elscreen
8809 (defvar anything-c-source-elscreen
8810 '((name . "Elscreen")
8811 (candidates
8812 . (lambda ()
8813 (if (cdr (elscreen-get-screen-to-name-alist))
8814 (sort
8815 (loop for sname in (elscreen-get-screen-to-name-alist)
8816 append (list (format "[%d] %s" (car sname) (cdr sname))))
8817 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8818 (action
8819 . (("Change Screen" .
8820 (lambda (candidate)
8821 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8822 ("Kill Screen(s)" .
8823 (lambda (candidate)
8824 (dolist (i (anything-marked-candidates))
8825 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8826 (elscreen-kill))))
8827 ("Only Screen" .
8828 (lambda (candidate)
8829 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8830 (elscreen-kill-others)))))))
8831 ;; (anything 'anything-c-source-elscreen)
8834 ;;;; <System>
8836 ;;; Top (process)
8837 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8838 "Top command (batch mode). %s is replaced with `frame-width'.")
8839 (defvar anything-c-source-top
8840 '((name . "Top (Press C-c C-u to refresh)")
8841 (init . anything-c-top-init)
8842 (candidates-in-buffer)
8843 (display-to-real . anything-c-top-display-to-real)
8844 (persistent-action . anything-c-top-sh-persistent-action)
8845 (persistent-help . "SIGTERM")
8846 (action
8847 ("kill (TERM)" . (lambda (pid)
8848 (anything-c-top-sh (format "kill -TERM %s" pid))))
8849 ("kill (KILL)" . (lambda (pid)
8850 (anything-c-top-sh (format "kill -KILL %s" pid))))
8851 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8852 ;; (anything 'anything-c-source-top)
8854 (defun anything-c-top-sh (cmd)
8855 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8857 (defun anything-c-top-sh-persistent-action (pid)
8858 (delete-other-windows)
8859 (anything-c-top-sh (format "kill -TERM %s" pid))
8860 (anything-force-update))
8862 (defun anything-c-top-init ()
8863 (with-current-buffer (anything-candidate-buffer 'global)
8864 (call-process-shell-command
8865 (format anything-c-top-command
8866 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8867 nil (current-buffer))))
8869 (defun anything-c-top-display-to-real (line)
8870 (car (split-string line)))
8872 ;;; Timers
8873 (defvar anything-c-source-absolute-time-timers
8874 '((name . "Absolute Time Timers")
8875 (candidates . timer-list)
8876 (type . timer)))
8877 ;; (anything 'anything-c-source-absolute-time-timers)
8879 (defvar anything-c-source-idle-time-timers
8880 '((name . "Idle Time Timers")
8881 (candidates . timer-idle-list)
8882 (type . timer)))
8883 ;; (anything 'anything-c-source-idle-time-timers)
8885 (defun anything-c-timer-real-to-display (timer)
8886 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8887 (append timer nil) ;use `append' to convert vector->list
8888 (format "%s repeat=%5S %s(%s)"
8889 (let ((time (list t1 t2 t3)))
8890 (if idle-delay
8891 (format-time-string "idle-for=%5s" time)
8892 (format-time-string "%m/%d %T" time)))
8893 repeat-delay
8894 func
8895 (mapconcat 'prin1-to-string args " "))))
8897 ;;; X RandR resolution change
8898 ;;; FIXME I do not care multi-display.
8899 (defvar anything-c-xrandr-output "VGA")
8900 (defvar anything-c-xrandr-screen "0")
8901 (defvar anything-c-source-xrandr-change-resolution
8902 '((name . "Change Resolution")
8903 (candidates
8904 . (lambda ()
8905 (with-temp-buffer
8906 (call-process "xrandr" nil (current-buffer) nil
8907 "--screen" anything-c-xrandr-screen "-q")
8908 (goto-char 1)
8909 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8910 collect (match-string 1)))))
8911 (action
8912 ("Change Resolution" . (lambda (mode)
8913 (call-process "xrandr" nil nil nil
8914 "--screen" anything-c-xrandr-screen
8915 "--output" anything-c-xrandr-output
8916 "--mode" mode))))))
8917 ;; (anything 'anything-c-source-xrandr-change-resolution)
8919 ;;; Xfont selection
8922 (defun anything-c-persistent-xfont-action (elm)
8923 "Show current font temporarily"
8924 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8925 (default-font elm))
8926 (unwind-protect
8927 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8928 (set-frame-font current-font))))
8930 (defvar anything-c-xfonts-cache nil)
8931 (defvar anything-c-source-xfonts
8932 '((name . "X Fonts")
8933 (init . (lambda ()
8934 (unless anything-c-xfonts-cache
8935 (setq anything-c-xfonts-cache
8936 (x-list-fonts "*")))))
8937 (candidates . anything-c-xfonts-cache)
8938 (action . (("Copy to kill ring" . (lambda (elm)
8939 (kill-new elm)))
8940 ("Set Font" . (lambda (elm)
8941 (kill-new elm)
8942 (set-frame-font elm 'keep-size)
8943 (message "New font have been copied to kill ring")))))
8944 (persistent-action . anything-c-persistent-xfont-action)
8945 (persistent-help . "Switch to this font temporarily")))
8946 ;; (anything 'anything-c-source-xfonts)
8948 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8951 (defvar anything-c-ucs-max-len 0)
8952 (defun anything-c-calculate-ucs-max-len ()
8953 "Calculate the length of longest `ucs-names' candidate."
8954 (loop with count = 0
8955 for (n . v) in (ucs-names)
8956 for len = (length n)
8957 if (> len count)
8958 do (setq count len)
8959 finally return count))
8961 (defun anything-c-ucs-init ()
8962 "Initialize an anything buffer with ucs symbols.
8963 Only math* symbols are collected."
8964 (unless (> anything-c-ucs-max-len 0)
8965 (setq anything-c-ucs-max-len
8966 (anything-c-calculate-ucs-max-len)))
8967 (with-current-buffer (anything-candidate-buffer
8968 (get-buffer-create "*anything ucs*"))
8969 ;; `ucs-names' fn will not run again, data is cached in
8970 ;; var `ucs-names'.
8971 (loop for (n . v) in (ucs-names)
8972 for len = (length n)
8973 for diff = (+ (- anything-c-ucs-max-len len) 2)
8974 unless (string= "" n)
8975 do (progn (insert (concat
8976 n ":"
8977 (make-string
8978 diff ? )))
8979 (ucs-insert v)
8980 (insert "\n")))))
8982 (defun anything-c-ucs-forward-char (candidate)
8983 (with-anything-current-buffer
8984 (forward-char 1)))
8986 (defun anything-c-ucs-backward-char (candidate)
8987 (with-anything-current-buffer
8988 (forward-char -1)))
8990 (defun anything-c-ucs-delete-backward (candidate)
8991 (with-anything-current-buffer
8992 (delete-char -1)))
8994 (defun anything-c-ucs-insert-char (candidate)
8995 (with-anything-current-buffer
8996 (insert
8997 (replace-regexp-in-string
8998 " " ""
8999 (cadr (split-string candidate ":"))))))
9001 (defun anything-c-ucs-persistent-insert ()
9002 (interactive)
9003 (anything-attrset 'action-insert 'anything-c-ucs-insert-char)
9004 (anything-execute-persistent-action 'action-insert))
9006 (defun anything-c-ucs-persistent-forward ()
9007 (interactive)
9008 (anything-attrset 'action-forward 'anything-c-ucs-forward-char)
9009 (anything-execute-persistent-action 'action-forward))
9011 (defun anything-c-ucs-persistent-backward ()
9012 (interactive)
9013 (anything-attrset 'action-back 'anything-c-ucs-backward-char)
9014 (anything-execute-persistent-action 'action-back))
9016 (defun anything-c-ucs-persistent-delete ()
9017 (interactive)
9018 (anything-attrset 'action-delete 'anything-c-ucs-delete-backward)
9019 (anything-execute-persistent-action 'action-delete))
9021 (defvar anything-c-source-ucs
9022 '((name . "Ucs names")
9023 (init . anything-c-ucs-init)
9024 (candidate-number-limit . 9999)
9025 (candidates-in-buffer)
9026 (mode-line . anything-c-ucs-mode-line-string)
9027 (action . (("Insert" . anything-c-ucs-insert-char)
9028 ("Forward char" . anything-c-ucs-forward-char)
9029 ("Backward char" . anything-c-ucs-backward-char)
9030 ("Delete char backward" . anything-c-ucs-delete-backward))))
9031 "Source for collecting `ucs-names' math symbols.")
9034 ;;; Emacs process
9037 (defvar anything-c-source-emacs-process
9038 '((name . "Emacs Process")
9039 (candidates . (lambda () (mapcar #'process-name (process-list))))
9040 (persistent-action . (lambda (elm)
9041 (delete-process (get-process elm))
9042 (anything-delete-current-selection)))
9043 (persistent-help . "Kill Process")
9044 (action ("Kill Process" . (lambda (elm)
9045 (delete-process (get-process elm)))))))
9046 ;; (anything 'anything-c-source-emacs-process)
9048 ;;; World time
9051 (defvar anything-c-source-time-world
9052 '((name . "Time World List")
9053 (init . (lambda ()
9054 (let ((anything-buffer (anything-candidate-buffer 'global)))
9055 (with-current-buffer anything-buffer
9056 (display-time-world-display display-time-world-list)))))
9057 (candidates-in-buffer)))
9061 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9064 (defvar anything-c-source-apt
9065 '((name . "APT")
9066 (init . anything-c-apt-init)
9067 (candidates-in-buffer)
9068 (candidate-transformer anything-c-apt-candidate-transformer)
9069 (display-to-real . anything-c-apt-display-to-real)
9070 (requires-pattern . 2)
9071 (update . anything-c-apt-refresh)
9072 (action
9073 ("Show package description" . anything-c-apt-cache-show)
9074 ("Install package" . anything-c-apt-install)
9075 ("Remove package" . anything-c-apt-uninstall)
9076 ("Purge package" . anything-c-apt-purge))
9077 (persistent-action . anything-c-apt-persistent-action)
9078 (persistent-help . "Show package description")))
9079 ;; (anything 'anything-c-source-apt)
9081 (defvar anything-c-apt-query "emacs")
9082 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9083 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9084 (defvar anything-c-apt-installed-packages nil)
9085 (defvar anything-c-apt-all-packages nil)
9086 (defvar anything-c-apt-input-history nil)
9088 (defun anything-c-apt-refresh ()
9089 "Refresh installed candidates list."
9090 (setq anything-c-apt-installed-packages nil)
9091 (setq anything-c-apt-all-packages nil))
9093 (defun anything-c-apt-persistent-action (candidate)
9094 "Persistent action for APT source."
9095 (anything-c-apt-cache-show candidate))
9097 (defun anything-c-apt-candidate-transformer (candidates)
9098 "Show installed candidates in a different color."
9099 (loop
9100 with all
9101 for cand in candidates
9102 for name = (anything-c-apt-display-to-real cand)
9103 if (member name anything-c-apt-installed-packages)
9104 collect (propertize cand 'face 'anything-apt-installed) into all
9105 else collect cand into all finally return all))
9107 (defun anything-c-apt-init ()
9108 "Initialize list of debian packages."
9109 (let ((query ""))
9110 (unless (and anything-c-apt-installed-packages
9111 anything-c-apt-all-packages)
9112 (message "Loading package list...")
9113 (setq anything-c-apt-installed-packages
9114 (with-temp-buffer
9115 (call-process-shell-command "dpkg --get-selections"
9116 nil (current-buffer))
9117 (loop for i in (split-string (buffer-string) "\n" t)
9118 collect (car (split-string i)))))
9119 (setq anything-c-apt-all-packages
9120 (with-current-buffer
9121 (anything-candidate-buffer
9122 (get-buffer-create (format "*anything-apt*")))
9123 (erase-buffer)
9124 (call-process-shell-command
9125 (format anything-c-apt-search-command query)
9126 nil (current-buffer))))
9127 (message "Loading package list done")
9128 (sit-for 0.5))))
9130 (defun anything-c-apt-display-to-real (line)
9131 "Return only name of a debian package.
9132 LINE is displayed like:
9133 package name - description."
9134 (car (split-string line " - ")))
9136 (defun anything-c-shell-command-if-needed (command)
9137 "Run shell command COMMAND to describe package.
9138 If a buffer named COMMAND already exists, just switch to it."
9139 (let ((buf (get-buffer command)))
9140 (anything-c-switch-to-buffer (get-buffer-create command))
9141 (unless buf (insert (shell-command-to-string command)))))
9143 (defun anything-c-apt-cache-show (package)
9144 "Show information on apt package PACKAGE."
9145 (anything-c-shell-command-if-needed
9146 (format anything-c-apt-show-command package)))
9148 (defun anything-c-apt-install (package)
9149 "Run 'apt-get install' shell command on PACKAGE."
9150 (anything-c-apt-generic-action :action 'install))
9152 (defun anything-c-apt-uninstall (package)
9153 "Run 'apt-get remove' shell command on PACKAGE."
9154 (anything-c-apt-generic-action :action 'uninstall))
9156 (defun anything-c-apt-purge (package)
9157 "Run 'apt-get purge' shell command on PACKAGE."
9158 (anything-c-apt-generic-action :action 'purge))
9160 (defun* anything-c-apt-generic-action (&key action)
9161 "Run 'apt-get ACTION'.
9162 Support install, remove and purge actions."
9163 (ansi-term (getenv "SHELL") "anything apt")
9164 (term-line-mode)
9165 (let ((command (case action
9166 ('install "sudo apt-get install ")
9167 ('uninstall "sudo apt-get remove ")
9168 ('purge "sudo apt-get purge ")
9169 (t (error "Unknow action"))))
9170 (beg (point))
9172 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9173 (anything-marked-candidates) " ")))
9174 (goto-char (point-max))
9175 (insert (concat command cand-list))
9176 (setq end (point))
9177 (if (y-or-n-p (format "%s package" (symbol-name action)))
9178 (progn
9179 (setq anything-c-external-commands-list nil)
9180 (setq anything-c-apt-installed-packages nil)
9181 (term-char-mode) (term-send-input))
9182 (delete-region beg end) (term-send-eof) (kill-buffer))))
9184 ;; (anything-c-apt-install "jed")
9187 ;;; Anything UI for gentoo portage.
9190 (defvar anything-c-gentoo-use-flags nil)
9191 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9192 (defvar anything-c-cache-gentoo nil)
9193 (defvar anything-c-cache-world nil)
9194 (defvar anything-c-source-gentoo
9195 '((name . "Portage sources")
9196 (init . (lambda ()
9197 (get-buffer-create anything-c-gentoo-buffer)
9198 (unless anything-c-cache-gentoo
9199 (anything-c-gentoo-setup-cache))
9200 (unless anything-c-cache-world
9201 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9202 (anything-c-gentoo-init-list)))
9203 (candidates-in-buffer)
9204 (match . identity)
9205 (candidate-transformer anything-c-highlight-world)
9206 (action . (("Show package" . (lambda (elm)
9207 (anything-c-gentoo-eshell-action elm "eix")))
9208 ("Show history" . (lambda (elm)
9209 (if (member elm anything-c-cache-world)
9210 (anything-c-gentoo-eshell-action elm "genlop -qe")
9211 (message "No infos on packages not yet installed"))))
9212 ("Copy in kill-ring" . kill-new)
9213 ("insert at point" . insert)
9214 ("Browse HomePage" . (lambda (elm)
9215 (let ((urls (anything-c-gentoo-get-url elm)))
9216 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9217 ("Show extra infos" . (lambda (elm)
9218 (if (member elm anything-c-cache-world)
9219 (anything-c-gentoo-eshell-action elm "genlop -qi")
9220 (message "No infos on packages not yet installed"))))
9221 ("Show use flags" . (lambda (elm)
9222 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9223 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9224 (font-lock-mode 1)))
9225 ("Run emerge pretend" . (lambda (elm)
9226 (anything-c-gentoo-eshell-action elm "emerge -p")))
9227 ("Emerge" . (lambda (elm)
9228 (anything-gentoo-install elm :action 'install)))
9229 ("Unmerge" . (lambda (elm)
9230 (anything-gentoo-install elm :action 'uninstall)))
9231 ("Show dependencies" . (lambda (elm)
9232 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9233 ("Show related files" . (lambda (elm)
9234 (anything-c-gentoo-default-action elm "equery" "files")))
9235 ("Refresh" . (lambda (elm)
9236 (anything-c-gentoo-setup-cache)
9237 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9239 ;; (anything 'anything-c-source-gentoo)
9241 (defun* anything-gentoo-install (candidate &key action)
9242 (setq anything-c-external-commands-list nil)
9243 (ansi-term (getenv "SHELL") "Gentoo emerge")
9244 (term-line-mode)
9245 (let ((command (case action
9246 ('install "sudo emerge -av ")
9247 ('uninstall "sudo emerge -avC ")
9248 (t (error "Unknow action"))))
9249 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9250 (beg (point)) end)
9251 (goto-char (point-max))
9252 (insert (concat command elms))
9253 (setq end (point))
9254 (term-char-mode) (term-send-input)))
9256 (defun anything-c-gentoo-default-action (elm command &rest args)
9257 "Gentoo default action that use `anything-c-gentoo-buffer'."
9258 (if (member elm anything-c-cache-world)
9259 (progn
9260 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9261 (erase-buffer)
9262 (let ((com-list (append args (list elm))))
9263 (apply #'call-process command nil t nil
9264 com-list)))
9265 (message "No infos on packages not yet installed")))
9267 (defvar anything-c-source-use-flags
9268 '((name . "Use Flags")
9269 (init . (lambda ()
9270 (unless anything-c-gentoo-use-flags
9271 (anything-c-gentoo-setup-use-flags-cache))
9272 (anything-c-gentoo-get-use)))
9273 (candidates-in-buffer)
9274 (match . identity)
9275 (candidate-transformer anything-c-highlight-local-use)
9276 (action . (("Description"
9277 . (lambda (elm)
9278 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9279 (erase-buffer)
9280 (apply #'call-process "euse" nil t nil
9281 `("-i"
9282 ,elm))
9283 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9284 (font-lock-mode 1)))
9285 ("Enable"
9286 . (lambda (elm)
9287 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9288 ("Disable"
9289 . (lambda (elm)
9290 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9291 ("Remove"
9292 . (lambda (elm)
9293 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9294 ("Show which dep use this flag"
9295 . (lambda (elm)
9296 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9297 (erase-buffer)
9298 (apply #'call-process "equery" nil t nil
9299 `("-C"
9301 ,elm))))))))
9304 ;; (anything 'anything-c-source-use-flags)
9306 (defun anything-c-gentoo-init-list ()
9307 "Initialize buffer with all packages in Portage."
9308 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9309 (buf (anything-candidate-buffer 'portage-buf)))
9310 (with-current-buffer buf
9311 (dolist (i anything-c-cache-gentoo)
9312 (insert (concat i "\n"))))))
9314 (defun anything-c-gentoo-setup-cache ()
9315 "Set up `anything-c-cache-gentoo'"
9316 (setq anything-c-cache-gentoo
9317 (split-string (with-temp-buffer
9318 (call-process "eix" nil t nil
9319 "--only-names")
9320 (buffer-string)))))
9322 (defun anything-c-gentoo-eshell-action (elm command)
9323 (when (get-buffer "*EShell Command Output*")
9324 (kill-buffer "*EShell Command Output*"))
9325 (message "Wait searching...")
9326 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9327 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9328 (progn
9329 (save-window-excursion
9330 (pop-to-buffer "*scratch*")
9331 (eshell-command (format "%s %s" command elm)))
9332 (pop-to-buffer "*EShell Command Output*"))
9333 (eshell-command (format "%s %s" command elm)))))
9335 (defun anything-c-gentoo-get-use ()
9336 "Initialize buffer with all use flags."
9337 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9338 (buf (anything-candidate-buffer 'use-buf)))
9339 (with-current-buffer buf
9340 (dolist (i anything-c-gentoo-use-flags)
9341 (insert (concat i "\n"))))))
9344 (defun anything-c-gentoo-setup-use-flags-cache ()
9345 "Setup `anything-c-gentoo-use-flags'"
9346 (setq anything-c-gentoo-use-flags
9347 (split-string (with-temp-buffer
9348 (call-process "eix" nil t nil
9349 "--print-all-useflags")
9350 (buffer-string)))))
9352 (defun anything-c-gentoo-get-url (elm)
9353 "Return a list of urls from eix output."
9354 (loop
9355 with url-list = (split-string
9356 (with-temp-buffer
9357 (call-process "eix" nil t nil
9358 elm "--format" "<homepage>\n")
9359 (buffer-string)))
9360 with all
9361 for i in url-list
9362 when (and (string-match "^http://.*" i)
9363 (not (member i all)))
9364 collect i into all
9365 finally return all))
9367 (defun anything-c-gentoo-get-world ()
9368 "Return list of all installed package on your system."
9369 (split-string (with-temp-buffer
9370 (call-process "qlist" nil t nil
9371 "-I")
9372 (buffer-string))))
9374 (defun anything-c-gentoo-get-local-use ()
9375 (split-string (with-temp-buffer
9376 (call-process "portageq" nil t nil
9377 "envvar"
9378 "USE")
9379 (buffer-string))))
9382 (defun anything-c-highlight-world (eix)
9383 "Highlight all installed package."
9384 (loop for i in eix
9385 if (member i anything-c-cache-world)
9386 collect (propertize i 'face 'anything-gentoo-match-face)
9387 else
9388 collect i))
9390 (defun anything-c-highlight-local-use (use-flags)
9391 (let ((local-uses (anything-c-gentoo-get-local-use)))
9392 (loop for i in use-flags
9393 if (member i local-uses)
9394 collect (propertize i 'face 'anything-gentoo-match-face)
9395 else
9396 collect i)))
9400 ;;; Anything ratpoison UI
9403 (defvar anything-c-source-ratpoison-commands
9404 '((name . "Ratpoison Commands")
9405 (init . anything-c-ratpoison-commands-init)
9406 (candidates-in-buffer)
9407 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9408 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9409 (candidate-number-limit)))
9410 ;; (anything 'anything-c-source-ratpoison-commands)
9412 (defun anything-c-ratpoison-commands-init ()
9413 (unless (anything-candidate-buffer)
9414 (with-current-buffer (anything-candidate-buffer 'global)
9415 ;; with ratpoison prefix key
9416 (save-excursion
9417 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9418 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9419 (replace-match "<ratpoison> \\1: \\2"))
9420 (goto-char (point-max))
9421 ;; direct binding
9422 (save-excursion
9423 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9424 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9425 (replace-match "\\1: \\2")))))
9427 (defun anything-c-ratpoison-commands-display-to-real (display)
9428 (and (string-match ": " display)
9429 (substring display (match-end 0))))
9431 (defun anything-c-ratpoison-commands-execute (candidate)
9432 (call-process "ratpoison" nil nil nil "-ic" candidate))
9436 ;;; Anything `completing-read' replacement
9439 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9440 "Convert COLLECTION to list removing elements that don't match TEST.
9441 See `anything-comp-read' about supported COLLECTION arguments.
9443 SORT-FN is a predicate to sort COLLECTION.
9445 ALISTP when non--nil will not use `all-completions' to collect
9446 candidates because it doesn't handle alists correctly for anything.
9447 i.e In `all-completions' the keys \(cars of elements\)
9448 are the possible completions. In anything we want to use the cdr instead
9449 like \(display . real\).
9453 \(setq A '((a . 1) (b . 2) (c . 3)))
9454 ==>((a . 1) (b . 2) (c . 3))
9455 \(anything-comp-read \"test: \" A :alistp nil
9456 :exec-when-only-one t
9457 :initial-input \"a\")
9458 ==>\"a\"
9459 \(anything-comp-read \"test: \" A :alistp t
9460 :exec-when-only-one t
9461 :initial-input \"1\")
9462 ==>\"1\"
9464 See docstring of `all-completions' for more info.
9466 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9467 (let ((cands
9468 (cond ((and (eq collection obarray) test)
9469 (all-completions "" collection test))
9470 ((and (vectorp collection) test)
9471 (loop for i across collection when (funcall test i) collect i))
9472 ((vectorp collection)
9473 (loop for i across collection collect i))
9474 ((and alistp test)
9475 (loop for i in collection when (funcall test i) collect i))
9476 ((and (symbolp collection) (boundp collection))
9477 (symbol-value collection))
9478 (alistp collection)
9479 ((and collection test)
9480 (all-completions "" collection test))
9481 (t (all-completions "" collection)))))
9482 (if sort-fn (sort cands sort-fn) cands)))
9484 (defun anything-cr-default-transformer (candidates source)
9485 "Default filter candidate function for `anything-comp-read'.
9486 Do nothing, just return candidate list unmodified."
9487 candidates)
9489 (defun* anything-comp-read (prompt collection
9490 &key
9491 test
9492 initial-input
9493 default
9494 preselect
9495 (buffer "*Anything Completions*")
9496 must-match
9497 (requires-pattern 0)
9498 (history nil)
9499 input-history
9500 (persistent-action nil)
9501 (persistent-help "DoNothing")
9502 (name "Anything Completions")
9503 candidates-in-buffer
9504 exec-when-only-one
9505 (volatile t)
9506 sort
9507 (fc-transformer 'anything-cr-default-transformer)
9508 (marked-candidates nil)
9509 (alistp t))
9510 "Read a string in the minibuffer, with anything completion.
9512 It is anything `completing-read' equivalent.
9514 - PROMPT is the prompt name to use.
9516 - COLLECTION can be a list, vector, obarray or hash-table.
9517 It can be also a function that receives three arguments:
9518 the values string, predicate and t. See `all-completions' for more details.
9520 Keys description:
9522 - TEST: A predicate called with one arg i.e candidate.
9524 - INITIAL-INPUT: Same as input arg in `anything'.
9526 - PRESELECT: See preselect arg of `anything'.
9528 - DEFAULT: This option is used only for compatibility with regular
9529 Emacs `completing-read'.
9531 - BUFFER: Name of anything-buffer.
9533 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9535 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9537 - HISTORY: A list containing specific history, default is nil.
9538 When it is non--nil, all elements of HISTORY are displayed in
9539 a special source before COLLECTION.
9541 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9542 stored there, if nil or not provided, `minibuffer-history'
9543 will be used instead.
9545 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9547 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9549 - NAME: The name related to this local source.
9551 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9552 to non--nil. (possibles values are t or nil).
9554 - VOLATILE: Use volatile attribute \(enabled by default\).
9556 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9558 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9560 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9562 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9564 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9565 `anything-candidates-in-buffer' which is much faster.
9566 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9568 Any prefix args passed during `anything-comp-read' invocation will be recorded
9569 in `anything-current-prefix-arg', otherwise if prefix args were given before
9570 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9571 That's mean you can pass prefix args before or after calling a command
9572 that use `anything-comp-read' See `anything-M-x' for example."
9573 (when (get-buffer anything-action-buffer)
9574 (kill-buffer anything-action-buffer))
9575 (flet ((action-fn (candidate)
9576 (if marked-candidates
9577 (anything-marked-candidates)
9578 (identity candidate))))
9579 ;; Assume completion have been already required,
9580 ;; so always use 'confirm.
9581 (when (eq must-match 'confirm-after-completion)
9582 (setq must-match 'confirm))
9583 (let* ((minibuffer-completion-confirm (unless (eq must-match t)
9584 must-match))
9585 (keymap (when must-match minibuffer-local-must-match-map))
9586 (anything-map (make-composed-keymap
9587 ;; Merge some anything bindings
9588 ;; that clash with minibuffer ones.
9589 (list '(keymap
9590 (7 . anything-keyboard-quit)
9591 (up . anything-previous-line)
9592 (down . anything-next-line))
9593 keymap)
9594 anything-map))
9595 (src-hist `((name . ,(format "%s History" name))
9596 (candidates
9597 . (lambda ()
9598 (let ((all (anything-comp-read-get-candidates
9599 history nil nil ,alistp)))
9600 (delete
9602 (anything-fast-remove-dups
9603 (if (and default (not (string= default "")))
9604 (delq nil (cons default
9605 (delete default all)))
9606 all)
9607 :test 'equal)))))
9608 (filtered-candidate-transformer
9609 . (lambda (candidates sources)
9610 (loop for i in candidates
9611 do (set-text-properties 0 (length i) nil i)
9612 collect i)))
9613 (persistent-action . ,persistent-action)
9614 (persistent-help . ,persistent-help)
9615 (action . ,'action-fn)))
9616 (src `((name . ,name)
9617 (candidates
9618 . (lambda ()
9619 (let ((cands (anything-comp-read-get-candidates
9620 collection test sort alistp)))
9621 (unless (or must-match (string= anything-pattern ""))
9622 (setq cands (append (list anything-pattern) cands)))
9623 (if (and default (not (string= default "")))
9624 (delq nil (cons default (delete default cands)))
9625 cands))))
9626 (filtered-candidate-transformer ,fc-transformer)
9627 (requires-pattern . ,requires-pattern)
9628 (persistent-action . ,persistent-action)
9629 (persistent-help . ,persistent-help)
9630 (action . ,'action-fn)))
9631 (src-1 `((name . ,name)
9632 (init
9633 . (lambda ()
9634 (let ((cands (anything-comp-read-get-candidates
9635 collection test sort alistp)))
9636 (unless (or must-match (string= anything-pattern ""))
9637 (setq cands (append (list anything-pattern) cands)))
9638 (with-current-buffer (anything-candidate-buffer 'global)
9639 (loop for i in
9640 (if (and default (not (string= default "")))
9641 (delq nil (cons default (delete default cands)))
9642 cands)
9643 do (insert (concat i "\n")))))))
9644 (candidates-in-buffer)
9645 (filtered-candidate-transformer ,fc-transformer)
9646 (requires-pattern . ,requires-pattern)
9647 (persistent-action . ,persistent-action)
9648 (persistent-help . ,persistent-help)
9649 (action . ,'action-fn)))
9650 (src-list (list src-hist
9651 (if candidates-in-buffer
9652 src-1
9653 (if volatile
9654 (append src '((volatile)))
9655 src))))
9656 (anything-execute-action-at-once-if-one exec-when-only-one))
9658 (anything
9659 :sources src-list
9660 :input initial-input
9661 :default default
9662 :preselect preselect
9663 :prompt prompt
9664 :resume 'noresume
9665 :history (and (symbolp input-history) input-history)
9666 :buffer buffer)
9667 (when (and (not (string= anything-pattern ""))
9668 (eq anything-exit-status 0)
9669 (eq must-match 'confirm))
9670 (identity anything-pattern))
9671 (unless (or (eq anything-exit-status 1) must-match)
9672 default)
9673 (keyboard-quit)))))
9675 ;; Generic completing-read
9677 ;; Support also function as collection.
9678 ;; e.g M-x man is supported.
9679 ;; Support hash-table and vectors as collection.
9680 ;; NOTE:
9681 ;; Some crap emacs functions may not be supported
9682 ;; like ffap-alternate-file (bad use of completing-read)
9683 ;; and maybe others.
9684 ;; Provide a mode `anything-completion-mode' which turn on
9685 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9687 (defvar anything-completion-mode-string " AC")
9689 (defvar anything-completion-mode-quit-message
9690 "Anything completion disabled")
9692 (defvar anything-completion-mode-start-message
9693 "Anything completion enabled")
9695 ;;; Specialized handlers
9698 (defun anything-completing-read-symbols
9699 (prompt collection test require-match init
9700 hist default inherit-input-method name buffer)
9701 "Specialized function for fast symbols completion in `ac-mode'."
9703 (anything
9704 :sources `((name . ,name)
9705 (init . (lambda ()
9706 (with-current-buffer (anything-candidate-buffer 'global)
9707 (goto-char (point-min))
9708 (when (and default (stringp default)
9709 ;; Some defaults args result as
9710 ;; (symbol-name nil) == "nil".
9711 ;; e.g debug-on-entry.
9712 (not (string= default "nil"))
9713 (not (string= default "")))
9714 (insert (concat default "\n")))
9715 (loop with all = (all-completions "" collection test)
9716 for sym in all
9717 unless (and default (eq sym default))
9718 do (insert (concat sym "\n"))))))
9719 (persistent-action . anything-lisp-completion-persistent-action)
9720 (persistent-help . "Show brief doc in mode-line")
9721 (candidates-in-buffer)
9722 (action . identity))
9723 :prompt prompt
9724 :buffer buffer
9725 :input init
9726 :history hist
9727 :resume 'noresume
9728 :default (or default ""))
9729 (keyboard-quit)))
9732 ;;; Generic completing read
9735 (defun anything-completing-read-default-1
9736 (prompt collection test require-match
9737 init hist default inherit-input-method
9738 name buffer &optional cands-in-buffer exec-when-only-one)
9739 "Call `anything-comp-read' with same args as `completing-read'.
9740 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9741 method which is faster.
9742 It should be used when candidate list don't need to rebuild dynamically."
9743 (let ((history (or (car-safe hist) hist)))
9744 (anything-comp-read
9745 prompt collection
9746 :test test
9747 :history history
9748 :input-history history
9749 :must-match require-match
9750 :alistp nil ; Be sure `all-completions' is used.
9751 :name name
9752 :candidates-in-buffer cands-in-buffer
9753 :exec-when-only-one exec-when-only-one
9754 :buffer buffer
9755 ;; If DEF is not provided, fallback to empty string
9756 ;; to avoid `thing-at-point' to be appended on top of list
9757 :default (or default "")
9758 :initial-input init)))
9760 (defun anything-completing-read-with-cands-in-buffer
9761 (prompt collection test require-match
9762 init hist default inherit-input-method
9763 name buffer)
9764 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9765 ;; Some commands like find-tag may use `read-file-name' from inside
9766 ;; the calculation of collection. in this case it clash with
9767 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9768 ;; So (re)calculate collection outside of main anything-session.
9769 (let ((cands (all-completions "" collection)))
9770 (anything-completing-read-default-1 prompt cands test require-match
9771 init hist default inherit-input-method
9772 name buffer t)))
9774 (defun* anything-completing-read-default
9775 (prompt collection &optional
9776 predicate require-match
9777 initial-input hist def
9778 inherit-input-method)
9779 "An anything replacement of `completing-read'.
9780 This function should be used only as a `completing-read-function'.
9782 Don't use it directly, use instead `anything-comp-read' in your programs.
9784 See documentation of `completing-read' and `all-completions' for details."
9785 (declare (special anything-completion-mode))
9786 (let* ((current-command this-command)
9787 (str-command (symbol-name current-command))
9788 (buf-name (format "*ac-mode-%s*" str-command))
9789 (entry (assq current-command
9790 anything-completing-read-handlers-alist))
9791 (def-com (cdr-safe entry))
9792 (str-defcom (and def-com (symbol-name def-com)))
9793 (def-args (list prompt collection predicate require-match
9794 initial-input hist def inherit-input-method))
9795 ;; Append the two extra args needed to set the buffer and source name
9796 ;; in anything specialized functions.
9797 (any-args (append def-args (list str-command buf-name)))
9798 anything-completion-mode-start-message ; Be quiet
9799 anything-completion-mode-quit-message
9800 (minibuffer-completion-table collection)
9801 (minibuffer-completion-predicate predicate)
9802 ;; Be sure this pesty *completion* buffer doesn't popup.
9803 (minibuffer-setup-hook (remove 'minibuffer-completion-help
9804 minibuffer-setup-hook)))
9805 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9806 (unless (or (not entry) def-com)
9807 ;; An entry in *read-handlers-alist exists but have
9808 ;; a nil value, so we exit from here, disable `ac-mode'
9809 ;; and run the command again with it original behavior.
9810 ;; `ac-mode' will be restored on exit.
9811 (return-from anything-completing-read-default
9812 (unwind-protect
9813 (progn
9814 (ac-mode -1)
9815 (apply completing-read-function def-args))
9816 (ac-mode 1))))
9817 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9818 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9819 (when (or (eq def-com 'completing-read)
9820 ;; All specialized functions are prefixed by "anything"
9821 (and (stringp str-defcom)
9822 (not (string-match "^anything" str-defcom))))
9823 (ac-mode -1))
9824 (unwind-protect
9825 (cond (;; An anything specialized function exists, run it.
9826 (and def-com anything-completion-mode)
9827 (apply def-com any-args))
9828 (;; Try to handle `ido-completing-read' everywhere.
9829 (and def-com (eq def-com 'ido-completing-read))
9830 (setcar (memq collection def-args)
9831 (all-completions "" collection predicate))
9832 (apply def-com def-args))
9833 (;; User set explicitely `completing-read' or something similar
9834 ;; in *read-handlers-alist, use this with exactly the same
9835 ;; args as in `completing-read'.
9836 ;; If we are here `anything-completion-mode' is now disabled.
9837 def-com
9838 (apply def-com def-args))
9839 (t ; Fall back to classic `anything-comp-read'.
9840 (anything-completing-read-default-1
9841 prompt collection predicate require-match
9842 initial-input hist def inherit-input-method
9843 str-command buf-name)))
9844 (ac-mode 1)
9845 ;; When exiting minibuffer, `this-command' is set to
9846 ;; `anything-exit-minibuffer', which is unwanted when starting
9847 ;; on another `completing-read', so restore `this-command' to
9848 ;; initial value when exiting.
9849 (setq this-command current-command))))
9851 (defun* anything-generic-read-file-name
9852 (prompt &optional dir default-filename mustmatch initial predicate)
9853 "An anything replacement of `read-file-name'."
9854 (declare (special anything-completion-mode))
9855 (let* ((default (and default-filename
9856 (if (listp default-filename)
9857 (car default-filename)
9858 default-filename)))
9859 (init (or default initial dir default-directory))
9860 (ini-input (and init (expand-file-name init)))
9861 (current-command this-command)
9862 (str-command (symbol-name current-command))
9863 (anything-file-completion-sources
9864 (cons str-command
9865 (remove str-command anything-file-completion-sources)))
9866 (buf-name (format "*ac-mode-%s*" str-command))
9867 (entry (assq current-command
9868 anything-completing-read-handlers-alist))
9869 (def-com (cdr-safe entry))
9870 (str-defcom (symbol-name def-com))
9871 (def-args (list prompt dir default-filename mustmatch initial predicate))
9872 ;; Append the two extra args needed to set the buffer and source name
9873 ;; in anything specialized functions.
9874 (any-args (append def-args (list str-command buf-name)))
9875 (ido-state ido-mode)
9876 anything-completion-mode-start-message ; Be quiet
9877 anything-completion-mode-quit-message ; Same here
9878 fname)
9879 ;; Some functions that normally call `completing-read' can switch
9880 ;; brutally to `read-file-name' (e.g find-tag), in this case
9881 ;; the anything specialized function will fail because it is build
9882 ;; for `completing-read', so set it to 'incompatible to be sure
9883 ;; we switch to `anything-c-read-file-name' and don't try to call it
9884 ;; with wrong number of args.
9885 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9886 (setq def-com 'incompatible))
9887 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9888 (unless (or (not entry) def-com)
9889 (return-from anything-generic-read-file-name
9890 (unwind-protect
9891 (progn
9892 (ac-mode -1)
9893 (apply read-file-name-function def-args))
9894 (ac-mode 1))))
9895 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9896 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9897 (when (or (eq def-com 'read-file-name)
9898 (eq def-com 'ido-read-file-name)
9899 (and (stringp str-defcom)
9900 (not (string-match "^anything" str-defcom))))
9901 (ac-mode -1))
9902 (unwind-protect
9903 (setq fname
9904 (cond (;; A specialized function exists, run it
9905 ;; with the two extra args specific to anything..
9906 (and def-com anything-completion-mode
9907 (not (eq def-com 'ido-read-file-name))
9908 (not (eq def-com 'incompatible)))
9909 (apply def-com any-args))
9910 (;; Def-com value is `ido-read-file-name'
9911 ;; run it with default args.
9912 (and def-com (eq def-com 'ido-read-file-name))
9913 (ido-mode 1)
9914 (apply def-com def-args))
9915 (;; Def-com value is `read-file-name'
9916 ;; run it with default args.
9917 (eq def-com 'read-file-name)
9918 (apply def-com def-args))
9919 (t ; Fall back to classic `anything-c-read-file-name'.
9920 (anything-c-read-file-name
9921 prompt
9922 :name str-command
9923 :buffer buf-name
9924 :initial-input (expand-file-name init dir)
9925 :alistp nil
9926 :must-match mustmatch
9927 :test predicate))))
9928 (ac-mode 1)
9929 (ido-mode (if ido-state 1 -1))
9930 ;; Same comment as in `anything-completing-read-default'.
9931 (setq this-command current-command))
9932 (if (and mustmatch (not (file-exists-p fname)))
9933 (if (y-or-n-p "File does not exists, create buffer?")
9934 fname (error "Abort file does not exists"))
9935 fname)))
9937 ;;;###autoload
9938 (define-minor-mode anything-completion-mode
9939 "Toggle generic anything completion.
9941 All functions in Emacs that use `completing-read'
9942 or `read-file-name' and friends will use anything interface
9943 when this mode is turned on.
9944 However you can modify this behavior for functions of your choice
9945 with `anything-completing-read-handlers-alist'.
9947 Called with a positive arg, turn on unconditionally, with a
9948 negative arg turn off.
9949 You can turn it on with `ac-mode'.
9951 Some crap emacs functions may not be supported,
9952 e.g `ffap-alternate-file' and maybe others
9953 You can add such functions to `anything-completing-read-handlers-alist'
9954 with a nil value.
9956 Note: This mode will work only partially on Emacs23."
9957 :group 'anything
9958 :global t
9959 :lighter anything-completion-mode-string
9960 (declare (special completing-read-function))
9961 (if anything-completion-mode
9962 (progn
9963 (setq completing-read-function 'anything-completing-read-default
9964 read-file-name-function 'anything-generic-read-file-name)
9965 (message anything-completion-mode-start-message))
9966 (setq completing-read-function (and (fboundp 'completing-read-default)
9967 'completing-read-default)
9968 read-file-name-function (and (fboundp 'read-file-name-default)
9969 'read-file-name-default))
9970 (message anything-completion-mode-quit-message)))
9972 (defalias 'ac-mode 'anything-completion-mode)
9976 ;;; Eshell completion.
9978 ;; Enable like this in .emacs:
9980 ;; (add-hook 'eshell-mode-hook
9981 ;; #'(lambda ()
9982 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9984 (defvar anything-c-source-esh
9985 '((name . "Eshell completions")
9986 (init . (lambda ()
9987 (setq pcomplete-current-completions nil
9988 pcomplete-last-completion-raw nil)
9989 ;; Eshell-command add this hook in all minibuffers
9990 ;; Remove it for the anything one. (Fixed in Emacs24)
9991 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9992 (candidates . anything-esh-get-candidates)
9993 (action . anything-ec-insert))
9994 "Anything source for Eshell completion.")
9996 ;; Internal.
9997 (defvar anything-ec-target "")
9998 (defun anything-ec-insert (candidate)
9999 "Insert CANDIDATE at point.
10000 This is the same as `ac-insert', just inlined here for compatibility."
10001 (let ((pt (point)))
10002 (when (and anything-ec-target
10003 (search-backward anything-ec-target nil t)
10004 (string= (buffer-substring (point) pt) anything-ec-target))
10005 (delete-region (point) pt)))
10006 (insert candidate))
10008 (defun anything-esh-get-candidates ()
10009 "Get candidates for eshell completion using `pcomplete'."
10010 (catch 'pcompleted
10011 (let* ((pcomplete-stub)
10012 pcomplete-seen pcomplete-norm-func
10013 pcomplete-args pcomplete-last pcomplete-index
10014 (pcomplete-autolist pcomplete-autolist)
10015 (pcomplete-suffix-list pcomplete-suffix-list))
10016 (with-anything-current-buffer
10017 (loop
10018 with table = (pcomplete-completions)
10019 with entry = (condition-case nil
10020 ;; For Emacs24
10021 (try-completion anything-pattern (pcomplete-entries))
10022 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10023 (error
10025 (let ((fc (car (last (pcomplete-parse-arguments)))))
10026 ;; Check if last arg require fname completion.
10027 (and (file-name-directory fc) fc))))
10028 for i in (if (listp table) table ; Emacs23 or commands.
10029 (all-completions pcomplete-stub table)) ; Emacs24
10030 for file-cand = (and entry
10031 (if (file-remote-p i) i
10032 (expand-file-name i (file-name-directory entry))))
10033 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
10034 collect file-cand into ls
10035 else collect i into ls
10036 finally return
10037 (if (and entry (not (string= entry "")) (file-exists-p entry))
10038 (append (list (expand-file-name entry default-directory)) ls) ls))))))
10040 ;;; Eshell history.
10043 (defvar anything-c-source-eshell-history
10044 '((name . "Eshell history")
10045 (init . (lambda ()
10046 (let (eshell-hist-ignoredups)
10047 ;; Write the content's of ring to file.
10048 (eshell-write-history eshell-history-file-name t)
10049 (with-current-buffer (anything-candidate-buffer 'global)
10050 (insert-file-contents eshell-history-file-name)))
10051 ;; Same comment as in `anything-c-source-esh'
10052 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
10053 (candidates-in-buffer)
10054 (filtered-candidate-transformer . (lambda (candidates sources)
10055 (reverse candidates)))
10056 (candidate-number-limit . 9999)
10057 (action . (lambda (candidate)
10058 (eshell-kill-input)
10059 (insert candidate))))
10060 "Anything source for Eshell history.")
10063 ;;; Show completion - an alternative of anything-show-completion.el.
10065 ;; Provide show completion with macro `with-anything-show-completion'.
10068 ;; Called each time cursor move in anything-buffer.
10069 (defun anything-c-show-completion ()
10070 (with-anything-current-buffer
10071 (overlay-put anything-c-show-completion-overlay
10072 'display (anything-get-selection))))
10074 (defun anything-c-show-completion-init-overlay (beg end)
10075 (and anything-c-turn-on-show-completion
10076 (setq anything-c-show-completion-overlay (make-overlay beg end))
10077 (overlay-put anything-c-show-completion-overlay
10078 'face 'anything-lisp-show-completion)))
10080 (defmacro with-anything-show-completion (beg end &rest body)
10081 "Show anything candidate in an overlay at point.
10082 BEG and END are the beginning and end position of the current completion
10083 in `anything-current-buffer'.
10084 BODY is an anything call where we want to enable show completion.
10085 If `anything-c-turn-on-show-completion' is nil just do nothing."
10086 (declare (indent 2) (debug t))
10087 `(let ((anything-move-selection-after-hook
10088 (and anything-c-turn-on-show-completion
10089 (append (list 'anything-c-show-completion)
10090 anything-move-selection-after-hook))))
10091 (unwind-protect
10092 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10093 ,@body)
10094 (and anything-c-turn-on-show-completion
10095 (delete-overlay anything-c-show-completion-overlay)))))
10098 ;;; Lisp symbol completion.
10101 ;;;###autoload
10102 (defun anything-lisp-completion-at-point ()
10103 "Anything lisp symbol completion at point."
10104 (interactive)
10105 (let* ((data (lisp-completion-at-point))
10106 (beg (car data))
10107 (end (point)) ; 'cadr data' is wrong when no space after point.
10108 (plist (nthcdr 3 data))
10109 (pred (plist-get plist :predicate))
10110 (lgst-len 0)
10111 (target (and beg end (buffer-substring-no-properties beg end)))
10112 (candidates (all-completions target (nth 2 data) pred))
10113 (anything-quit-if-no-candidate t)
10114 (anything-execute-action-at-once-if-one t)
10115 (anything-match-plugin-enabled
10116 (member 'anything-compile-source--match-plugin
10117 anything-compile-source-functions)))
10118 (if candidates
10119 (with-anything-show-completion beg end
10120 ;; Overlay is initialized now in anything-current-buffer.
10121 (anything
10122 :sources
10123 '((name . "Lisp completion")
10124 (init . (lambda ()
10125 (with-current-buffer (anything-candidate-buffer 'global)
10126 (loop for sym in candidates
10127 for len = (length sym)
10128 when (> len lgst-len) do (setq lgst-len len)
10129 do (insert (concat sym "\n"))))))
10130 (candidates-in-buffer)
10131 (persistent-action . anything-lisp-completion-persistent-action)
10132 (persistent-help . "Show brief doc in mode-line")
10133 (filtered-candidate-transformer anything-lisp-completion-transformer)
10134 (action . (lambda (candidate)
10135 (delete-region beg end)
10136 (insert candidate))))
10137 :input (if anything-match-plugin-enabled (concat target " ") target)))
10138 (message "[No Match]"))))
10140 (defun anything-lisp-completion-persistent-action (candidate)
10141 (let ((cursor-in-echo-area t)
10142 mode-line-in-non-selected-windows)
10143 (anything-c-show-info-in-mode-line
10144 (propertize
10145 (anything-c-get-first-line-documentation
10146 (intern candidate))
10147 'face 'anything-lisp-completion-info))))
10149 (defun anything-lisp-completion-transformer (candidates source)
10150 "Anything candidates transformer for lisp completion."
10151 (declare (special lgst-len))
10152 (loop for c in candidates
10153 for sym = (intern c)
10154 for annot = (cond ((commandp sym) " (Com)")
10155 ((fboundp sym) " (Fun)")
10156 ((boundp sym) " (Var)")
10157 ((facep sym) " (Face)"))
10158 for spaces = (make-string (- lgst-len (length c)) ? )
10159 collect (cons (concat c spaces annot) c)))
10161 (defun anything-c-get-first-line-documentation (sym)
10162 "Return first line documentation of symbol SYM.
10163 If SYM is not documented, return \"Not documented\"."
10164 (let ((doc (cond ((fboundp sym)
10165 (documentation sym t))
10166 ((boundp sym)
10167 (documentation-property sym 'variable-documentation t))
10168 ((facep sym)
10169 (face-documentation sym))
10170 (t nil))))
10171 (if (and doc (not (string= doc ""))
10172 ;; `documentation' return "\n\n(args...)"
10173 ;; for CL-style functions.
10174 (not (string-match-p "^\n\n" doc)))
10175 (car (split-string doc "\n"))
10176 "Not documented")))
10178 ;;; File completion.
10180 ;; Complete file name at point.
10181 (defun anything-c-thing-before-point ()
10182 "Get symbol name before point.
10183 Borrowed from anything-complete.el, inlined here for compatibility."
10184 (save-excursion
10185 (let ((beg (point)))
10186 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10187 (when (re-search-backward
10188 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10189 (buffer-substring-no-properties beg (match-end 0))))))
10191 ;;;###autoload
10192 (defun anything-c-complete-file-name-at-point ()
10193 "Complete file name at point."
10194 (interactive)
10195 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10196 (end (point))
10197 (beg (- (point) (length init)))
10198 (anything-quit-if-no-candidate t)
10199 (anything-execute-action-at-once-if-one t)
10200 completion)
10201 (with-anything-show-completion beg end
10202 (setq completion (anything-c-read-file-name "FileName: "
10203 :initial-input init)))
10204 (anything-c-insert-file-name-completion-at-point completion)))
10206 ;; Internal
10207 (defvar anything-lisp-completion-counter 0)
10208 ;;;###autoload
10209 (defun anything-lisp-completion-at-point-or-indent (arg)
10210 "First call indent and second call complete lisp symbol.
10211 The second call should happen before `anything-lisp-completion-or-indent-delay',
10212 after this delay, next call will indent again.
10213 After completion, next call is always indent.
10214 See that like click and double mouse click.
10215 One hit indent, two quick hits maybe indent and complete."
10216 (interactive "P")
10217 ;; Be sure `indent-for-tab-command' will not try
10218 ;; to use `completion-at-point'.
10219 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10220 t tab-always-indent)))
10221 (incf anything-lisp-completion-counter)
10222 (unwind-protect
10223 (if (> anything-lisp-completion-counter 1)
10224 (anything-lisp-completion-or-file-name-at-point)
10225 (indent-for-tab-command arg))
10226 ;; After `anything-lisp-completion-or-indent-delay' seconds
10227 ;; reset to 0.
10228 (run-with-timer anything-lisp-completion-or-indent-delay nil
10229 #'(lambda ()
10230 (setq anything-lisp-completion-counter 0)))
10231 ;; Always reset to 0 at second hit.
10232 (when (eq anything-lisp-completion-counter 2)
10233 (setq anything-lisp-completion-counter 0)))))
10235 ;;;###autoload
10236 (defun anything-lisp-completion-or-file-name-at-point ()
10237 "Complete lisp symbol or filename at point.
10238 Filename completion happen if filename is started in
10239 or between double quotes."
10240 (interactive)
10241 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10242 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10243 (save-excursion (search-backward "\"" (point-at-bol) t)))
10244 (anything-c-complete-file-name-at-point)
10245 (anything-lisp-completion-at-point))))
10247 (defun anything-c-apropos-init (test default)
10248 "Init candidates buffer for `anything-c-apropos' sources."
10249 (with-current-buffer (anything-candidate-buffer 'global)
10250 (goto-char (point-min))
10251 (when (and default (stringp default)
10252 ;; Some defaults args result as
10253 ;; (symbol-name nil) == "nil".
10254 ;; e.g debug-on-entry.
10255 (not (string= default "nil"))
10256 (funcall test (intern default)))
10257 (insert (concat default "\n")))
10258 (loop with all = (all-completions "" obarray test)
10259 for sym in all
10260 unless (and default (eq sym default))
10261 do (insert (concat sym "\n")))))
10264 ;;; Run Externals commands within Emacs with anything completion
10267 (defvar anything-external-command-history nil)
10269 (defun anything-c-external-commands-list-1 (&optional sort)
10270 "Returns a list of all external commands the user can execute.
10271 If `anything-c-external-commands-list' is non-nil it will
10272 return its contents. Else it calculates all external commands
10273 and sets `anything-c-external-commands-list'."
10274 (if anything-c-external-commands-list
10275 anything-c-external-commands-list
10276 (setq anything-c-external-commands-list
10277 (loop
10278 with paths = (split-string (getenv "PATH") path-separator)
10279 with completions = ()
10280 for dir in paths
10281 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10282 for lsdir = (loop for i in (directory-files dir t)
10283 for bn = (file-name-nondirectory i)
10284 when (and (not (member bn completions))
10285 (not (file-directory-p i))
10286 (file-executable-p i))
10287 collect bn)
10288 append lsdir into completions
10289 finally return (if sort (sort completions 'string-lessp) completions)))))
10291 (defun anything-run-or-raise (exe &optional file)
10292 "Generic command that run asynchronously EXE.
10293 If EXE is already running just jump to his window if `anything-raise-command'
10294 is non--nil.
10295 When FILE argument is provided run EXE with FILE.
10296 In this case EXE must be provided as \"EXE %s\"."
10297 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10298 "%s" "" exe))))
10299 (proc (if file (concat real-com " " file) real-com)))
10300 (if (get-process proc)
10301 (if anything-raise-command
10302 (shell-command (format anything-raise-command real-com))
10303 (error "Error: %s is already running" real-com))
10304 (when (loop for i in anything-c-external-commands-list thereis real-com)
10305 (message "Starting %s..." real-com)
10306 (if file
10307 (start-process-shell-command
10308 proc nil (format exe (shell-quote-argument
10309 (if (eq system-type 'windows-nt)
10310 (anything-w32-prepare-filename file)
10311 file))))
10312 (start-process-shell-command proc nil real-com))
10313 (set-process-sentinel
10314 (get-process proc)
10315 #'(lambda (process event)
10316 (when (and (string= event "finished\n")
10317 anything-raise-command
10318 (not (anything-c-get-pid-from-process-name real-com)))
10319 (shell-command (format anything-raise-command "emacs")))
10320 (message "%s process...Finished." process))))
10321 (setq anything-c-external-commands-list
10322 (cons real-com
10323 (delete real-com anything-c-external-commands-list))))))
10327 ;;; Generic action functions
10330 (defun anything-c-file-buffers (filename)
10331 "Returns a list of buffer names corresponding to FILENAME."
10332 (let ((name (expand-file-name filename))
10333 (buf-list ()))
10334 (dolist (buf (buffer-list) buf-list)
10335 (let ((bfn (buffer-file-name buf)))
10336 (when (and bfn (string= name bfn))
10337 (push (buffer-name buf) buf-list))))))
10339 (defun anything-revert-buffer (candidate)
10340 (with-current-buffer candidate
10341 (when (or (buffer-modified-p)
10342 (not (verify-visited-file-modtime
10343 (get-buffer candidate))))
10344 (revert-buffer t t))))
10346 (defun anything-revert-marked-buffers (ignore)
10347 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10349 (defun anything-kill-marked-buffers (ignore)
10350 (mapc 'kill-buffer (anything-marked-candidates)))
10352 (defun anything-c-delete-file (file &optional error-if-dot-file-p)
10353 "Delete the given file after querying the user.
10354 Ask to kill buffers associated with that file, too."
10355 (when (and error-if-dot-file-p
10356 (anything-ff-dot-file-p file))
10357 (error "Error: Cannot operate on `.' or `..'"))
10358 (let ((buffers (anything-c-file-buffers file)))
10359 (if (< emacs-major-version 24)
10360 ;; `dired-delete-file' in Emacs versions < 24
10361 ;; doesn't support delete-by-moving-to-trash
10362 ;; so use `delete-directory' and `delete-file'
10363 ;; that handle it.
10364 (cond ((and (not (file-symlink-p file))
10365 (file-directory-p file)
10366 (directory-files file t dired-re-no-dot))
10367 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10368 (delete-directory file 'recursive)))
10369 ((and (not (file-symlink-p file))
10370 (file-directory-p file))
10371 (delete-directory file))
10372 (t (delete-file file)))
10373 (dired-delete-file
10374 file 'dired-recursive-deletes delete-by-moving-to-trash))
10375 (when buffers
10376 (dolist (buf buffers)
10377 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10378 (kill-buffer buf))))))
10380 (defun anything-get-mailcap-for-file (filename)
10381 "Get the command to use for FILENAME from mailcap files.
10382 The command is like <command %s> and is meant to use with `format'."
10383 (mailcap-parse-mailcaps)
10384 (let* ((ext (file-name-extension filename))
10385 (mime (when ext (mailcap-extension-to-mime ext)))
10386 (result (when mime (mailcap-mime-info mime))))
10387 ;; If elisp file have no associations in .mailcap
10388 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10389 (when (stringp result) result)))
10391 (defun anything-get-default-program-for-file (filename)
10392 "Try to find a default program to open FILENAME.
10393 Try first in `anything-c-external-programs-associations' and then in mailcap file
10394 if nothing found return nil."
10395 (let* ((ext (file-name-extension filename))
10396 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10397 (cond ((and def-prog (not (string= def-prog "")))
10398 (concat def-prog " %s"))
10399 ((and anything-c-default-external-file-browser
10400 (file-directory-p filename))
10401 (concat anything-c-default-external-file-browser " %s"))
10402 (t (anything-get-mailcap-for-file filename)))))
10404 (defun anything-c-open-file-externally (file)
10405 "Open FILE with an external program.
10406 Try to guess which program to use with `anything-get-default-program-for-file'.
10407 If not found or a prefix arg is given query the user which tool to use."
10408 (let* ((fname (expand-file-name file))
10409 (collection (anything-c-external-commands-list-1 'sort))
10410 (def-prog (anything-get-default-program-for-file fname))
10411 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10412 ;; Prefix arg or no default program.
10413 (prog1
10414 (anything-comp-read
10415 "Program: " collection
10416 :must-match t
10417 :name "Open file Externally"
10418 :history anything-external-command-history)
10419 ;; Always prompt to set this program as default.
10420 (setq def-prog nil))
10421 ;; No prefix arg or default program exists.
10422 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10423 (program (concat real-prog-name " %s")))
10424 (unless (or def-prog ; Association exists, no need to record it.
10425 ;; Don't try to record non--filenames associations (e.g urls).
10426 (not (file-exists-p fname)))
10427 (when
10428 (y-or-n-p
10429 (format
10430 "Do you want to make `%s' the default program for this kind of files? "
10431 real-prog-name))
10432 (anything-aif (assoc (file-name-extension fname)
10433 anything-c-external-programs-associations)
10434 (setq anything-c-external-programs-associations
10435 (delete it anything-c-external-programs-associations)))
10436 (push (cons (file-name-extension fname)
10437 (read-string
10438 "Program (Add args maybe and confirm): " real-prog-name))
10439 anything-c-external-programs-associations)
10440 (customize-save-variable 'anything-c-external-programs-associations
10441 anything-c-external-programs-associations)))
10442 (anything-run-or-raise program file)
10443 (setq anything-external-command-history
10444 (cons real-prog-name
10445 (delete real-prog-name
10446 (loop for i in anything-external-command-history
10447 when (executable-find i) collect i))))))
10449 (defun anything-c-find-file-or-marked (candidate)
10450 "Open file CANDIDATE or open anything marked files in background."
10451 (let ((marked (anything-marked-candidates))
10452 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10453 (find-file-wildcards nil))
10454 (if (> (length marked) 1)
10455 ;; Open all marked files in background and display
10456 ;; the first one.
10457 (progn (mapc 'find-file-noselect (cdr marked))
10458 (find-file (car marked)))
10459 (if (and (not (file-exists-p candidate))
10460 (and ffap-url-regexp
10461 (not (string-match ffap-url-regexp candidate)))
10462 (string-match "/$" candidate))
10463 ;; A a non--existing filename ending with /
10464 ;; Create a directory and jump to it.
10465 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10466 (let ((dirfname (directory-file-name candidate)))
10467 (if (file-exists-p dirfname)
10468 (error "Mkdir: Unable to create directory `%s': file exists."
10469 (anything-c-basename dirfname))
10470 (make-directory candidate 'parent)))
10471 (anything-find-files-1 candidate))
10472 ;; A non--existing filename NOT ending with / or
10473 ;; an existing filename, create or jump to it.
10474 (find-file-at-point (car marked))))))
10476 (defun anything-delete-marked-files (ignore)
10477 (let* ((files (anything-marked-candidates))
10478 (len (length files)))
10479 (if (not (y-or-n-p
10480 (format "Delete *%s File(s):\n%s"
10482 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10483 (message "(No deletions performed)")
10484 (dolist (i files)
10485 (set-text-properties 0 (length i) nil i)
10486 (anything-c-delete-file i anything-ff-signal-error-on-dot-files))
10487 (message "%s File(s) deleted" len))))
10489 (defun anything-ediff-marked-buffers (candidate &optional merge)
10490 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10491 With optional arg MERGE call `ediff-merge-buffers'."
10492 (let ((lg-lst (length (anything-marked-candidates)))
10493 buf1 buf2)
10494 (case lg-lst
10496 (error "Error:You have to mark at least 1 buffer"))
10498 (setq buf1 anything-current-buffer
10499 buf2 (first (anything-marked-candidates))))
10501 (setq buf1 (first (anything-marked-candidates))
10502 buf2 (second (anything-marked-candidates))))
10504 (error "Error:To much buffers marked!")))
10505 (if merge
10506 (ediff-merge-buffers buf1 buf2)
10507 (ediff-buffers buf1 buf2))))
10509 (defun anything-ediff-marked-buffers-merge (candidate)
10510 "Ediff merge `anything-current-buffer' with CANDIDATE.
10511 See `anything-ediff-marked-buffers'."
10512 (anything-ediff-marked-buffers candidate t))
10514 (defun anything-bookmark-get-bookmark-from-name (bmk)
10515 "Return bookmark name even if it is a bookmark with annotation.
10516 e.g prepended with *.
10517 Return nil if bmk is not a valid bookmark."
10518 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10519 (if (assoc bookmark bookmark-alist)
10520 bookmark
10521 (when (assoc bmk bookmark-alist)
10522 bmk))))
10524 (defun anything-delete-marked-bookmarks (ignore)
10525 "Delete this bookmark or all marked bookmarks."
10526 (dolist (i (anything-marked-candidates))
10527 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10528 'batch)))
10530 (defun anything-require-or-error (feature function)
10531 (or (require feature nil t)
10532 (error "Need %s to use `%s'." feature function)))
10534 (defun anything-find-buffer-on-elscreen (candidate)
10535 "Open buffer in new screen, if marked buffers open all in elscreens."
10536 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10537 (anything-aif (anything-marked-candidates)
10538 (dolist (i it)
10539 (let ((target-screen (elscreen-find-screen-by-buffer
10540 (get-buffer i) 'create)))
10541 (elscreen-goto target-screen)))
10542 (let ((target-screen (elscreen-find-screen-by-buffer
10543 (get-buffer candidate) 'create)))
10544 (elscreen-goto target-screen))))
10546 (defun anything-elscreen-find-file (file)
10547 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10548 (elscreen-find-file file))
10550 (defun anything-w32-prepare-filename (file)
10551 "Convert filename FILE to something usable by external w32 executables."
10552 (replace-regexp-in-string ; For UNC paths
10553 "/" "\\"
10554 (replace-regexp-in-string ; Strip cygdrive paths
10555 "/cygdrive/\\(.\\)" "\\1:"
10556 file nil nil) nil t))
10558 ;;;###autoload
10559 (defun anything-w32-shell-execute-open-file (file)
10560 (interactive "fOpen file:")
10561 (with-no-warnings
10562 (w32-shell-execute "open" (anything-w32-prepare-filename file))))
10564 (defun anything-c-open-file-with-default-tool (file)
10565 "Open FILE with the default tool on this platform."
10566 (if (eq system-type 'windows-nt)
10567 (anything-w32-shell-execute-open-file file)
10568 (start-process "anything-c-open-file-with-default-tool"
10570 (cond ((eq system-type 'gnu/linux)
10571 "xdg-open")
10572 ((or (eq system-type 'darwin) ;; Mac OS X
10573 (eq system-type 'macos)) ;; Mac OS 9
10574 "open"))
10575 file)))
10577 (defun anything-c-open-dired (file)
10578 "Opens a dired buffer in FILE's directory. If FILE is a
10579 directory, open this directory."
10580 (if (file-directory-p file)
10581 (dired file)
10582 (dired (file-name-directory file))
10583 (dired-goto-file file)))
10585 (defun anything-c-display-to-real-line (candidate)
10586 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10587 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10588 (error "Line number not found")))
10590 (defun anything-c-action-line-goto (lineno-and-content)
10591 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10592 (append lineno-and-content
10593 (list (if (and (anything-attr-defined 'target-file)
10594 (not anything-in-persistent-action))
10595 'find-file-other-window
10596 'find-file)))))
10598 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10599 (apply #'anything-goto-file-line
10600 (if (stringp file-line-content)
10601 ;; Case: filtered-candidate-transformer is skipped
10602 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10603 file-line-content)))
10605 (require 'compile)
10606 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10607 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10609 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10610 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10611 (let ((filename (match-string 1 candidate))
10612 (lineno (match-string 2 candidate))
10613 (content (match-string 3 candidate)))
10614 (cons (format "%s:%s\n %s"
10615 (propertize filename 'face compilation-info-face)
10616 (propertize lineno 'face compilation-line-face)
10617 content)
10618 (list (expand-file-name
10619 filename
10620 (or (anything-interpret-value (anything-attr 'default-directory))
10621 (and (anything-candidate-buffer)
10622 (buffer-local-value
10623 'default-directory (anything-candidate-buffer)))))
10624 (string-to-number lineno) content)))))
10626 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10627 (anything-aif (anything-attr 'before-jump-hook)
10628 (funcall it))
10629 (when file (funcall find-file-function file))
10630 (if (anything-attr-defined 'adjust)
10631 (anything-c-goto-line-with-adjustment lineno content)
10632 (anything-goto-line lineno))
10633 (unless (anything-attr-defined 'recenter)
10634 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10635 (anything-aif (anything-attr 'after-jump-hook)
10636 (funcall it))
10637 (when anything-in-persistent-action
10638 (anything-match-line-color-current-line)))
10640 (defun anything-find-file-as-root (candidate)
10641 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10643 (defun anything-find-many-files (ignore)
10644 (mapc 'find-file (anything-marked-candidates)))
10646 ;; borrowed from etags.el
10647 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10648 (defun anything-c-goto-line-with-adjustment (line line-content)
10649 (let ((startpos)
10650 offset found pat)
10651 ;; This constant is 1/2 the initial search window.
10652 ;; There is no sense in making it too small,
10653 ;; since just going around the loop once probably
10654 ;; costs about as much as searching 2000 chars.
10655 (setq offset 1000
10656 found nil
10657 pat (concat (if (eq selective-display t)
10658 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10659 (regexp-quote line-content)))
10660 ;; If no char pos was given, try the given line number.
10661 (setq startpos (progn (anything-goto-line line) (point)))
10662 (or startpos (setq startpos (point-min)))
10663 ;; First see if the tag is right at the specified location.
10664 (goto-char startpos)
10665 (setq found (looking-at pat))
10666 (while (and (not found)
10667 (progn
10668 (goto-char (- startpos offset))
10669 (not (bobp))))
10670 (setq found
10671 (re-search-forward pat (+ startpos offset) t)
10672 offset (* 3 offset))) ; expand search window
10673 (or found
10674 (re-search-forward pat nil t)
10675 (error "not found")))
10676 ;; Position point at the right place
10677 ;; if the search string matched an extra Ctrl-m at the beginning.
10678 (and (eq selective-display t)
10679 (looking-at "\^m")
10680 (forward-char 1))
10681 (beginning-of-line))
10683 (anything-document-attribute 'default-directory "type . file-line"
10684 "`default-directory' to interpret file.")
10685 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10686 "Function to call before jumping to the target location.")
10687 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10688 "Function to call after jumping to the target location.")
10689 (anything-document-attribute 'adjust "type . file-line"
10690 "Search around line matching line contents.")
10691 (anything-document-attribute 'recenter "type . file-line / line"
10692 "`recenter' after jumping.")
10693 (anything-document-attribute 'target-file "type . line"
10694 "Goto line of target-file.")
10696 ;;;###autoload
10697 (defun anything-c-call-interactively (cmd-or-name)
10698 "Execute CMD-OR-NAME as Emacs command.
10699 It is added to `extended-command-history'.
10700 `anything-current-prefix-arg' is used as the command's prefix argument."
10701 (setq extended-command-history
10702 (cons (anything-c-stringify cmd-or-name)
10703 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10704 (let ((current-prefix-arg anything-current-prefix-arg)
10705 (cmd (anything-c-symbolify cmd-or-name)))
10706 (if (stringp (symbol-function cmd))
10707 (execute-kbd-macro (symbol-function cmd))
10708 (setq this-command cmd)
10709 (call-interactively cmd))))
10711 ;;;###autoload
10712 (defun anything-c-set-variable (var)
10713 "Set value to VAR interactively."
10714 (interactive)
10715 (let ((sym (anything-c-symbolify var)))
10716 (set sym (eval-minibuffer (format "Set %s: " var)
10717 (prin1-to-string (symbol-value sym))))))
10718 ;; (setq hh 12)
10719 ;; (anything-c-set-variable 'hh)
10723 ;;; Persistent Action Helpers
10726 (defvar anything-match-line-overlay-face nil)
10727 (defvar anything-match-line-overlay nil)
10729 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10730 "Highlight and underline current position"
10731 (let ((args (list (or start (line-beginning-position))
10732 (or end (1+ (line-end-position)))
10733 buf)))
10734 (if (not anything-match-line-overlay)
10735 (setq anything-match-line-overlay (apply 'make-overlay args))
10736 (apply 'move-overlay anything-match-line-overlay args)))
10737 (overlay-put anything-match-line-overlay
10738 'face (or face anything-match-line-overlay-face))
10739 (when rec
10740 (goto-char start)
10741 (recenter)))
10743 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10746 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10748 (defun anything-match-line-cleanup ()
10749 (when anything-match-line-overlay
10750 (delete-overlay anything-match-line-overlay)
10751 (setq anything-match-line-overlay nil)))
10753 (defun anything-match-line-update ()
10754 (when anything-match-line-overlay
10755 (delete-overlay anything-match-line-overlay)
10756 (anything-match-line-color-current-line)))
10758 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10759 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10762 ;;; Actions Transformers
10765 ;;; Files
10766 (defun anything-c-transform-file-load-el (actions candidate)
10767 "Add action to load the file CANDIDATE if it is an emacs lisp
10768 file. Else return ACTIONS unmodified."
10769 (if (member (file-name-extension candidate) '("el" "elc"))
10770 (append actions '(("Load Emacs Lisp File" . load-file)))
10771 actions))
10773 (defun anything-c-transform-file-browse-url (actions candidate)
10774 "Add an action to browse the file CANDIDATE if it in a html
10775 file or URL. Else return ACTIONS unmodified."
10776 (let ((browse-action '("Browse with Browser" . browse-url)))
10777 (cond ((string-match "^http\\|^ftp" candidate)
10778 (cons browse-action actions))
10779 ((string-match "\\.html?$" candidate)
10780 (append actions (list browse-action)))
10781 (t actions))))
10783 ;;; Function
10784 (defun anything-c-transform-function-call-interactively (actions candidate)
10785 "Add an action to call the function CANDIDATE interactively if
10786 it is a command. Else return ACTIONS unmodified."
10787 (if (commandp (intern-soft candidate))
10788 (append actions '(("Call Interactively"
10790 anything-c-call-interactively)))
10791 actions))
10793 ;;;; S-Expressions
10794 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10795 "If CANDIDATE's `car' is a command, then add an action to
10796 evaluate it and put it onto the `command-history'."
10797 (if (commandp (car (read candidate)))
10798 ;; Make it first entry
10799 (cons '("Eval and put onto command-history" .
10800 (lambda (sexp)
10801 (let ((sym (read sexp)))
10802 (eval sym)
10803 (setq command-history
10804 (cons sym command-history)))))
10805 actions)
10806 actions))
10809 ;;; Candidate Transformers
10812 ;;; Buffers
10813 (defun anything-c-skip-boring-buffers (buffers)
10814 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10816 (defun anything-c-skip-current-buffer (buffers)
10817 (if anything-allow-skipping-current-buffer
10818 (remove (buffer-name anything-current-buffer) buffers)
10819 buffers))
10821 (defun anything-c-shadow-boring-buffers (buffers)
10822 "Buffers matching `anything-c-boring-buffer-regexp' will be
10823 displayed with the `file-name-shadow' face if available."
10824 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10826 (defvar anything-c-buffer-display-string-functions
10827 '(anything-c-buffer-display-string--compilation
10828 anything-c-buffer-display-string--shell
10829 anything-c-buffer-display-string--eshell)
10830 "Functions to setup display string for buffer.
10832 Function has one argument, buffer name.
10833 If it returns string, use it.
10834 If it returns nil, display buffer name.
10835 See `anything-c-buffer-display-string--compilation' for example.")
10837 (defun anything-c-transform-buffer-display-string (buffers)
10838 "Setup display string for buffer candidates
10839 using `anything-c-buffer-display-string-functions'."
10840 (loop for buf in buffers
10841 if (consp buf)
10842 collect buf
10843 else
10844 for disp = (progn (set-buffer buf)
10845 (run-hook-with-args-until-success
10846 'anything-c-buffer-display-string-functions buf))
10847 collect (if disp (cons disp buf) buf)))
10849 (defun anything-c-buffer-display-string--compilation (buf)
10850 (anything-aif (car compilation-arguments)
10851 (format "%s: %s [%s]" buf it default-directory)))
10853 (defun anything-c-buffer-display-string--eshell (buf)
10854 (declare (special eshell-history-ring))
10855 (when (eq major-mode 'eshell-mode)
10856 (format "%s: %s [%s]" buf
10857 (ignore-errors (ring-ref eshell-history-ring 0))
10858 default-directory)))
10860 (defun anything-c-buffer-display-string--shell (buf)
10861 (when (eq major-mode 'shell-mode)
10862 (format "%s: %s [%s]" buf
10863 (ignore-errors (ring-ref comint-input-ring 0))
10864 default-directory)))
10866 ;;; Files
10867 (defun anything-c-shadow-boring-files (files)
10868 "Files matching `anything-c-boring-file-regexp' will be
10869 displayed with the `file-name-shadow' face if available."
10870 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10872 (defun anything-c-skip-boring-files (files)
10873 "Files matching `anything-c-boring-file-regexp' will be skipped."
10874 (anything-c-skip-entries files anything-c-boring-file-regexp))
10875 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10877 (defun anything-c-skip-current-file (files)
10878 "Current file will be skipped."
10879 (remove (buffer-file-name anything-current-buffer) files))
10881 (defun anything-c-w32-pathname-transformer (args)
10882 "Change undesirable features of windows pathnames to ones more acceptable to
10883 other candidate transformers."
10884 (if (eq system-type 'windows-nt)
10885 (mapcar (lambda (x)
10886 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10887 (mapcar (lambda (y)
10888 (replace-regexp-in-string "\\\\" "/" y)) args))
10889 args))
10891 (defun anything-c-shorten-home-path (files)
10892 "Replaces /home/user with ~."
10893 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10894 (getenv "HOME"))))
10895 (mapcar (lambda (file)
10896 (if (and (stringp file) (string-match home file))
10897 (cons (replace-match "~" nil nil file) file)
10898 file))
10899 files)))
10901 ;;; Functions
10902 (defun anything-c-mark-interactive-functions (functions)
10903 "Mark interactive functions (commands) with (i) after the function name."
10904 (let (list)
10905 (loop for function in functions
10906 do (push (cons (concat function
10907 (when (commandp (intern-soft function)) " (i)"))
10908 function)
10909 list)
10910 finally (return (nreverse list)))))
10913 ;;; Adaptive Sorting of Candidates
10916 ;; Internal
10917 (defvar anything-c-adaptive-done nil
10918 "nil if history information is not yet stored for the current
10919 selection.")
10921 (defvar anything-c-adaptive-history nil
10922 "Contains the stored history information.
10923 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10925 ;; Should run at beginning of `anything-initial-setup'.
10926 (add-hook 'anything-before-initialize-hook #'(lambda ()
10927 (when anything-c-use-adaptative-sorting
10928 (setq anything-c-adaptive-done nil))))
10930 ;; Should run at beginning of `anything-exit-minibuffer'.
10931 (add-hook 'anything-before-action-hook #'(lambda ()
10932 (when anything-c-use-adaptative-sorting
10933 (anything-c-adaptive-store-selection))))
10935 ;; Should run at beginning of `anything-select-action'.
10936 (add-hook 'anything-select-action-hook #'(lambda ()
10937 (when anything-c-use-adaptative-sorting
10938 (anything-c-adaptive-store-selection))))
10940 (defun anything-c-source-use-adaptative-p (&optional source-name)
10941 "Return current source only if it use adaptative history, nil otherwise."
10942 (when anything-c-use-adaptative-sorting
10943 (let* ((source (or source-name (anything-get-current-source)))
10944 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10945 (assoc (assoc-default 'type source)
10946 anything-type-attributes))
10947 (assoc-default 'candidate-transformer
10948 (assoc (assoc-default 'type source)
10949 anything-type-attributes))
10950 (assoc-default 'filtered-candidate-transformer source)
10951 (assoc-default 'candidate-transformer source))))
10952 (if (listp adapt-source)
10953 (when (member 'anything-c-adaptive-sort adapt-source) source)
10954 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10956 (defun anything-c-adaptive-store-selection ()
10957 "Store history information for the selected candidate."
10958 (unless anything-c-adaptive-done
10959 (setq anything-c-adaptive-done t)
10960 (let ((source (anything-c-source-use-adaptative-p)))
10961 (when source
10962 (let* ((source-name (or (assoc-default 'type source)
10963 (assoc-default 'name source)))
10964 (source-info (or (assoc source-name anything-c-adaptive-history)
10965 (progn
10966 (push (list source-name) anything-c-adaptive-history)
10967 (car anything-c-adaptive-history))))
10968 (selection (anything-get-selection))
10969 (selection-info (progn
10970 (setcdr source-info
10971 (cons
10972 (let ((found (assoc selection (cdr source-info))))
10973 (if (not found)
10974 ;; new entry
10975 (list selection)
10977 ;; move entry to the beginning of the
10978 ;; list, so that it doesn't get
10979 ;; trimmed when the history is
10980 ;; truncated
10981 (setcdr source-info
10982 (delete found (cdr source-info)))
10983 found))
10984 (cdr source-info)))
10985 (cadr source-info)))
10986 (pattern-info (progn
10987 (setcdr selection-info
10988 (cons
10989 (let ((found (assoc anything-pattern (cdr selection-info))))
10990 (if (not found)
10991 ;; new entry
10992 (cons anything-pattern 0)
10994 ;; move entry to the beginning of the
10995 ;; list, so if two patterns used the
10996 ;; same number of times then the one
10997 ;; used last appears first in the list
10998 (setcdr selection-info
10999 (delete found (cdr selection-info)))
11000 found))
11001 (cdr selection-info)))
11002 (cadr selection-info))))
11004 ;; increase usage count
11005 (setcdr pattern-info (1+ (cdr pattern-info)))
11007 ;; truncate history if needed
11008 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
11009 (setcdr selection-info
11010 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
11012 (defun anything-c-adaptative-maybe-load-history ()
11013 (when (and anything-c-use-adaptative-sorting
11014 (file-readable-p anything-c-adaptive-history-file))
11015 (load-file anything-c-adaptive-history-file)))
11017 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
11018 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
11020 (defun anything-c-adaptive-save-history (&optional arg)
11021 "Save history information to file given by `anything-c-adaptive-history-file'."
11022 (interactive "p")
11023 (when anything-c-use-adaptative-sorting
11024 (with-temp-buffer
11025 (insert
11026 ";; -*- mode: emacs-lisp -*-\n"
11027 ";; History entries used for anything adaptive display.\n")
11028 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
11029 (current-buffer))
11030 (insert ?\n)
11031 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11032 (unless arg 'quiet)))))
11034 (defun anything-c-adaptive-sort (candidates source)
11035 "Sort the CANDIDATES for SOURCE by usage frequency.
11036 This is a filtered candidate transformer you can use for the
11037 attribute `filtered-candidate-transformer' of a source in
11038 `anything-sources' or a type in `anything-type-attributes'."
11039 (let* ((source-name (or (assoc-default 'type source)
11040 (assoc-default 'name source)))
11041 (source-info (assoc source-name anything-c-adaptive-history)))
11042 (if source-info
11043 (let ((usage
11044 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11045 ;; pairs
11046 (mapcar (lambda (candidate-info)
11047 (let ((count 0))
11048 (dolist (pattern-info (cdr candidate-info))
11049 (if (not (equal (car pattern-info)
11050 anything-pattern))
11051 (incf count (cdr pattern-info))
11053 ;; if current pattern is equal to the previously
11054 ;; used one then this candidate has priority
11055 ;; (that's why its count is boosted by 10000) and
11056 ;; it only has to compete with other candidates
11057 ;; which were also selected with the same pattern
11058 (setq count (+ 10000 (cdr pattern-info)))
11059 (return)))
11060 (cons (car candidate-info) count)))
11061 (cdr source-info)))
11062 sorted)
11063 (if (and usage (consp usage))
11064 ;; sort the list in descending order, so candidates with highest
11065 ;; priorty come first
11066 (progn
11067 (setq usage (sort usage (lambda (first second)
11068 (> (cdr first) (cdr second)))))
11070 ;; put those candidates first which have the highest usage count
11071 (dolist (info usage)
11072 (when (member* (car info) candidates
11073 :test 'anything-c-adaptive-compare)
11074 (push (car info) sorted)
11075 (setq candidates (remove* (car info) candidates
11076 :test 'anything-c-adaptive-compare))))
11078 ;; and append the rest
11079 (append (reverse sorted) candidates nil))
11080 (message "Your `%s' is maybe corrupted or too old, \
11081 you should reinitialize it with `anything-c-reset-adaptative-history'"
11082 anything-c-adaptive-history-file)
11083 (sit-for 1)
11084 candidates))
11085 ;; if there is no information stored for this source then do nothing
11086 candidates)))
11088 ;;;###autoload
11089 (defun anything-c-reset-adaptative-history ()
11090 "Delete all `anything-c-adaptive-history' and his file.
11091 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11092 (interactive)
11093 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11094 (setq anything-c-adaptive-history nil)
11095 (delete-file anything-c-adaptive-history-file)))
11097 (defun anything-c-adaptive-compare (x y)
11098 "Compare candidates X and Y taking into account that the
11099 candidate can be in (DISPLAY . REAL) format."
11100 (equal (if (listp x)
11101 (cdr x)
11103 (if (listp y)
11104 (cdr y)
11105 y)))
11109 ;;; Outliner
11112 (defvar anything-outline-goto-near-line-flag t)
11113 (defvar anything-outline-using nil)
11114 (defun anything-after-update-hook--outline ()
11115 (if (and (eq anything-outline-using t)
11116 (eq anything-outline-goto-near-line-flag t))
11117 (anything-outline-goto-near-line)))
11118 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11120 (defun anything-outline-goto-near-line ()
11121 (with-anything-window
11122 ;; TODO need consideration whether to update position by every input.
11123 (when t ; (equal anything-pattern "")
11124 (anything-goto-line 2)
11125 (let ((lineno (with-anything-current-buffer
11126 (line-number-at-pos (car anything-current-position)))))
11127 (block exit
11128 (while (<= (progn (skip-chars-forward " ")
11129 (or (number-at-point) lineno))
11130 lineno)
11131 (forward-line 1)
11132 (when (eobp)
11133 (forward-line -1)
11134 (return-from exit))))
11135 (forward-line -1)
11136 (and (bobp) (forward-line 1))
11137 (and (anything-pos-header-line-p) (forward-line -2))
11138 (anything-mark-current-line)))))
11142 ;;; Plug-in
11145 ;; Plug-in: info-index
11146 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11147 (let (result)
11148 (unless (anything-candidate-buffer)
11149 (save-window-excursion
11150 (info file)
11151 (let (Info-history
11152 (tobuf (anything-candidate-buffer 'global))
11153 (infobuf (current-buffer))
11154 s e)
11155 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11156 (Info-goto-node node)
11157 (goto-char (point-min))
11158 (while (search-forward "\n* " nil t)
11159 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11160 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11161 (setq s (point-at-bol)
11162 e (point-at-eol))
11163 (with-current-buffer tobuf
11164 (insert-buffer-substring infobuf s e)
11165 (insert "\n"))))))))))
11167 (defun anything-c-info-goto (node-line)
11168 (Info-goto-node (car node-line))
11169 (anything-goto-line (cdr node-line)))
11171 (defun anything-c-info-display-to-real (line)
11172 (and (string-match
11173 ;; This regexp is stolen from Info-apropos-matches
11174 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11175 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11176 (string-to-number (or (match-string 3 line) "1")))))
11178 (defun anything-c-make-info-source (source file)
11179 `(,@source
11180 (name . ,(concat "Info Index: " file))
11181 (info-file . ,file)
11182 (init . anything-c-info-init)
11183 (display-to-real . anything-c-info-display-to-real)
11184 (get-line . buffer-substring)
11185 (candidates-in-buffer)
11186 (action ("Goto node" . anything-c-info-goto))))
11188 (defun anything-compile-source--info-index (source)
11189 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11190 (anything-c-make-info-source source it)
11191 source))
11192 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11194 (anything-document-attribute 'info-index "info-index plugin"
11195 "Create a source of info index very easily.
11197 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11199 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11200 "Index nodes of info file.
11202 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11203 Some info files are missing index specification.
11205 ex. See `anything-c-source-info-screen'.")
11207 ;; Plug-in: candidates-file
11208 (defun anything-compile-source--candidates-file (source)
11209 (if (assoc-default 'candidates-file source)
11210 `((init anything-p-candidats-file-init
11211 ,@(let ((orig-init (assoc-default 'init source)))
11212 (cond ((null orig-init) nil)
11213 ((functionp orig-init) (list orig-init))
11214 (t orig-init))))
11215 (candidates-in-buffer)
11216 ,@source)
11217 source))
11218 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11220 (defun anything-p-candidats-file-init ()
11221 (destructuring-bind (file &optional updating)
11222 (anything-mklist (anything-attr 'candidates-file))
11223 (setq file (anything-interpret-value file))
11224 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11225 (when updating
11226 (buffer-disable-undo)
11227 (font-lock-mode -1)
11228 (auto-revert-mode 1)))))
11230 (anything-document-attribute 'candidates-file "candidates-file plugin"
11231 "Use a file as the candidates buffer.
11233 1st argument is a filename, string or function name or variable name.
11234 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11236 ;; Plug-in: headline
11237 (defun anything-compile-source--anything-headline (source)
11238 (if (assoc-default 'headline source)
11239 (append '((init . anything-headline-init)
11240 (get-line . buffer-substring)
11241 (type . line))
11242 source
11243 '((candidates-in-buffer)
11244 (persistent-help . "Show this line")))
11245 source))
11246 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11248 (defun anything-headline-init ()
11249 (when (and (anything-current-buffer-is-modified)
11250 (with-anything-current-buffer
11251 (eval (or (anything-attr 'condition) t))))
11252 (anything-headline-make-candidate-buffer
11253 (anything-interpret-value (anything-attr 'headline))
11254 (anything-interpret-value (anything-attr 'subexp)))))
11256 (anything-document-attribute 'headline "Headline plug-in"
11257 "Regexp string for anything-headline to scan.")
11258 (anything-document-attribute 'condition "Headline plug-in"
11259 "A sexp representing the condition to use anything-headline.")
11260 (anything-document-attribute 'subexp "Headline plug-in"
11261 "Display (match-string-no-properties subexp).")
11263 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11264 ;; of regexps.
11266 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11267 ;; 2. Sort this list by start-of-match.
11268 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11270 ;; It's quite brilliantly written.
11274 (defun anything-headline-get-candidates (regexp subexp)
11275 (with-anything-current-buffer
11276 (save-excursion
11277 (goto-char (point-min))
11278 (if (functionp regexp) (setq regexp (funcall regexp)))
11279 (let (hierarchy curhead)
11280 (flet ((matched ()
11281 (if (numberp subexp)
11282 (cons (match-string-no-properties subexp) (match-beginning subexp))
11283 (cons (buffer-substring (point-at-bol) (point-at-eol))
11284 (point-at-bol))))
11285 (hierarchies (headlines)
11286 (1+ (loop for (_ . hierarchy) in headlines
11287 maximize hierarchy)))
11288 (vector-0-n (v n)
11289 (loop for i from 0 to hierarchy
11290 collecting (aref curhead i)))
11291 (arrange (headlines)
11292 (unless (null headlines) ; FIX headlines empty bug!
11293 (loop with curhead = (make-vector (hierarchies headlines) "")
11294 for ((str . pt) . hierarchy) in headlines
11295 do (aset curhead hierarchy str)
11296 collecting
11297 (cons
11298 (format "H%d:%s" (1+ hierarchy)
11299 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11300 pt)))))
11301 (if (listp regexp)
11302 (arrange
11303 (sort
11304 (loop for re in regexp
11305 for hierarchy from 0
11306 do (goto-char (point-min))
11307 appending
11308 (loop
11309 while (re-search-forward re nil t)
11310 collect (cons (matched) hierarchy)))
11311 (lambda (a b) (> (cdar b) (cdar a)))))
11312 (loop while (re-search-forward regexp nil t)
11313 collect (matched))))))))
11316 (defun anything-headline-make-candidate-buffer (regexp subexp)
11317 (with-current-buffer (anything-candidate-buffer 'local)
11318 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11319 do (insert
11320 (format "%5d:%s\n"
11321 (with-anything-current-buffer
11322 (line-number-at-pos pos))
11323 content)))))
11325 (defun anything-headline-goto-position (pos recenter)
11326 (goto-char pos)
11327 (unless recenter
11328 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11331 ;; Plug-in: persistent-help
11332 (defun anything-compile-source--persistent-help (source)
11333 (append source '((header-line . anything-persistent-help-string))))
11334 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11336 (defun anything-persistent-help-string ()
11337 (substitute-command-keys
11338 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11339 (or (anything-interpret-value (anything-attr 'persistent-help))
11340 (anything-aif (or (assoc-default 'persistent-action
11341 (anything-get-current-source))
11342 (assoc-default 'action
11343 (anything-get-current-source)))
11344 (cond ((symbolp it) (symbol-name it))
11345 ((listp it) (or (ignore-errors (caar it)) ""))))
11347 " (keeping session)")))
11349 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11350 "A string to explain persistent-action of this source.
11351 It also accepts a function or a variable name.")
11353 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11355 ;; Plug-in: Type customize
11356 (defun anything-c-uniq-list (lst)
11357 "Like `remove-duplicates' in CL.
11358 But cut deeper duplicates and test by `equal'. "
11359 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11360 (defvar anything-additional-type-attributes nil)
11361 (defun anything-c-arrange-type-attribute (type spec)
11362 "Override type attributes by `define-anything-type-attribute'.
11364 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11366 Example: Set `play-sound-file' as default action
11367 (anything-c-arrange-type-attribute 'file
11368 '((action (\"Play sound\" . play-sound-file)
11369 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11372 (add-to-list 'anything-additional-type-attributes
11373 (cons type
11374 (loop with typeattr = (assoc-default type anything-type-attributes)
11375 for (attr . value) in spec
11376 if (listp value)
11377 collect (cons attr
11378 (anything-c-uniq-list
11379 (loop for v in value
11380 if (eq v 'REST)
11381 append (assoc-default attr typeattr)
11382 else
11383 collect v)))
11384 else
11385 collect (cons attr value)))))
11386 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11388 (defun anything-compile-source--type-customize (source)
11389 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11390 (append it source)
11391 source))
11392 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11394 ;; Plug-in: default-action
11395 (defun anything-compile-source--default-action (source)
11396 (anything-aif (assoc-default 'default-action source)
11397 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11398 source)
11399 source))
11400 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11401 (anything-document-attribute 'default-action "default-action plug-in"
11402 "Default action.")
11405 ;;; Toggle anything-match-plugin
11408 (defvar anything-mp-initial-highlight-delay nil)
11410 ;;;###autoload
11411 (defun anything-c-toggle-match-plugin ()
11412 "Toggle anything-match-plugin."
11413 (interactive)
11414 (let ((anything-match-plugin-enabled
11415 (member 'anything-compile-source--match-plugin
11416 anything-compile-source-functions)))
11417 (flet ((disable-match-plugin ()
11418 (setq anything-compile-source-functions
11419 (delq 'anything-compile-source--match-plugin
11420 anything-compile-source-functions))
11421 (setq anything-mp-initial-highlight-delay
11422 anything-mp-highlight-delay)
11423 (setq anything-mp-highlight-delay nil))
11424 (enable-match-plugin ()
11425 (require 'anything-match-plugin)
11426 (unless anything-mp-initial-highlight-delay
11427 (setq anything-mp-initial-highlight-delay
11428 anything-mp-highlight-delay))
11429 (setq anything-compile-source-functions
11430 (cons 'anything-compile-source--match-plugin
11431 anything-compile-source-functions))
11432 (unless anything-mp-highlight-delay
11433 (setq anything-mp-highlight-delay
11434 anything-mp-initial-highlight-delay))))
11435 (if anything-match-plugin-enabled
11436 (when (y-or-n-p "Really disable match-plugin? ")
11437 (disable-match-plugin)
11438 (message "Anything-match-plugin disabled"))
11439 (when (y-or-n-p "Really enable match-plugin? ")
11440 (enable-match-plugin)
11441 (message "Anything-match-plugin enabled"))))))
11445 ;;; Type Attributes
11448 (define-anything-type-attribute 'buffer
11449 `((action
11450 ("Switch to buffer" . anything-c-switch-to-buffer)
11451 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11452 ("Switch to buffer other window" . switch-to-buffer-other-window)
11453 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11454 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11455 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11456 ("Query replace" . anything-c-buffer-query-replace)
11457 ("View buffer" . view-buffer)
11458 ("Display buffer" . display-buffer)
11459 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11460 ("Revert buffer(s)" . anything-revert-marked-buffers)
11461 ("Insert buffer" . insert-buffer)
11462 ("Kill buffer(s)" . anything-kill-marked-buffers)
11463 ("Diff with file" . diff-buffer-with-file)
11464 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11465 ("Ediff Merge marked buffers" . (lambda (candidate)
11466 (anything-ediff-marked-buffers candidate t))))
11467 (persistent-help . "Show this buffer")
11468 (candidate-transformer anything-c-skip-current-buffer
11469 anything-c-skip-boring-buffers
11470 anything-c-transform-buffer-display-string))
11471 "Buffer or buffer name.")
11473 (define-anything-type-attribute 'file
11474 `((action
11475 ("Find file" . anything-find-many-files)
11476 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11477 ("Find file as root" . anything-find-file-as-root)
11478 ("Find file other window" . find-file-other-window)
11479 ("Find file other frame" . find-file-other-frame)
11480 ("Open dired in file's directory" . anything-c-open-dired)
11481 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11482 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11483 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11484 ("Checksum File" . anything-ff-checksum)
11485 ("Ediff File" . anything-find-files-ediff-files)
11486 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11487 ("View file" . view-file)
11488 ("Insert file" . insert-file)
11489 ("Delete file(s)" . anything-delete-marked-files)
11490 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11491 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11492 ("Find file in hex dump" . hexl-find-file))
11493 (persistent-help . "Show this file")
11494 (action-transformer anything-c-transform-file-load-el
11495 anything-c-transform-file-browse-url)
11496 (candidate-transformer anything-c-w32-pathname-transformer
11497 anything-c-skip-current-file
11498 anything-c-skip-boring-files
11499 anything-c-shorten-home-path))
11500 "File name.")
11502 (let ((actions '(("Describe command" . describe-function)
11503 ("Add command to kill ring" . anything-c-kill-new)
11504 ("Go to command's definition" . find-function)
11505 ("Debug on entry" . debug-on-entry)
11506 ("Cancel debug on entry" . cancel-debug-on-entry)
11507 ("Trace function" . trace-function)
11508 ("Trace function (background)" . trace-function-background)
11509 ("Untrace function" . untrace-function))))
11510 (define-anything-type-attribute 'command
11511 `((action ("Call interactively" . anything-c-call-interactively)
11512 ,@actions)
11513 ;; Sort commands according to their usage count.
11514 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11515 (coerce . anything-c-symbolify)
11516 (persistent-action . describe-function))
11517 "Command. (string or symbol)")
11519 (define-anything-type-attribute 'function
11520 `((action . ,actions)
11521 (action-transformer anything-c-transform-function-call-interactively)
11522 (candidate-transformer anything-c-mark-interactive-functions)
11523 (coerce . anything-c-symbolify))
11524 "Function. (string or symbol)"))
11526 (define-anything-type-attribute 'variable
11527 '((action ("Describe variable" . describe-variable)
11528 ("Add variable to kill ring" . anything-c-kill-new)
11529 ("Go to variable's definition" . find-variable)
11530 ("Set variable" . anything-c-set-variable))
11531 (coerce . anything-c-symbolify))
11532 "Variable.")
11534 (define-anything-type-attribute 'sexp
11535 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11536 ("Add s-expression to kill ring" . kill-new))
11537 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11538 "String representing S-Expressions.")
11540 (define-anything-type-attribute 'bookmark
11541 `((coerce . anything-bookmark-get-bookmark-from-name)
11542 (action
11543 ("Jump to bookmark" . (lambda (bookmark)
11544 (let ((current-prefix-arg anything-current-prefix-arg))
11545 (bookmark-jump bookmark))
11546 (anything-update)))
11547 ("Jump to BM other window" . (lambda (bookmark)
11548 (bookmark-jump-other-window bookmark)
11549 (anything-update)))
11550 ("Bookmark edit annotation" . bookmark-edit-annotation)
11551 ("Bookmark show annotation" . bookmark-show-annotation)
11552 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11553 ,@(and (locate-library "bookmark-extensions")
11554 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11555 ("Rename bookmark" . bookmark-rename)
11556 ("Relocate bookmark" . bookmark-relocate)))
11557 "Bookmark name.")
11559 (define-anything-type-attribute 'line
11560 '((display-to-real . anything-c-display-to-real-line)
11561 (action ("Go to Line" . anything-c-action-line-goto)))
11562 "LINENO:CONTENT string, eg. \" 16:foo\".
11564 Optional `target-file' attribute is a name of target file.
11566 Optional `before-jump-hook' attribute is a function with no
11567 arguments which is called before jumping to position.
11569 Optional `after-jump-hook' attribute is a function with no
11570 arguments which is called after jumping to position.
11572 If `adjust' attribute is specified, searches the line whose
11573 content is CONTENT near the LINENO.
11575 If `recenter' attribute is specified, the line is displayed at
11576 the center of window, otherwise at the top of window.
11579 (define-anything-type-attribute 'file-line
11580 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11581 (multiline)
11582 (action ("Go to" . anything-c-action-file-line-goto)))
11583 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11585 Optional `default-directory' attribute is a default-directory
11586 FILENAME is interpreted.
11588 Optional `before-jump-hook' attribute is a function with no
11589 arguments which is called before jumping to position.
11591 Optional `after-jump-hook' attribute is a function with no
11592 arguments which is called after jumping to position.
11594 If `adjust' attribute is specified, searches the line whose
11595 content is CONTENT near the LINENO.
11597 If `recenter' attribute is specified, the line is displayed at
11598 the center of window, otherwise at the top of window.
11601 (define-anything-type-attribute 'timer
11602 '((real-to-display . anything-c-timer-real-to-display)
11603 (action ("Cancel Timer" . cancel-timer)
11604 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11605 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11606 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11607 (persistent-help . "Describe Function"))
11608 "Timer.")
11611 ;;; Default `anything-sources'
11612 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11613 ;; tend to invoke M-x anything directly. So I offer default setting.
11614 (setq anything-sources
11615 '(anything-c-source-buffers-list
11616 anything-c-source-recentf
11617 anything-c-source-files-in-current-dir+))
11620 ;;; Preconfigured Anything
11623 ;;;###autoload
11624 (defun anything-mini ()
11625 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11626 (interactive)
11627 (anything-other-buffer '(anything-c-source-buffers-list
11628 anything-c-source-recentf
11629 anything-c-source-buffer-not-found)
11630 "*anything mini*"))
11631 ;;;###autoload
11632 (defun anything-for-files ()
11633 "Preconfigured `anything' for opening files.
11634 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11635 (interactive)
11636 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11638 ;;;###autoload
11639 (defun anything-recentf ()
11640 "Preconfigured `anything' for `recentf'."
11641 (interactive)
11642 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11644 ;;;###autoload
11645 (defun anything-info-at-point (arg)
11646 "Preconfigured `anything' for searching info at point.
11647 With a prefix-arg insert symbol at point."
11648 (interactive "P")
11649 (let ((anything-c-google-suggest-default-function
11650 'anything-c-google-suggest-emacs-lisp))
11651 (anything :sources '(anything-c-source-info-elisp
11652 anything-c-source-info-cl
11653 anything-c-source-info-pages
11654 anything-c-source-google-suggest)
11655 :input (and arg (thing-at-point 'symbol))
11656 :buffer "*anything info*")))
11658 ;;;###autoload
11659 (defun anything-info-emacs ()
11660 "Preconfigured anything for Emacs manual index."
11661 (interactive)
11662 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11664 ;;;###autoload
11665 (defun anything-show-kill-ring ()
11666 "Preconfigured `anything' for `kill-ring'.
11667 It is drop-in replacement of `yank-pop'.
11668 You may bind this command to M-y.
11669 First call open the kill-ring browser, next calls move to next line."
11670 (interactive)
11671 (let ((buf "*anything kill-ring*"))
11672 (if (get-buffer-window buf)
11673 (with-anything-window
11674 (if (eq (overlay-end anything-selection-overlay) (point-max))
11675 (anything-beginning-of-buffer)
11676 (anything-next-line)))
11677 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11679 ;;;###autoload
11680 (defun anything-minibuffer-history ()
11681 "Preconfigured `anything' for `minibuffer-history'."
11682 (interactive)
11683 (let ((enable-recursive-minibuffers t))
11684 (anything-other-buffer 'anything-c-source-minibuffer-history
11685 "*anything minibuffer-history*")))
11687 ;;;###autoload
11688 (defun anything-gentoo ()
11689 "Preconfigured `anything' for gentoo linux."
11690 (interactive)
11691 (anything-other-buffer '(anything-c-source-gentoo
11692 anything-c-source-use-flags)
11693 "*anything gentoo*"))
11695 ;;;###autoload
11696 (defun anything-imenu ()
11697 "Preconfigured `anything' for `imenu'."
11698 (interactive)
11699 (anything :sources 'anything-c-source-imenu
11700 :buffer "*anything imenu*"))
11702 ;;;###autoload
11703 (defun anything-google-suggest ()
11704 "Preconfigured `anything' for google search with google suggest."
11705 (interactive)
11706 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11708 ;;;###autoload
11709 (defun anything-yahoo-suggest ()
11710 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11711 (interactive)
11712 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11714 ;;; Converted from anything-show-*-only
11715 ;;;###autoload
11716 (defun anything-for-buffers ()
11717 "Preconfigured `anything' for buffer."
11718 (interactive)
11719 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11721 ;;;###autoload
11722 (defun anything-buffers-list ()
11723 "Enhanced preconfigured `anything' for buffer."
11724 (interactive)
11725 (anything :sources '(anything-c-source-buffers-list
11726 anything-c-source-buffer-not-found)
11727 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11728 (defalias 'anything-buffers+ 'anything-buffer-list)
11729 ;;;###autoload
11730 (defun anything-bbdb ()
11731 "Preconfigured `anything' for BBDB.
11733 Needs BBDB.
11735 http://bbdb.sourceforge.net/"
11736 (interactive)
11737 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11739 ;;;###autoload
11740 (defun anything-locate (arg)
11741 "Preconfigured `anything' for Locate.
11742 Note: you can add locate options after entering pattern.
11743 See 'man locate' for valid options.
11745 You can specify a specific database with prefix argument ARG \(C-u\).
11746 Many databases can be used: navigate and mark them.
11747 See also `anything-locate-with-db'.
11749 To create a user specific db, use
11750 \"updatedb -l 0 -o db_path -U directory\".
11751 Where db_path is a filename matched by
11752 `anything-locate-db-file-regexp'."
11753 (interactive "P")
11754 (anything-locate-1 arg))
11756 ;;;###autoload
11757 (defun anything-w3m-bookmarks ()
11758 "Preconfigured `anything' for w3m bookmark.
11760 Needs w3m and emacs-w3m.
11762 http://w3m.sourceforge.net/
11763 http://emacs-w3m.namazu.org/"
11764 (interactive)
11765 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11766 "*anything w3m bookmarks*"))
11768 ;;;###autoload
11769 (defun anything-firefox-bookmarks ()
11770 "Preconfigured `anything' for firefox bookmark.
11771 You will have to enable html bookmarks in firefox:
11772 open about:config in firefox and double click on this line to enable value \
11773 to true:
11775 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11777 You should have now:
11779 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11781 After closing firefox, you will be able to browse you bookmarks.
11783 (interactive)
11784 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11785 "*Anything Firefox*"))
11787 ;;;###autoload
11788 (defun anything-colors ()
11789 "Preconfigured `anything' for color."
11790 (interactive)
11791 (anything-other-buffer
11792 '(anything-c-source-colors anything-c-source-customize-face)
11793 "*anything colors*"))
11795 ;;;###autoload
11796 (defun anything-bookmarks ()
11797 "Preconfigured `anything' for bookmarks."
11798 (interactive)
11799 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11801 ;;;###autoload
11802 (defun anything-c-pp-bookmarks ()
11803 "Preconfigured `anything' for bookmarks (pretty-printed)."
11804 (interactive)
11805 (anything-other-buffer '(anything-c-source-bookmarks-local
11806 anything-c-source-bookmarks-su
11807 anything-c-source-bookmarks-ssh)
11808 "*anything pp bookmarks*"))
11810 ;;;###autoload
11811 (defun anything-c-insert-latex-math ()
11812 "Preconfigured anything for latex math symbols completion."
11813 (interactive)
11814 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11816 ;;;###autoload
11817 (defun anything-register ()
11818 "Preconfigured `anything' for Emacs registers."
11819 (interactive)
11820 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11822 ;;;###autoload
11823 (defun anything-man-woman ()
11824 "Preconfigured `anything' for Man and Woman pages."
11825 (interactive)
11826 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11828 ;;;###autoload
11829 (defun anything-org-keywords ()
11830 "Preconfigured `anything' for org keywords."
11831 (interactive)
11832 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11834 ;;;###autoload
11835 (defun anything-emms ()
11836 "Preconfigured `anything' for emms sources."
11837 (interactive)
11838 (anything :sources '(anything-c-source-emms-streams
11839 anything-c-source-emms-files
11840 anything-c-source-emms-dired)
11841 :buffer "*Anything Emms*"))
11843 ;;;###autoload
11844 (defun anything-eev-anchors ()
11845 "Preconfigured `anything' for eev anchors."
11846 (interactive)
11847 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11849 ;;;###autoload
11850 (defun anything-bm-list ()
11851 "Preconfigured `anything' for visible bookmarks.
11853 Needs bm.el
11855 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11856 (interactive)
11857 (let ((anything-outline-using t))
11858 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11860 ;;;###autoload
11861 (defun anything-timers ()
11862 "Preconfigured `anything' for timers."
11863 (interactive)
11864 (anything-other-buffer '(anything-c-source-absolute-time-timers
11865 anything-c-source-idle-time-timers)
11866 "*anything timers*"))
11868 ;;;###autoload
11869 (defun anything-list-emacs-process ()
11870 "Preconfigured `anything' for emacs process."
11871 (interactive)
11872 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11874 ;;;###autoload
11875 (defun anything-occur ()
11876 "Preconfigured Anything for Occur source.
11877 If region is active, search only in region,
11878 otherwise search in whole buffer."
11879 (interactive)
11880 (let ((anything-compile-source-functions
11881 ;; rule out anything-match-plugin because the input is one regexp.
11882 (delq 'anything-compile-source--match-plugin
11883 (copy-sequence anything-compile-source-functions))))
11884 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11886 ;;;###autoload
11887 (defun anything-browse-code ()
11888 "Preconfigured anything to browse code."
11889 (interactive)
11890 (anything :sources 'anything-c-source-browse-code
11891 :buffer "*anything browse code*"
11892 :default (thing-at-point 'symbol)))
11894 ;;;###autoload
11895 (defun anything-org-headlines ()
11896 "Preconfigured anything to show org headlines."
11897 (interactive)
11898 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11900 ;;;###autoload
11901 (defun anything-info-gnus ()
11902 "Preconfigured anything to browse Gnus Manual."
11903 (interactive)
11904 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11906 ;;;###autoload
11907 (defun anything-regexp ()
11908 "Preconfigured anything to build regexps.
11909 `query-replace-regexp' can be run from there against found regexp."
11910 (interactive)
11911 (save-restriction
11912 (let ((anything-compile-source-functions
11913 ;; rule out anything-match-plugin because the input is one regexp.
11914 (delq 'anything-compile-source--match-plugin
11915 (copy-sequence anything-compile-source-functions))))
11916 (when (and (anything-region-active-p)
11917 ;; Don't narrow to region if buffer is already narrowed.
11918 (not (anything-current-buffer-narrowed-p)))
11919 (narrow-to-region (region-beginning) (region-end)))
11920 (anything :sources anything-c-source-regexp
11921 :buffer "*anything regexp*"
11922 :prompt "Regexp: "
11923 :history 'anything-build-regexp-history))))
11925 ;;;###autoload
11926 (defun anything-c-copy-files-async ()
11927 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11928 (interactive)
11929 (let* ((flist (anything-c-read-file-name
11930 "Copy File async: "
11931 :marked-candidates t))
11932 (dest (anything-c-read-file-name
11933 "Copy File async To: "
11934 :preselect (car flist)
11935 :initial-input (car anything-ff-history)
11936 :history (anything-find-files-history :comp-read nil))))
11937 (anything-c-copy-async-with-log flist dest)))
11939 ;;;###autoload
11940 (defun anything-find-files (arg)
11941 "Preconfigured `anything' for anything implementation of `find-file'.
11942 Called with a prefix arg show history if some.
11943 Don't call it from programs, use `anything-find-files-1' instead.
11944 This is the starting point for nearly all actions you can do on files."
11945 (interactive "P")
11946 (let ((any-input (if (and arg anything-ff-history)
11947 (anything-find-files-history)
11948 (anything-find-files-initial-input)))
11949 (presel (buffer-file-name (current-buffer))))
11950 (when (and (eq major-mode 'org-agenda-mode)
11951 org-directory
11952 (not any-input))
11953 (setq any-input (expand-file-name org-directory)))
11954 (set-text-properties 0 (length any-input) nil any-input)
11955 (if any-input
11956 (anything-find-files-1 any-input)
11957 (setq any-input (expand-file-name (anything-c-current-directory)))
11958 (anything-find-files-1
11959 any-input (if anything-ff-transformer-show-only-basename
11960 (and presel (anything-c-basename presel))
11961 presel)))))
11963 ;;;###autoload
11964 (defun anything-write-file ()
11965 "Preconfigured `anything' providing completion for `write-file'."
11966 (interactive)
11967 (let ((anything-mp-highlight-delay nil))
11968 (anything :sources 'anything-c-source-write-file
11969 :input (expand-file-name default-directory)
11970 :prompt "Write buffer to file: "
11971 :buffer "*Anything write file*")))
11973 ;;;###autoload
11974 (defun anything-insert-file ()
11975 "Preconfigured `anything' providing completion for `insert-file'."
11976 (interactive)
11977 (let ((anything-mp-highlight-delay nil))
11978 (anything :sources 'anything-c-source-insert-file
11979 :input (expand-file-name default-directory)
11980 :prompt "Insert file: "
11981 :buffer "*Anything insert file*")))
11983 ;;;###autoload
11984 (defun anything-dired-rename-file ()
11985 "Preconfigured `anything' to rename files from dired."
11986 (interactive)
11987 (anything-dired-do-action-on-file :action 'rename))
11989 ;;;###autoload
11990 (defun anything-dired-copy-file ()
11991 "Preconfigured `anything' to copy files from dired."
11992 (interactive)
11993 (anything-dired-do-action-on-file :action 'copy))
11995 ;;;###autoload
11996 (defun anything-dired-symlink-file ()
11997 "Preconfigured `anything' to symlink files from dired."
11998 (interactive)
11999 (anything-dired-do-action-on-file :action 'symlink))
12001 ;;;###autoload
12002 (defun anything-dired-hardlink-file ()
12003 "Preconfigured `anything' to hardlink files from dired."
12004 (interactive)
12005 (anything-dired-do-action-on-file :action 'hardlink))
12007 ;;;###autoload
12008 (defun anything-do-grep ()
12009 "Preconfigured anything for grep.
12010 Contrarily to Emacs `grep' no default directory is given, but
12011 the full path of candidates in ONLY.
12012 That allow to grep different files not only in `default-directory' but anywhere
12013 by marking them (C-<SPACE>). If one or more directory is selected
12014 grep will search in all files of these directories.
12015 You can use also wildcard in the base name of candidate.
12016 If a prefix arg is given use the -r option of grep.
12017 The prefix arg can be passed before or after start.
12018 See also `anything-do-grep-1'."
12019 (interactive)
12020 (let ((only (anything-c-read-file-name
12021 "Search in file(s): "
12022 :marked-candidates t
12023 :preselect (or (dired-get-filename nil t)
12024 (buffer-file-name (current-buffer)))))
12025 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
12026 (anything-do-grep-1 only prefarg)))
12028 ;;;###autoload
12029 (defun anything-do-zgrep (candidate)
12030 "Preconfigured anything for zgrep."
12031 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
12032 (ls (anything-c-read-file-name
12033 "Search in file(s): "
12034 :marked-candidates t
12035 :preselect (or (dired-get-filename nil t)
12036 (buffer-file-name (current-buffer))))))
12037 (anything-ff-zgrep-1 ls prefarg)))
12039 (defun anything-c-etags-select (arg)
12040 "Preconfigured anything for etags.
12041 Called with one prefix arg use symbol at point as initial input.
12042 Called with two prefix arg reinitialize cache.
12043 If tag file have been modified reinitialize cache."
12044 (interactive "P")
12045 (let ((tag (anything-c-etags-get-tag-file))
12046 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
12047 (anything-quit-if-no-candidate t)
12048 (anything-execute-action-at-once-if-one t)
12049 (anything-compile-source-functions
12050 (if anything-c-etags-use-regexp-search
12051 ;; rule out anything-match-plugin because the input is one regexp.
12052 (delq 'anything-compile-source--match-plugin
12053 (copy-sequence anything-compile-source-functions))
12054 anything-compile-source-functions)))
12055 (when (or (equal arg '(16))
12056 (and anything-c-etags-mtime-alist
12057 (anything-c-etags-file-modified-p tag)))
12058 (remhash tag anything-c-etags-cache))
12059 (if (and tag (file-exists-p tag))
12060 (anything :sources 'anything-c-source-etags-select
12061 :keymap anything-c-etags-map
12062 :input init
12063 :buffer "*anything etags*")
12064 (message "Error: No tag file found, please create one with etags shell command."))))
12066 ;;;###autoload
12067 (defun anything-filelist ()
12068 "Preconfigured `anything' to open files instantly.
12070 See `anything-c-filelist-file-name' docstring for usage."
12071 (interactive)
12072 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
12074 ;;;###autoload
12075 (defun anything-filelist+ ()
12076 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
12078 This is a replacement for `anything-for-files'.
12079 See `anything-c-filelist-file-name' docstring for usage."
12080 (interactive)
12081 (anything-other-buffer
12082 '(anything-c-source-ffap-line
12083 anything-c-source-ffap-guesser
12084 anything-c-source-buffers-list
12085 anything-c-source-recentf
12086 anything-c-source-bookmarks
12087 anything-c-source-file-cache
12088 anything-c-source-filelist)
12089 "*anything file list*"))
12091 ;;;###autoload
12092 (defun anything-M-x ()
12093 "Preconfigured `anything' for Emacs commands.
12094 It is `anything' replacement of regular `M-x' `execute-extended-command'."
12095 (interactive)
12096 (let* (in-help
12097 help-cand
12098 special-display-buffer-names
12099 special-display-regexps
12100 anything-persistent-action-use-special-display
12101 (history (loop with hist
12102 for i in extended-command-history
12103 for com = (intern i)
12104 when (fboundp com)
12105 collect i into hist finally return hist)))
12106 (flet ((pers-help (candidate)
12107 (let ((hbuf (get-buffer (help-buffer))))
12108 (if (and in-help (string= candidate help-cand))
12109 (progn
12110 ;; When M-x is started from a help buffer,
12111 ;; Don't kill it as it is anything-current-buffer.
12112 (unless (equal hbuf anything-current-buffer)
12113 (kill-buffer hbuf))
12114 (setq in-help nil))
12115 ;; Be sure anything-current-buffer
12116 ;; have not a dedicated window.
12117 (set-window-dedicated-p
12118 (get-buffer-window anything-current-buffer) nil)
12119 (describe-function (intern candidate))
12120 (message nil) ; Erase the new stupid message Type "q"[...]
12121 (setq in-help t))
12122 (setq help-cand candidate))))
12123 (let* ((command
12125 (anything
12126 :sources
12127 `(((name . "Emacs Commands history")
12128 (candidates . ,history)
12129 (filtered-candidate-transformer
12130 . (lambda (candidates sources)
12131 (loop for i in candidates
12132 do (set-text-properties 0 (length i) nil i)
12133 collect i)))
12134 (persistent-action . pers-help)
12135 (persistent-help . "Describe this command")
12136 (action . identity))
12137 ((name . "Emacs Commands")
12138 (init
12139 . (lambda ()
12140 (with-current-buffer (anything-candidate-buffer 'global)
12141 (goto-char (point-min))
12142 (loop for sym in
12143 (all-completions "" obarray 'commandp)
12144 do (insert (concat sym "\n"))))))
12145 (persistent-action . pers-help)
12146 (persistent-help . "Describe this command")
12147 (filtered-candidate-transformer . anything-M-x-transformer)
12148 (candidates-in-buffer)
12149 (action . identity)))
12150 :resume 'noresume
12151 :prompt "M-x "
12152 :history 'anything-M-x-input-history
12153 :buffer "*anything M-x*")
12154 (keyboard-quit)))
12155 (sym-com (intern command)))
12156 (unless current-prefix-arg
12157 (setq current-prefix-arg anything-current-prefix-arg))
12158 ;; Avoid having `this-command' set to *exit-minibuffer.
12159 (setq this-command sym-com)
12160 (call-interactively sym-com)
12161 (setq extended-command-history
12162 (cons command (delete command history)))))))
12164 ;;;###autoload
12165 (defun anything-manage-advice ()
12166 "Preconfigured `anything' to disable/enable function advices."
12167 (interactive)
12168 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12170 ;;;###autoload
12171 (defun anything-bookmark-ext ()
12172 "Preconfigured `anything' for bookmark-extensions sources.
12173 Needs bookmark-ext.el:
12174 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12175 Contain also `anything-c-source-google-suggest'."
12176 (interactive)
12177 (anything
12178 :sources
12179 '(anything-c-source-bookmark-files&dirs
12180 anything-c-source-bookmark-w3m
12181 anything-c-source-google-suggest
12182 anything-c-source-bmkext-addressbook
12183 anything-c-source-bookmark-gnus
12184 anything-c-source-bookmark-info
12185 anything-c-source-bookmark-man
12186 anything-c-source-bookmark-images
12187 anything-c-source-bookmark-su-files&dirs
12188 anything-c-source-bookmark-ssh-files&dirs)
12189 :prompt "SearchBookmark: "
12190 :buffer "*anything bmkext*"))
12192 ;;;###autoload
12193 (defun anything-simple-call-tree ()
12194 "Preconfigured `anything' for simple-call-tree. List function relationships.
12196 Needs simple-call-tree.el.
12197 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12198 (interactive)
12199 (anything-other-buffer
12200 '(anything-c-source-simple-call-tree-functions-callers
12201 anything-c-source-simple-call-tree-callers-functions)
12202 "*anything simple-call-tree*"))
12204 ;;;###autoload
12205 (defun anything-mark-ring ()
12206 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12207 (interactive)
12208 (anything :sources 'anything-c-source-mark-ring))
12210 ;;;###autoload
12211 (defun anything-global-mark-ring ()
12212 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12213 (interactive)
12214 (anything :sources 'anything-c-source-global-mark-ring))
12216 ;;;###autoload
12217 (defun anything-all-mark-rings ()
12218 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12219 `anything-c-source-mark-ring'."
12220 (interactive)
12221 (anything :sources '(anything-c-source-mark-ring
12222 anything-c-source-global-mark-ring)))
12224 ;;;###autoload
12225 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12226 "Preconfigured `anything' to edit or view EmacsWiki page.
12228 Needs yaoddmuse.el.
12230 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12231 (interactive)
12232 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12234 ;;;###autoload
12235 (defun anything-yaoddmuse-emacswiki-post-library ()
12236 "Preconfigured `anything' to post library to EmacsWiki.
12238 Needs yaoddmuse.el.
12240 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12241 (interactive)
12242 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12244 ;;;###autoload
12245 (defun anything-eval-expression (arg)
12246 "Preconfigured anything for `anything-c-source-evaluation-result'."
12247 (interactive "P")
12248 (anything :sources 'anything-c-source-evaluation-result
12249 :input (when arg (thing-at-point 'sexp))
12250 :buffer "*anything eval*"
12251 :history 'anything-eval-expression-input-history
12252 :keymap anything-eval-expression-map))
12254 ;;;###autoload
12255 (defun anything-eval-expression-with-eldoc ()
12256 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12257 (interactive)
12258 (declare (special eldoc-idle-delay))
12259 (let ((timer (run-with-idle-timer eldoc-idle-delay
12260 'repeat 'anything-eldoc-show-in-eval))
12261 (minibuffer-completing-symbol t) ; Enable lisp completion.
12262 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12263 (unwind-protect
12264 (minibuffer-with-setup-hook
12265 'anything-eldoc-store-minibuffer
12266 (call-interactively 'anything-eval-expression))
12267 (and timer (cancel-timer timer))
12268 (setq anything-eldoc-active-minibuffers-list
12269 (cdr anything-eldoc-active-minibuffers-list)))))
12271 ;;;###autoload
12272 (defun anything-calcul-expression ()
12273 "Preconfigured anything for `anything-c-source-calculation-result'."
12274 (interactive)
12275 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12277 ;;;###autoload
12278 (defun anything-surfraw (pattern engine)
12279 "Preconfigured `anything' to search PATTERN with search ENGINE."
12280 (interactive (list (read-string "SearchFor: "
12281 nil 'anything-surfraw-input-history)
12282 (anything-comp-read
12283 "Engine: "
12284 (anything-c-build-elvi-list)
12285 :must-match t
12286 :name "Surfraw Search Engines"
12287 :history anything-surfraw-engines-history)))
12288 (let* ((engine-nodesc (car (split-string engine)))
12289 (url (with-temp-buffer
12290 (apply 'call-process "surfraw" nil t nil
12291 ;;JAVE
12292 (append (list engine-nodesc "-p") (split-string pattern)))
12293 (replace-regexp-in-string
12294 "\n" "" (buffer-string))))
12295 (browse-url-browser-function (or anything-surfraw-default-browser-function
12296 browse-url-browser-function)))
12297 (if (string= engine-nodesc "W")
12298 (anything-c-browse-url)
12299 (anything-c-browse-url url)
12300 (setq anything-surfraw-engines-history
12301 (cons engine (delete engine anything-surfraw-engines-history))))))
12303 ;;;###autoload
12304 (defun anything-call-source ()
12305 "Preconfigured `anything' to call anything source."
12306 (interactive)
12307 (anything :sources 'anything-c-source-call-source
12308 :buffer anything-source-select-buffer))
12310 ;;;###autoload
12311 (defun anything-execute-anything-command ()
12312 "Preconfigured `anything' to execute preconfigured `anything'."
12313 (interactive)
12314 (anything-other-buffer 'anything-c-source-anything-commands
12315 "*anything commands*"))
12317 ;;;###autoload
12318 (defun anything-create (&optional string initial-input)
12319 "Preconfigured `anything' to do many create actions from STRING.
12320 See also `anything-create--actions'."
12321 (interactive)
12322 (setq string (or string (read-string "Create Anything: " initial-input)))
12323 (anything :sources '(((name . "Anything Create")
12324 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12325 (candidates . anything-create--actions)
12326 (candidate-number-limit)
12327 (action . (lambda (func) (funcall func string)))))))
12329 ;;;###autoload
12330 (defun anything-top ()
12331 "Preconfigured `anything' for top command."
12332 (interactive)
12333 (let ((anything-samewindow t)
12334 (anything-enable-shortcuts)
12335 (anything-display-function 'anything-default-display-buffer)
12336 (anything-candidate-number-limit 9999))
12337 (save-window-excursion
12338 (delete-other-windows)
12339 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12341 ;;;###autoload
12342 (defun anything-select-xfont ()
12343 "Preconfigured `anything' to select Xfont."
12344 (interactive)
12345 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12347 ;;;###autoload
12348 (defun anything-world-time ()
12349 "Preconfigured `anything' to show world time."
12350 (interactive)
12351 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12353 ;;;###autoload
12354 (defun anything-apt (arg)
12355 "Preconfigured `anything' : frontend of APT package manager.
12356 With a prefix arg reload cache."
12357 (interactive "P")
12358 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12359 (when arg (anything-c-apt-refresh))
12360 (anything :sources 'anything-c-source-apt
12361 :prompt "Search Package: "
12362 :input query
12363 :history 'anything-c-apt-input-history)))
12365 ;;;###autoload
12366 (defun anything-esh-pcomplete ()
12367 "Preconfigured anything to provide anything completion in eshell."
12368 (interactive)
12369 (let* ((anything-quit-if-no-candidate t)
12370 (anything-execute-action-at-once-if-one t)
12371 (target (thing-at-point 'symbol))
12372 (end (point))
12373 (beg (or (and target (- end (length target)))
12374 ;; Nothing at point.
12375 (progn (insert " ") (point)))))
12376 (setq anything-ec-target (or target " "))
12377 (with-anything-show-completion beg end
12378 (anything :sources 'anything-c-source-esh
12379 :input (anything-ff-set-pattern ; Handle tramp filenames.
12380 (car (last (ignore-errors ; Needed in lisp symbols completion.
12381 (pcomplete-parse-arguments)))))))))
12383 ;;;###autoload
12384 (defun anything-eshell-history ()
12385 "Preconfigured anything for eshell history."
12386 (interactive)
12387 (let* ((end (point))
12388 (beg (save-excursion (eshell-bol) (point)))
12389 flag-empty)
12390 (when (eq beg end)
12391 (insert " ")
12392 (setq flag-empty t)
12393 (setq end (point)))
12394 (unwind-protect
12395 (with-anything-show-completion beg end
12396 (anything :sources 'anything-c-source-eshell-history
12397 :buffer "*Eshell history*"))
12398 (when (and flag-empty
12399 (looking-back " "))
12400 (delete-char -1)))))
12402 ;;;###autoload
12403 (defun anything-c-run-external-command (program)
12404 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12405 If program is already running exit with error.
12406 You can set your own list of commands with
12407 `anything-c-external-commands-list'."
12408 (interactive (list
12409 (anything-comp-read
12410 "RunProgram: "
12411 (anything-c-external-commands-list-1 'sort)
12412 :must-match t
12413 :name "External Commands"
12414 :history anything-external-command-history)))
12415 (anything-run-or-raise program)
12416 (setq anything-external-command-history
12417 (cons program (delete program
12418 (loop for i in anything-external-command-history
12419 when (executable-find i) collect i)))))
12421 ;;;###autoload
12422 (defun anything-ratpoison-commands ()
12423 "Preconfigured `anything' to execute ratpoison commands."
12424 (interactive)
12425 (anything-other-buffer 'anything-c-source-ratpoison-commands
12426 "*anything ratpoison commands*"))
12428 ;;;###autoload
12429 (defun anything-ucs ()
12430 "Preconfigured anything for `ucs-names' math symbols."
12431 (interactive)
12432 (anything :sources 'anything-c-source-ucs
12433 :keymap anything-c-ucs-map))
12435 ;;;###autoload
12436 (defun anything-c-apropos ()
12437 "Preconfigured anything to describe commands, functions, variables and faces."
12438 (interactive)
12439 (let ((default (thing-at-point 'symbol)))
12440 (anything :sources
12441 `(((name . "Commands")
12442 (init . (lambda ()
12443 (anything-c-apropos-init 'commandp ,default)))
12444 (persistent-action . anything-lisp-completion-persistent-action)
12445 (persistent-help . "Show brief doc in mode-line")
12446 (candidates-in-buffer)
12447 (action . (lambda (candidate)
12448 (describe-function (intern candidate)))))
12449 ((name . "Functions")
12450 (init . (lambda ()
12451 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12452 (not (commandp x))))
12453 ,default)))
12454 (persistent-action . anything-lisp-completion-persistent-action)
12455 (persistent-help . "Show brief doc in mode-line")
12456 (candidates-in-buffer)
12457 (action . (lambda (candidate)
12458 (describe-function (intern candidate)))))
12459 ((name . "Variables")
12460 (init . (lambda ()
12461 (anything-c-apropos-init 'boundp ,default)))
12462 (persistent-action . anything-lisp-completion-persistent-action)
12463 (persistent-help . "Show brief doc in mode-line")
12464 (candidates-in-buffer)
12465 (action . (lambda (candidate)
12466 (describe-variable (intern candidate)))))
12467 ((name . "Faces")
12468 (init . (lambda ()
12469 (anything-c-apropos-init 'facep ,default)))
12470 (persistent-action . anything-lisp-completion-persistent-action)
12471 (persistent-help . "Show brief doc in mode-line")
12472 (candidates-in-buffer)
12473 (filtered-candidate-transformer . (lambda (candidates source)
12474 (loop for c in candidates
12475 collect (propertize c 'face (intern c)))))
12476 (action . (lambda (candidate)
12477 (describe-face (intern candidate)))))
12478 ((name . "Anything attributes")
12479 (candidates . (lambda ()
12480 (mapcar 'symbol-name anything-additional-attributes)))
12481 (action . (lambda (candidate)
12482 (with-output-to-temp-buffer "*Help*"
12483 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12486 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12489 (provide 'anything-config)
12491 ;;; Local Variables:
12492 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12493 ;;; End:
12495 ;; How to save (DO NOT REMOVE!!)
12496 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12497 ;;; anything-config.el ends here
12499 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12500 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12501 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12502 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12503 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12504 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12505 ;;; LocalWords: dotimes Thierry online vname
12506 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12507 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12508 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12509 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12510 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12511 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12512 ;;; LocalWords: startpos noselect dont desc