* anything-config.el (anything-c-read-file-name): Fix minibuffer-completion-table.
[anything-config.git] / anything-config.el
blobdae38b0e8259b21fb788c9d3b765f6ebce428bf7
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-ff-run-toggle-basename)
1613 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1614 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1615 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1616 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1617 (when anything-ff-lynx-style-map
1618 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1619 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1620 (define-key map (kbd "<M-left>") 'anything-previous-source)
1621 (define-key map (kbd "<M-right>") 'anything-next-source))
1622 (delq nil map))
1623 "Keymap for `anything-c-read-file-name'.")
1625 (defvar anything-generic-files-map
1626 (let ((map (copy-keymap anything-map)))
1627 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1628 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1629 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1630 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1631 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1632 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1633 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1634 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1635 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1636 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1637 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1638 map)
1639 "Generic Keymap for files.")
1641 (defvar anything-c-grep-map
1642 (let ((map (copy-keymap anything-map)))
1643 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1644 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1645 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1646 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1647 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1648 (when anything-c-grep-use-ioccur-style-keys
1649 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1650 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1651 (define-key map (kbd "C-c ?") 'anything-grep-help)
1652 (delq nil map))
1653 "Keymap used in Grep sources.")
1655 (defvar anything-c-pdfgrep-map
1656 (let ((map (copy-keymap anything-map)))
1657 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1658 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1659 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1660 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1661 map)
1662 "Keymap used in pdfgrep.")
1664 (defvar anything-c-etags-map
1665 (let ((map (copy-keymap anything-map)))
1666 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1667 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1668 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1669 (define-key map (kbd "C-c ?") 'anything-etags-help)
1670 map)
1671 "Keymap used in Etags.")
1673 (defvar anything-eval-expression-map
1674 (let ((map (copy-keymap anything-map)))
1675 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1676 (define-key map (kbd "<tab>") 'lisp-indent-line)
1677 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1678 (define-key map (kbd "C-p") 'previous-line)
1679 (define-key map (kbd "C-n") 'next-line)
1680 (define-key map (kbd "<up>") 'previous-line)
1681 (define-key map (kbd "<down>") 'next-line)
1682 (define-key map (kbd "<right>") 'forward-char)
1683 (define-key map (kbd "<left>") 'backward-char)
1684 map))
1686 (defvar anything-c-ucs-map
1687 (let ((map (copy-keymap anything-map)))
1688 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1689 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1690 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1691 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1692 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1693 map)
1694 "Keymap for `anything-ucs'.")
1698 ;;; Embeded documentation.
1701 (defun anything-c-list-preconfigured-anything ()
1702 "Collect preconfigured anything functions in this file."
1703 (loop with doc
1704 with sym
1705 for entry in (cdr (assoc
1706 (file-truename (locate-library "anything-config"))
1707 load-history))
1708 if (and (consp entry)
1709 (eq (car entry) 'defun)
1710 (string-match "^Preconfigured.+$"
1711 (setq doc (or (documentation (setq sym (cdr entry)))
1712 ""))))
1713 collect (cons sym (match-string 0 doc))))
1715 (defun anything-c-format-preconfigured-anything ()
1716 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1717 (anything-c-list-preconfigured-anything)))
1719 ;;; Global help message - Used by `anything-help'
1722 (setq anything-help-message
1723 (lambda ()
1724 (concat
1725 "\\<anything-map>"
1726 "`anything' is QuickSilver-like candidate-selection framework.
1728 Narrow the list by typing some pattern,
1729 Multiple patterns are allowed by splitting by space.
1730 Select with natural Emacs operations, choose with RET.
1732 If you have any problems, press C-c C-x C-b!!
1733 Feel free to send bug reports. I'll fix them.
1734 The steps are described in the beginning of anything.el file.
1736 == Basic Operations ==
1737 C-p, Up: Previous Line
1738 C-n, Down : Next Line
1739 M-v, PageUp : Previous Page
1740 C-v, PageDown : Next Page
1741 Enter : Execute first (default) action / Select
1742 M-< : First Line
1743 M-> : Last Line
1744 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1745 M-PageDown, C-M-v : Next Page (other-window)
1747 Tab, C-i : Show action list
1748 Left : Previous Source
1749 Right, C-o : Next Source
1750 C-k : Delete pattern
1751 C-z : Persistent Action (Execute action with anything session kept)
1752 C-c C-x C-b: Send a bug report
1754 == Shortcuts For 2nd/3rd Action ==
1755 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1756 \\[anything-select-3rd-action] : Execute 3rd Action
1758 == Visible Marks ==
1759 Visible marks store candidate. Some actions uses marked candidates.
1761 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1762 \\[anything-prev-visible-mark] : Previous Mark
1763 \\[anything-next-visible-mark] : Next Mark
1765 == Miscellaneous Commands ==
1766 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1767 \\[anything-quit-and-find-file] : Drop into `find-file'
1768 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1769 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1770 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1771 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1772 \\[anything-force-update] : Recalculate And Redisplay Candidates
1774 == Global Commands ==
1775 \\<global-map>\\[anything-resume] revives last `anything' session.
1776 It is very useful, so you should bind any key.
1778 Single source is executed by \\[anything-call-source].
1780 == Preconfigured `anything' ==
1781 Preconfigured `anything' is commands that uses `anything' interface.
1782 You can use them without configuration.
1785 (apply 'concat (anything-c-format-preconfigured-anything))
1787 Enjoy!")))
1789 ;;; `anything-buffer-list' help
1792 ;;;###autoload
1793 (defun anything-c-buffer-help ()
1794 "Help command for anything buffers."
1795 (interactive)
1796 (let ((anything-help-message "== Anything Buffer ==
1797 \nTips:
1798 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1799 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1800 \nSpecific commands for `anything-buffers-list':
1801 \\<anything-c-buffer-map>
1802 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1803 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1804 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1805 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1806 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1807 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1808 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1809 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1810 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1811 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1812 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1813 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1814 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1815 \\[anything-mark-all]\t\t->Mark all.
1816 \\[anything-c-buffer-help]\t\t->Display this help.
1817 \n== Anything Map ==
1818 \\{anything-map}
1820 (anything-help)))
1823 ;;; Find files help (`anything-find-files')
1826 ;;;###autoload
1827 (defun anything-ff-help ()
1828 "Help command for `anything-find-files'."
1829 (interactive)
1830 (let ((anything-help-message "== Anything Find Files ==
1831 \nTips:
1832 \n- Enter `~/' at end of pattern to quickly reach home directory.
1833 - Enter `/' at end of pattern to quickly reach root of your file system.
1834 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1835 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1836 - Use `C-u C-z' to watch an image.
1837 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1838 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1840 \nSpecific commands for `anything-find-files':
1841 \\<anything-find-files-map>
1842 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1843 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1844 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1845 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1846 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1847 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1848 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1849 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1850 \\[anything-ff-run-load-file]\t\t->Load File.
1851 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1852 \\[anything-ff-run-delete-file]\t\t->Delete File.
1853 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1854 \\[anything-ff-persistent-delete]\t->Delete file without quitting.
1855 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1856 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1857 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1858 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1859 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1860 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1861 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1862 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1863 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1864 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1865 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1866 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1867 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1868 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1869 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1870 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1871 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1872 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1873 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1874 \\[anything-narrow-window]\t\t->Narrow anything window.
1875 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1876 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1877 \\[anything-ff-help]\t\t->Display this help info.
1878 \n== Anything Map ==
1879 \\{anything-map}
1881 (anything-help)))
1883 ;;; Help for `anything-c-read-file-name'
1886 ;;;###autoload
1887 (defun anything-read-file-name-help ()
1888 (interactive)
1889 (let ((anything-help-message "== Anything read file name Map ==\
1890 \nSpecific commands for anything-c-read-file-name:
1891 \\<anything-c-read-file-map>
1892 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1893 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1894 \\[anything-next-source]\t\t->Goto next source.
1895 \\[anything-previous-source]\t->Goto previous source.
1896 \\[anything-read-file-name-help]\t\t->Display this help info.
1897 \n== Anything Map ==
1898 \\{anything-map}
1900 (anything-help)))
1902 ;;; Generic file help - Used by locate.
1905 ;;;###autoload
1906 (defun anything-generic-file-help ()
1907 (interactive)
1908 (let ((anything-help-message "== Anything Generic files Map ==\
1909 \nSpecific commands for anything locate and others files sources:
1910 \\<anything-generic-files-map>
1911 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1912 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1913 \\[anything-ff-run-delete-file]\t\t->Delete file.
1914 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1915 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1916 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1917 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1918 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1919 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1920 \nLocate tips:
1921 You can add after writing search pattern any of the locate command line options.
1922 e.g -b, -e, -n <number>...etc.
1923 See Man locate for more infos.
1924 \n== Anything Map ==
1925 \\{anything-map}"))
1926 (anything-help)))
1929 ;;; Grep help
1932 ;;;###autoload
1933 (defun anything-grep-help ()
1934 (interactive)
1935 (let ((anything-help-message "== Anything Grep Map ==\
1936 \nSpecific commands for Grep and Etags:
1937 \\<anything-c-grep-map>
1938 \\[anything-c-goto-next-file]\t->Next File.
1939 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1940 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1941 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1942 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1943 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1944 \\[anything-grep-help]\t\t->Show this help.
1945 \n== Anything Map ==
1946 \\{anything-map}"))
1947 (anything-help)))
1949 ;;; Pdf grep help
1952 ;;;###autoload
1953 (defun anything-pdfgrep-help ()
1954 (interactive)
1955 (let ((anything-help-message "== Anything PdfGrep Map ==\
1956 \nSpecific commands for Pdf Grep:
1957 \\<anything-c-pdfgrep-map>
1958 \\[anything-c-goto-next-file]\t->Next File.
1959 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1960 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1961 \\[anything-pdfgrep-help]\t\t->Show this help.
1962 \n== Anything Map ==
1963 \\{anything-map}"))
1964 (anything-help)))
1966 ;;; Etags help
1969 ;;;###autoload
1970 (defun anything-etags-help ()
1971 "The help function for etags."
1972 (interactive)
1973 (let ((anything-help-message "== Anything Etags Map ==\
1974 \nSpecific commands for Etags:
1975 \\<anything-c-etags-map>
1976 \\[anything-c-goto-next-file]\t->Next File.
1977 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1978 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1979 \\[anything-etags-help]\t\t->Show this help.
1980 \n== Anything Map ==
1981 \\{anything-map}"))
1982 (anything-help)))
1984 ;;; Ucs help
1987 (defun anything-c-ucs-help ()
1988 "Help command for `anything-ucs'."
1989 (interactive)
1990 (let ((anything-help-message "== Anything Ucs ==
1991 \nSpecific commands for `anything-ucs':
1992 \\<anything-c-ucs-map>
1993 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1994 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1995 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1996 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1997 \\[anything-c-ucs-help]\t\t->Show this help.
1999 \n== Anything Map ==
2000 \\{anything-map}
2002 (anything-help)))
2006 ;;; Mode line strings
2009 (defvar anything-buffer-mode-line-string
2010 '("Buffer(s)"
2011 "\\<anything-c-buffer-map>\
2012 \\[anything-c-buffer-help]:Help, \
2013 \\<anything-map>\
2014 \\[anything-select-action]:Acts,\
2015 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2016 \\[anything-select-3rd-action]:NthAct,\
2017 \\[anything-send-bug-report-from-anything]:BugReport."
2018 "String displayed in mode-line in `anything-c-source-buffers-list'"))
2020 (defvar anything-ff-mode-line-string
2021 "\\<anything-find-files-map>\
2022 \\[anything-ff-help]:Help, \
2023 \\[anything-send-bug-report-from-anything]:BugReport, \
2024 \\<anything-map>\
2025 \\[anything-select-action]:Acts, \
2026 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2027 \\[anything-select-3rd-action]:NthAct"
2028 "String displayed in mode-line in `anything-c-source-find-files'")
2030 (defvar anything-read-file-name-mode-line-string
2031 "\\<anything-c-read-file-map>\
2032 \\[anything-read-file-name-help]:Help, \
2033 \\<anything-map>\
2034 \\[anything-select-action]:Acts,\
2035 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2036 \\[anything-select-3rd-action]:NthAct"
2037 "String displayed in mode-line in `anything-c-source-find-files'")
2039 (defvar anything-generic-file-mode-line-string
2040 "\\<anything-generic-files-map>\
2041 \\[anything-generic-file-help]:Help, \
2042 \\<anything-map>\
2043 \\[anything-select-action]:Acts,\
2044 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2045 \\[anything-select-3rd-action]:NthAct,\
2046 \\[anything-send-bug-report-from-anything]:BugReport."
2047 "String displayed in mode-line in Locate.")
2049 (defvar anything-grep-mode-line-string
2050 "\\<anything-c-grep-map>\
2051 \\[anything-grep-help]:Help,\
2052 \\<anything-map>\
2053 \\[anything-select-action]:Acts,\
2054 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2055 \\[anything-select-3rd-action]:NthAct,\
2056 \\[anything-send-bug-report-from-anything]:BugReport."
2057 "String displayed in mode-line in `anything-do-grep'.")
2059 (defvar anything-pdfgrep-mode-line-string
2060 "\\<anything-c-pdfgrep-map>\
2061 \\[anything-pdfgrep-help]:Help,\
2062 \\<anything-map>\
2063 \\[anything-select-action]:Acts,\
2064 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2065 \\[anything-select-3rd-action]:NthAct,\
2066 \\[anything-send-bug-report-from-anything]:BugReport."
2067 "String displayed in mode-line in `anything-do-pdfgrep'.")
2069 (defvar anything-etags-mode-line-string
2070 "\\<anything-c-etags-map>\
2071 \\[anything-etags-help]:Help,\
2072 \\<anything-map>\
2073 \\[anything-select-action]:Acts,\
2074 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2075 \\[anything-select-3rd-action]:NthAct,\
2076 \\[anything-send-bug-report-from-anything]:BugReport."
2077 "String displayed in mode-line in `anything-c-etags-select'.")
2080 (defvar anything-c-ucs-mode-line-string
2081 "\\<anything-c-ucs-map>\
2082 \\[anything-c-ucs-help]:Help, \
2083 \\<anything-map>\
2084 \\[anything-select-action]:Acts,\
2085 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2086 \\[anything-select-3rd-action]:NthAct."
2087 "String displayed in mode-line in `anything-ucs'.")
2091 ;;; Utilities Functions
2094 (defun anything-ff-find-printers ()
2095 "Return a list of available printers on Unix systems."
2096 (when (executable-find "lpstat")
2097 (let ((printer-list (with-temp-buffer
2098 (call-process "lpstat" nil t nil "-a")
2099 (split-string (buffer-string) "\n"))))
2100 (loop for p in printer-list
2101 for printer = (car (split-string p))
2102 when printer
2103 collect printer))))
2105 ;; Shut up byte compiler in emacs24*.
2106 (defun anything-c-switch-to-buffer (buffer-or-name)
2107 "Same as `switch-to-buffer' whithout warnings at compile time."
2108 (with-no-warnings
2109 (switch-to-buffer buffer-or-name)))
2111 (defsubst* anything-c-position (item seq &key (test 'eq))
2112 "A simple and faster replacement of CL `position'."
2113 (loop for i in seq for index from 0
2114 when (funcall test i item) return index))
2116 (defun anything-c-get-pid-from-process-name (process-name)
2117 "Get pid from running process PROCESS-NAME."
2118 (loop with process-list = (list-system-processes)
2119 for pid in process-list
2120 for process = (assoc-default 'comm (process-attributes pid))
2121 when (and process (string-match process-name process))
2122 return pid))
2124 (defun* anything-current-buffer-narrowed-p (&optional
2125 (buffer anything-current-buffer))
2126 "Check if BUFFER is narrowed.
2127 Default is `anything-current-buffer'."
2128 (with-current-buffer buffer
2129 (let ((beg (point-min))
2130 (end (point-max))
2131 (total (buffer-size)))
2132 (or (/= beg 1) (/= end (1+ total))))))
2134 (defun anything-region-active-p ()
2135 (and transient-mark-mode mark-active (/= (mark) (point))))
2137 (defun anything-goto-line (lineno)
2138 "Goto LINENO opening only outline headline if needed."
2139 (goto-char (point-min)) (forward-line (1- lineno))
2140 (when (or (eq major-mode 'org-mode)
2141 (and (boundp 'outline-minor-mode)
2142 outline-minor-mode))
2143 (require 'org) ; On some old Emacs versions org may not be loaded.
2144 (org-reveal))
2145 (anything-match-line-color-current-line) (sit-for 0.3)
2146 (anything-match-line-cleanup))
2148 (defun anything-show-this-source-only ()
2149 "Show all candidates of this source."
2150 (interactive)
2151 (setq anything-candidate-number-limit nil)
2152 (anything-set-source-filter
2153 (list (assoc-default 'name (anything-get-current-source)))))
2155 ;;;###autoload
2156 (defun anything-test-sources ()
2157 "List all anything sources for test.
2158 The output is sexps which are evaluated by \\[eval-last-sexp]."
2159 (interactive)
2160 (with-output-to-temp-buffer "*Anything Test Sources*"
2161 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2162 (apropos-internal "^anything-c-source" #'boundp))
2163 (pop-to-buffer standard-output)))
2165 (defun anything-nest (&rest same-as-anything)
2166 "Nested `anything'. If you use `anything' within `anything', use it."
2167 (with-selected-window (anything-window)
2168 (let (anything-current-position
2169 anything-current-buffer
2170 (orig-anything-buffer anything-buffer)
2171 anything-pattern
2172 anything-buffer
2173 anything-sources
2174 anything-compiled-sources
2175 anything-buffer-chars-modified-tick
2176 (anything-samewindow t)
2177 (enable-recursive-minibuffers t))
2178 (unwind-protect
2179 (apply #'anything same-as-anything)
2180 (anything-initialize-overlays orig-anything-buffer)
2181 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2183 (defun anything-displaying-source-names ()
2184 "Display sources name."
2185 (with-current-buffer anything-buffer
2186 (goto-char (point-min))
2187 (loop with pos
2188 while (setq pos (next-single-property-change (point) 'anything-header))
2189 do (goto-char pos)
2190 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2191 do (forward-line 1))))
2193 ;; [Obsolete]
2194 (defun anything-select-source ()
2195 "[OBSOLETE] Select source."
2196 (interactive)
2197 (let ((default (assoc-default 'name (anything-get-current-source)))
2198 (source-names (anything-displaying-source-names))
2199 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2200 (anything-get-sources))))
2201 (setq anything-candidate-number-limit 9999)
2202 (anything-aif
2203 (let (anything-source-filter)
2204 (anything-nest '(((name . "Anything Source")
2205 (candidates . source-names)
2206 (action . identity))
2207 ((name . "Anything Source (ALL)")
2208 (candidates . all-source-names)
2209 (action . identity)))
2210 nil "Source: " nil
2211 default "*anything select source*"))
2212 (anything-set-source-filter (list it))
2213 (anything-set-source-filter nil))))
2215 ;; Same as anything-set-pattern but bad written, please fix.
2216 (defun anything-insert-string (str)
2217 "Insert STR."
2218 (delete-minibuffer-contents)
2219 (insert str))
2221 ;;;###autoload
2222 (defun anything-insert-buffer-name ()
2223 "Insert buffer name."
2224 (interactive)
2225 (anything-set-pattern
2226 (with-anything-current-buffer
2227 (if buffer-file-name (file-name-nondirectory buffer-file-name)
2228 (buffer-name)))))
2230 (defalias 'anything-insert-symbol 'next-history-element)
2231 (defalias 'anything-insert-selection 'anything-yank-selection)
2233 (defun anything-c-match-on-file-name (candidate)
2234 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2235 (string-match anything-pattern (file-name-nondirectory candidate)))
2237 (defun anything-c-match-on-directory-name (candidate)
2238 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2239 (anything-aif (file-name-directory candidate)
2240 (string-match anything-pattern it)))
2242 (defun anything-c-match-on-basename (candidate)
2243 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2244 (string-match anything-pattern (anything-c-basename candidate)))
2246 (defun anything-c-string-match (candidate)
2247 "Return non-nil if `anything-pattern' match CANDIDATE.
2248 The match is done with `string-match'."
2249 (string-match anything-pattern candidate))
2251 (defun anything-c-skip-entries (list regexp)
2252 "Remove entries which matches REGEXP from LIST."
2253 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2254 list))
2256 (defun anything-c-shadow-entries (list regexp)
2257 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2258 (mapcar (lambda (file)
2259 ;; Add shadow face property to boring files.
2260 (let ((face (if (facep 'file-name-shadow)
2261 'file-name-shadow
2262 ;; fall back to default on XEmacs
2263 'default)))
2264 (if (string-match regexp file)
2265 (setq file (propertize file 'face face))))
2266 file)
2267 list))
2269 (defsubst anything-c-stringify (str-or-sym)
2270 "Get string of STR-OR-SYM."
2271 (if (stringp str-or-sym)
2272 str-or-sym
2273 (symbol-name str-or-sym)))
2275 (defsubst anything-c-symbolify (str-or-sym)
2276 "Get symbol of STR-OR-SYM."
2277 (if (symbolp str-or-sym)
2278 str-or-sym
2279 (intern str-or-sym)))
2281 (defun anything-c-describe-function (func)
2282 "FUNC is symbol or string."
2283 (describe-function (anything-c-symbolify func)))
2285 (defun anything-c-describe-variable (var)
2286 "VAR is symbol or string."
2287 (describe-variable (anything-c-symbolify var)))
2289 (defun anything-c-find-function (func)
2290 "FUNC is symbol or string."
2291 (find-function (anything-c-symbolify func)))
2293 (defun anything-c-find-variable (var)
2294 "VAR is symbol or string."
2295 (find-variable (anything-c-symbolify var)))
2297 (defun anything-c-kill-new (candidate &optional replace)
2298 "CANDIDATE is symbol or string.
2299 See `kill-new' for argument REPLACE."
2300 (kill-new (anything-c-stringify candidate) replace))
2302 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2303 "Remove duplicates elements in list SEQ.
2304 This is same as `remove-duplicates' but with memoisation.
2305 It is much faster, especially in large lists.
2306 A test function can be provided with TEST argument key.
2307 Default is `eq'."
2308 (loop with cont = (make-hash-table :test test)
2309 for elm in seq
2310 unless (gethash elm cont)
2311 do (puthash elm elm cont)
2312 finally return
2313 (loop for i being the hash-values in cont collect i)))
2315 (defadvice eval-defun (after anything-source-hack activate)
2316 "Allow immediate execution of anything source when evaling it.
2317 See `anything-c-enable-eval-defun-hack'."
2318 (when anything-c-enable-eval-defun-hack
2319 (let ((varsym (save-excursion
2320 (beginning-of-defun)
2321 (forward-char 1)
2322 (when (memq (read (current-buffer)) '(defvar setq))
2323 (read (current-buffer))))))
2324 (when (string-match "^anything-c-source-" (symbol-name varsym))
2325 (anything varsym)))))
2326 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2329 ;; Move this function from anything.el and redefine here
2330 ;; to avoid an unneeded defadvice.
2331 (defun anything-quit-and-find-file ()
2332 "Drop into `anything-find-files' from `anything'.
2333 If current selection is a buffer or a file, `anything-find-files'
2334 from its directory."
2335 (interactive)
2336 (anything-run-after-quit
2337 (lambda (f)
2338 (if (file-exists-p f)
2339 (anything-find-files-1 (file-name-directory f)
2340 (if anything-ff-transformer-show-only-basename
2341 (anything-c-basename f) f))
2342 (anything-find-files-1 f)))
2343 (anything-aif (get-buffer (anything-get-selection))
2344 (or (buffer-file-name it)
2345 (car (rassoc it dired-buffers))
2346 (and (with-current-buffer it
2347 (eq major-mode 'org-agenda-mode))
2348 org-directory
2349 (expand-file-name org-directory))
2350 default-directory)
2351 (let ((sel (anything-get-selection)))
2352 (if (file-exists-p sel)
2353 (expand-file-name sel)
2354 default-directory)))))
2357 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2358 "Walk through DIRECTORY tree.
2359 PATH can be one of basename, relative, or full.
2360 DIRECTORIES when non--nil (default) return also directories names, otherwise
2361 skip directories names.
2362 MATCH match only filenames matching regexp MATCH."
2363 `(let (result
2364 (fn (case ,path
2365 (basename 'file-name-nondirectory)
2366 (relative 'file-relative-name)
2367 (full 'identity)
2368 (t 'file-name-nondirectory))))
2369 (labels ((ls-R (dir)
2370 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2371 for f in ls
2372 if (file-directory-p f)
2373 do (progn (when ,directories
2374 (push (funcall fn f) result))
2375 ;; Don't recurse in directory symlink.
2376 (unless (file-symlink-p f)
2377 (ls-R f)))
2378 else do
2379 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2380 (push (funcall fn f) result)))))
2381 (ls-R ,directory)
2382 (nreverse result))))
2384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2386 ;;; Anything regexp.
2389 (defvar anything-build-regexp-history nil)
2390 (defun anything-c-query-replace-regexp (candidate)
2391 "Query replace regexp from `anything-regexp'.
2392 With a prefix arg replace only matches surrounded by word boundaries,
2393 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2394 (let ((regexp (funcall (anything-attr 'regexp))))
2395 (apply 'query-replace-regexp
2396 (anything-c-query-replace-args regexp))))
2398 (defun anything-c-kill-regexp-as-sexp (candidate)
2399 "Kill regexp in a format usable in lisp code."
2400 (anything-c-regexp-kill-new
2401 (prin1-to-string (funcall (anything-attr 'regexp)))))
2403 (defun anything-c-kill-regexp (candidate)
2404 "Kill regexp as it is in `anything-pattern'."
2405 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2407 (defun anything-c-query-replace-args (regexp)
2408 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2409 (let ((region-only (anything-region-active-p)))
2410 (list
2411 regexp
2412 (query-replace-read-to regexp
2413 (format "Query replace %sregexp %s"
2414 (if anything-current-prefix-arg "word " "")
2415 (if region-only "in region " ""))
2417 anything-current-prefix-arg
2418 (when region-only (region-beginning))
2419 (when region-only (region-end)))))
2421 (defvar anything-c-source-regexp
2422 '((name . "Regexp Builder")
2423 (init . (lambda ()
2424 (anything-candidate-buffer anything-current-buffer)))
2425 (candidates-in-buffer)
2426 (get-line . anything-c-regexp-get-line)
2427 (persistent-action . anything-c-regexp-persistent-action)
2428 (persistent-help . "Show this line")
2429 (multiline)
2430 (delayed)
2431 (requires-pattern . 2)
2432 (mode-line . "Press TAB to select action.")
2433 (regexp . (lambda () anything-input))
2434 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2435 ("Query Replace Regexp (C-u Not inside word.)"
2436 . anything-c-query-replace-regexp)
2437 ("Kill Regexp" . anything-c-kill-regexp)))))
2439 (defun anything-c-regexp-get-line (s e)
2440 (propertize
2441 (apply 'concat
2442 ;; Line contents
2443 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2444 ;; subexps
2445 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2446 collect (format "\n %s'%s'"
2447 (if (zerop i) "Group 0: " (format "Group %d: " i))
2448 (match-string i))))
2449 ;; match beginning
2450 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2451 ;; It is implementation problem of candidates-in-buffer.
2452 'anything-realvalue
2453 (1- s)))
2455 (defun anything-c-regexp-persistent-action (pt)
2456 (goto-char pt)
2457 (anything-persistent-highlight-point))
2459 (defun anything-c-regexp-kill-new (input)
2460 (kill-new input)
2461 (message "Killed: %s" input))
2465 ;;; Toggle all marks.
2468 ;;;###autoload
2469 (defun anything-mark-all ()
2470 "Mark all visible unmarked candidates in current source."
2471 (interactive)
2472 (with-anything-window
2473 (save-excursion
2474 (goto-char (anything-get-previous-header-pos))
2475 (anything-next-line)
2476 (let* ((next-head (anything-get-next-header-pos))
2477 (end (and next-head
2478 (save-excursion
2479 (goto-char next-head)
2480 (forward-line -1)
2481 (point))))
2482 (maxpoint (or end (point-max))))
2483 (while (< (point) maxpoint)
2484 (anything-mark-current-line)
2485 (let ((prefix (get-text-property (point-at-bol) 'display))
2486 (bn (anything-c-basename (anything-get-selection)))
2487 (src (assoc-default 'name (anything-get-current-source))))
2488 (when (and (not (anything-this-visible-mark))
2489 (not (or (string= prefix "[?]")
2490 (string= prefix "[@]"))))
2491 ;; Don't mark possibles directories ending with . or ..
2492 ;; and also autosave files/links.
2493 (unless
2494 (and (or (anything-file-completion-source-p)
2495 (equal src "Files from Current Directory"))
2496 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2497 (anything-make-visible-mark))))
2498 (forward-line 1) (end-of-line))))
2499 (anything-mark-current-line)
2500 (message "%s candidates marked" (length anything-marked-candidates))))
2502 ;;;###autoload
2503 (defun anything-unmark-all ()
2504 "Unmark all candidates in all sources of current anything session."
2505 (interactive)
2506 (with-anything-window
2507 (let ((len (length anything-marked-candidates)))
2508 (save-excursion
2509 (anything-clear-visible-mark))
2510 (setq anything-marked-candidates nil)
2511 (anything-mark-current-line)
2512 (message "%s candidates unmarked" len))))
2514 ;;;###autoload
2515 (defun anything-toggle-all-marks ()
2516 "Toggle all marks.
2517 Mark all visible candidates of current source or unmark all candidates
2518 visible or invisible in all sources of current anything session"
2519 (interactive)
2520 (let ((marked (anything-marked-candidates)))
2521 (if (and (>= (length marked) 1)
2522 (with-anything-window anything-visible-mark-overlays))
2523 (anything-unmark-all)
2524 (anything-mark-all))))
2528 ;;; Buffers
2531 (defun anything-c-buffer-list ()
2532 "Return the list of names of buffers with boring buffers filtered out.
2533 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2534 The first buffer in the list will be the last recently used
2535 buffer that is not the current buffer."
2536 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2537 (append (cdr buffers) (list (car buffers)))))
2539 (defvar anything-c-source-buffers
2540 '((name . "Buffers")
2541 (candidates . anything-c-buffer-list)
2542 (type . buffer)))
2543 ;; (anything 'anything-c-source-buffers)
2545 (defvar anything-c-source-buffer-not-found
2546 '((name . "Create buffer")
2547 (dummy)
2548 (filtered-candidate-transformer (lambda (cands source)
2549 (list anything-pattern)))
2550 (action . (lambda (candidate)
2551 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2552 ;; (anything 'anything-c-source-buffer-not-found)
2554 ;;; Buffers-list (was buffers+)
2557 (eval-when-compile (require 'dired))
2559 (defun anything-c-highlight-buffers (buffers)
2560 (loop for i in buffers
2561 for buf = (get-buffer i)
2562 for bfname = (buffer-file-name buf)
2563 collect
2564 (cond (;; A dired buffer.
2565 (rassoc buf dired-buffers)
2566 (propertize i 'face 'anything-ff-directory
2567 'help-echo (car (rassoc buf dired-buffers))))
2568 ;; A buffer file modified somewhere outside of emacs.
2569 ((and bfname (not (file-remote-p bfname))
2570 (file-exists-p bfname)
2571 (not (verify-visited-file-modtime buf)))
2572 (propertize i 'face 'anything-buffer-saved-out
2573 'help-echo bfname))
2574 ;; A new buffer file not already saved on disk.
2575 ((and bfname (not (file-remote-p bfname))
2576 (not (verify-visited-file-modtime buf)))
2577 (propertize i 'face 'anything-buffer-not-saved
2578 'help-echo bfname))
2579 ;; A Remote buffer file modified and not saved on disk.
2580 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2581 (let ((prefix (propertize
2582 " " 'display
2583 (propertize "@ " 'face 'anything-ff-prefix))))
2584 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2585 'help-echo bfname)) i)))
2586 ;; A buffer file modified and not saved on disk.
2587 ((and bfname (buffer-modified-p buf))
2588 (propertize i 'face 'anything-ff-symlink
2589 'help-echo bfname))
2590 ;; A remote buffer file not modified and saved on disk.
2591 ((and bfname (file-remote-p bfname))
2592 (let ((prefix (propertize
2593 " " 'display
2594 (propertize "@ " 'face 'anything-ff-prefix))))
2595 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2596 'help-echo bfname)) i)))
2597 ;; A buffer file not modified and saved on disk.
2598 (bfname
2599 (propertize i 'face 'font-lock-type-face
2600 'help-echo bfname))
2601 ;; Any non--file buffer.
2602 (t (propertize i 'face 'italic)))))
2605 (defvar anything-c-source-buffers-list
2606 '((name . "Buffers")
2607 (candidates . anything-c-buffer-list)
2608 (type . buffer)
2609 (match anything-c-buffer-match-major-mode)
2610 (candidate-transformer
2611 anything-c-skip-current-buffer
2612 anything-c-skip-boring-buffers
2613 anything-c-highlight-buffers)
2614 (persistent-action . anything-c-buffers-list-persistent-action)
2615 (volatile)
2616 (mode-line . anything-buffer-mode-line-string)
2617 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2618 ;; (anything 'anything-c-source-buffers-list)
2619 (defvaralias 'anything-c-source-buffers+ 'anything-c-source-buffers-list)
2621 (defun anything-c-buffer-match-major-mode (candidate)
2622 "Match maybe buffer by major-mode.
2623 If you give a major-mode or partial major-mode,
2624 it will list all buffers of this major-mode and/or buffers with name
2625 matching this major-mode.
2626 If you add a space after major-mode and then a space,
2627 it will match all buffers of the major-mode
2628 before space matching pattern after space.
2629 If you give a pattern which doesn't match a major-mode, it will search buffer
2630 with name matching pattern."
2631 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2632 (buf (get-buffer cand)))
2633 (when buf
2634 (with-current-buffer buf
2635 (let ((mjm (symbol-name major-mode))
2636 (split (split-string anything-pattern)))
2637 (cond ((string-match "\\s-$" anything-pattern)
2638 (string-match (car split) mjm))
2639 ((string-match "\\s-" anything-pattern)
2640 (and (string-match (car split) mjm)
2641 (string-match (cadr split) cand)))
2642 (t (or (string-match anything-pattern mjm)
2643 (string-match anything-pattern cand)))))))))
2645 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2646 "Query replace in marked buffers.
2647 If REGEXP-FLAG is given use `query-replace-regexp'."
2648 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2649 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2650 (bufs (anything-marked-candidates)))
2651 (loop
2652 with replace = (query-replace-read-from prompt regexp-flag)
2653 with tostring = (unless (consp replace)
2654 (query-replace-read-to
2655 replace prompt regexp-flag))
2656 for buf in bufs
2658 (save-window-excursion
2659 (anything-c-switch-to-buffer buf)
2660 (save-excursion
2661 (let ((case-fold-search t))
2662 (goto-char (point-min))
2663 (if (consp replace)
2664 (apply fn (list (car replace) (cdr replace)))
2665 (apply fn (list replace tostring)))))))))
2667 (defun anything-c-buffer-query-replace-regexp (candidate)
2668 (anything-c-buffer-query-replace-1 'regexp))
2670 (defun anything-c-buffer-query-replace (candidate)
2671 (anything-c-buffer-query-replace-1))
2673 (defun anything-buffer-toggle-diff (candidate)
2674 "Toggle diff buffer CANDIDATE with it's file."
2675 (if (get-buffer-window "*Diff*")
2676 (kill-buffer "*Diff*")
2677 (diff-buffer-with-file (get-buffer candidate))))
2679 ;;;###autoload
2680 (defun anything-buffer-diff-persistent ()
2681 "Toggle diff buffer without quitting anything."
2682 (interactive)
2683 (anything-attrset 'diff-action 'anything-buffer-toggle-diff)
2684 (anything-execute-persistent-action 'diff-action))
2686 (defun anything-buffer-revert-and-update (candidate)
2687 (let ((marked (anything-marked-candidates)))
2688 (loop for buf in marked do (anything-revert-buffer buf))
2689 (anything-force-update candidate)))
2691 ;;;###autoload
2692 (defun anything-buffer-revert-persistent ()
2693 "Revert buffer without quitting anything."
2694 (interactive)
2695 (anything-attrset 'revert-action 'anything-buffer-revert-and-update)
2696 (anything-execute-persistent-action 'revert-action 'onewindow))
2698 (defun anything-buffer-save-and-update (candidate)
2699 (let ((marked (anything-marked-candidates))
2700 (enable-recursive-minibuffers t))
2701 (loop for buf in marked do
2702 (with-current-buffer (get-buffer buf)
2703 (save-buffer)))
2704 (anything-force-update candidate)))
2706 ;;;###autoload
2707 (defun anything-buffer-save-persistent ()
2708 "Save buffer without quitting anything."
2709 (interactive)
2710 (anything-attrset 'save-action 'anything-buffer-save-and-update)
2711 (anything-execute-persistent-action 'save-action 'onewindow))
2713 ;;;###autoload
2714 (defun anything-buffer-run-kill-buffers ()
2715 "Run kill buffer action from `anything-c-source-buffers-list'."
2716 (interactive)
2717 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2719 ;;;###autoload
2720 (defun anything-buffer-run-grep ()
2721 "Run Grep action from `anything-c-source-buffers-list'."
2722 (interactive)
2723 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2725 ;;;###autoload
2726 (defun anything-buffer-run-zgrep ()
2727 "Run Grep action from `anything-c-source-buffers-list'."
2728 (interactive)
2729 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2731 ;;;###autoload
2732 (defun anything-buffer-run-query-replace-regexp ()
2733 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2734 (interactive)
2735 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2737 ;;;###autoload
2738 (defun anything-buffer-run-query-replace ()
2739 "Run Query replace action from `anything-c-source-buffers-list'."
2740 (interactive)
2741 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2743 ;;;###autoload
2744 (defun anything-buffer-switch-other-window ()
2745 "Run switch to other window action from `anything-c-source-buffers-list'."
2746 (interactive)
2747 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2749 ;;;###autoload
2750 (defun anything-buffer-switch-other-frame ()
2751 "Run switch to other frame action from `anything-c-source-buffers-list'."
2752 (interactive)
2753 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2755 ;;;###autoload
2756 (defun anything-buffer-switch-to-elscreen ()
2757 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2758 (interactive)
2759 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2761 ;;;###autoload
2762 (defun anything-buffer-run-ediff ()
2763 "Run ediff action from `anything-c-source-buffers-list'."
2764 (interactive)
2765 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2767 (defun anything-buffer-run-ediff-merge ()
2768 "Run ediff action from `anything-c-source-buffers-list'."
2769 (interactive)
2770 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2772 (defun anything-c-buffers-persistent-kill (buffer)
2773 "Persistent action to kill buffer."
2774 (with-current-buffer (get-buffer buffer)
2775 (if (and (buffer-modified-p)
2776 (buffer-file-name (current-buffer)))
2777 (progn
2778 (save-buffer)
2779 (kill-buffer buffer))
2780 (kill-buffer buffer)))
2781 (anything-delete-current-selection))
2783 (defun anything-c-buffers-list-persistent-action (candidate)
2784 (if current-prefix-arg
2785 (anything-c-buffers-persistent-kill candidate)
2786 (anything-c-switch-to-buffer candidate)))
2789 ;;;; <File>
2792 ;;; File name history
2793 (defvar anything-c-source-file-name-history
2794 '((name . "File Name History")
2795 (candidates . file-name-history)
2796 (match anything-c-match-on-basename)
2797 (type . file)))
2798 ;; (anything 'anything-c-source-file-name-history)
2800 ;;; Files in current dir
2803 (defvar anything-c-source-files-in-current-dir
2804 '((name . "Files from Current Directory")
2805 (candidates . (lambda ()
2806 (with-anything-current-buffer
2807 (directory-files (anything-c-current-directory)))))
2808 ;; volatile is not needed, I think.
2809 (type . file)))
2810 ;; (anything 'anything-c-source-files-in-current-dir)
2812 (defun anything-c-highlight-files (files)
2813 (loop for i in files
2814 if (file-directory-p i)
2815 collect (propertize (file-name-nondirectory i)
2816 'face 'anything-ff-directory
2817 'help-echo (expand-file-name i))
2818 else
2819 collect (propertize (file-name-nondirectory i)
2820 'face 'anything-ff-file
2821 'help-echo (expand-file-name i))))
2823 (defvar anything-c-source-files-in-current-dir+
2824 '((name . "Files from Current Directory")
2825 (candidates . (lambda ()
2826 (with-anything-current-buffer
2827 (directory-files (anything-c-current-directory) t))))
2828 (candidate-transformer anything-c-highlight-files)
2829 ;; volatile is not needed, I think.
2830 (type . file)))
2831 ;; (anything 'anything-c-source-files-in-current-dir+)
2835 ;;; Anything-find-files - The anything files browser.
2838 ;; Internal.
2839 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2840 "*The doc that is inserted in the Name header of a find-files or dired source.")
2841 (defvar anything-ff-auto-update-flag nil
2842 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2843 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2844 (defvar anything-ff-last-expanded nil
2845 "Store last expanded directory or file.")
2846 (defvar anything-ff-default-directory nil)
2847 (defvar anything-ff-history nil)
2848 (defvar anything-ff-cand-to-mark nil)
2851 (defvar anything-c-source-find-files
2852 `((name . "Find Files")
2853 (header-name . (lambda (name)
2854 (concat name anything-c-find-files-doc-header)))
2855 ;; It is needed for filenames with capital letters
2856 (disable-shortcuts)
2857 (init . (lambda ()
2858 (setq anything-ff-auto-update-flag
2859 anything-ff-auto-update-initial-value)))
2860 (candidates . anything-find-files-get-candidates)
2861 (filtered-candidate-transformer anything-c-find-files-transformer)
2862 (persistent-action . anything-find-files-persistent-action)
2863 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2864 (mode-line . anything-ff-mode-line-string)
2865 (volatile)
2866 (candidate-number-limit . 9999)
2867 (action-transformer . anything-find-files-action-transformer)
2868 (action
2869 . ,(delq
2871 `(("Find File" . anything-c-find-file-or-marked)
2872 ("Find file in Dired" . anything-c-point-file-in-dired)
2873 ,(and (locate-library "elscreen")
2874 '("Find file in Elscreen" . anything-elscreen-find-file))
2875 ,(and (locate-library "popwin")
2876 '("Find file in popup window" . popwin:find-file))
2877 ("Checksum File" . anything-ff-checksum)
2878 ("Complete at point `M-tab'"
2879 . anything-c-insert-file-name-completion-at-point)
2880 ("Open file externally `C-c C-x, C-u to choose'"
2881 . anything-c-open-file-externally)
2882 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2883 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2884 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2885 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2886 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2887 . anything-find-files-eshell-command-on-file)
2888 ("Find file as root" . anything-find-file-as-root)
2889 ("Find file in hex dump" . hexl-find-file)
2890 ("Ediff File `C-='" . anything-find-files-ediff-files)
2891 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2892 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2893 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2894 ("Copy file(s) Async" . anything-ff-copy-async)
2895 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2896 ("Serial rename files" . anything-ff-serial-rename)
2897 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2898 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2899 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2900 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2901 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2902 ("Find file other window `C-o'" . find-file-other-window)
2903 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2904 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2905 ("Print File `C-c p'" . anything-ff-print)
2906 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2907 ;; (anything 'anything-c-source-find-files)
2909 (defun anything-find-files-set-prompt-for-action (action files)
2910 "Set prompt for action ACTION for FILES."
2911 (let ((len (length files)))
2912 (format "%s *%s File(s)\n%s to: "
2913 action len
2914 (mapconcat (lambda (f)
2915 (format "- %s\n" f)) files ""))))
2917 (defun anything-dwim-target-directory ()
2918 "Return value of `default-directory' of buffer in other window.
2919 If there is only one window return the value ot `default-directory'
2920 for current buffer."
2921 (with-anything-current-buffer
2922 (let ((num-windows (length (window-list))))
2923 (if (> num-windows 1)
2924 (save-selected-window
2925 (other-window 1)
2926 default-directory)
2927 (car anything-ff-history)))))
2929 (defun anything-find-files-do-action (action)
2930 "Generic function for creating action from `anything-c-source-find-files'.
2931 ACTION must be an action supported by `anything-dired-action'."
2932 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2933 (anything-marked-candidates)))
2934 (cand (anything-get-selection)) ; Target
2935 (prompt (anything-find-files-set-prompt-for-action
2936 (capitalize (symbol-name action)) ifiles))
2937 (parg anything-current-prefix-arg)
2938 (dest (anything-c-read-file-name
2939 prompt
2940 :preselect (if anything-ff-transformer-show-only-basename
2941 (anything-c-basename cand) cand)
2942 :initial-input (anything-dwim-target-directory)
2943 :history (anything-find-files-history :comp-read nil))))
2944 (anything-dired-action
2945 dest :files ifiles :action action :follow parg)))
2947 (defun anything-find-files-copy (candidate)
2948 "Copy files from `anything-find-files'."
2949 (anything-find-files-do-action 'copy))
2951 (defun anything-find-files-rename (candidate)
2952 "Rename files from `anything-find-files'."
2953 (anything-find-files-do-action 'rename))
2955 (defun anything-find-files-symlink (candidate)
2956 "Symlink files from `anything-find-files'."
2957 (anything-find-files-do-action 'symlink))
2959 (defun anything-find-files-relsymlink (candidate)
2960 "Relsymlink files from `anything-find-files'."
2961 (anything-find-files-do-action 'relsymlink))
2963 (defun anything-find-files-hardlink (candidate)
2964 "Hardlink files from `anything-find-files'."
2965 (anything-find-files-do-action 'hardlink))
2967 (defun anything-find-files-byte-compile (candidate)
2968 "Byte compile elisp files from `anything-find-files'."
2969 (let ((files (anything-marked-candidates))
2970 (parg anything-current-prefix-arg))
2971 (loop for fname in files
2972 do (byte-compile-file fname parg))))
2974 (defun anything-find-files-load-files (candidate)
2975 "Load elisp files from `anything-find-files'."
2976 (let ((files (anything-marked-candidates)))
2977 (loop for fname in files
2978 do (load fname))))
2980 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2981 "Generic function to ediff/merge files in `anything-find-files'."
2982 (let ((bname (anything-c-basename candidate))
2983 (prompt (if merge "Ediff Merge `%s' With File: "
2984 "Ediff `%s' With File: "))
2985 (fun (if merge 'ediff-merge-files 'ediff-files)))
2986 (funcall fun
2987 candidate
2988 (condition-case quit
2989 (anything-c-read-file-name
2990 (format prompt bname))
2991 (quit ;; Hit C-g ask user to fallback to locate.
2992 (if (y-or-n-p "Search file for ediff with locate? ")
2993 (anything-c-locate-read-file-name
2994 (format prompt bname)
2995 ;; Check if -b option is available.
2996 (if (and (eq system-type 'windows-nt)
2997 (string-match "^es" anything-c-locate-command))
2998 bname
2999 (concat bname " -b")))
3000 (error "Error: Ediff Operation aborted")))))))
3002 (defun anything-find-files-ediff-files (candidate)
3003 (anything-find-files-ediff-files-1 candidate))
3005 (defun anything-find-files-ediff-merge-files (candidate)
3006 (anything-find-files-ediff-files-1 candidate 'merge))
3008 (defun anything-find-files-grep (candidate)
3009 "Default action to grep files from `anything-find-files'."
3010 (anything-do-grep-1 (anything-marked-candidates)
3011 anything-current-prefix-arg))
3013 (defun anything-ff-zgrep (candidate)
3014 "Default action to zgrep files from `anything-find-files'."
3015 (let ((prefarg anything-current-prefix-arg)
3016 (ls (anything-marked-candidates)))
3017 (anything-ff-zgrep-1 ls prefarg)))
3019 (defun anything-ff-pdfgrep (candidate)
3020 "Default action to pdfgrep files from `anything-find-files'."
3021 (let ((cands (loop for file in (anything-marked-candidates)
3022 if (or (string= (file-name-extension file) "pdf")
3023 (string= (file-name-extension file) "PDF"))
3024 collect file))
3025 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
3026 (when cands
3027 (anything-do-pdfgrep-1 cands))))
3029 (defun anything-ff-etags-select (candidate)
3030 "Default action to jump to etags from `anything-find-files'."
3031 (when (get-buffer anything-action-buffer)
3032 (kill-buffer anything-action-buffer))
3033 (let ((default-directory anything-ff-default-directory))
3034 (anything-c-etags-select anything-current-prefix-arg)))
3036 (defun anything-find-files-switch-to-hist (candidate)
3037 "Switch to anything-find-files history."
3038 (anything-find-files t))
3040 ;;; Asynchronous copy of files.
3043 (defun anything-c-copy-files-async-1 (flist dest)
3044 "Copy a list of Files FLIST to DEST asynchronously.
3045 It use another emacs process to do the job.
3046 Communication with background emacs is done with temp file
3047 `anything-c-copy-files-async-log-file'."
3048 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3049 "-Q" "--batch" "--eval"
3050 (format "(progn
3051 (require 'dired) (require 'cl)
3052 (let ((dired-recursive-copies 'always)
3053 failures success
3054 (ovw-count 0)
3055 (cpf-count 0))
3056 (dolist (f '%S)
3057 (condition-case err
3058 (let ((file-exists (file-exists-p
3059 (expand-file-name
3060 (file-name-nondirectory (directory-file-name f))
3061 (file-name-directory
3062 (file-name-as-directory \"%s\"))))))
3063 (dired-copy-file f \"%s\" t)
3064 (if file-exists
3065 (progn (push (cons \"Overwriting\" f) success)
3066 (incf ovw-count))
3067 (push (cons \"Copying\" f) success)
3068 (incf cpf-count)))
3069 (file-error
3070 (push (dired-make-relative
3071 (expand-file-name
3072 (file-name-nondirectory (directory-file-name f))
3073 (file-name-directory \"%s\")))
3074 failures))))
3075 (with-current-buffer (find-file-noselect \"%s\")
3076 (erase-buffer)
3077 (when failures
3078 (dolist (fail (reverse failures))
3079 (insert (concat \"Failed to copy \" fail \"\n\"))))
3080 (when success
3081 (loop for (a . s) in (reverse success) do
3082 (insert (concat a \" \" s \" to %s done\n\"))))
3083 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3084 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3085 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3086 (save-buffer))))"
3087 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3089 (defun anything-c-copy-async-with-log (flist dest)
3090 "Copy file list FLIST to DEST showing log.
3091 Log is send to `anything-c-copy-files-async-log-file'.
3092 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3093 (declare (special auto-revert-interval))
3094 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3095 (set (make-local-variable 'auto-revert-interval) 1)
3096 (erase-buffer)
3097 (insert "Wait copying files...\n")
3098 (sit-for 0.5) (save-buffer)
3099 (goto-char (point-max))
3100 (auto-revert-mode 1)
3101 (anything-c-copy-files-async-1 flist dest))
3103 (defun anything-ff-copy-async (candidate)
3104 "Anything find files action to copy files async.
3105 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3106 (let* ((flist (anything-marked-candidates))
3107 (dest (anything-c-read-file-name
3108 (anything-find-files-set-prompt-for-action
3109 "Copy Async" flist)
3110 :preselect candidate
3111 :initial-input (car anything-ff-history)
3112 :history (anything-find-files-history :comp-read nil))))
3113 (anything-c-copy-async-with-log flist dest)))
3115 (defvar eshell-command-aliases-list nil)
3116 (defvar anything-eshell-command-on-file-input-history nil)
3117 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3118 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3120 Basename of CANDIDATE can be a wild-card.
3121 If MAP is given run `eshell-command' on all marked files at once,
3122 Otherwise, run `eshell-command' on each marked files.
3124 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3125 `eshell-command-aliases-list' will not be loaded first time you use this."
3126 (when (or eshell-command-aliases-list
3127 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3128 (and eshell-command-aliases-list (eshell-read-aliases-list))
3129 (let* ((cand-list (anything-marked-candidates))
3130 (default-directory (or anything-ff-default-directory
3131 ;; If candidate is an url *-ff-default-directory is nil
3132 ;; so keep value of default-directory.
3133 default-directory))
3134 (command (anything-comp-read
3135 "Command: "
3136 (loop for (a . c) in eshell-command-aliases-list
3137 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3138 collect (propertize a 'help-echo (car c)) into ls
3139 finally return (sort ls 'string<))
3140 :buffer "*esh command on file*"
3141 :name "Eshell command"
3142 :input-history
3143 'anything-eshell-command-on-file-input-history))
3144 (com-value (car (assoc-default command eshell-command-aliases-list))))
3145 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3146 (> (length cand-list) 1))
3147 ;; Run eshell-command with ALL marked files as arguments.
3148 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3149 (eshell-command (format "%s %s" command mapfiles)))
3150 ;; Run eshell-command on EACH marked files.
3151 (loop
3152 for i in cand-list
3153 for bn = (anything-c-basename i)
3154 for files = (if (and bn (string-match "^\*" bn))
3155 ;; Assume if fname is a wildcard
3156 ;; cand-list have a length of 1.
3157 (mapconcat
3158 'shell-quote-argument
3159 (file-expand-wildcards i t) " ")
3160 (format "'%s'" i))
3161 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3162 ;; This allow to enter other args AFTER filename
3163 ;; i.e <command %s some_more_args>
3164 (format command files)
3165 (format "%s %s" command files))
3166 do (eshell-command com))))))
3168 (defun anything-find-files-eshell-command-on-file (candidate)
3169 "Run `eshell-command' on CANDIDATE or marked candidates.
3170 See `anything-find-files-eshell-command-on-file-1' for more info."
3171 (anything-find-files-eshell-command-on-file-1
3172 candidate anything-current-prefix-arg))
3174 (defun anything-ff-switch-to-eshell (candidate)
3175 "Switch to eshell and cd to `anything-ff-default-directory'."
3176 (flet ((cd-eshell ()
3177 (goto-char (point-max))
3178 (insert
3179 (format "cd '%s'" anything-ff-default-directory))
3180 (eshell-send-input)))
3181 (if (get-buffer "*eshell*")
3182 (progn
3183 (anything-c-switch-to-buffer "*eshell*")
3184 (cd-eshell))
3185 (call-interactively 'eshell)
3186 (cd-eshell))))
3188 (defun anything-ff-serial-rename-action (method)
3189 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3190 See `anything-ff-serial-rename-1'."
3191 (let* ((cands (anything-marked-candidates))
3192 (name (read-string "NewName: "))
3193 (start (read-number "StartAtNumber: "))
3194 (extension (read-string "Extension: " (file-name-extension (car cands))))
3195 (dir (expand-file-name
3196 (anything-c-read-file-name
3197 "Serial Rename to directory: " :initial-input
3198 (expand-file-name anything-ff-default-directory)))))
3199 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3200 (length cands) dir name))
3201 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3202 (anything-find-files-1 dir))))
3204 (defun anything-ff-member-directory-p (file directory)
3205 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3206 (cur-dir (expand-file-name (file-name-as-directory directory))))
3207 (string= dir-file cur-dir)))
3209 (defun* anything-ff-serial-rename-1
3210 (directory collection new-name start-at-num extension &key (method 'rename))
3211 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3212 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3213 EXTENSION is the file extension to use, in empty prompt,
3214 reuse the original extension of file.
3215 METHOD can be one of rename, copy or symlink.
3216 Files will be renamed if they are files of current directory, otherwise they
3217 will be treated with METHOD.
3218 Default METHOD is rename."
3219 ;; Maybe remove directories selected by error in collection.
3220 (setq collection (remove-if 'file-directory-p collection))
3221 (flet ((symlink-file (file dest)
3222 (let ((flist (list file)))
3223 (anything-dired-action
3224 dest :action 'symlink :files flist))))
3226 (let* ((tmp-dir (file-name-as-directory
3227 (concat (file-name-as-directory directory)
3228 (symbol-name (gensym "tmp")))))
3229 (fn (case method
3230 (copy 'copy-file)
3231 (symlink 'symlink-file)
3232 (rename 'rename-file)
3233 (t (error "Error: Unknow method %s" method)))))
3234 (make-directory tmp-dir)
3235 (loop for i in collection
3236 for count from start-at-num
3237 for fnum = (if (< count 10) "0%s" "%s")
3238 for nname = (concat tmp-dir new-name (format fnum count)
3239 (if (not (string= extension ""))
3240 (format ".%s" (replace-regexp-in-string
3241 "[.]" "" extension))
3242 (file-name-extension i 'dot)))
3243 do (if (anything-ff-member-directory-p i directory)
3244 (rename-file i nname)
3245 (funcall fn i nname)))
3246 (loop with dirlist = (directory-files
3247 tmp-dir t directory-files-no-dot-files-regexp)
3248 for f in dirlist do
3249 (if (file-symlink-p f)
3250 (symlink-file (file-truename f)
3251 (concat (file-name-as-directory directory)
3252 (anything-c-basename f)))
3253 (rename-file f directory)))
3254 (delete-directory tmp-dir t))))
3256 (defun anything-ff-serial-rename (candidate)
3257 "Serial rename all marked files to `anything-ff-default-directory'.
3258 Rename only file of current directory, and symlink files coming from
3259 other directories.
3260 See `anything-ff-serial-rename-1'."
3261 (anything-ff-serial-rename-action 'rename))
3263 (defun anything-ff-serial-rename-by-symlink (candidate)
3264 "Serial rename all marked files to `anything-ff-default-directory'.
3265 Rename only file of current directory, and symlink files coming from
3266 other directories.
3267 See `anything-ff-serial-rename-1'."
3268 (anything-ff-serial-rename-action 'symlink))
3270 (defun anything-ff-serial-rename-by-copying (candidate)
3271 "Serial rename all marked files to `anything-ff-default-directory'.
3272 Rename only file of current directory, and copy files coming from
3273 other directories.
3274 See `anything-ff-serial-rename-1'."
3275 (anything-ff-serial-rename-action 'copy))
3277 (defun anything-c-quit-and-execute-action (action)
3278 "Quit current anything session and execute ACTION."
3279 (setq anything-saved-action action)
3280 (anything-exit-minibuffer))
3282 (defun anything-ff-toggle-auto-update (candidate)
3283 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3284 (message "[Auto expansion %s]"
3285 (if anything-ff-auto-update-flag "enabled" "disabled")))
3287 ;;;###autoload
3288 (defun anything-ff-run-toggle-auto-update ()
3289 (interactive)
3290 (anything-attrset 'toggle-auto-update 'anything-ff-toggle-auto-update)
3291 (anything-execute-persistent-action 'toggle-auto-update))
3293 ;;;###autoload
3294 (defun anything-ff-run-switch-to-history ()
3295 "Run Switch to history action from `anything-c-source-find-files'."
3296 (interactive)
3297 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3299 ;;;###autoload
3300 (defun anything-ff-run-grep ()
3301 "Run Grep action from `anything-c-source-find-files'."
3302 (interactive)
3303 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3305 ;;;###autoload
3306 (defun anything-ff-run-pdfgrep ()
3307 "Run Pdfgrep action from `anything-c-source-find-files'."
3308 (interactive)
3309 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3311 ;;;###autoload
3312 (defun anything-ff-run-zgrep ()
3313 "Run Grep action from `anything-c-source-find-files'."
3314 (interactive)
3315 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3317 ;;;###autoload
3318 (defun anything-ff-run-copy-file ()
3319 "Run Copy file action from `anything-c-source-find-files'."
3320 (interactive)
3321 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3323 ;;;###autoload
3324 (defun anything-ff-run-rename-file ()
3325 "Run Rename file action from `anything-c-source-find-files'."
3326 (interactive)
3327 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3329 ;;;###autoload
3330 (defun anything-ff-run-byte-compile-file ()
3331 "Run Byte compile file action from `anything-c-source-find-files'."
3332 (interactive)
3333 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3335 ;;;###autoload
3336 (defun anything-ff-run-load-file ()
3337 "Run Load file action from `anything-c-source-find-files'."
3338 (interactive)
3339 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3341 ;;;###autoload
3342 (defun anything-ff-run-eshell-command-on-file ()
3343 "Run eshell command on file action from `anything-c-source-find-files'."
3344 (interactive)
3345 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3347 ;;;###autoload
3348 (defun anything-ff-run-ediff-file ()
3349 "Run Ediff file action from `anything-c-source-find-files'."
3350 (interactive)
3351 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3353 ;;;###autoload
3354 (defun anything-ff-run-ediff-merge-file ()
3355 "Run Ediff merge file action from `anything-c-source-find-files'."
3356 (interactive)
3357 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3359 ;;;###autoload
3360 (defun anything-ff-run-symlink-file ()
3361 "Run Symlink file action from `anything-c-source-find-files'."
3362 (interactive)
3363 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3365 ;;;###autoload
3366 (defun anything-ff-run-delete-file ()
3367 "Run Delete file action from `anything-c-source-find-files'."
3368 (interactive)
3369 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3371 ;;;###autoload
3372 (defun anything-ff-run-complete-fn-at-point ()
3373 "Run complete file name action from `anything-c-source-find-files'."
3374 (interactive)
3375 (anything-c-quit-and-execute-action
3376 'anything-c-insert-file-name-completion-at-point))
3378 ;;;###autoload
3379 (defun anything-ff-run-switch-to-eshell ()
3380 "Run switch to eshell action from `anything-c-source-find-files'."
3381 (interactive)
3382 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3384 ;;;###autoload
3385 (defun anything-ff-run-switch-other-window ()
3386 "Run switch to other window action from `anything-c-source-find-files'."
3387 (interactive)
3388 (anything-c-quit-and-execute-action 'find-file-other-window))
3390 ;;;###autoload
3391 (defun anything-ff-run-switch-other-frame ()
3392 "Run switch to other frame action from `anything-c-source-find-files'."
3393 (interactive)
3394 (anything-c-quit-and-execute-action 'find-file-other-frame))
3396 ;;;###autoload
3397 (defun anything-ff-run-open-file-externally ()
3398 "Run open file externally command action from `anything-c-source-find-files'."
3399 (interactive)
3400 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3402 (defun anything-ff-locate (candidate)
3403 "Locate action function for `anything-find-files'."
3404 (let ((input (concat (anything-c-basename
3405 (expand-file-name
3406 candidate
3407 anything-ff-default-directory))
3408 ;; The locate '-b' option doesn't exists
3409 ;; in everything.
3410 (unless (and (eq system-type 'windows-nt)
3411 (string-match "^es" anything-c-locate-command))
3412 " -b")))
3413 (anything-mp-highlight-delay 0.7))
3414 (anything-locate-1 anything-current-prefix-arg input)))
3416 ;;;###autoload
3417 (defun anything-ff-run-locate ()
3418 "Run locate action from `anything-c-source-find-files'."
3419 (interactive)
3420 (anything-c-quit-and-execute-action 'anything-ff-locate))
3422 ;;;###autoload
3423 (defun anything-ff-run-gnus-attach-files ()
3424 "Run gnus attach files command action from `anything-c-source-find-files'."
3425 (interactive)
3426 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3428 ;;;###autoload
3429 (defun anything-ff-run-etags ()
3430 "Run Etags command action from `anything-c-source-find-files'."
3431 (interactive)
3432 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3435 (defun anything-ff-print (candidate)
3436 "Print marked files.
3437 You have to set in order
3438 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3440 e.g:
3441 \(setq lpr-command \"gtklp\"\)
3442 \(setq lpr-switches '(\"-P\")\)
3443 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3445 Same as `dired-do-print' but for anything."
3446 (unless anything-ff-printer-list
3447 (setq anything-ff-printer-list
3448 (anything-ff-find-printers)))
3449 (let* ((file-list (anything-marked-candidates))
3450 (len (length file-list))
3451 (printer-name (if anything-ff-printer-list
3452 (anything-comp-read
3453 "Printer: " anything-ff-printer-list)
3454 printer-name))
3455 (command (read-string
3456 (format "Print *%s File(s):\n%s with: "
3458 (mapconcat
3459 (lambda (f) (format "- %s\n" f))
3460 file-list ""))
3461 (when (and lpr-command
3462 (or lpr-switches
3463 printer-name))
3464 (mapconcat 'identity
3465 (cons lpr-command
3466 (append (if (stringp lpr-switches)
3467 (list lpr-switches)
3468 lpr-switches)
3469 (list printer-name)))
3470 " "))))
3471 (file-args (mapconcat #'(lambda (x)
3472 (format "'%s'" x))
3473 file-list " "))
3474 (cmd-line (concat command " " file-args)))
3475 (if command
3476 (start-process-shell-command "anything-print" nil cmd-line)
3477 (error "Error: Please verify your printer settings in Emacs."))))
3479 ;;;###autoload
3480 (defun anything-ff-run-print-file ()
3481 "Run Print file action from `anything-c-source-find-files'."
3482 (interactive)
3483 (anything-c-quit-and-execute-action 'anything-ff-print))
3485 (defun anything-ff-checksum (file)
3486 "Calculate the checksum of FILE.
3487 Provide completion on different algorithms to use on Emacs24.
3488 On Emacs23 only 'sha1' is available.
3489 The checksum is copied to kill-ring."
3490 (let ((algo-list (and (fboundp 'secure-hash)
3491 '(md5 sha1 sha224 sha256 sha384 sha512))))
3492 (kill-new
3493 (if algo-list
3494 (secure-hash (intern
3495 (anything-comp-read
3496 "Algorithm: " algo-list))
3497 file)
3498 (sha1 (with-temp-buffer
3499 (insert-file-contents file)
3500 (buffer-string)))))
3501 (message "Checksum copied to kill-ring.")))
3503 (defun anything-ff-toggle-basename (candidate)
3504 (setq anything-ff-transformer-show-only-basename
3505 (not anything-ff-transformer-show-only-basename))
3506 (let ((target (if anything-ff-transformer-show-only-basename
3507 (anything-c-basename candidate) candidate)))
3508 (anything-force-update target)))
3510 (defun anything-ff-run-toggle-basename ()
3511 (interactive)
3512 (anything-attrset 'toggle-basename 'anything-ff-toggle-basename)
3513 (anything-execute-persistent-action 'toggle-basename))
3515 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3516 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3517 If LEVEL is positive reduce from end else from beginning.
3518 If UNIX-CLOSE is non--nil close filename with /.
3519 If EXPAND is non--nil expand-file-name."
3520 (let* ((exp-fname (expand-file-name fname))
3521 (fname-list (split-string (if (or (string= fname "~/") expand)
3522 exp-fname fname) "/" t))
3523 (len (length fname-list))
3524 (pop-list (if (< level 0)
3525 (subseq fname-list (* level -1))
3526 (subseq fname-list 0 (- len level))))
3527 (result (mapconcat 'identity pop-list "/"))
3528 (empty (string= result "")))
3529 (when unix-close (setq result (concat result "/")))
3530 (if (string-match "^~" result)
3531 (if (string= result "~/") "~/" result)
3532 (if (< level 0)
3533 (if empty "../" (concat "../" result))
3534 (cond ((eq system-type 'windows-nt)
3535 (if empty (expand-file-name "/") ; Expand to "/" or "c:/".
3536 result))
3537 (empty "/")
3539 (concat "/" result)))))))
3541 ;; Internal
3542 (defvar anything-file-completion-sources
3543 '("Find Files" "Read File Name"
3544 "Read File Name History" "Copy Files"
3545 "Rename Files" "Symlink Files"
3546 "Hardlink Files" "Write File" "Insert File")
3547 "Sources that use the *find-files mechanism can be added here.
3548 Sources generated by `ac-mode' don't need to be added here, it will
3549 be done automatically.
3550 You should not modify this yourself unless you know what you do.")
3552 (defun anything-file-completion-source-p ()
3553 "Test if current source is a dired or find-files source."
3554 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3555 (loop for i in anything-file-completion-sources
3556 thereis (string= cur-source i))))
3558 (defun anything-find-files-down-one-level (arg)
3559 "Go down one level like unix command `cd ..'.
3560 If prefix numeric arg is given go ARG level down."
3561 (interactive "p")
3562 (when (and (anything-file-completion-source-p)
3563 (not (anything-ff-invalid-tramp-name-p)))
3564 (with-anything-window
3565 (setq anything-follow-mode nil))
3566 ;; When going to precedent level we want to be at the line
3567 ;; corresponding to actual directory, so store this info
3568 ;; in `anything-ff-last-expanded'.
3569 (if (and (not (file-directory-p anything-pattern))
3570 (file-exists-p anything-pattern))
3571 (setq anything-ff-last-expanded anything-pattern)
3572 (setq anything-ff-last-expanded anything-ff-default-directory))
3573 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3574 :unix-close t :expand t)))
3575 (anything-set-pattern new-pattern))))
3577 (defun anything-ff-retrieve-last-expanded ()
3578 "Move overlay to last visited directory `anything-ff-last-expanded'.
3579 This happen after using `anything-find-files-down-one-level',
3580 or hitting C-z on \"..\"."
3581 (when (and anything-ff-last-expanded
3582 (anything-file-completion-source-p))
3583 (let ((dirname (if anything-ff-transformer-show-only-basename
3584 (anything-c-basename
3585 (directory-file-name anything-ff-last-expanded))
3586 (directory-file-name anything-ff-last-expanded))))
3587 (with-anything-window
3588 (when (or (re-search-forward (concat dirname "$") nil t)
3589 (re-search-forward
3590 (concat anything-ff-last-expanded "$") nil t))
3591 (forward-line 0)
3592 (anything-mark-current-line)))
3593 (setq anything-ff-last-expanded nil))))
3594 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3596 ;; Auto-update - anything-find-files auto expansion of directories.
3598 (defun anything-ff-update-when-only-one-matched ()
3599 "Expand to directory when sole completion.
3600 When only one candidate is remaining and it is a directory,
3601 expand to this directory."
3602 (when (and anything-ff-auto-update-flag
3603 (anything-file-completion-source-p)
3604 (not (anything-ff-invalid-tramp-name-p)))
3605 (let* ((history-p (string= (assoc-default
3606 'name (anything-get-current-source))
3607 "Read File Name History"))
3608 (pat (if (string-match tramp-file-name-regexp
3609 anything-pattern)
3610 (anything-create-tramp-name anything-pattern)
3611 anything-pattern))
3612 (completed-p (string= (file-name-as-directory pat)
3613 anything-ff-default-directory)))
3614 (when (and (or
3615 ;; Only one candidate remaining
3616 ;; and at least 2 char in basename.
3617 (and (<= (anything-approximate-candidate-number) 2)
3618 (>= (length (anything-c-basename anything-pattern)) 2))
3619 ;; Already completed.
3620 completed-p)
3621 (not history-p)) ; Don't try to auto complete in history.
3622 (with-anything-window
3623 (let ((cur-cand (prog2
3624 (unless completed-p
3625 ;; Only one non--existing candidate
3626 ;; and one directory candidate, move to it.
3627 (anything-next-line))
3628 (anything-get-selection))))
3629 (when (file-directory-p cur-cand)
3630 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3631 ;; Maybe we are here because completed-p is true
3632 ;; but check this again to be sure. (Windows fix)
3633 (<= (anything-approximate-candidate-number) 2)) ; [2]
3634 ;; If after going to next line the candidate
3635 ;; is not one of "." or ".." [1]
3636 ;; and only one candidate is remaining [2],
3637 ;; assume candidate is a new directory to expand, and do it.
3638 (anything-set-pattern (file-name-as-directory cur-cand))
3639 ;; The candidate is one of "." or ".."
3640 ;; that mean we have entered the last letter of the directory name
3641 ;; in prompt, so expansion is already done, just add the "/" at end
3642 ;; of name unless anything-pattern ends with "."
3643 ;; (i.e we are writing something starting with ".")
3644 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3645 (anything-set-pattern
3646 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3647 (expand-file-name (file-name-as-directory anything-pattern)))))
3648 (anything-check-minibuffer-input-1))))))))
3649 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3651 ;; Allow expanding to home directory or root
3652 ;; when entering respectively "~/" or "//" at end of pattern.
3653 ;; e.g /home/thierry/labo/anything-config-qp/~/
3654 ;; will expand to "~/"
3655 ;; and /home/thierry/labo/anything-config-qp//
3656 ;; will expand to "/"
3657 (defun anything-ff-auto-expand-to-home-or-root ()
3658 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3659 This happen only in function using sources that are
3660 `anything-file-completion-source-p' compliant."
3661 (when (and (anything-file-completion-source-p)
3662 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3663 anything-pattern))
3664 (let ((match (match-string 1 anything-pattern)))
3665 (cond ((string= match "//")
3666 ;; Expand to "/" or "c:/"
3667 (setq anything-pattern (expand-file-name "/")))
3668 ((string= match "/~/")
3669 (if (eq system-type 'windows-nt)
3670 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3671 (setq anything-pattern "~/")))
3672 ((string= match "/./")
3673 (setq anything-pattern
3674 (with-anything-current-buffer
3675 (expand-file-name default-directory))))))
3676 (setq anything-ff-default-directory anything-pattern)
3677 ;; For some reasons, i must use here with-current-buffer => mini buffer
3678 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3679 (with-current-buffer (window-buffer (minibuffer-window))
3680 (delete-minibuffer-contents)
3681 (insert anything-pattern))))
3683 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3685 (defun anything-c-point-file-in-dired (file)
3686 "Put point on filename FILE in dired buffer."
3687 (dired (file-name-directory file))
3688 (dired-goto-file file))
3690 (defun anything-create-tramp-name (fname)
3691 "Build filename for `anything-pattern' like /su:: or /sudo::."
3692 (apply #'tramp-make-tramp-file-name
3693 (loop with v = (tramp-dissect-file-name fname)
3694 for i across v collect i)))
3696 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3697 "Get a list of hosts for tramp method found in `anything-pattern'.
3698 Argument PATTERN default to `anything-pattern', it is here only for debugging
3699 purpose."
3700 (when (string-match tramp-file-name-regexp pattern)
3701 (let ((method (match-string 1 pattern))
3702 (tn (match-string 0 pattern))
3703 (all-methods (mapcar 'car tramp-methods)))
3704 (remove-duplicates
3705 (loop for (f . h) in (tramp-get-completion-function method)
3706 append (loop for e in (funcall f (car h))
3707 for host = (and (consp e) (cadr e))
3708 when (and host (not (member host all-methods)))
3709 collect (concat tn host)))
3710 :test 'equal))))
3712 (defun anything-ff-before-action-hook-fn ()
3713 "Exit anything when user try to execute action on an invalid tramp fname."
3714 (let ((cand (anything-get-selection)))
3715 (when (and (anything-file-completion-source-p)
3716 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3717 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3718 (error "Error: Unknow file or directory `%s'" cand))))
3719 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3721 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3722 "Return non--nil when PATTERN is an invalid tramp filename."
3723 (string= (anything-ff-set-pattern pattern)
3724 "Invalid tramp file name"))
3726 (defun anything-ff-set-pattern (pattern)
3727 "Handle tramp filenames in `anything-pattern'."
3728 (let ((methods (mapcar 'car tramp-methods))
3729 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3730 cur-method tramp-name)
3731 (cond ((string= pattern "") "")
3732 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3733 (with-anything-current-buffer
3734 (expand-file-name default-directory)))
3735 ((string-match ".*\\(~//\\|//\\)$" pattern)
3736 (expand-file-name "/") ; Expand to "/" or "c:/"
3738 ((string-match "^~\\|.*/~/$" pattern)
3739 (let* ((home (expand-file-name (getenv "HOME"))))
3740 (replace-match home nil t pattern)))
3741 ;; Match "/method:maybe_hostname:"
3742 ((and (string-match reg pattern)
3743 (setq cur-method (match-string 1 pattern))
3744 (member cur-method methods))
3745 (setq tramp-name (anything-create-tramp-name
3746 (match-string 0 pattern)))
3747 (replace-match tramp-name nil t pattern))
3748 ;; Match "/hostname:"
3749 ((and (string-match tramp-file-name-regexp pattern)
3750 (setq cur-method (match-string 1 pattern))
3751 (and cur-method (not (member cur-method methods))))
3752 (setq tramp-name (anything-create-tramp-name
3753 (match-string 0 pattern)))
3754 (replace-match tramp-name nil t pattern))
3755 ;; Match "/method:" in this case don't try to connect.
3756 ((and (not (string-match reg pattern))
3757 (string-match tramp-file-name-regexp pattern)
3758 (member (match-string 1 pattern) methods))
3759 "Invalid tramp file name") ; Write in anything-buffer.
3760 ;; PATTERN is a directory, end it with "/".
3761 ;; This will make PATTERN not ending yet with "/"
3762 ;; candidate for `anything-ff-default-directory',
3763 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3764 ;; when descending level.
3765 ((file-directory-p pattern)
3766 (file-name-as-directory pattern))
3767 ;; Return PATTERN unchanged.
3768 (t pattern))))
3770 (defun anything-find-files-get-candidates (&optional require-match)
3771 "Create candidate list for `anything-c-source-find-files'."
3772 (let* ((path (anything-ff-set-pattern anything-pattern))
3773 (path-name-dir (if (file-directory-p path)
3774 (file-name-as-directory path)
3775 (file-name-directory path)))
3776 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3777 (set-text-properties 0 (length path) nil path)
3778 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3779 ;; like that the actual value (e.g /ssh:) is passed to
3780 ;; `anything-ff-tramp-hostnames'.
3781 (unless (string= path "Invalid tramp file name")
3782 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3783 (setq anything-ff-default-directory
3784 (if (string= anything-pattern "")
3785 (expand-file-name "/") ; Expand to "/" or "c:/"
3786 (unless (string-match ffap-url-regexp path)
3787 ;; If path is an url *default-directory have to be nil.
3788 path-name-dir)))
3789 (cond ((string= path "Invalid tramp file name")
3790 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3791 (prog2
3792 ;; `anything-pattern' have not been modified yet.
3793 ;; Set it here to the value of `path' that should be now
3794 ;; "Invalid tramp file name" and set the candidates list
3795 ;; to ("Invalid tramp file name") to make `anything-pattern'
3796 ;; match single candidate "Invalid tramp file name".
3797 (setq anything-pattern path)
3798 ;; "Invalid tramp file name" is now printed
3799 ;; in `anything-buffer'.
3800 (list path))))
3801 ((or (file-regular-p path)
3802 (and (not (file-exists-p path)) (string-match "/$" path))
3803 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3804 (list path))
3805 ((string= path "") (anything-ff-directory-files "/" t))
3806 ((and (file-directory-p path) (not (file-readable-p path)))
3807 (list (format "Opening directory: access denied, `%s'" path)))
3808 ((file-directory-p path) (anything-ff-directory-files path t))
3810 (append (unless require-match (list path))
3811 (anything-ff-directory-files path-name-dir t))))))
3813 (defun anything-ff-directory-files (directory &optional full)
3814 "List contents of DIRECTORY.
3815 Argument FULL mean absolute path.
3816 It is same as `directory-files' but always returns the
3817 dotted filename '.' and '..' on root directories on Windows
3818 systems."
3819 (setq directory (expand-file-name directory))
3820 (if (string-match "^[a-zA-Z]\\{1\\}:/$" directory)
3821 (let* ((dot (concat directory "."))
3822 (dot2 (concat directory ".."))
3823 (lsdir (remove
3824 dot2
3825 (remove
3827 (directory-files directory full)))))
3828 (append (list dot dot2) lsdir))
3829 (directory-files directory full)))
3831 (defun anything-ff-transform-fname-for-completion (fname)
3832 "Return FNAME with it's basename modified as a regexp.
3833 e.g foo => f.*o.*o .
3834 If basename contain one or more space or FNAME is a valid directory name
3835 return FNAME unchanged."
3836 (let ((bn (anything-c-basename fname)))
3837 (if (or (not anything-ff-smart-completion)
3838 (string-match "\\s-" bn)
3839 (string-match "/$" fname) ; Allow mkdir.
3840 (file-directory-p fname))
3841 fname ; Fall back to match-plugin.
3842 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3843 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3844 (concat (file-name-directory fname) bn))))
3846 (defun anything-ff-save-history ()
3847 "Store the last value of `anything-ff-default-directory' \
3848 in `anything-ff-history'."
3849 (when (and anything-ff-default-directory
3850 (anything-file-completion-source-p))
3851 (push anything-ff-default-directory anything-ff-history)))
3852 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3854 (defun anything-ff-valid-symlink-p (file)
3855 (file-exists-p (file-truename file)))
3857 (defun anything-ff-properties (candidate)
3858 "Show file properties of CANDIDATE in a tooltip or message."
3859 (let ((type (anything-ff-attributes candidate :type t))
3860 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3861 (if (window-system)
3862 (tooltip-show
3863 (concat
3864 (anything-c-basename candidate) ": \n"
3865 "Type: " type "\n"
3866 (when (string= type "symlink")
3867 (format "True name: '%s'\n"
3868 (cond ((string-match "^\.#" (anything-c-basename candidate))
3869 "Autosave symlink")
3870 ((anything-ff-valid-symlink-p candidate)
3871 (file-truename candidate))
3872 (t "Invalid Symlink"))))
3873 dired-line))
3874 (message dired-line) (sit-for 5))))
3876 ;;;###autoload
3877 (defun anything-ff-properties-persistent ()
3878 "Show properties without quitting anything."
3879 (interactive)
3880 (anything-attrset 'properties-action 'anything-ff-properties)
3881 (anything-execute-persistent-action 'properties-action))
3883 ;;;###autoload
3884 (defun anything-ff-persistent-delete ()
3885 "Delete current candidate without quitting."
3886 (interactive)
3887 (anything-attrset 'quick-delete 'anything-ff-quick-delete)
3888 (anything-execute-persistent-action 'quick-delete))
3890 (defun anything-ff-dot-file-p (file)
3891 "Check if FILE is `.' or `..'."
3892 (member (anything-c-basename file) '("." "..")))
3894 (defun anything-ff-quick-delete (candidate)
3895 "Delete file CANDIDATE without quitting."
3896 (if (and anything-ff-signal-error-on-dot-files
3897 (anything-ff-dot-file-p candidate))
3898 (message "Error: Cannot operate on `.' or `..'")
3899 (let ((presel (prog1 (save-excursion
3900 (let (sel)
3901 (anything-next-line)
3902 (setq sel (anything-get-selection))
3903 (if (string= sel candidate)
3904 (progn (anything-previous-line)
3905 (anything-get-selection))
3906 sel)))
3907 (anything-mark-current-line))))
3908 (setq presel (if (and anything-ff-transformer-show-only-basename
3909 (not (anything-ff-dot-file-p presel)))
3910 (anything-c-basename presel) presel))
3911 (if anything-ff-quick-delete-dont-prompt-for-deletion
3912 (anything-c-delete-file candidate)
3913 (save-selected-window
3914 (when (y-or-n-p (format "Really Delete file `%s'? " candidate))
3915 (anything-c-delete-file candidate))))
3916 (anything-force-update presel))))
3918 (defun anything-ff-kill-buffer-fname (candidate)
3919 (let* ((buf (get-file-buffer candidate))
3920 (buf-name (buffer-name buf)))
3921 (if buf
3922 (progn
3923 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3924 (message "No buffer to kill"))))
3926 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3927 "Find file CANDIDATE or kill it's buffer if it is visible.
3928 Never kill `anything-current-buffer'.
3929 Never kill buffer modified.
3930 This is called normally on third hit of \
3931 \\<anything-map>\\[anything-execute-persistent-action]
3932 in `anything-find-files-persistent-action'."
3933 (let* ((buf (get-file-buffer candidate))
3934 (buf-name (buffer-name buf)))
3935 (if (and buf (get-buffer-window buf)
3936 (not (eq buf (get-buffer anything-current-buffer)))
3937 (not (buffer-modified-p buf)))
3938 (progn
3939 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3940 (find-file candidate))))
3942 ;;;###autoload
3943 (defun anything-ff-run-kill-buffer-persistent ()
3944 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3945 (interactive)
3946 (anything-attrset 'kill-buffer-fname 'anything-ff-kill-buffer-fname)
3947 (anything-execute-persistent-action 'kill-buffer-fname))
3949 (defun anything-ff-human-size (size)
3950 "Return a string showing SIZE of a file in human readable form.
3951 SIZE can be an integer or a float depending it's value.
3952 `file-attributes' will take care of that to avoid overflow error.
3953 KBSIZE if a floating point number, default value is 1024.0."
3954 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3955 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3956 (K (cons "K" (/ size anything-ff-default-kbsize)))
3957 (B (cons "B" size)))
3958 (loop with result = B
3959 for (a . b) in
3960 (loop for (x . y) in (list M G K B)
3961 unless (< y 1) collect (cons x y))
3962 when (< b (cdr result)) do (setq result (cons a b))
3963 finally return (if (string= (car result) "B")
3964 (format "%s" size)
3965 (format "%.1f%s" (cdr result) (car result))))))
3967 (defun* anything-ff-attributes
3968 (file &key type links uid gid access-time modif-time
3969 status size mode gid-change inode device-num dired human-size)
3970 "Easy interface for `file-attributes'."
3971 (let ((all (destructuring-bind
3972 (type links uid gid access-time modif-time
3973 status size mode gid-change inode device-num)
3974 (file-attributes file 'string)
3975 (list :type type
3976 :links links
3977 :uid uid
3978 :gid gid
3979 :access-time access-time
3980 :modif-time modif-time
3981 :status status
3982 :size size
3983 :mode mode
3984 :gid-change gid-change
3985 :inode inode
3986 :device-num device-num))))
3987 (cond (type
3988 (let ((result (getf all :type)))
3989 (cond ((stringp result)
3990 "symlink")
3991 (result "directory")
3992 (t "file"))))
3993 (links (getf all :links))
3994 (uid (getf all :uid))
3995 (gid (getf all :gid))
3996 (access-time
3997 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3998 (modif-time
3999 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
4000 (status
4001 (format-time-string "%Y-%m-%d %R" (getf all :status)))
4002 (size (if human-size (anything-ff-human-size (getf all :size))
4003 (getf all :size)))
4004 (mode (getf all :mode))
4005 (gid-change (getf all :gid-change))
4006 (inode (getf all :inode))
4007 (device-num (getf all :device-num))
4008 (dired
4009 (concat
4010 (getf all :mode) " "
4011 (number-to-string (getf all :links)) " "
4012 (getf all :uid) ":"
4013 (getf all :gid) " "
4014 (if human-size (anything-ff-human-size (getf all :size))
4015 (int-to-string (getf all :size))) " "
4016 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
4017 (t all))))
4019 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
4020 "Return filename FNAME maybe prefixed with [?] or [@].
4021 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4022 existing filename or valid symlink and there is no need to test it.
4023 NEW-FILE when non--nil mean FNAME is a non existing file and
4024 return FNAME prefixed with [?]."
4025 (let* ((prefix-new (propertize
4026 " " 'display
4027 (propertize "[?]" 'face 'anything-ff-prefix)))
4028 (prefix-url (propertize
4029 " " 'display
4030 (propertize "[@]" 'face 'anything-ff-prefix))))
4031 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
4032 ((string-match ffap-url-regexp fname)
4033 (concat prefix-url " " fname))
4034 ((or new-file (not (file-exists-p fname)))
4035 (concat prefix-new " " fname)))))
4037 (defun anything-c-find-files-transformer (files sources)
4038 "Transformer for `anything-c-source-find-files'.
4039 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4040 is non--nil."
4041 (if (and (string-match tramp-file-name-regexp anything-pattern)
4042 anything-ff-tramp-not-fancy)
4043 (if anything-ff-transformer-show-only-basename
4044 (loop for i in files collect
4045 (if (string-match "[.]\\{1,2\\}$" i)
4046 i (cons (anything-c-basename i) i)))
4047 files)
4048 (anything-ff-highlight-files files sources)))
4050 (defun anything-ff-highlight-files (files sources)
4051 "Candidate transformer for `anything-c-source-find-files' without icons."
4052 (loop for i in files
4053 for disp = (if (and anything-ff-transformer-show-only-basename
4054 (not (string-match "[.]\\{1,2\\}$" i))
4055 (not (string-match ffap-url-regexp i)))
4056 (anything-c-basename i) i)
4057 collect
4058 (cond ((and (stringp (car (file-attributes i)))
4059 (not (anything-ff-valid-symlink-p i))
4060 (not (string-match "^\.#" (anything-c-basename i))))
4061 (cons (anything-ff-prefix-filename
4062 (propertize disp 'face 'anything-ff-invalid-symlink) t)
4064 ((stringp (car (file-attributes i)))
4065 (cons (anything-ff-prefix-filename
4066 (propertize disp 'face 'anything-ff-symlink) t)
4068 ((eq t (car (file-attributes i)))
4069 (cons (anything-ff-prefix-filename
4070 (propertize disp 'face 'anything-ff-directory) t)
4072 ((file-executable-p i)
4073 (cons (anything-ff-prefix-filename
4074 (propertize disp 'face 'anything-ff-executable) t)
4076 ((file-exists-p i)
4077 (cons (anything-ff-prefix-filename
4078 (propertize disp 'face 'anything-ff-file) t)
4081 (cons (anything-ff-prefix-filename
4082 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4083 i)))))
4085 (defun anything-find-files-action-transformer (actions candidate)
4086 "Action transformer for `anything-c-source-find-files'."
4087 (cond ((with-anything-current-buffer
4088 (eq major-mode 'message-mode))
4089 (append (subseq actions 0 4)
4090 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4091 (subseq actions 4)))
4092 ((string-match (image-file-name-regexp) candidate)
4093 (append (subseq actions 0 4)
4094 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4095 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4096 (subseq actions 4)))
4097 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4098 (car it) candidate))
4099 (append (subseq actions 0 4)
4100 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4101 . anything-find-files-byte-compile)
4102 ("Load File(s) `M-L'" . anything-find-files-load-files))
4103 (subseq actions 4)))
4104 ((and (string-match "\.html?$" candidate)
4105 (file-exists-p candidate))
4106 (append (subseq actions 0 4)
4107 '(("Browse url file" . browse-url-of-file))
4108 (subseq actions 5)))
4109 ((or (string= (file-name-extension candidate) "pdf")
4110 (string= (file-name-extension candidate) "PDF"))
4111 (append (subseq actions 0 4)
4112 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4113 (subseq actions 5)))
4114 (t actions)))
4116 (defun anything-ff-gnus-attach-files (candidate)
4117 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4118 (let ((flist (anything-marked-candidates)))
4119 (gnus-dired-attach flist)))
4121 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4122 "Rotate current image at NUM-ARG degrees.
4123 This is a destructive operation on FILE made by external tool mogrify."
4124 (declare (special image-dired-display-image-buffer))
4125 (setq file (file-truename file)) ; For symlinked images.
4126 ;; When FILE is not an image-file, do nothing.
4127 (when (string-match (image-file-name-regexp) file)
4128 (if (executable-find "mogrify")
4129 (progn
4130 (shell-command (format "mogrify -rotate %s %s"
4131 (or num-arg 90)
4132 (shell-quote-argument file)))
4133 (when (buffer-live-p image-dired-display-image-buffer)
4134 (kill-buffer image-dired-display-image-buffer))
4135 (image-dired-display-image file)
4136 (message nil)
4137 (display-buffer (get-buffer image-dired-display-image-buffer)))
4138 (error "mogrify not found"))))
4140 (defun anything-ff-rotate-image-left (candidate)
4141 "Rotate image file CANDIDATE left.
4142 This affect directly file CANDIDATE."
4143 (anything-ff-rotate-current-image-1 candidate -90))
4145 (defun anything-ff-rotate-image-right (candidate)
4146 "Rotate image file CANDIDATE right.
4147 This affect directly file CANDIDATE."
4148 (anything-ff-rotate-current-image-1 candidate))
4150 (defun anything-ff-rotate-left-persistent ()
4151 "Rotate image left without quitting anything."
4152 (interactive)
4153 (anything-attrset 'image-action1 'anything-ff-rotate-image-left)
4154 (anything-execute-persistent-action 'image-action1))
4156 (defun anything-ff-rotate-right-persistent ()
4157 "Rotate image right without quitting anything."
4158 (interactive)
4159 (anything-attrset 'image-action2 'anything-ff-rotate-image-right)
4160 (anything-execute-persistent-action 'image-action2))
4162 (defun anything-ff-exif-data (candidate)
4163 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4164 (if (and anything-ff-exif-data-program
4165 (executable-find anything-ff-exif-data-program))
4166 (shell-command-to-string (format "%s %s %s"
4167 anything-ff-exif-data-program
4168 anything-ff-exif-data-program-args
4169 candidate))
4170 (format "No program %s found to extract exif"
4171 anything-ff-exif-data-program)))
4173 (defun anything-find-files-persistent-action (candidate)
4174 "Open subtree CANDIDATE without quitting anything.
4175 If CANDIDATE is not a directory expand CANDIDATE filename.
4176 If CANDIDATE is alone, open file CANDIDATE filename.
4177 That's mean:
4178 First hit on C-z expand CANDIDATE second hit open file.
4179 If a prefix arg is given or `anything-follow-mode' is on open file."
4180 (let ((follow (buffer-local-value
4181 'anything-follow-mode
4182 (get-buffer-create anything-buffer)))
4183 (new-pattern (anything-get-selection))
4184 (num-lines-buf (with-current-buffer anything-buffer
4185 (count-lines (point-min) (point-max)))))
4186 (flet ((insert-in-minibuffer (fname)
4187 (with-selected-window (minibuffer-window)
4188 (unless follow
4189 (delete-minibuffer-contents)
4190 (set-text-properties 0 (length fname) nil fname)
4191 (insert fname)))))
4192 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4193 "Invalid tramp file name")
4194 (string-match tramp-file-name-regexp candidate))
4195 ;; First hit insert hostname and
4196 ;; second hit insert ":" and expand.
4197 (if (string= candidate anything-pattern)
4198 (insert-in-minibuffer (concat candidate ":"))
4199 (insert-in-minibuffer candidate)))
4200 (;; A symlink directory, expand it's truename.
4201 (and (file-directory-p candidate) (file-symlink-p candidate))
4202 (insert-in-minibuffer (file-name-as-directory
4203 (file-truename
4204 (expand-file-name candidate)))))
4205 ;; A directory, open it.
4206 ((file-directory-p candidate)
4207 (when (string= (anything-c-basename candidate) "..")
4208 (setq anything-ff-last-expanded anything-ff-default-directory))
4209 (insert-in-minibuffer (file-name-as-directory
4210 (expand-file-name candidate))))
4211 ;; A symlink file, expand to it's true name. (first hit)
4212 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4213 (insert-in-minibuffer (file-truename candidate)))
4214 ;; A regular file, expand it, (first hit)
4215 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4216 (insert-in-minibuffer new-pattern))
4217 ;; An image file and it is the second hit on C-z,
4218 ;; show the file in `image-dired'.
4219 ((string-match (image-file-name-regexp) candidate)
4220 (when (buffer-live-p image-dired-display-image-buffer)
4221 (kill-buffer image-dired-display-image-buffer))
4222 (image-dired-display-image candidate)
4223 (message nil)
4224 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4225 (with-current-buffer image-dired-display-image-buffer
4226 (let ((exif-data (anything-ff-exif-data candidate)))
4227 (image-dired-update-property 'help-echo exif-data))))
4228 ;; Allow browsing archive on avfs fs.
4229 ;; Assume volume is already mounted with mountavfs.
4230 ((and anything-ff-avfs-directory
4231 (string-match
4232 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4233 (file-name-directory candidate))
4234 (anything-ff-file-compressed-p candidate))
4235 (insert-in-minibuffer (concat candidate "#")))
4236 ;; On second hit we open file.
4237 ;; On Third hit we kill it's buffer maybe.
4239 (anything-ff-kill-or-find-buffer-fname candidate))))))
4241 (defun anything-ff-file-compressed-p (candidate)
4242 "Whether CANDIDATE is a compressed file or not."
4243 (member (file-name-extension candidate)
4244 anything-ff-file-compressed-list))
4246 (defun anything-c-insert-file-name-completion-at-point (candidate)
4247 "Insert file name completion at point."
4248 (with-anything-current-buffer
4249 (if buffer-read-only
4250 (error "Error: Buffer `%s' is read-only" (buffer-name))
4251 (let* ((end (point))
4252 (guess (substring-no-properties (thing-at-point 'filename)))
4253 (beg (- (point) (length guess)))
4254 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4255 (string-match-p "^[^\~]" guess))))
4256 (set-text-properties 0 (length candidate) nil candidate)
4257 (if (and guess (not (string= guess ""))
4258 (string-match-p "^~\\|/.*" guess))
4259 (progn
4260 (delete-region beg end)
4261 (insert (if full-path-p
4262 (expand-file-name candidate)
4263 (abbreviate-file-name candidate))))
4264 (error "Aborting completion: No valid file name at point"))))))
4266 (defun* anything-find-files-history (&key (comp-read t))
4267 "The `anything-find-files' history.
4268 Show the first `anything-ff-history-max-length' elements of
4269 `anything-ff-history' in an `anything-comp-read'."
4270 (let ((history (when anything-ff-history
4271 (anything-fast-remove-dups anything-ff-history
4272 :test 'equal))))
4273 (when history
4274 (setq anything-ff-history
4275 (if (>= (length history) anything-ff-history-max-length)
4276 (subseq history 0 anything-ff-history-max-length)
4277 history))
4278 (if comp-read
4279 (anything-comp-read
4280 "Switch to Directory: "
4281 anything-ff-history
4282 :name "Anything Find Files History"
4283 :must-match t)
4284 anything-ff-history))))
4286 (defun anything-find-files-1 (fname &optional preselect)
4287 "Find FNAME with `anything' completion.
4288 Like `find-file' but with `anything' support.
4289 Use it for non--interactive calls of `anything-find-files'."
4290 (when (get-buffer anything-action-buffer)
4291 (kill-buffer anything-action-buffer))
4292 (let ((anything-mp-highlight-delay nil)
4293 ;; Be sure we don't erase the precedent minibuffer if some.
4294 (anything-ff-auto-update-initial-value
4295 (not (minibuffer-window-active-p (minibuffer-window))))
4296 anything-samewindow)
4297 (anything :sources 'anything-c-source-find-files
4298 :input fname
4299 :preselect preselect
4300 :keymap anything-find-files-map
4301 :prompt "Find Files or Url: "
4302 :buffer "*Anything Find Files*")))
4305 (defun anything-find-files-initial-input (&optional input)
4306 "Return INPUT if present, otherwise try to guess it."
4307 (or (and input (expand-file-name input))
4308 (anything-find-files-input
4309 (ffap-guesser)
4310 (thing-at-point 'filename))))
4312 (defun anything-find-files-input (fap tap)
4313 "Default input of `anything-find-files'."
4314 (let* ((def-dir (anything-c-current-directory))
4315 (lib (anything-find-library-at-point))
4316 (url (anything-ff-find-url-at-point))
4317 (file-p (and fap (not (string= fap ""))
4318 (file-exists-p fap)
4319 tap (not (string= tap ""))
4320 (file-exists-p
4321 (file-name-directory (expand-file-name tap def-dir))))))
4322 (cond (lib) ; e.g we are inside a require sexp.
4323 (url) ; String at point is an hyperlink.
4324 (file-p (expand-file-name tap def-dir))
4325 (t (and (not (string= fap "")) fap)))))
4327 (defun anything-c-current-directory ()
4328 "Return current-directory name at point.
4329 Useful in dired buffers when there is inserted subdirs."
4330 (if (eq major-mode 'dired-mode)
4331 (dired-current-directory)
4332 default-directory))
4334 (defun anything-ff-find-url-at-point ()
4335 "Try to find link to an url in text-property at point."
4336 (let* ((he (get-text-property (point) 'help-echo))
4337 (ov (overlays-at (point)))
4338 (ov-he (and ov (overlay-get
4339 (car (overlays-at (point))) 'help-echo)))
4340 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4341 (nt-prop (get-text-property (point) 'nt-link)))
4342 ;; Org link.
4343 (when (and (stringp he) (string-match "^LINK: " he))
4344 (setq he (replace-match "" t t he)))
4345 (loop for i in (list he ov-he w3m-l nt-prop)
4346 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4348 (defun anything-find-library-at-point ()
4349 "Try to find library path at point.
4350 Find inside `require' and `declare-function' sexp."
4351 (require 'find-func)
4352 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4353 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4354 (sexp (and beg-sexp end-sexp
4355 (buffer-substring-no-properties
4356 (1+ beg-sexp) (1- end-sexp)))))
4357 (ignore-errors
4358 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4359 (find-library-name
4360 (replace-regexp-in-string
4361 "'\\|\)\\|\(" ""
4362 ;; If require use third arg, ignore it,
4363 ;; always use library path found in `load-path'.
4364 (second (split-string (match-string 0 sexp))))))
4365 ((and sexp (string-match-p "^declare-function" sexp))
4366 (find-library-name
4367 (replace-regexp-in-string
4368 "\"\\|ext:" ""
4369 (third (split-string sexp)))))
4370 (t nil)))))
4372 ;;; Anything completion for `write-file'.==> C-x C-w
4373 (defvar anything-c-source-write-file
4374 `((name . "Write File")
4375 (header-name . (lambda (name)
4376 (concat name anything-c-find-files-doc-header)))
4377 ;; It is needed for filenames with capital letters
4378 (disable-shortcuts)
4379 (candidates . anything-find-files-get-candidates)
4380 (filtered-candidate-transformer anything-c-find-files-transformer)
4381 (persistent-action . anything-find-files-persistent-action)
4382 (persistent-help . "Expand Candidate")
4383 (volatile)
4384 (action .
4385 (("Write File" . (lambda (candidate)
4386 (write-file candidate 'confirm)))))))
4388 ;;; Anything completion for `insert-file'.==> C-x i
4389 (defvar anything-c-source-insert-file
4390 `((name . "Insert File")
4391 (header-name . (lambda (name)
4392 (concat name anything-c-find-files-doc-header)))
4393 ;; It is needed for filenames with capital letters
4394 (disable-shortcuts)
4395 (candidates . anything-find-files-get-candidates)
4396 (filtered-candidate-transformer anything-c-find-files-transformer)
4397 (persistent-action . anything-find-files-persistent-action)
4398 (persistent-help . "Expand Candidate")
4399 (volatile)
4400 (action .
4401 (("Insert File" . (lambda (candidate)
4402 (when (y-or-n-p (format "Really insert %s in %s "
4403 candidate anything-current-buffer))
4404 (insert-file-contents candidate))))))))
4406 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4407 (defvar anything-c-source-copy-files
4408 `((name . "Copy Files")
4409 (header-name . (lambda (name)
4410 (concat name anything-c-find-files-doc-header)))
4411 ;; It is needed for filenames with capital letters
4412 (disable-shortcuts)
4413 (candidates . anything-find-files-get-candidates)
4414 (filtered-candidate-transformer anything-c-find-files-transformer)
4415 (persistent-action . anything-find-files-persistent-action)
4416 (persistent-help . "Expand Candidate")
4417 (volatile)
4418 (action .
4419 (("Copy File"
4420 . (lambda (candidate)
4421 (anything-dired-action candidate :action 'copy)))
4422 ("Copy and Follow"
4423 . (lambda (candidate)
4424 (anything-dired-action candidate :action 'copy :follow t)))))))
4427 (defvar anything-c-source-rename-files
4428 `((name . "Rename Files")
4429 (header-name . (lambda (name)
4430 (concat name anything-c-find-files-doc-header)))
4431 ;; It is needed for filenames with capital letters
4432 (disable-shortcuts)
4433 (candidates . anything-find-files-get-candidates)
4434 (filtered-candidate-transformer anything-c-find-files-transformer)
4435 (persistent-action . anything-find-files-persistent-action)
4436 (persistent-help . "Expand Candidate")
4437 (volatile)
4438 (action .
4439 (("Rename File"
4440 . (lambda (candidate)
4441 (anything-dired-action candidate :action 'rename)))
4442 ("Rename and Follow"
4443 . (lambda (candidate)
4444 (anything-dired-action candidate :action 'rename :follow t)))))))
4446 (defvar anything-c-source-symlink-files
4447 `((name . "Symlink Files")
4448 (header-name . (lambda (name)
4449 (concat name anything-c-find-files-doc-header)))
4450 ;; It is needed for filenames with capital letters
4451 (disable-shortcuts)
4452 (candidates . anything-find-files-get-candidates)
4453 (filtered-candidate-transformer anything-c-find-files-transformer)
4454 (persistent-action . anything-find-files-persistent-action)
4455 (persistent-help . "Expand Candidate")
4456 (volatile)
4457 (action
4458 . (("Symlink File"
4459 . (lambda (candidate)
4460 (anything-dired-action candidate :action 'symlink)))
4461 ("RelSymlink File"
4462 . (lambda (candidate)
4463 (anything-dired-action candidate :action 'relsymlink)))))))
4466 (defvar anything-c-source-hardlink-files
4467 `((name . "Hardlink Files")
4468 (header-name . (lambda (name)
4469 (concat name anything-c-find-files-doc-header)))
4470 ;; It is needed for filenames with capital letters
4471 (disable-shortcuts)
4472 (candidates . anything-find-files-get-candidates)
4473 (filtered-candidate-transformer anything-c-find-files-transformer)
4474 (persistent-action . anything-find-files-persistent-action)
4475 (persistent-help . "Expand Candidate")
4476 (volatile)
4477 (action
4478 . (("Hardlink File"
4479 . (lambda (candidate)
4480 (anything-dired-action candidate :action 'hardlink)))))))
4482 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4483 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4484 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4485 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4486 (let ((fn (case action
4487 ('copy 'dired-copy-file)
4488 ('rename 'dired-rename-file)
4489 ('symlink 'make-symbolic-link)
4490 ('relsymlink 'dired-make-relative-symlink)
4491 ('hardlink 'dired-hardlink)))
4492 (marker (case action
4493 ((copy rename) dired-keep-marker-copy)
4494 ('symlink dired-keep-marker-symlink)
4495 ('relsymlink dired-keep-marker-relsymlink)
4496 ('hardlink dired-keep-marker-hardlink)))
4497 (dirflag (and (= (length files) 1)
4498 (file-directory-p (car files))
4499 (not (file-directory-p candidate)))))
4500 (dired-create-files
4501 fn (symbol-name action) files
4502 ;; CANDIDATE is the destination.
4503 (if (file-directory-p candidate)
4504 ;; When CANDIDATE is a directory, build file-name in this directory.
4505 ;; Else we use CANDIDATE.
4506 #'(lambda (from)
4507 (expand-file-name (file-name-nondirectory from) candidate))
4508 #'(lambda (from) candidate))
4509 marker)
4510 (push (file-name-as-directory
4511 (if (file-directory-p candidate)
4512 candidate (file-name-directory candidate)))
4513 anything-ff-history)
4514 (when (and follow (not (get-buffer dired-log-buffer)))
4515 (let ((target (directory-file-name candidate)))
4516 (unwind-protect
4517 (progn
4518 (setq anything-ff-cand-to-mark
4519 (anything-get-dest-fnames-from-list files candidate dirflag))
4520 (if (and dirflag (eq action 'rename))
4521 (anything-find-files-1 (file-name-directory target)
4522 (if anything-ff-transformer-show-only-basename
4523 (anything-c-basename target) target))
4524 (anything-find-files-1 (expand-file-name candidate))))
4525 (setq anything-ff-cand-to-mark nil))))))
4528 (defun anything-c-basename (fname)
4529 "Resolve basename of file or directory named FNAME."
4530 (file-name-nondirectory (directory-file-name fname)))
4532 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4533 "Transform filenames of FLIST to abs of DEST-CAND.
4534 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4535 members of FLIST."
4536 ;; At this point files have been renamed/copied at destination.
4537 ;; That's mean DEST-CAND exists.
4538 (loop
4539 with dest = (expand-file-name dest-cand)
4540 for src in flist
4541 for basename-src = (anything-c-basename src)
4542 for fname = (cond (rename-dir-flag (directory-file-name dest))
4543 ((file-directory-p dest)
4544 (concat (file-name-as-directory dest) basename-src))
4545 (t dest))
4546 when (file-exists-p fname)
4547 collect fname into tmp-list
4548 finally return (sort tmp-list 'string<)))
4550 (defun anything-ff-maybe-mark-candidates ()
4551 "Mark all candidates of list `anything-ff-cand-to-mark'."
4552 (when (and (string= (assoc-default 'name (anything-get-current-source))
4553 (assoc-default 'name anything-c-source-find-files))
4554 anything-ff-cand-to-mark)
4555 (with-anything-window
4556 (while anything-ff-cand-to-mark
4557 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4558 (progn
4559 (anything-make-visible-mark)
4560 (anything-next-line)
4561 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4562 (anything-next-line)))
4563 (unless (anything-this-visible-mark)
4564 (anything-prev-visible-mark)))))
4566 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4568 (defun* anything-dired-do-action-on-file (&key action)
4569 (let* ((files (dired-get-marked-files))
4570 (len (length files))
4571 (fname (if (> len 1)
4572 (format "* %d Files" len)
4573 (car files)))
4574 (source (case action
4575 ('copy 'anything-c-source-copy-files)
4576 ('rename 'anything-c-source-rename-files)
4577 ('symlink 'anything-c-source-symlink-files)
4578 ('hardlink 'anything-c-source-hardlink-files)))
4579 (prompt-fm (case action
4580 ('copy "Copy %s to: ")
4581 ('rename "Rename %s to: ")
4582 ('symlink "Symlink %s to: ")
4583 ('hardlink "Hardlink %s to: ")))
4584 (buffer (case action
4585 ('copy "*Anything Copy Files*")
4586 ('rename "*Anything Rename Files*")
4587 ('symlink "*Anything Symlink Files*")
4588 ('hardlink "*Anything Hardlink Files*")))
4589 (anything-mp-highlight-delay nil))
4590 (anything :sources source
4591 :input (or (dired-dwim-target-directory)
4592 (expand-file-name (anything-c-current-directory)))
4593 :preselect (dired-get-filename)
4594 :prompt (format prompt-fm fname)
4595 :keymap anything-c-read-file-map
4596 :buffer buffer)))
4598 ;;;###autoload
4599 (define-minor-mode anything-dired-mode ()
4600 "Enable anything completion in Dired functions.
4601 Bindings affected are C, R, S, H.
4602 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4603 :group 'anything-config
4604 :global t
4605 (if anything-dired-mode
4606 (progn
4607 (substitute-key-definition
4608 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4609 (substitute-key-definition
4610 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4611 (substitute-key-definition
4612 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4613 (substitute-key-definition
4614 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4615 (substitute-key-definition
4616 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4617 (substitute-key-definition
4618 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4619 (substitute-key-definition
4620 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4621 (substitute-key-definition
4622 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4624 (defalias 'anything-dired-bindings 'anything-dired-mode)
4626 (defun* anything-c-read-file-name (prompt
4627 &key
4628 (name "Read File Name")
4629 (initial-input (expand-file-name default-directory))
4630 (buffer "*Anything Completions*")
4631 test
4632 (preselect nil)
4633 (history nil)
4634 must-match
4635 (marked-candidates nil)
4636 (alistp t)
4637 (persistent-action 'anything-find-files-persistent-action)
4638 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4639 "Anything `read-file-name' emulation.
4640 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4641 (when (get-buffer anything-action-buffer)
4642 (kill-buffer anything-action-buffer))
4644 ;; Assume completion have been already required,
4645 ;; so always use 'confirm.
4646 (when (eq must-match 'confirm-after-completion)
4647 (setq must-match 'confirm))
4649 (flet ((action-fn (candidate)
4650 (if marked-candidates
4651 (anything-marked-candidates)
4652 (identity candidate))))
4654 (let* ((anything-mp-highlight-delay nil)
4655 ;; Be sure we don't erase the underlying minibuffer if some.
4656 (anything-ff-auto-update-initial-value
4657 (not (minibuffer-window-active-p (minibuffer-window))))
4658 anything-same-window
4659 (hist (and history (anything-comp-read-get-candidates
4660 history nil nil alistp)))
4661 (minibuffer-completion-table nil)
4662 (minibuffer-completion-predicate (or test 'file-exists-p))
4663 (minibuffer-completion-confirm (unless (eq must-match t)
4664 must-match))
4665 (keymap (when must-match minibuffer-local-must-match-map))
4666 (anything-map (make-composed-keymap
4667 ;; Merge some anything bindings
4668 ;; that clash with minibuffer ones.
4669 (list '(keymap
4670 (7 . anything-keyboard-quit)
4671 (up . anything-previous-line)
4672 (down . anything-next-line))
4673 keymap)
4674 anything-c-read-file-map)))
4676 (or (anything
4677 :sources
4678 `(((name . ,(format "%s History" name))
4679 (header-name . (lambda (name)
4680 (concat name anything-c-find-files-doc-header)))
4681 (disable-shortcuts)
4682 (mode-line . anything-read-file-name-mode-line-string)
4683 (candidates . hist)
4684 (persistent-action . ,persistent-action)
4685 (persistent-help . ,persistent-help)
4686 (action . ,'action-fn))
4687 ((name . ,name)
4688 (header-name . (lambda (name)
4689 (concat name anything-c-find-files-doc-header)))
4690 (init . (lambda ()
4691 (setq anything-ff-auto-update-flag
4692 anything-ff-auto-update-initial-value)))
4693 ;; It is needed for filenames with capital letters
4694 (disable-shortcuts)
4695 (mode-line . anything-read-file-name-mode-line-string)
4696 (candidates . (lambda ()
4697 (let ((seq (anything-find-files-get-candidates must-match)))
4698 (when must-match
4699 ;; Add anything-pattern to list of candidates
4700 ;; Fix issue with must-match == 'confirm.
4701 (setq minibuffer-completion-table
4702 (append (list anything-pattern) seq)))
4703 seq)))
4704 (filtered-candidate-transformer anything-c-find-files-transformer)
4705 (persistent-action . ,persistent-action)
4706 (candidate-number-limit . 9999)
4707 (toggle-auto-update . anything-ff-toggle-auto-update)
4708 (persistent-help . ,persistent-help)
4709 (volatile)
4710 (action . ,'action-fn)))
4711 :input initial-input
4712 :prompt prompt
4713 :resume 'noresume
4714 :buffer buffer
4715 :preselect preselect)
4716 (when (and (not (string= anything-pattern ""))
4717 (eq anything-exit-status 0)
4718 (eq must-match 'confirm))
4719 (identity anything-pattern))
4720 (keyboard-quit)))))
4723 ;;; File Cache
4724 (defvar anything-c-file-cache-initialized-p nil)
4726 (defvar anything-c-file-cache-files nil)
4728 (defvar anything-c-source-file-cache
4729 '((name . "File Cache")
4730 (init
4731 . (lambda ()
4732 (require 'filecache nil t)
4733 (unless anything-c-file-cache-initialized-p
4734 (setq anything-c-file-cache-files
4735 (loop for item in file-cache-alist append
4736 (destructuring-bind (base &rest dirs) item
4737 (loop for dir in dirs collect
4738 (concat dir base)))))
4739 (defadvice file-cache-add-file (after file-cache-list activate)
4740 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4741 (setq anything-c-file-cache-initialized-p t))))
4742 (candidates . anything-c-file-cache-files)
4743 (match anything-c-match-on-basename)
4744 (type . file)))
4745 ;; (anything 'anything-c-source-file-cache)
4748 ;;; Locate
4751 ;; NOTE for WINDOZE users:
4752 ;; You have to install Everything with his command line interface here:
4753 ;; http://www.voidtools.com/download.php
4755 (defun anything-locate-1 (&optional localdb init)
4756 "Generic function to run Locate.
4757 if LOCALDB is non--nil search and use a local locate db file.
4758 INIT is a string to use as initial input in prompt.
4759 See `anything-locate-with-db' and `anything-locate'."
4760 (anything-locate-with-db
4761 (and localdb
4762 (anything-c-read-file-name
4763 "LocateDBFiles: "
4764 :marked-candidates t
4765 :preselect anything-locate-db-file-regexp
4766 :test #'(lambda (x)
4767 (if anything-locate-db-file-regexp
4768 ;; Select only locate db files and directories
4769 ;; to allow navigation.
4770 (or (string-match
4771 anything-locate-db-file-regexp x)
4772 (file-directory-p x))
4773 x))))
4774 init))
4775 ;; (anything-locate-1 t)
4777 (defun anything-locate-with-db (&optional db initial-input)
4778 "Run locate -d DB.
4779 If DB is not given or nil use locate without -d option.
4780 Argument DB can be given as a string or list of db files.
4781 Argument INITIAL-INPUT is a string to use as initial-input.
4782 See also `anything-locate'."
4783 (when (and db (stringp db)) (setq db (list db)))
4784 (let ((anything-c-locate-command
4785 (if db
4786 (replace-regexp-in-string
4787 "locate"
4788 (format "locate -d %s"
4789 (mapconcat 'identity
4790 ;; Remove eventually
4791 ;; marked directories by error.
4792 (loop for i in db
4793 unless (file-directory-p i)
4794 collect i) ":"))
4795 anything-c-locate-command)
4796 anything-c-locate-command)))
4797 (anything :sources 'anything-c-source-locate
4798 :buffer "*anything locate*"
4799 :input initial-input
4800 :keymap anything-generic-files-map)))
4801 ;; (anything-locate-with-db "~/locate.db")
4803 (defun anything-c-locate-init ()
4804 "Initialize async locate process for `anything-c-source-locate'."
4805 (setq mode-line-format
4806 '(" " mode-line-buffer-identification " "
4807 (line-number-mode "%l") " "
4808 (:eval (propertize "(Locate Process Running) "
4809 'face '((:foreground "red"))))))
4810 (unless anything-c-locate-command
4811 (setq anything-c-locate-command
4812 (case system-type
4813 ('gnu/linux "locate -i -r %s")
4814 ('berkeley-unix "locate -i %s")
4815 ('windows-nt "es -i -r %s")
4816 (t "locate %s"))))
4817 (prog1
4818 (start-process-shell-command "locate-process" nil
4819 (format anything-c-locate-command
4820 anything-pattern))
4821 (set-process-sentinel (get-process "locate-process")
4822 #'(lambda (process event)
4823 (when (string= event "finished\n")
4824 (with-anything-window
4825 (force-mode-line-update nil)
4826 (anything-update-move-first-line)))))))
4828 (defvar anything-c-source-locate
4829 '((name . "Locate")
4830 (candidates . anything-c-locate-init)
4831 (type . file)
4832 (requires-pattern . 3)
4833 (candidate-number-limit . 9999)
4834 (mode-line . anything-generic-file-mode-line-string)
4835 (delayed))
4836 "Find files matching the current input pattern with locate.")
4837 ;; (anything 'anything-c-source-locate)
4839 (defun anything-c-locate-read-file-name (prompt &optional init)
4840 "Search a file with locate and return it's filename.
4841 Use argument PROMPT and INIT for `anything' arguments
4842 prompt and input."
4843 (anything :sources
4844 '((name . "Locate")
4845 (candidates . anything-c-locate-init)
4846 (action . identity)
4847 (requires-pattern . 3)
4848 (candidate-number-limit . 9999)
4849 (mode-line . anything-generic-file-mode-line-string)
4850 (delayed))
4851 :prompt prompt
4852 :input init
4853 :buffer "*anything locate rfn*"))
4857 ;;; Anything Incremental Grep.
4860 ;; Allow to grep incrementally with anything interface.
4861 ;; It allow also to Grep files recursively without using 'find' shell command.
4862 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4863 (defvar anything-c-grep-default-command
4864 "grep -d skip %e -niH -e %p %f"
4865 "Default grep format command for `anything-do-grep-1'.
4866 Where:
4867 '%e' format spec is for --exclude or --include grep options.
4868 '%p' format spec is for pattern.
4869 '%f' format spec is for filenames.")
4871 (defvar anything-c-grep-default-recurse-command
4872 "grep -d recurse %e -niH -e %p %f"
4873 "Default recursive grep format command for `anything-do-grep-1'.
4874 See `anything-c-grep-default-command' for format specs.")
4876 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4878 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4880 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4882 (defvar anything-c-grep-debug-command-line nil
4883 "Turn on anything grep command-line debugging when non--nil.")
4885 (defvar anything-c-zgrep-recurse-flag nil)
4887 (defvar anything-c-grep-history nil)
4889 (defvar anything-c-grep-max-length-history 100
4890 "*Max number of elements to save in `anything-c-grep-history'.")
4892 (defun anything-c-grep-prepare-candidates (candidates)
4893 "Prepare filenames and directories CANDIDATES for grep command line."
4894 ;; If one or more candidate is a directory, search in all files
4895 ;; of this candidate (e.g /home/user/directory/*).
4896 ;; If r option is enabled search also in subdidrectories.
4897 ;; We need here to expand wildcards to support crap windows filenames
4898 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4899 (if anything-c-zgrep-recurse-flag
4900 (mapconcat 'shell-quote-argument candidates " ")
4901 (loop for i in candidates append
4902 (cond ( ;; Candidate is a directory and we use recursion.
4903 (and (file-directory-p i)
4904 (anything-c-grep-recurse-p))
4905 (list (expand-file-name i)))
4906 ;; Candidate is a directory, search in all files.
4907 ((file-directory-p i)
4908 (file-expand-wildcards
4909 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4910 ;; Candidate is a file or wildcard and we use recursion, use the
4911 ;; current directory instead of candidate.
4912 ((and (or (file-exists-p i) (string-match "\*" i))
4913 (anything-c-grep-recurse-p))
4914 (list (expand-file-name
4915 (directory-file-name ; Needed for windoze.
4916 (file-name-directory (directory-file-name i))))))
4917 ;; Candidate use wildcard.
4918 ((string-match "^\*" (anything-c-basename i))
4919 (file-expand-wildcards i t))
4920 ;; Else should be one or more file.
4921 (t (list i))) into all-files
4922 finally return
4923 (mapconcat 'shell-quote-argument all-files " "))))
4925 (defun anything-c-grep-recurse-p ()
4926 "Check if `anything-do-grep-1' have switched to recursive."
4927 (let ((args (replace-regexp-in-string
4928 "grep" "" anything-c-grep-default-command)))
4929 (string-match-p "r\\|recurse" args)))
4931 (defun anything-c-grep-init (only-files &optional include zgrep)
4932 "Start an asynchronous grep process in ONLY-FILES list."
4933 (let* ((fnargs (anything-c-grep-prepare-candidates
4934 (if (file-remote-p anything-ff-default-directory)
4935 (mapcar #'(lambda (x)
4936 (file-remote-p x 'localname))
4937 only-files)
4938 only-files)))
4939 (ignored-files (mapconcat
4940 #'(lambda (x)
4941 (concat "--exclude=" (shell-quote-argument x)))
4942 grep-find-ignored-files " "))
4943 (ignored-dirs (mapconcat
4944 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4945 #'(lambda (x)
4946 (concat "--exclude-dir=" (shell-quote-argument x)))
4947 grep-find-ignored-directories " "))
4948 (exclude (if (anything-c-grep-recurse-p)
4949 (concat (or include ignored-files) " " ignored-dirs)
4950 ignored-files))
4951 (cmd-line (format-spec
4952 anything-c-grep-default-command
4953 (delq nil
4954 (list (unless zgrep (cons ?e exclude))
4955 (cons ?p (shell-quote-argument anything-pattern))
4956 (cons ?f fnargs))))))
4957 (when anything-c-grep-debug-command-line
4958 (with-current-buffer (get-buffer-create "*any grep debug*")
4959 (goto-char (point-max))
4960 (insert (concat ">>> " cmd-line "\n\n"))))
4961 (setq mode-line-format
4962 '(" " mode-line-buffer-identification " "
4963 (line-number-mode "%l") " "
4964 (:eval (when (get-process "grep-process")
4965 (propertize "[Grep Process Running] "
4966 'face 'anything-grep-running)))))
4967 (force-mode-line-update nil)
4968 (prog1
4969 (let ((default-directory anything-ff-default-directory))
4970 (start-file-process-shell-command "grep-process" nil cmd-line))
4971 (message nil)
4972 (set-process-sentinel
4973 (get-process "grep-process")
4974 #'(lambda (process event)
4975 (when (string= event "finished\n")
4976 (with-anything-window
4977 (anything-update-move-first-line)
4978 (setq mode-line-format
4979 '(" " mode-line-buffer-identification " "
4980 (line-number-mode "%l") " "
4981 (:eval (propertize
4982 (format "[Grep Process Finished - (%s results)] "
4983 (let ((nlines (1- (count-lines
4984 (point-min)
4985 (point-max)))))
4986 (if (> nlines 0) nlines 0)))
4987 'face 'anything-grep-finish))))
4988 (force-mode-line-update nil))))))))
4990 (defun anything-c-grep-action (candidate &optional where mark)
4991 "Define a default action for `anything-do-grep' on CANDIDATE.
4992 WHERE can be one of other-window, elscreen, other-frame."
4993 (let* ((split (anything-c-grep-split-line candidate))
4994 (lineno (string-to-number (nth 1 split)))
4995 (loc-fname (car split))
4996 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4997 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4998 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4999 (fname (if tramp-host
5000 (concat tramp-prefix loc-fname) loc-fname)))
5001 (case where
5002 (other-window (find-file-other-window fname))
5003 (elscreen (anything-elscreen-find-file fname))
5004 (other-frame (find-file-other-frame fname))
5005 (t (find-file fname)))
5006 (anything-goto-line lineno)
5007 (when mark
5008 (set-marker (mark-marker) (point))
5009 (push-mark (point) 'nomsg))
5010 ;; Save history
5011 (unless (or anything-in-persistent-action
5012 (string= anything-pattern ""))
5013 (setq anything-c-grep-history
5014 (cons anything-pattern
5015 (delete anything-pattern anything-c-grep-history)))
5016 (when (> (length anything-c-grep-history)
5017 anything-c-grep-max-length-history)
5018 (setq anything-c-grep-history
5019 (delete (car (last anything-c-grep-history))
5020 anything-c-grep-history))))))
5022 (defun anything-c-grep-other-window (candidate)
5023 "Jump to result in other window from anything grep."
5024 (anything-c-grep-action candidate 'other-window))
5026 (defun anything-c-grep-other-frame (candidate)
5027 "Jump to result in other frame from anything grep."
5028 (anything-c-grep-action candidate 'other-frame))
5030 (defun anything-c-grep-jump-elscreen (candidate)
5031 "Jump to result in elscreen from anything grep."
5032 (anything-c-grep-action candidate 'elscreen))
5034 (defun anything-c-grep-save-results (candidate)
5035 "Save anything grep result in a `grep-mode' buffer."
5036 (let ((buf "*grep*")
5037 new-buf)
5038 (when (get-buffer buf)
5039 (setq new-buf (read-string "GrepBufferName: " buf))
5040 (loop for b in (anything-c-buffer-list)
5041 when (and (string= new-buf b)
5042 (not (y-or-n-p
5043 (format "Buffer `%s' already exists overwrite? "
5044 new-buf))))
5045 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
5046 (setq buf new-buf))
5047 (with-current-buffer (get-buffer-create buf)
5048 (let ((inhibit-read-only t))
5049 (erase-buffer)
5050 (insert "-*- mode: grep -*-\n\n"
5051 (format "Grep Results for `%s':\n\n" anything-pattern))
5052 (save-excursion
5053 (insert (with-current-buffer anything-buffer
5054 (forward-line 1)
5055 (buffer-substring (point) (point-max))))
5056 (grep-mode))))
5057 (message "Anything Grep Results saved in `%s' buffer" buf)))
5059 (defun anything-c-grep-persistent-action (candidate)
5060 "Persistent action for `anything-do-grep'.
5061 With a prefix arg record CANDIDATE in `mark-ring'."
5062 (if current-prefix-arg
5063 (anything-c-grep-action candidate nil 'mark)
5064 (anything-c-grep-action candidate))
5065 (anything-match-line-color-current-line))
5067 (defun anything-c-grep-guess-extensions (files)
5068 "Try to guess file extensions in FILES list when using grep recurse.
5069 These extensions will be added to command line with --include arg of grep."
5070 (loop
5071 with glob-list = nil
5072 with lst = (if (file-directory-p (car files))
5073 (directory-files
5074 (car files) nil
5075 directory-files-no-dot-files-regexp)
5076 files)
5077 for i in lst
5078 for ext = (file-name-extension i t)
5079 for glob = (and ext (not (string= ext ""))
5080 (concat "*" ext))
5081 unless (or (not glob)
5082 (member glob glob-list)
5083 (member glob grep-find-ignored-files))
5084 collect glob into glob-list
5085 finally return glob-list))
5087 (defun anything-do-grep-1 (only &optional recurse zgrep)
5088 "Launch grep with a list of ONLY files.
5089 When RECURSE is given use -r option of grep and prompt user
5090 to set the --include args of grep.
5091 You can give more than one arg separated by space.
5092 e.g *.el *.py *.tex.
5093 If it's empty --exclude `grep-find-ignored-files' is used instead."
5094 (let* ((anything-compile-source-functions
5095 ;; rule out anything-match-plugin because the input is one regexp.
5096 (delq 'anything-compile-source--match-plugin
5097 (copy-sequence anything-compile-source-functions)))
5098 (exts (anything-c-grep-guess-extensions only))
5099 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5100 (include-files (and recurse (not zgrep)
5101 (read-string "OnlyExt(*.[ext]): "
5102 globs)))
5103 ;; Set `minibuffer-history' AFTER includes-files
5104 ;; to avoid storing wild-cards here.
5105 (minibuffer-history anything-c-grep-history)
5106 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5107 (recurse anything-c-grep-default-recurse-command)
5108 (zgrep anything-c-default-zgrep-command)
5109 (t anything-c-grep-default-command)))
5110 ;; Disable match-plugin and use here own highlighting.
5111 (anything-mp-highlight-delay nil))
5112 (when include-files
5113 (setq include-files
5114 (and (not (string= include-files ""))
5115 (mapconcat #'(lambda (x)
5116 (concat "--include=" (shell-quote-argument x)))
5117 (split-string include-files) " "))))
5118 ;; When called as action from an other source e.g *-find-files
5119 ;; we have to kill action buffer.
5120 (when (get-buffer anything-action-buffer)
5121 (kill-buffer anything-action-buffer))
5122 ;; `anything-find-files' haven't already started,
5123 ;; give a default value to `anything-ff-default-directory'.
5124 (setq anything-ff-default-directory (or anything-ff-default-directory
5125 default-directory))
5126 (anything
5127 :sources
5128 `(((name . "Grep (C-c ? Help)")
5129 (candidates
5130 . (lambda ()
5131 (funcall anything-c-grep-default-function only include-files zgrep)))
5132 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5133 (candidate-number-limit . 9999)
5134 (mode-line . anything-grep-mode-line-string)
5135 (action . ,(delq
5137 `(("Find File" . anything-c-grep-action)
5138 ("Find file other frame" . anything-c-grep-other-frame)
5139 ,(and (locate-library "elscreen")
5140 '("Find file in Elscreen"
5141 . anything-c-grep-jump-elscreen))
5142 ("Save results in grep buffer" . anything-c-grep-save-results)
5143 ("Find file other window" . anything-c-grep-other-window))))
5144 (persistent-action . anything-c-grep-persistent-action)
5145 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5146 (requires-pattern . 3)
5147 (delayed)))
5148 :keymap anything-c-grep-map
5149 :buffer "*anything grep*")))
5151 (defun anything-ff-zgrep-1 (flist recursive)
5152 (unwind-protect
5153 (let* ((def-dir (or anything-ff-default-directory
5154 default-directory))
5155 (only (if recursive
5156 (or (gethash def-dir anything-c-rzgrep-cache)
5157 (puthash
5158 def-dir
5159 (anything-c-walk-directory
5160 def-dir
5161 :directories nil
5162 :path 'full
5163 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5164 anything-c-rzgrep-cache))
5165 flist)))
5166 (when recursive (setq anything-c-zgrep-recurse-flag t))
5167 (anything-do-grep-1 only recursive 'zgrep))
5168 (setq anything-c-zgrep-recurse-flag nil)))
5170 (defun anything-c-grep-split-line (line)
5171 "Split a grep output line."
5172 (let (beg fname lineno str)
5173 ;; Don't print until grep line is valid.
5174 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5175 (with-temp-buffer
5176 (insert line)
5177 (goto-char (point-min))
5178 (setq beg (point))
5179 (forward-char 2)
5180 (re-search-forward ":" nil t)
5181 (setq fname (buffer-substring-no-properties beg (1- (point))))
5182 (setq beg (point))
5183 (re-search-forward ":" nil t)
5184 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5185 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5186 (list fname lineno str))))
5188 (defun anything-c-grep-cand-transformer (candidates sources)
5189 "Filtered candidate transformer function for `anything-do-grep'."
5190 (loop for i in candidates
5191 for split = (and i (anything-c-grep-split-line i))
5192 for fname = (car split)
5193 for lineno = (nth 1 split)
5194 for str = (nth 2 split)
5195 when (and fname lineno str)
5196 collect
5197 (cons (concat (propertize (file-name-nondirectory fname)
5198 'face 'anything-grep-file
5199 'help-echo fname) ":"
5200 (propertize lineno 'face 'anything-grep-lineno) ":"
5201 (anything-c-grep-highlight-match str))
5202 i)))
5204 (defun anything-c-grep-highlight-match (str)
5205 "Highlight in string STR all occurences matching `anything-pattern'."
5206 (condition-case nil
5207 (with-temp-buffer
5208 (insert str)
5209 (goto-char (point-min))
5210 (while (and (re-search-forward anything-pattern nil t)
5211 (> (- (match-end 0) (match-beginning 0)) 0))
5212 (add-text-properties
5213 (match-beginning 0) (match-end 0)
5214 '(face anything-grep-match)))
5215 (buffer-string))
5216 (error nil)))
5218 ;; Go to next or precedent file (common to etags and grep).
5219 (defun anything-c-goto-next-or-prec-file (n)
5220 "Go to next or precedent candidate file in anything grep/etags buffers.
5221 If N is positive go forward otherwise go backward."
5222 (with-anything-window
5223 (let* ((current-line-list (split-string
5224 (buffer-substring
5225 (point-at-bol)
5226 (point-at-eol)) ":"))
5227 (current-fname (nth 0 current-line-list))
5228 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5229 (catch 'break
5230 (while (not (funcall fn-b-o-f))
5231 (forward-line n) ; Go forward or backward depending of n value.
5232 (unless (search-forward current-fname (point-at-eol) t)
5233 (anything-mark-current-line)
5234 (throw 'break nil))))
5235 (cond ((and (eq n 1) (eobp))
5236 (re-search-backward ".")
5237 (forward-line 0)
5238 (anything-mark-current-line))
5239 ((and (< n 1) (bobp))
5240 (forward-line 1)
5241 (anything-mark-current-line))))))
5243 ;;;###autoload
5244 (defun anything-c-goto-precedent-file ()
5245 "Go to precedent file in anything grep/etags buffers."
5246 (interactive)
5247 (anything-c-goto-next-or-prec-file -1))
5249 ;;;###autoload
5250 (defun anything-c-goto-next-file ()
5251 "Go to precedent file in anything grep/etags buffers."
5252 (interactive)
5253 (anything-c-goto-next-or-prec-file 1))
5255 ;;;###autoload
5256 (defun anything-c-grep-run-persistent-action ()
5257 "Run grep persistent action from `anything-do-grep-1'."
5258 (interactive)
5259 (anything-attrset 'jump-persistent 'anything-c-grep-persistent-action)
5260 (anything-execute-persistent-action 'jump-persistent))
5262 ;;;###autoload
5263 (defun anything-c-grep-run-default-action ()
5264 "Run grep default action from `anything-do-grep-1'."
5265 (interactive)
5266 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5268 ;;;###autoload
5269 (defun anything-c-grep-run-other-window-action ()
5270 "Run grep goto other window action from `anything-do-grep-1'."
5271 (interactive)
5272 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5274 ;;;###autoload
5275 (defun anything-c-grep-run-save-buffer ()
5276 "Run grep save results action from `anything-do-grep-1'."
5277 (interactive)
5278 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5280 ;; Grep buffers
5281 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5282 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5283 If one of selected buffers is not a file--buffer,
5284 it is ignored and grep will run on all others file--buffers.
5285 If only one candidate is selected and it is not a file--buffer,
5286 switch to this buffer and run `anything-occur'.
5287 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5288 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5289 (cands (if prefarg
5290 (buffer-list)
5291 (anything-marked-candidates)))
5292 (win-conf (current-window-configuration))
5293 ;; Non--fname buffers are ignored.
5294 (bufs (loop for buf in cands
5295 for fname = (buffer-file-name (get-buffer buf))
5296 when fname
5297 collect (expand-file-name fname))))
5298 (if bufs
5299 (if zgrep
5300 (anything-do-grep-1 bufs nil 'zgrep)
5301 (anything-do-grep-1 bufs))
5302 ;; bufs is empty, thats mean we have only CANDIDATE
5303 ;; and it is not a buffer-filename, fallback to occur.
5304 (anything-c-switch-to-buffer candidate)
5305 (when (get-buffer anything-action-buffer)
5306 (kill-buffer anything-action-buffer))
5307 (anything-occur)
5308 (when (eq anything-exit-status 1)
5309 (set-window-configuration win-conf)))))
5311 (defun anything-c-grep-buffers (candidate)
5312 "Action to grep buffers."
5313 (anything-c-grep-buffers-1 candidate))
5315 (defun anything-c-zgrep-buffers (candidate)
5316 "Action to zgrep buffers."
5317 (anything-c-grep-buffers-1 candidate 'zgrep))
5320 ;;; Anything interface for pdfgrep
5321 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5322 ;; and a pdf-reader (e.g xpdf) are needed.
5324 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5325 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5326 (defvar anything-c-pdfgrep-debug-command-line nil)
5328 (defun anything-c-pdfgrep-init (only-files)
5329 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5330 (let* ((fnargs (anything-c-grep-prepare-candidates
5331 (if (file-remote-p anything-ff-default-directory)
5332 (mapcar #'(lambda (x)
5333 (file-remote-p x 'localname))
5334 only-files)
5335 only-files)))
5336 (cmd-line (format anything-c-pdfgrep-default-command
5337 anything-pattern
5338 fnargs)))
5339 (when anything-c-pdfgrep-debug-command-line
5340 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5341 (goto-char (point-max))
5342 (insert (concat ">>> " cmd-line "\n\n"))))
5343 (setq mode-line-format
5344 '(" " mode-line-buffer-identification " "
5345 (line-number-mode "%l") " "
5346 (:eval (propertize "(Pdfgrep Process Running) "
5347 'face '((:foreground "red"))))))
5348 (prog1
5349 (let ((default-directory anything-ff-default-directory))
5350 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5351 (message nil)
5352 (set-process-sentinel
5353 (get-process "pdfgrep-process")
5354 #'(lambda (process event)
5355 (when (string= event "finished\n")
5356 (with-anything-window
5357 (anything-update-move-first-line))
5358 (force-mode-line-update nil)))))))
5361 (defun anything-do-pdfgrep-1 (only)
5362 "Launch pdfgrep with a list of ONLY files."
5363 (unless (executable-find "pdfgrep")
5364 (error "Error: No such program `pdfgrep'."))
5365 (let* ((anything-compile-source-functions
5366 ;; rule out anything-match-plugin because the input is one regexp.
5367 (delq 'anything-compile-source--match-plugin
5368 (copy-sequence anything-compile-source-functions)))
5369 ;; Disable match-plugin and use here own highlighting.
5370 (anything-mp-highlight-delay nil))
5371 ;; When called as action from an other source e.g *-find-files
5372 ;; we have to kill action buffer.
5373 (when (get-buffer anything-action-buffer)
5374 (kill-buffer anything-action-buffer))
5375 ;; If `anything-find-files' haven't already started,
5376 ;; give a default value to `anything-ff-default-directory'.
5377 (setq anything-ff-default-directory (or anything-ff-default-directory
5378 default-directory))
5379 (anything
5380 :sources
5381 `(((name . "PdfGrep")
5382 (candidates
5383 . (lambda ()
5384 (funcall anything-c-pdfgrep-default-function only)))
5385 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5386 (candidate-number-limit . 9999)
5387 (mode-line . anything-pdfgrep-mode-line-string)
5388 (action . anything-c-pdfgrep-action)
5389 (persistent-help . "Jump to PDF Page")
5390 (requires-pattern . 3)
5391 (delayed)))
5392 :keymap anything-c-pdfgrep-map
5393 :buffer "*anything grep*")))
5396 (defun anything-c-pdfgrep-action (candidate)
5397 (let* ((split (anything-c-grep-split-line candidate))
5398 (pageno (nth 1 split))
5399 (fname (car split)))
5400 (start-file-process-shell-command
5401 "pdf-reader" nil
5402 (format-spec anything-c-pdfgrep-default-read-command
5403 (list (cons ?f fname) (cons ?p pageno))))))
5405 (defun anything-do-pdfgrep ()
5406 (interactive)
5407 (let ((only (anything-c-read-file-name
5408 "Search in file(s): "
5409 :marked-candidates t
5410 :test #'(lambda (file)
5411 (or (string= (file-name-extension file) "pdf")
5412 (string= (file-name-extension file) "PDF")
5413 (file-directory-p file)))
5414 :preselect (or (dired-get-filename nil t)
5415 (buffer-file-name (current-buffer)))))
5416 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5417 (anything-do-pdfgrep-1 only)))
5420 ;; Yank text at point.
5423 ;; Internal
5424 (defvar anything-yank-point nil)
5426 ;;;###autoload
5427 (defun anything-yank-text-at-point ()
5428 "Yank text at point in minibuffer."
5429 (interactive)
5430 (let (input)
5431 (flet ((insert-in-minibuffer (word)
5432 (with-selected-window (minibuffer-window)
5433 (let ((str anything-pattern))
5434 (delete-minibuffer-contents)
5435 (set-text-properties 0 (length word) nil word)
5436 (insert (concat str word))))))
5437 (with-anything-current-buffer
5438 ;; Start to initial point if C-w have never been hit.
5439 (unless anything-yank-point (setq anything-yank-point (point)))
5440 (and anything-yank-point (goto-char anything-yank-point))
5441 (forward-word 1)
5442 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5443 (setq anything-yank-point (point))) ; End of last forward-word
5444 (insert-in-minibuffer input))))
5446 (defun anything-reset-yank-point ()
5447 (setq anything-yank-point nil))
5449 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5450 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5453 ;;; Recentf files
5456 (defvar anything-c-source-recentf
5457 '((name . "Recentf")
5458 (init . (lambda ()
5459 (require 'recentf)
5460 (or recentf-mode (recentf-mode 1))))
5461 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5462 (candidates . recentf-list)
5463 (match anything-c-match-on-basename)
5464 (type . file))
5465 "See (info \"(emacs)File Conveniences\").
5466 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5467 ;; (anything 'anything-c-source-recentf)
5469 ;;; ffap
5470 (eval-when-compile (require 'ffap))
5471 (defvar anything-c-source-ffap-guesser
5472 '((name . "File at point")
5473 (init . (lambda () (require 'ffap)))
5474 (candidates . (lambda ()
5475 (anything-aif
5476 (with-anything-current-buffer
5477 (ffap-guesser))
5478 (list it))))
5479 (type . file)))
5480 ;; (anything 'anything-c-source-ffap-guesser)
5482 ;;; ffap with line number
5483 (defun anything-c-ffap-file-line-at-point ()
5484 "Get (FILENAME . LINENO) at point."
5485 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5486 (save-excursion
5487 (beginning-of-line)
5488 (when (and (search-forward it nil t)
5489 (looking-at ":\\([0-9]+\\)"))
5490 (cons it (string-to-number (match-string 1)))))))
5492 (defvar anything-c-ffap-line-location nil
5493 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5494 It is cleared after jumping line.")
5496 (defun anything-c-ffap-line-candidates ()
5497 (with-anything-current-buffer
5498 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5499 (when anything-c-ffap-line-location
5500 (destructuring-bind (file . line) anything-c-ffap-line-location
5501 (list (cons (format "%s (line %d)" file line) file)))))
5503 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5504 (defun anything-c-ffap-line-goto-line ()
5505 (when (car anything-c-ffap-line-location)
5506 (unwind-protect
5507 (ignore-errors
5508 (with-selected-window
5509 (get-buffer-window
5510 (get-file-buffer (car anything-c-ffap-line-location)))
5511 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5512 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5513 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5515 (defvar anything-c-source-ffap-line
5516 '((name . "File/Lineno at point")
5517 (init . (lambda () (require 'ffap)))
5518 (candidates . anything-c-ffap-line-candidates)
5519 (type . file)))
5520 ;; (anything 'anything-c-source-ffap-line)
5522 ;;; list of files gleaned from every dired buffer
5523 (defun anything-c-files-in-all-dired-candidates ()
5524 (save-excursion
5525 (mapcan
5526 (lambda (dir)
5527 (cond ((listp dir) ;filelist
5528 dir)
5529 ((equal "" (file-name-nondirectory dir)) ;dir
5530 (directory-files dir t))
5531 (t ;wildcard
5532 (file-expand-wildcards dir t))))
5533 (delq nil
5534 (mapcar (lambda (buf)
5535 (set-buffer buf)
5536 (when (eq major-mode 'dired-mode)
5537 (if (consp dired-directory)
5538 (cdr dired-directory) ;filelist
5539 dired-directory))) ;dir or wildcard
5540 (buffer-list))))))
5541 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5543 (defvar anything-c-source-files-in-all-dired
5544 '((name . "Files in all dired buffer.")
5545 (candidates . anything-c-files-in-all-dired-candidates)
5546 (type . file)))
5547 ;; (anything 'anything-c-source-files-in-all-dired)
5549 (defvar anything-c-source-filelist
5550 '((name . "FileList")
5551 (grep-candidates . anything-c-filelist-file-name)
5552 (candidate-number-limit . 200)
5553 (requires-pattern . 4)
5554 (type . file))
5555 "Source to find files instantly.
5556 See `anything-c-filelist-file-name' docstring for usage.")
5559 ;;;; <info>
5560 ;;; Info pages
5561 (defvar anything-c-info-pages nil
5562 "All info pages on system.
5563 Will be calculated the first time you invoke anything with this
5564 source.")
5566 (defun anything-c-info-pages-init ()
5567 "Collect candidates for initial Info node Top."
5568 (if anything-c-info-pages
5569 anything-c-info-pages
5570 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5571 topics)
5572 (require 'info)
5573 (with-temp-buffer
5574 (Info-find-node "dir" "top")
5575 (goto-char (point-min))
5576 (while (re-search-forward info-topic-regexp nil t)
5577 (push (match-string-no-properties 1) topics))
5578 (kill-buffer))
5579 (setq anything-c-info-pages topics))))
5581 (defvar anything-c-source-info-pages
5582 `((name . "Info Pages")
5583 (init . anything-c-info-pages-init)
5584 (candidates . anything-c-info-pages)
5585 (action . (("Show with Info" .(lambda (node-str)
5586 (info (replace-regexp-in-string
5587 "^[^:]+: " "" node-str))))))
5588 (requires-pattern . 2)))
5589 ;; (anything 'anything-c-source-info-pages)
5592 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5593 (defun anything-c-describe-attributes (anything-attribute)
5594 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5595 Same as `anything-describe-anything-attribute' but with anything completion."
5596 (interactive (list (intern
5597 (anything-comp-read
5598 "Describe anything attribute: "
5599 (mapcar 'symbol-name anything-additional-attributes)
5600 :must-match t
5601 :persistent-action
5602 #'(lambda (candidate)
5603 (with-output-to-temp-buffer "*Help*"
5604 (princ (get (intern candidate) 'anything-attrdoc))))))))
5605 (with-output-to-temp-buffer "*Help*"
5606 (princ (get anything-attribute 'anything-attrdoc))))
5609 ;;; Use info-index plug-in.
5612 ;; Note that `name' attribute is not needed since
5613 ;; `anything-c-insert-summary' have been removed.
5614 ;; Info Elisp
5615 (defvar anything-c-source-info-elisp
5616 '((name . "Info index: elisp")
5617 (info-index . "elisp")))
5618 ;; (anything 'anything-c-source-info-elisp)
5620 ;; Info-Common-Lisp
5621 (defvar anything-c-source-info-cl
5622 '((name . "Info index: cl")
5623 (info-index . "cl")))
5624 ;; (anything 'anything-c-source-info-cl)
5626 ;; Info Index org
5627 (defvar anything-c-source-info-org
5628 '((name . "Info index: org")
5629 (info-index . "org")))
5630 ;; (anything 'anything-c-source-info-org)
5632 ;; Info Index gnus
5633 (defvar anything-c-source-info-gnus
5634 '((name . "Info index: Gnus")
5635 (info-index . "gnus")))
5637 ;; Info Index ratpoison
5638 (defvar anything-c-source-info-ratpoison
5639 '((name . "Info index: ratpoison")
5640 (info-index . "ratpoison")))
5641 ;; (anything 'anything-c-source-info-ratpoison)
5643 ;; Info Index zsh
5644 (defvar anything-c-source-info-zsh
5645 '((name . "Info index: zsh")
5646 (info-index . "zsh")))
5647 ;; (anything 'anything-c-source-info-zsh)
5649 ;; Info Index bash
5650 (defvar anything-c-source-info-bash
5651 '((name . "Info index: bash")
5652 (info-index . "bash")))
5653 ;; (anything 'anything-c-source-info-bash)
5655 ;; Info Index coreutils
5656 (defvar anything-c-source-info-coreutils
5657 '((name . "Info index: coreutils")
5658 (info-index . "coreutils")))
5659 ;; (anything 'anything-c-source-info-coreutils)
5661 ;; Info Index fileutils
5662 (defvar anything-c-source-info-fileutils
5663 '((name . "Info index: fileutils")
5664 (info-index . "fileutils")))
5665 ;; (anything 'anything-c-source-info-fileutils)
5667 ;; Info Index find
5668 (defvar anything-c-source-info-find
5669 '((name . "Info index: find")
5670 (info-index . "find")))
5671 ;; (anything 'anything-c-source-info-find)
5673 ;; Info Index sh-utils
5674 (defvar anything-c-source-info-sh-utils
5675 '((name . "Info index: sh-utils")
5676 (info-index . "sh-utils")))
5677 ;; (anything 'anything-c-source-info-sh-utils)
5679 ;; Info Index textutils
5680 (defvar anything-c-source-info-textutils
5681 '((name . "Info index: textutils")
5682 (info-index . "textutils")))
5683 ;; (anything 'anything-c-source-info-textutils)
5685 ;; Info Index libc
5686 (defvar anything-c-source-info-libc
5687 '((name . "Info index: libc")
5688 (info-index . "libc")))
5689 ;; (anything 'anything-c-source-info-libc)
5691 ;; Info Index make
5692 (defvar anything-c-source-info-make
5693 '((name . "Info index: make")
5694 (info-index . "make")))
5695 ;; (anything 'anything-c-source-info-make)
5697 ;; Info Index automake
5698 (defvar anything-c-source-info-automake
5699 '((name . "Info index: automake")
5700 (info-index . "automake")))
5701 ;; (anything 'anything-c-source-info-automake)
5703 ;; Info Index autoconf
5704 (defvar anything-c-source-info-autoconf
5705 '((name . "Info index: autoconf")
5706 (info-index . "autoconf")))
5707 ;; (anything 'anything-c-source-info-autoconf)
5709 ;; Info Index emacs-lisp-intro
5710 (defvar anything-c-source-info-emacs-lisp-intro
5711 '((name . "Info index: emacs-lisp-intro")
5712 (info-index . "emacs-lisp-intro")))
5713 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5715 ;; Info Index emacs
5716 (defvar anything-c-source-info-emacs
5717 '((name . "Info index: emacs")
5718 (info-index . "emacs")))
5719 ;; (anything 'anything-c-source-info-emacs)
5721 ;; Info Index elib
5722 (defvar anything-c-source-info-elib
5723 '((name . "Info index: elib")
5724 (info-index . "elib")))
5725 ;; (anything 'anything-c-source-info-elib)
5727 ;; Info Index eieio
5728 (defvar anything-c-source-info-eieio
5729 '((name . "Info index: eieio")
5730 (info-index . "eieio")))
5731 ;; (anything 'anything-c-source-info-eieio)
5733 ;; Info Index gauche-refe
5734 (defvar anything-c-source-info-gauche-refe
5735 '((name . "Info index: gauche")
5736 (info-index . "gauche-refe")))
5737 ;; (anything 'anything-c-source-info-gauche-refe)
5739 ;; Info Index guile
5740 (defvar anything-c-source-info-guile
5741 '((name . "Info index: guile")
5742 (info-index . "guile")))
5743 ;; (anything 'anything-c-source-info-guile)
5745 ;; Info Index guile-tut
5746 (defvar anything-c-source-info-guile-tut
5747 '((name . "Info index: guile-tut")
5748 (info-index . "guile-tut")))
5749 ;; (anything 'anything-c-source-info-guile-tut)
5751 ;; Info Index goops
5752 (defvar anything-c-source-info-goops
5753 '((name . "Info index: goops")
5754 (info-index . "goops")))
5755 ;; (anything 'anything-c-source-info-goops)
5757 ;; Info Index screen
5758 (defvar anything-c-source-info-screen
5759 '((name . "Info index: screen")
5760 (info-index . "screen")
5761 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5762 ;; (anything 'anything-c-source-info-screen)
5764 ;; Info Index latex
5765 (defvar anything-c-source-info-latex
5766 '((name . "Info index: latex")
5767 (info-index . "latex")))
5768 ;; (anything 'anything-c-source-info-latex)
5770 ;; Info Index gawk
5771 (defvar anything-c-source-info-gawk
5772 '((name . "Info index: gawk")
5773 (info-index . "gawk")))
5774 ;; (anything 'anything-c-source-info-gawk)
5776 ;; Info Index sed
5777 (defvar anything-c-source-info-sed
5778 '((name . "Info index: sed")
5779 (info-index . "sed")))
5780 ;; (anything 'anything-c-source-info-sed)
5782 ;; Info Index m4
5783 (defvar anything-c-source-info-m4
5784 '((name . "Info index: m4")
5785 (info-index . "m4")))
5786 ;; (anything 'anything-c-source-info-m4)
5788 ;; Info Index wget
5789 (defvar anything-c-source-info-wget
5790 '((name . "Info index: wget")
5791 (info-index . "wget")))
5792 ;; (anything 'anything-c-source-info-wget)
5794 ;; Info Index binutils
5795 (defvar anything-c-source-info-binutils
5796 '((name . "Info index: binutils")
5797 (info-index . "binutils")))
5798 ;; (anything 'anything-c-source-info-binutils)
5800 ;; Info Index as
5801 (defvar anything-c-source-info-as
5802 '((name . "Info index: as")
5803 (info-index . "as")))
5804 ;; (anything 'anything-c-source-info-as)
5806 ;; Info Index bfd
5807 (defvar anything-c-source-info-bfd
5808 '((name . "Info index: bfd")
5809 (info-index . "bfd")))
5810 ;; (anything 'anything-c-source-info-bfd)
5812 ;; Info Index gprof
5813 (defvar anything-c-source-info-gprof
5814 '((name . "Info index: gprof")
5815 (info-index . "gprof")))
5816 ;; (anything 'anything-c-source-info-gprof)
5818 ;; Info Index ld
5819 (defvar anything-c-source-info-ld
5820 '((name . "Info index: ld")
5821 (info-index . "ld")))
5822 ;; (anything 'anything-c-source-info-ld)
5824 ;; Info Index diff
5825 (defvar anything-c-source-info-diff
5826 '((name . "Info index: diff")
5827 (info-index . "diff")))
5828 ;; (anything 'anything-c-source-info-diff)
5830 ;; Info Index flex
5831 (defvar anything-c-source-info-flex
5832 '((name . "Info index: flex")
5833 (info-index . "flex")))
5834 ;; (anything 'anything-c-source-info-flex)
5836 ;; Info Index grep
5837 (defvar anything-c-source-info-grep
5838 '((name . "Info index: grep")
5839 (info-index . "grep")))
5840 ;; (anything 'anything-c-source-info-grep)
5842 ;; Info Index gzip
5843 (defvar anything-c-source-info-gzip
5844 '((name . "Info index: gzip")
5845 (info-index . "gzip")))
5846 ;; (anything 'anything-c-source-info-gzip)
5848 ;; Info Index libtool
5849 (defvar anything-c-source-info-libtool
5850 '((name . "Info index: libtool")
5851 (info-index . "libtool")))
5852 ;; (anything 'anything-c-source-info-libtool)
5854 ;; Info Index texinfo
5855 (defvar anything-c-source-info-texinfo
5856 '((name . "Info index: texinfo")
5857 (info-index . "texinfo")))
5858 ;; (anything 'anything-c-source-info-texinfo)
5860 ;; Info Index info
5861 (defvar anything-c-source-info-info
5862 '((name . "Info index: info")
5863 (info-index . "info")))
5864 ;; (anything 'anything-c-source-info-info)
5866 ;; Info Index gdb
5867 (defvar anything-c-source-info-gdb
5868 '((name . "Info index: gdb")
5869 (info-index . "gdb")))
5870 ;; (anything 'anything-c-source-info-gdb)
5872 ;; Info Index stabs
5873 (defvar anything-c-source-info-stabs
5874 '((name . "Info index: stabs")
5875 (info-index . "stabs")))
5876 ;; (anything 'anything-c-source-info-stabs)
5878 ;; Info Index cvsbook
5879 (defvar anything-c-source-info-cvsbook
5880 '((name . "Info index: cvsbook")
5881 (info-index . "cvsbook")))
5882 ;; (anything 'anything-c-source-info-cvsbook)
5884 ;; Info Index cvs
5885 (defvar anything-c-source-info-cvs
5886 '((name . "Info index: cvs")
5887 (info-index . "cvs")))
5888 ;; (anything 'anything-c-source-info-cvs)
5890 ;; Info Index bison
5891 (defvar anything-c-source-info-bison
5892 '((name . "Info index: bison")
5893 (info-index . "bison")))
5894 ;; (anything 'anything-c-source-info-bison)
5896 ;; Info Index id-utils
5897 (defvar anything-c-source-info-id-utils
5898 '((name . "Info index: id-utils")
5899 (info-index . "id-utils")))
5900 ;; (anything 'anything-c-source-info-id-utils)
5902 ;; Info Index global
5903 (defvar anything-c-source-info-global
5904 '((name . "Info index: global")
5905 (info-index . "global")))
5906 ;; (anything 'anything-c-source-info-global)
5909 ;;; Man and woman UI
5912 (defvar anything-c-man-pages nil
5913 "All man pages on system.
5914 Will be calculated the first time you invoke anything with this
5915 source.")
5917 (defun anything-c-man-default-action (candidate)
5918 "Default action for jumping to a woman or man page from anything."
5919 (let ((wfiles (woman-file-name-all-completions candidate)))
5920 (condition-case err
5921 (if (> (length wfiles) 1)
5922 (woman-find-file
5923 (anything-comp-read
5924 "ManFile: " wfiles :must-match t))
5925 (woman candidate))
5926 ;; If woman is unable to format correctly
5927 ;; use man instead.
5928 (error (kill-buffer) ; Kill woman buffer.
5929 (let ((Man-notify-method 'meek))
5930 (Man-getpage-in-background candidate))))))
5932 (defvar anything-c-source-man-pages
5933 `((name . "Manual Pages")
5934 (candidates . (lambda ()
5935 (if anything-c-man-pages
5936 anything-c-man-pages
5937 ;; XEmacs doesn't have a woman :)
5938 (setq anything-c-man-pages
5939 (ignore-errors
5940 (require 'woman)
5941 (woman-file-name "")
5942 (sort (mapcar 'car woman-topic-all-completions)
5943 'string-lessp))))))
5944 (action ("Show with Woman" . anything-c-man-default-action))
5945 ;; Woman does not work OS X
5946 ;; http://xahlee.org/emacs/modernization_man_page.html
5947 (action-transformer . (lambda (actions candidate)
5948 (if (eq system-type 'darwin)
5949 '(("Show with Man" . man))
5950 actions)))
5951 (requires-pattern . 2)))
5952 ;; (anything 'anything-c-source-man-pages)
5955 ;;;; <Command>
5956 ;;; Anything M-x - Enhanced M-x UI
5959 ;; Another replacement of `M-x' that act exactly like the
5960 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5961 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5962 ;; anything invocation.
5963 ;; Documentation of commands available without quitting,
5964 ;; Show keybindings of commands.
5965 ;; Show history.
5966 (defvar anything-M-x-input-history nil)
5968 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5969 "Return alist of MODE-MAP."
5970 (loop for key being the key-seqs of mode-map using (key-bindings com)
5971 for str-key = (key-description key)
5972 for ismenu = (string-match "<menu-bar>" str-key)
5973 unless ismenu collect (cons str-key com)))
5975 (defun anything-get-mode-map-from-mode (mode)
5976 "Guess the mode-map name according to MODE.
5977 Some modes don't use conventional mode-map name
5978 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5979 Return nil if no mode-map found."
5980 (loop
5981 ;; Start with a conventional mode-map name.
5982 with mode-map = (intern-soft (format "%s-map" mode))
5983 with mode-string = (symbol-name mode)
5984 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5985 while (not mode-map)
5986 for count downfrom (length mode-name)
5987 ;; Return when no result after parsing entire string.
5988 when (eq count 0) return nil
5989 for sub-name = (substring mode-name 0 count)
5990 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5991 finally return mode-map))
5993 (defun anything-M-x-current-mode-map-alist ()
5994 "Return mode-map alist of current `major-mode'."
5995 (let ((map (anything-get-mode-map-from-mode major-mode)))
5996 (when (and map (boundp map))
5997 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
6000 (defun anything-M-x-transformer (candidates sources)
6001 "filtered-candidate-transformer to show bindings in emacs commands.
6002 Show global bindings and local bindings according to current `major-mode'."
6003 (with-anything-current-buffer
6004 (loop
6005 with local-map = (anything-M-x-current-mode-map-alist)
6006 for cand in candidates
6007 for local-key = (car (rassq cand local-map))
6008 for key = (substitute-command-keys (format "\\[%s]" cand))
6009 collect
6010 (cons (cond ((and (string-match "^M-x" key) local-key)
6011 (format "%s (%s)"
6012 cand (propertize
6013 local-key
6014 'face 'anything-M-x-key-face)))
6015 ((string-match "^M-x" key) cand)
6016 (t (format "%s (%s)"
6017 cand (propertize
6019 'face 'anything-M-x-key-face))))
6020 cand) into ls
6021 finally return
6022 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
6025 ;;; Complex command history
6028 (defvar anything-c-source-complex-command-history
6029 '((name . "Complex Command History")
6030 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
6031 (type . sexp)))
6032 ;; (anything 'anything-c-source-complex-command-history)
6034 ;;; M-x history (not related to `anything-M-x')
6037 (defvar anything-c-source-extended-command-history
6038 '((name . "Emacs Commands History")
6039 (candidates
6040 . (lambda ()
6041 (anything-fast-remove-dups extended-command-history :test 'equal)))
6042 (type . command)))
6043 ;; (anything 'anything-c-source-extended-command-history)
6045 ;;; Emacs commands (Basic source for emacs commands)
6048 (defvar anything-c-source-emacs-commands
6049 '((name . "Emacs Commands")
6050 (candidates . (lambda ()
6051 (let (commands)
6052 (mapatoms (lambda (a)
6053 (if (commandp a)
6054 (push (symbol-name a)
6055 commands))))
6056 (sort commands 'string-lessp))))
6057 (type . command)
6058 (requires-pattern . 2))
6059 "Source for completing and invoking Emacs commands.
6060 A command is a function with interactive spec that can
6061 be invoked with `M-x'.
6063 To get non-interactive functions listed, use
6064 `anything-c-source-emacs-functions'.")
6065 ;; (anything 'anything-c-source-emacs-commands)
6068 ;;;; <Function>
6069 ;;; Emacs functions
6072 (defvar anything-c-source-emacs-functions
6073 '((name . "Emacs Functions")
6074 (candidates . (lambda ()
6075 (let (commands)
6076 (mapatoms (lambda (a)
6077 (if (functionp a)
6078 (push (symbol-name a) commands))))
6079 (sort commands 'string-lessp))))
6080 (type . function)
6081 (requires-pattern . 2))
6082 "Source for completing Emacs functions.")
6083 ;; (anything 'anything-c-source-emacs-functions)
6085 ;;; With abbrev expansion
6086 ;;; Similar to my exec-abbrev-cmd.el
6087 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6088 (defvar anything-c-function-abbrev-regexp nil
6089 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6090 Regexp built from the current `anything-pattern' interpreting it
6091 as abbreviation.
6092 Only for internal use.")
6094 (defun anything-c-match-function-by-abbrev (candidate)
6095 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6097 Abbreviations are made by taking the first character from each
6098 word in the function's name, e.g. \"bb\" is an abbrev for
6099 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6100 (string-match anything-c-function-abbrev-regexp candidate))
6102 (defvar anything-c-source-emacs-functions-with-abbrevs
6103 (append anything-c-source-emacs-functions
6104 '((match anything-c-match-function-by-abbrev
6105 anything-c-string-match))
6106 '((init
6107 . (lambda ()
6108 (defadvice anything-update
6109 (before anything-c-update-function-abbrev-regexp activate)
6110 (let ((char-list (append anything-pattern nil))
6111 (str "^"))
6112 (dolist (c char-list)
6113 (setq str (concat str (list c) "[^-]*-")))
6114 (setq str (concat (substring str 0 (1- (length str))) "$"))
6115 (setq anything-c-function-abbrev-regexp str))))))))
6116 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6118 (defvar anything-c-source-advice
6119 '((name . "Function Advice")
6120 (candidates . anything-c-advice-candidates)
6121 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6122 (persistent-action . anything-c-advice-persistent-action)
6123 (multiline)
6124 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6125 ;; (anything 'anything-c-source-advice)
6126 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6127 ;; (testadvice)
6129 (defun anything-c-advice-candidates ()
6130 (require 'advice)
6131 (loop for (fname) in ad-advised-functions
6132 for function = (intern fname)
6133 append
6134 (loop for class in ad-advice-classes append
6135 (loop for advice in (ad-get-advice-info-field function class)
6136 for enabled = (ad-advice-enabled advice)
6137 collect
6138 (cons (format
6139 "%s %s %s"
6140 (if enabled "Enabled " "Disabled")
6141 (propertize fname 'face 'font-lock-function-name-face)
6142 (ad-make-single-advice-docstring advice class nil))
6143 (list function class advice))))))
6145 (defun anything-c-advice-persistent-action (func-class-advice)
6146 (if current-prefix-arg
6147 (anything-c-advice-toggle func-class-advice)
6148 (describe-function (car func-class-advice))))
6150 (defun anything-c-advice-toggle (func-class-advice)
6151 (destructuring-bind (function class advice) func-class-advice
6152 (cond ((ad-advice-enabled advice)
6153 (ad-advice-set-enabled advice nil)
6154 (message "Disabled"))
6155 (t ;disabled
6156 (ad-advice-set-enabled advice t)
6157 (message "Enabled")))
6158 (ad-activate function)
6159 (and anything-in-persistent-action
6160 (anything-c-advice-update-current-display-string))))
6162 (defun anything-c-advice-update-current-display-string ()
6163 (anything-edit-current-selection
6164 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6165 ((looking-at "Enabled") "Disabled")))
6166 realvalue)
6167 (when newword
6168 (delete-region (point) (progn (forward-word 1) (point)))
6169 (insert newword)))))
6172 ;;;; <Variable>
6173 ;;; Emacs variables
6176 (defvar anything-c-source-emacs-variables
6177 '((name . "Emacs Variables")
6178 (candidates . (lambda ()
6179 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6180 (type . variable)
6181 (requires-pattern . 2))
6182 "Source for completing Emacs variables.")
6183 ;; (anything 'anything-c-source-emacs-variables)
6186 ;;; LaCarte
6187 (defvar anything-c-source-lacarte
6188 '((name . "Lacarte")
6189 (init . (lambda () (require 'lacarte )))
6190 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6191 (candidate-number-limit . 9999)
6192 (action . anything-c-call-interactively))
6193 "Needs lacarte.el.
6195 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6196 ;; (anything 'anything-c-source-lacarte)
6199 ;;; Bookmarks
6202 ;; Bind some faces for bookmarks.
6203 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6204 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6205 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6207 (eval-when-compile (require 'bookmark))
6208 (defvar anything-c-source-bookmarks
6209 '((name . "Bookmarks")
6210 (init . (lambda ()
6211 (require 'bookmark)))
6212 (candidates . bookmark-all-names)
6213 (type . bookmark))
6214 "See (info \"(emacs)Bookmarks\").")
6215 ;; (anything 'anything-c-source-bookmarks)
6217 ;;; bookmark-set
6218 (defvar anything-c-source-bookmark-set
6219 '((name . "Set Bookmark")
6220 (dummy)
6221 (action . bookmark-set))
6222 "See (info \"(emacs)Bookmarks\").")
6223 ;; (anything 'anything-c-source-bookmark-set)
6225 ;;; Visible Bookmarks
6226 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6229 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6230 (defvar anything-c-source-bm
6231 '((name . "Visible Bookmarks")
6232 (init . anything-c-bm-init)
6233 (candidates-in-buffer)
6234 (type . line))
6235 "Needs bm.el.
6237 http://www.nongnu.org/bm/")
6239 (defun anything-c-bm-init ()
6240 "Init function for `anything-c-source-bm'."
6241 (when (require 'bm nil t)
6242 (with-no-warnings
6243 (let ((bookmarks (bm-lists))
6244 (buf (anything-candidate-buffer 'global)))
6245 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6246 '< :key 'overlay-start))
6247 (let ((start (overlay-start bm))
6248 (end (overlay-end bm))
6249 (annotation (or (overlay-get bm 'annotation) "")))
6250 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6251 (let ((str (format "%5d: [%s]: %s\n"
6252 (line-number-at-pos start)
6253 annotation
6254 (buffer-substring start (1- end)))))
6255 (with-current-buffer buf (insert str))))))))))
6257 ;;; Special bookmarks
6258 (defvar anything-c-source-bookmarks-ssh
6259 '((name . "Bookmarks-ssh")
6260 (init . (lambda ()
6261 (require 'bookmark)))
6262 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6263 (type . bookmark))
6264 "See (info \"(emacs)Bookmarks\").")
6265 ;; (anything 'anything-c-source-bookmarks-ssh)
6267 (defvar anything-c-source-bookmarks-su
6268 '((name . "Bookmarks-root")
6269 (init . (lambda ()
6270 (require 'bookmark)))
6271 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6272 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6274 (type . bookmark))
6275 "See (info \"(emacs)Bookmarks\").")
6276 ;; (anything 'anything-c-source-bookmarks-su)
6278 (defvar anything-c-source-bookmarks-local
6279 '((name . "Bookmarks-Local")
6280 (init . (lambda ()
6281 (require 'bookmark)))
6282 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6283 (filtered-candidate-transformer
6284 anything-c-adaptive-sort
6285 anything-c-highlight-bookmark)
6286 (type . bookmark))
6287 "See (info \"(emacs)Bookmarks\").")
6288 ;; (anything 'anything-c-source-bookmarks-local)
6290 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6291 (let* ((lis-all (bookmark-all-names))
6292 (lis-loc (cond (local (loop for i in lis-all
6293 unless (string-match "^(ssh)\\|^(su)" i)
6294 collect i))
6295 (su (loop for i in lis-all
6296 when (string-match "^(su)" i)
6297 collect i))
6298 (sudo (loop for i in lis-all
6299 when (string-match "^(sudo)" i)
6300 collect i))
6301 (ssh (loop for i in lis-all
6302 when (string-match "^(ssh)" i)
6303 collect i)))))
6304 (sort lis-loc 'string-lessp)))
6306 (defun anything-c-bookmark-root-logged-p ()
6307 (catch 'break
6308 (dolist (i (mapcar #'buffer-name (buffer-list)))
6309 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6310 (throw 'break t)))))
6312 (defun anything-c-highlight-bookmark-su (files source)
6313 (if (anything-c-bookmark-root-logged-p)
6314 (anything-c-highlight-bookmark files source)
6315 (anything-c-highlight-not-logged files source)))
6317 (defun anything-c-highlight-not-logged (files source)
6318 (loop for i in files
6319 collect (propertize i 'face anything-c-bookmarks-face3)))
6321 (defun anything-c-highlight-bookmark (bookmarks source)
6322 "Used as `candidate-transformer' to colorize bookmarks.
6323 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6324 (loop for i in bookmarks
6325 for isfile = (bookmark-get-filename i)
6326 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6327 (bmkext-get-buffer-name i))
6328 for handlerp = (and (fboundp 'bookmark-get-handler)
6329 (bookmark-get-handler i))
6330 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6331 (bmkext-w3m-bookmark-p i))
6332 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6333 (bmkext-gnus-bookmark-p i))
6334 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6335 (bmkext-man-bookmark-p i))
6336 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6337 (bmkext-woman-bookmark-p i))
6338 for handlerp = (bookmark-get-handler i)
6339 for isannotation = (bookmark-get-annotation i)
6340 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6341 for isinfo = (eq handlerp 'Info-bookmark-jump)
6342 ;; Add a * if bookmark have annotation
6343 if (and isannotation (not (string-equal isannotation "")))
6344 do (setq i (concat "*" i))
6345 collect (cond (;; info buffers
6346 isinfo
6347 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6348 (;; w3m buffers
6349 isw3m
6350 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6351 (;; gnus buffers
6352 isgnus
6353 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6354 (;; Man Woman
6355 (or iswoman isman)
6356 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6357 (;; Addressbook
6358 isabook
6359 (propertize i 'face '((:foreground "Tomato"))))
6360 (;; directories
6361 (and isfile (file-directory-p isfile))
6362 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6363 (;; regular files
6365 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6369 ;;; Sources to filter bookmark-extensions bookmarks.
6372 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6373 ;; If you want to enable google-maps in addressbook you will need
6374 ;; Julien Danjou google-maps-el package available here:
6375 ;; http://julien.danjou.info/google-maps-el.html
6377 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6378 "Return a filtered `bookmark-alist' sorted alphabetically."
6379 (loop
6380 with alist = (if args
6381 (apply #'(lambda (x) (funcall fn x)) args)
6382 (funcall fn))
6383 for i in alist
6384 for b = (car i)
6385 collect b into sa
6386 finally return (sort sa 'string-lessp)))
6388 ;;; Addressbook.
6391 (defvar anything-c-source-bmkext-addressbook
6392 '((name . "Bookmark Addressbook")
6393 (init . (lambda ()
6394 (require 'bookmark-extensions)
6395 (bookmark-maybe-load-default-file)))
6396 (candidates . anything-c-bmkext-addressbook-setup-alist)
6397 (persistent-action
6398 . (lambda (candidate)
6399 (let ((bmk (anything-bookmark-get-bookmark-from-name
6400 candidate)))
6401 (bookmark--jump-via bmk 'pop-to-buffer))))
6402 (persistent-help . "Show contact - Prefix with C-u to append")
6403 (filtered-candidate-transformer
6404 anything-c-adaptive-sort
6405 anything-c-highlight-bookmark)
6406 (action . (("Show Contact(s)"
6407 . (lambda (candidate)
6408 (let* ((contacts (anything-marked-candidates))
6409 (current-prefix-arg (or anything-current-prefix-arg
6410 (> (length contacts) 1))))
6411 (bookmark-jump
6412 (anything-bookmark-get-bookmark-from-name (car contacts)))
6413 (anything-aif (cdr contacts)
6414 (loop for bmk in it do
6415 (bookmark-jump
6416 (anything-bookmark-get-bookmark-from-name bmk)))))))
6417 ("Send Mail"
6418 . (lambda (candidate)
6419 (let* ((contacts (anything-marked-candidates))
6420 (bmk (anything-bookmark-get-bookmark-from-name
6421 (car contacts)))
6422 (append (message-buffers)))
6423 (if append
6424 (addressbook-set-mail-buffer1 bmk 'append)
6425 (addressbook-set-mail-buffer1 bmk))
6426 (setq contacts (cdr contacts))
6427 (when contacts
6428 (loop for bmk in contacts do
6429 (addressbook-set-mail-buffer1 bmk 'append))))))
6430 ("Edit Bookmark"
6431 . (lambda (candidate)
6432 (let ((bmk (anything-bookmark-get-bookmark-from-name
6433 candidate)))
6434 (addressbook-bookmark-edit
6435 (assoc bmk bookmark-alist)))))
6436 ("Insert Email at point"
6437 . (lambda (candidate)
6438 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6439 candidate))
6440 (mlist (split-string
6441 (assoc-default
6442 'email (assoc bmk bookmark-alist))
6443 ", ")))
6444 (insert
6445 (if (> (length mlist) 1)
6446 (anything-comp-read
6447 "Insert Mail Address: " mlist :must-match t)
6448 (car mlist))))))
6449 ("Show annotation"
6450 . (lambda (candidate)
6451 (let ((bmk (anything-bookmark-get-bookmark-from-name
6452 candidate)))
6453 (bookmark-show-annotation bmk))))
6454 ("Edit annotation"
6455 . (lambda (candidate)
6456 (let ((bmk (anything-bookmark-get-bookmark-from-name
6457 candidate)))
6458 (bookmark-edit-annotation bmk))))
6459 ("Show Google map"
6460 . (lambda (candidate)
6461 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6462 candidate))
6463 (full-bmk (assoc bmk bookmark-alist)))
6464 (addressbook-google-map full-bmk))))))))
6467 (defun anything-c-bmkext-addressbook-setup-alist ()
6468 "Specialized filter function for bookmarks w3m."
6469 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6471 ;; W3m bookmarks from bookmark-extensions.
6472 (defvar anything-c-source-bookmark-w3m
6473 '((name . "Bookmark W3m")
6474 (init . (lambda ()
6475 (require 'bookmark-extensions)
6476 (bookmark-maybe-load-default-file)))
6477 (candidates . anything-c-bookmark-w3m-setup-alist)
6478 (filtered-candidate-transformer
6479 anything-c-adaptive-sort
6480 anything-c-highlight-bookmark)
6481 (type . bookmark)))
6482 ;; (anything 'anything-c-source-bookmark-w3m)
6484 (defun anything-c-bookmark-w3m-setup-alist ()
6485 "Specialized filter function for bookmarks w3m."
6486 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6488 ;; Images
6489 (defvar anything-c-source-bookmark-images
6490 '((name . "Bookmark Images")
6491 (init . (lambda ()
6492 (require 'bookmark-extensions)
6493 (bookmark-maybe-load-default-file)))
6494 (candidates . anything-c-bookmark-images-setup-alist)
6495 (filtered-candidate-transformer
6496 anything-c-adaptive-sort
6497 anything-c-highlight-bookmark)
6498 (type . bookmark)))
6499 ;; (anything 'anything-c-source-bookmark-images)
6501 (defun anything-c-bookmark-images-setup-alist ()
6502 "Specialized filter function for images bookmarks."
6503 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6505 ;; Woman Man
6506 (defvar anything-c-source-bookmark-man
6507 '((name . "Bookmark Woman&Man")
6508 (init . (lambda ()
6509 (require 'bookmark-extensions)
6510 (bookmark-maybe-load-default-file)))
6511 (candidates . anything-c-bookmark-man-setup-alist)
6512 (filtered-candidate-transformer
6513 anything-c-adaptive-sort
6514 anything-c-highlight-bookmark)
6515 (type . bookmark)))
6516 ;; (anything 'anything-c-source-bookmark-man)
6518 (defun anything-c-bookmark-man-setup-alist ()
6519 "Specialized filter function for bookmarks w3m."
6520 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6521 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6523 ;; Gnus
6524 (defvar anything-c-source-bookmark-gnus
6525 '((name . "Bookmark Gnus")
6526 (init . (lambda ()
6527 (require 'bookmark-extensions)
6528 (bookmark-maybe-load-default-file)))
6529 (candidates . anything-c-bookmark-gnus-setup-alist)
6530 (filtered-candidate-transformer
6531 anything-c-adaptive-sort
6532 anything-c-highlight-bookmark)
6533 (type . bookmark)))
6534 ;; (anything 'anything-c-source-bookmark-gnus)
6536 (defun anything-c-bookmark-gnus-setup-alist ()
6537 "Specialized filter function for bookmarks gnus."
6538 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6540 ;; Info
6541 (defvar anything-c-source-bookmark-info
6542 '((name . "Bookmark Info")
6543 (init . (lambda ()
6544 (require 'bookmark-extensions)
6545 (bookmark-maybe-load-default-file)))
6546 (candidates . anything-c-bookmark-info-setup-alist)
6547 (filtered-candidate-transformer
6548 anything-c-adaptive-sort
6549 anything-c-highlight-bookmark)
6550 (type . bookmark)))
6551 ;; (anything 'anything-c-source-bookmark-info)
6553 (defun anything-c-bookmark-info-setup-alist ()
6554 "Specialized filter function for bookmarks info."
6555 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6557 ;; Local Files&directories
6558 (defvar anything-c-source-bookmark-files&dirs
6559 '((name . "Bookmark Files&Directories")
6560 (init . (lambda ()
6561 (require 'bookmark-extensions)
6562 (bookmark-maybe-load-default-file)))
6563 (candidates . anything-c-bookmark-local-files-setup-alist)
6564 (filtered-candidate-transformer
6565 anything-c-adaptive-sort
6566 anything-c-highlight-bookmark)
6567 (type . bookmark)))
6568 ;; (anything 'anything-c-source-bookmark-files&dirs)
6570 (defun anything-c-bookmark-local-files-setup-alist ()
6571 "Specialized filter function for bookmarks locals files."
6572 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6574 ;; Su Files&directories
6575 (defvar anything-c-source-bookmark-su-files&dirs
6576 '((name . "Bookmark Root-Files&Directories")
6577 (init . (lambda ()
6578 (require 'bookmark-extensions)
6579 (bookmark-maybe-load-default-file)))
6580 (candidates . anything-c-bookmark-su-files-setup-alist)
6581 (filtered-candidate-transformer
6582 anything-c-adaptive-sort
6583 anything-c-highlight-bookmark-su)
6584 (type . bookmark)))
6585 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6587 (defun anything-c-bookmark-su-files-setup-alist ()
6588 "Specialized filter function for bookmarks su/sudo files."
6589 (declare (special bmkext-su-or-sudo-regexp))
6590 (loop
6591 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6592 for i in l
6593 for isfile = (bookmark-get-filename i)
6594 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6595 (save-match-data
6596 (string-match tramp-file-name-regexp isfile)))
6597 for issu = (and istramp
6598 (string-match bmkext-su-or-sudo-regexp isfile))
6599 if issu
6600 collect i))
6602 ;; Ssh Files&directories
6603 (defvar anything-c-source-bookmark-ssh-files&dirs
6604 '((name . "Bookmark Ssh-Files&Directories")
6605 (init . (lambda ()
6606 (require 'bookmark-extensions)
6607 (bookmark-maybe-load-default-file)))
6608 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6609 (filtered-candidate-transformer . anything-c-adaptive-sort)
6610 (type . bookmark)))
6611 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6613 (defun anything-c-bookmark-ssh-files-setup-alist ()
6614 "Specialized filter function for bookmarks ssh files."
6615 (loop
6616 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6617 for i in l
6618 for isfile = (bookmark-get-filename i)
6619 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6620 (save-match-data
6621 (string-match tramp-file-name-regexp isfile)))
6622 for isssh = (and istramp
6623 (string-match "/ssh:" isfile))
6624 if isssh
6625 collect i))
6629 ;;; Firefox bookmarks
6632 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6633 ;; (only for firefox versions >=3)
6634 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6635 ;; to true:
6636 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6637 ;; You should have now:
6638 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6640 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6641 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6643 (defun anything-get-firefox-user-init-dir ()
6644 "Guess the default Firefox user directory name."
6645 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6646 (moz-user-dir
6647 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6648 (goto-char (point-min))
6649 (prog1
6650 (when (search-forward "Path=" nil t)
6651 (buffer-substring-no-properties (point) (point-at-eol)))
6652 (kill-buffer)))))
6653 (file-name-as-directory (concat moz-dir moz-user-dir))))
6655 (defun anything-guess-firefox-bookmark-file ()
6656 "Return the path of the Firefox bookmarks file."
6657 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6659 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6660 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6661 (let (bookmarks-alist url title)
6662 (with-temp-buffer
6663 (insert-file-contents file)
6664 (goto-char (point-min))
6665 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6666 (forward-line 0)
6667 (when (re-search-forward url-regexp nil t)
6668 (setq url (match-string 0)))
6669 (when (re-search-forward bmk-regexp nil t)
6670 (setq title (match-string 1)))
6671 (push (cons title url) bookmarks-alist)
6672 (forward-line)))
6673 (nreverse bookmarks-alist)))
6675 (defvar anything-c-firefox-bookmarks-alist nil)
6676 (defvar anything-c-source-firefox-bookmarks
6677 '((name . "Firefox Bookmarks")
6678 (init . (lambda ()
6679 (setq anything-c-firefox-bookmarks-alist
6680 (anything-html-bookmarks-to-alist
6681 (anything-guess-firefox-bookmark-file)
6682 anything-firefox-bookmark-url-regexp
6683 anything-firefox-bookmarks-regexp))))
6684 (candidates . (lambda ()
6685 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6686 (filtered-candidate-transformer
6687 anything-c-adaptive-sort
6688 anything-c-highlight-firefox-bookmarks)
6689 (action . (("Browse Url Firefox"
6690 . (lambda (candidate)
6691 (browse-url-firefox
6692 (anything-c-firefox-bookmarks-get-value candidate))))
6693 ("Browse Url w3m"
6694 . (lambda (candidate)
6695 (w3m-browse-url
6696 (anything-c-firefox-bookmarks-get-value candidate))))
6697 ("Copy Url"
6698 . (lambda (elm)
6699 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6701 ;; (anything 'anything-c-source-firefox-bookmarks)
6703 (defun anything-c-firefox-bookmarks-get-value (elm)
6704 (assoc-default elm anything-c-firefox-bookmarks-alist))
6706 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6707 (loop for i in bookmarks
6708 collect (propertize
6709 i 'face '((:foreground "YellowGreen"))
6710 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6714 ;;; W3m bookmark - anything interface.
6717 ;; Some users have the emacs-w3m library in load-path
6718 ;; without having the w3m executable :-;
6719 ;; So check if w3m program is present before trying to load
6720 ;; emacs-w3m.
6721 (eval-when-compile
6722 (when (executable-find "w3m")
6723 (require 'w3m-bookmark nil t)))
6725 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6726 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6727 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6728 (defvar anything-c-w3m-bookmarks-alist nil)
6729 (defvar anything-c-source-w3m-bookmarks
6730 '((name . "W3m Bookmarks")
6731 (init . (lambda ()
6732 (setq anything-c-w3m-bookmarks-alist
6733 (anything-html-bookmarks-to-alist
6734 w3m-bookmark-file
6735 anything-w3m-bookmark-url-regexp
6736 anything-w3m-bookmarks-regexp))))
6737 (candidates . (lambda ()
6738 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6739 (filtered-candidate-transformer
6740 anything-c-adaptive-sort
6741 anything-c-highlight-w3m-bookmarks)
6742 (action . (("Browse Url"
6743 . (lambda (candidate)
6744 (anything-c-w3m-browse-bookmark candidate)))
6745 ("Copy Url"
6746 . (lambda (elm)
6747 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6748 ("Browse Url Firefox"
6749 . (lambda (candidate)
6750 (anything-c-w3m-browse-bookmark candidate t)))
6751 ("Delete Bookmark"
6752 . (lambda (candidate)
6753 (anything-c-w3m-delete-bookmark candidate)))
6754 ("Rename Bookmark"
6755 . (lambda (candidate)
6756 (anything-c-w3m-rename-bookmark candidate)))))
6757 (persistent-action . (lambda (candidate)
6758 (if current-prefix-arg
6759 (anything-c-w3m-browse-bookmark candidate t)
6760 (anything-c-w3m-browse-bookmark candidate nil t))))
6761 (persistent-help . "Open URL with emacs-w3m in new tab / \
6762 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6763 "Needs w3m and emacs-w3m.
6765 http://w3m.sourceforge.net/
6766 http://emacs-w3m.namazu.org/")
6768 ;; (anything 'anything-c-source-w3m-bookmarks)
6770 (defun anything-c-w3m-bookmarks-get-value (elm)
6771 (replace-regexp-in-string
6772 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6774 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6775 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6776 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6777 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6779 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6780 (loop for i in bookmarks
6781 collect (propertize
6782 i 'face 'anything-w3m-bookmarks-face
6783 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6786 (defun anything-c-w3m-delete-bookmark (elm)
6787 "Delete w3m bookmark from `w3m-bookmark-file'."
6788 (with-current-buffer
6789 (find-file-literally w3m-bookmark-file)
6790 (goto-char (point-min))
6791 (when (re-search-forward elm nil t)
6792 (beginning-of-line)
6793 (delete-region (point)
6794 (line-end-position))
6795 (delete-blank-lines))
6796 (save-buffer)
6797 (kill-buffer)))
6799 (defun anything-c-w3m-rename-bookmark (elm)
6800 "Rename w3m bookmark in `w3m-bookmark-file'."
6801 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6802 (new-title (read-string "NewTitle: " old-title)))
6803 (with-current-buffer
6804 (find-file-literally w3m-bookmark-file)
6805 (goto-char (point-min))
6806 (when (re-search-forward (concat elm "<") nil t)
6807 (goto-char (1- (point)))
6808 (delete-char (- (length old-title)))
6809 (insert new-title))
6810 (save-buffer)
6811 (kill-buffer))))
6814 ;;;; <Library>
6815 ;;; Elisp library scan
6818 (defvar anything-c-source-elisp-library-scan
6819 '((name . "Elisp libraries (Scan)")
6820 (init . (anything-c-elisp-library-scan-init))
6821 (candidates-in-buffer)
6822 (action ("Find library"
6823 . (lambda (candidate) (find-file (find-library-name candidate))))
6824 ("Find library other window"
6825 . (lambda (candidate)
6826 (find-file-other-window (find-library-name candidate))))
6827 ("Load library"
6828 . (lambda (candidate) (load-library candidate))))))
6829 ;; (anything 'anything-c-source-elisp-library-scan)
6831 (defun anything-c-elisp-library-scan-init ()
6832 "Init anything buffer status."
6833 (let ((anything-buffer (anything-candidate-buffer 'global))
6834 (library-list (anything-c-elisp-library-scan-list)))
6835 (with-current-buffer anything-buffer
6836 (dolist (library library-list)
6837 (insert (format "%s\n" library))))))
6839 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6840 "Do completion for file names passed to `locate-file'.
6841 DIRS is directory to search path.
6842 STRING is string to match."
6843 ;; Use `load-path' as path when ignore `dirs'.
6844 (or dirs (setq dirs load-path))
6845 ;; Init with blank when ignore `string'.
6846 (or string (setq string ""))
6847 ;; Get library list.
6848 (let ((string-dir (file-name-directory string))
6849 ;; File regexp that suffix match `load-file-rep-suffixes'.
6850 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6851 name
6852 names)
6853 (dolist (dir dirs)
6854 (unless dir
6855 (setq dir default-directory))
6856 (if string-dir
6857 (setq dir (expand-file-name string-dir dir)))
6858 (when (file-directory-p dir)
6859 (dolist (file (file-name-all-completions
6860 (file-name-nondirectory string) dir))
6861 ;; Suffixes match `load-file-rep-suffixes'.
6862 (setq name (if string-dir (concat string-dir file) file))
6863 (if (string-match match-regexp name)
6864 (add-to-list 'names name)))))
6865 names))
6868 ;;;; <Programming>
6872 ;;; Imenu
6875 (defvar anything-c-imenu-delimiter " / ")
6877 (defvar anything-c-imenu-index-filter nil)
6878 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6880 (defvar anything-c-cached-imenu-alist nil)
6881 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6883 (defvar anything-c-cached-imenu-candidates nil)
6884 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6886 (defvar anything-c-cached-imenu-tick nil)
6887 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6889 (eval-when-compile (require 'imenu))
6890 (setq imenu-auto-rescan t)
6892 (defun anything-imenu-create-candidates (entry)
6893 "Create candidates with ENTRY."
6894 (if (listp (cdr entry))
6895 (mapcan
6896 (lambda (sub)
6897 (if (consp (cdr sub))
6898 (mapcar
6899 (lambda (subentry)
6900 (concat (car entry) anything-c-imenu-delimiter subentry))
6901 (anything-imenu-create-candidates sub))
6902 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6903 (cdr entry))
6904 (list entry)))
6906 (defvar anything-c-source-imenu
6907 '((name . "Imenu")
6908 (init . (lambda () (require 'imenu)))
6909 (candidates . anything-c-imenu-candidates)
6910 (persistent-action . (lambda (elm)
6911 (anything-c-imenu-default-action elm)
6912 (unless (fboundp 'semantic-imenu-tag-overlay)
6913 (anything-match-line-color-current-line))))
6914 (persistent-help . "Show this entry")
6915 (action . anything-c-imenu-default-action))
6916 "See (info \"(emacs)Imenu\")")
6918 ;; (anything 'anything-c-source-imenu)
6920 (defun anything-c-imenu-candidates ()
6921 (with-anything-current-buffer
6922 (let ((tick (buffer-modified-tick)))
6923 (if (eq anything-c-cached-imenu-tick tick)
6924 anything-c-cached-imenu-candidates
6925 (setq imenu--index-alist nil)
6926 (setq anything-c-cached-imenu-tick tick
6927 anything-c-cached-imenu-candidates
6928 (ignore-errors
6929 (mapcan
6930 'anything-imenu-create-candidates
6931 (setq anything-c-cached-imenu-alist
6932 (let ((index (imenu--make-index-alist)))
6933 (if anything-c-imenu-index-filter
6934 (funcall anything-c-imenu-index-filter index)
6935 index))))))
6936 (setq anything-c-cached-imenu-candidates
6937 (mapcar #'(lambda (x)
6938 (if (stringp x)
6940 (car x)))
6941 anything-c-cached-imenu-candidates))))))
6943 (setq imenu-default-goto-function 'imenu-default-goto-function)
6944 (defun anything-c-imenu-default-action (elm)
6945 "The default action for `anything-c-source-imenu'."
6946 (let ((path (split-string elm anything-c-imenu-delimiter))
6947 (alist anything-c-cached-imenu-alist))
6948 (dolist (elm path)
6949 (setq alist (assoc elm alist)))
6950 (imenu alist)))
6954 ;;; Ctags
6957 (defvar anything-c-ctags-modes
6958 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6959 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6960 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6962 (defun anything-c-source-ctags-init ()
6963 (when (and buffer-file-name
6964 (memq major-mode anything-c-ctags-modes)
6965 (anything-current-buffer-is-modified))
6966 (with-current-buffer (anything-candidate-buffer 'local)
6967 (call-process-shell-command
6968 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6969 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6970 anything-buffer-file-name)
6971 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6972 nil (current-buffer))
6973 (goto-char (point-min))
6974 (forward-line 2)
6975 (delete-region (point-min) (point))
6976 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6977 for lineno-start = (point)
6978 for lineno = (buffer-substring
6979 lineno-start
6980 (1- (search-forward "," (point-at-eol) t)))
6982 (beginning-of-line)
6983 (insert (format "%5s:" lineno))
6984 (search-forward "\177" (point-at-eol) t)
6985 (delete-region (1- (point)) (point-at-eol))
6986 (forward-line 1)))))
6988 (defvar anything-c-source-ctags
6989 '((name . "Exuberant ctags")
6990 (init . anything-c-source-ctags-init)
6991 (candidates-in-buffer)
6992 (adjust)
6993 (type . line))
6994 "Needs Exuberant Ctags.
6996 http://ctags.sourceforge.net/")
6997 ;; (anything 'anything-c-source-ctags)
7000 ;;; Etags
7003 ;; anything-etags.el is deprecated, if this file is found,
7004 ;; warn user at compile time.
7005 (eval-when-compile
7006 (when (locate-library "anything-etags.el")
7007 (display-warning
7008 '(anything-config)
7009 "You are using obsolete library `anything-etags.el' and should remove it."
7010 :warning)))
7012 (defvar anything-c-etags-tag-file-dir nil
7013 "Etags file directory.")
7014 (defvar anything-c-etags-mtime-alist nil
7015 "Store the last modification time of etags files here.")
7016 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
7017 "Cache content of etags files used here for faster access.")
7019 (defun anything-c-etags-get-tag-file (&optional directory)
7020 "Return the path of etags file if found."
7021 ;; Get tag file from `default-directory' or upper directory.
7022 (let ((current-dir (anything-c-etags-find-tag-file-directory
7023 (or directory default-directory))))
7024 ;; Return nil if not find tag file.
7025 (when current-dir
7026 ;; Set tag file directory.
7027 (setq anything-c-etags-tag-file-dir current-dir)
7028 (expand-file-name anything-c-etags-tag-file-name current-dir))))
7030 (defun anything-c-etags-find-tag-file-directory (current-dir)
7031 "Try to find the directory containing tag file.
7032 If not found in CURRENT-DIR search in upper directory."
7033 (flet ((file-exists? (dir)
7034 (let ((tag-path (expand-file-name
7035 anything-c-etags-tag-file-name dir)))
7036 (and (stringp tag-path)
7037 (file-exists-p tag-path)
7038 (file-readable-p tag-path)))))
7039 (loop with count = 0
7040 until (file-exists? current-dir)
7041 ;; Return nil if outside the value of
7042 ;; `anything-c-etags-tag-file-search-limit'.
7043 if (= count anything-c-etags-tag-file-search-limit)
7044 do (return nil)
7045 ;; Or search upper directories.
7046 else
7047 do (incf count)
7048 (setq current-dir (expand-file-name (concat current-dir "../")))
7049 finally return current-dir)))
7051 (defun anything-c-source-etags-header-name (x)
7052 "Create header name for this anything etags session."
7053 (concat "Etags in "
7054 (with-anything-current-buffer
7055 (anything-c-etags-get-tag-file))))
7057 (defmacro anything-c-etags-create-buffer (file)
7058 "Create the `anything-buffer' based on contents of etags tag FILE."
7059 `(let* ((tag-fname ,file)
7061 (split (with-current-buffer (find-file-noselect tag-fname)
7062 (prog1
7063 (split-string (buffer-string) "\n" 'omit-nulls)
7064 (setq max (line-number-at-pos (point-max)))
7065 (kill-buffer))))
7066 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7067 (loop
7068 with fname
7069 with cand
7070 for i in split for count from 0
7071 for elm = (unless (string-match "^\x0c" i)
7072 (anything-aif (string-match "\177" i)
7073 (substring i 0 it)
7075 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7076 (setq fname (match-string 1 elm)))
7077 (elm (setq cand (concat fname ": " elm)))
7078 (t (setq cand nil)))
7079 when cand do (progn
7080 (insert (concat cand "\n"))
7081 (progress-reporter-update progress-reporter count)))))
7083 (defun anything-c-etags-init ()
7084 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7085 If no entry in cache, create one."
7086 (let ((tagfile (anything-c-etags-get-tag-file)))
7087 (when tagfile
7088 (with-current-buffer (anything-candidate-buffer 'global)
7089 (anything-aif (gethash tagfile anything-c-etags-cache)
7090 ;; An entry is present in cache, insert it.
7091 (insert it)
7092 ;; No entry, create a new buffer using content of tag file (slower).
7093 (anything-c-etags-create-buffer tagfile)
7094 ;; Store content of buffer in cache.
7095 (puthash tagfile (buffer-string) anything-c-etags-cache)
7096 ;; Store or set the last modification of tag file.
7097 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7098 ;; If an entry exists modify it.
7099 (setcdr it (anything-c-etags-mtime tagfile))
7100 ;; No entry create a new one.
7101 (add-to-list 'anything-c-etags-mtime-alist
7102 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7104 (defvar anything-c-source-etags-select
7105 '((name . "Etags")
7106 (header-name . anything-c-source-etags-header-name)
7107 (init . anything-c-etags-init)
7108 (candidates-in-buffer)
7109 (search . (anything-c-etags-search-fn))
7110 (mode-line . anything-etags-mode-line-string)
7111 (action . anything-c-etags-default-action)
7112 (persistent-action . (lambda (candidate)
7113 (anything-c-etags-default-action candidate)
7114 (anything-match-line-color-current-line))))
7115 "Anything source for Etags.")
7117 (defun anything-c-etags-search-fn (pattern)
7118 "Search function for `anything-c-source-etags-select'."
7119 (re-search-forward
7120 (if anything-c-etags-use-regexp-search
7121 (format anything-c-etags-search-regexp pattern)
7122 pattern)
7123 nil t))
7125 (defun anything-c-etags-default-action (candidate)
7126 "Anything default action to jump to an etags entry."
7127 (let* ((split (split-string candidate ": "))
7128 (fname (expand-file-name
7129 (car split) anything-c-etags-tag-file-dir))
7130 (elm (cadr split)))
7131 (find-file fname)
7132 (goto-char (point-min))
7133 (search-forward elm nil t)
7134 (goto-char (match-beginning 0))))
7136 (defun anything-c-etags-mtime (file)
7137 "Last modification time of etags tag FILE."
7138 (cadr (nth 5 (file-attributes file))))
7140 (defun anything-c-etags-file-modified-p (file)
7141 "Check if tag FILE have been modified in this session.
7142 If FILE is nil return nil."
7143 (let ((last-modif (and file
7144 (assoc-default file anything-c-etags-mtime-alist))))
7145 (and last-modif
7146 (/= last-modif (anything-c-etags-mtime file)))))
7150 ;;; Semantic
7153 (defvar anything-semantic-candidates nil)
7155 (defun anything-semantic-construct-candidates (tags depth)
7156 (when (require 'semantic nil t)
7157 (apply
7158 'append
7159 (mapcar
7160 (lambda (tag)
7161 (if (listp tag)
7162 (let ((type (semantic-tag-type tag))
7163 (class (semantic-tag-class tag)))
7164 (if (or (and (stringp type)
7165 (or (string= type "class")
7166 (string= type "namespace")))
7167 (eq class 'function)
7168 (eq class 'variable))
7169 (cons (cons (concat (make-string (* depth 2) ?\s)
7170 (semantic-format-tag-summarize tag nil t))
7171 tag)
7172 (anything-semantic-construct-candidates
7173 (semantic-tag-components tag) (1+ depth)))))))
7174 tags))))
7176 (defun anything-semantic-default-action (candidate)
7177 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7178 (semantic-go-to-tag tag)))
7180 (defvar anything-c-source-semantic
7181 '((name . "Semantic Tags")
7182 (init . (lambda ()
7183 (setq anything-semantic-candidates
7184 (ignore-errors (anything-semantic-construct-candidates
7185 (semantic-fetch-tags) 0)))))
7186 (candidates . (lambda ()
7187 (if anything-semantic-candidates
7188 (mapcar 'car anything-semantic-candidates))))
7189 (persistent-action . (lambda (elm)
7190 (anything-semantic-default-action elm)
7191 (anything-match-line-color-current-line)))
7192 (persistent-help . "Show this entry")
7193 (action . anything-semantic-default-action)
7194 "Needs semantic in CEDET.
7196 http://cedet.sourceforge.net/semantic.shtml
7197 http://cedet.sourceforge.net/"))
7199 ;; (anything 'anything-c-source-semantic)
7202 ;;; Anything interface of `simple-call-tree.el'.
7204 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7206 ;; Function is called by
7207 (defvar anything-c-source-simple-call-tree-functions-callers
7208 '((name . "Function is called by")
7209 (init . anything-c-simple-call-tree-functions-callers-init)
7210 (multiline)
7211 (candidates . anything-c-simple-call-tree-candidates)
7212 (persistent-action . anything-c-simple-call-tree-persistent-action)
7213 (persistent-help . "Show function definitions by rotation")
7214 (action ("Find definition selected by persistent-action" .
7215 anything-c-simple-call-tree-find-definition)))
7216 "Needs simple-call-tree.el.
7217 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7219 (defvar anything-c-simple-call-tree-tick nil)
7220 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7221 (defun anything-c-simple-call-tree-analyze-maybe ()
7222 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7223 (simple-call-tree-analyze)
7224 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7226 (defun anything-c-simple-call-tree-init-base (function message)
7227 (require 'simple-call-tree)
7228 (with-no-warnings
7229 (when (anything-current-buffer-is-modified)
7230 (anything-c-simple-call-tree-analyze-maybe)
7231 (let ((list (funcall function simple-call-tree-alist)))
7232 (with-current-buffer (anything-candidate-buffer 'local)
7233 (dolist (entry list)
7234 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7235 (insert (car entry) message
7236 (if (string= funcs " ")
7237 " no functions."
7238 funcs)
7239 "\n\n"))))))))
7241 (defun anything-c-simple-call-tree-functions-callers-init ()
7242 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7243 " is called by\n"))
7245 (defun anything-c-simple-call-tree-candidates ()
7246 (with-current-buffer (anything-candidate-buffer)
7247 (split-string (buffer-string) "\n\n")))
7249 (defvar anything-c-simple-call-tree-related-functions nil)
7250 (defvar anything-c-simple-call-tree-function-index 0)
7251 (defun anything-c-simple-call-tree-persistent-action (candidate)
7252 (unless (eq last-command 'anything-execute-persistent-action)
7253 (setq anything-c-simple-call-tree-related-functions
7254 (delete "no functions."
7255 (split-string
7256 (replace-regexp-in-string " \\| is called by\\| calls "
7257 "" candidate)
7258 "\n")))
7259 (setq anything-c-simple-call-tree-function-index -1))
7260 (incf anything-c-simple-call-tree-function-index)
7261 (anything-c-simple-call-tree-find-definition candidate))
7263 (defun anything-c-simple-call-tree-find-definition (candidate)
7264 (find-function
7265 (intern
7266 (nth (mod anything-c-simple-call-tree-function-index
7267 (length anything-c-simple-call-tree-related-functions))
7268 anything-c-simple-call-tree-related-functions))))
7270 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7272 ;;; Function calls
7273 (defvar anything-c-source-simple-call-tree-callers-functions
7274 '((name . "Function calls")
7275 (init . anything-c-simple-call-tree-callers-functions-init)
7276 (multiline)
7277 (candidates . anything-c-simple-call-tree-candidates)
7278 (persistent-action . anything-c-simple-call-tree-persistent-action)
7279 (persistent-help . "Show function definitions by rotation")
7280 (action ("Find definition selected by persistent-action" .
7281 anything-c-simple-call-tree-find-definition)))
7282 "Needs simple-call-tree.el.
7283 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7285 (defun anything-c-simple-call-tree-callers-functions-init ()
7286 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7288 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7292 ;;; Anything UI of auto-document.el
7294 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7296 ;; Commands/Options with doc
7297 (defvar anything-c-auto-document-data nil)
7298 (make-variable-buffer-local 'anything-c-auto-document-data)
7299 (defvar anything-c-source-commands-and-options-in-file
7300 '((name . "Commands/Options in file")
7301 (header-name
7302 . (lambda (x) (format "Commands/Options in %s"
7303 (buffer-local-value 'buffer-file-name
7304 anything-current-buffer))))
7305 (candidates . anything-command-and-options-candidates)
7306 (multiline)
7307 (action . imenu))
7308 "List Commands and Options with doc. It needs auto-document.el .
7310 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7312 (eval-when-compile (require 'auto-document nil t))
7313 (defun anything-command-and-options-candidates ()
7314 (with-anything-current-buffer
7315 (when (and (require 'auto-document nil t)
7316 (eq major-mode 'emacs-lisp-mode)
7317 (or (anything-current-buffer-is-modified)
7318 (not anything-c-auto-document-data)))
7319 (or imenu--index-alist (imenu--make-index-alist t))
7320 (setq anything-c-auto-document-data
7321 (destructuring-bind (commands options)
7322 (adoc-construct anything-current-buffer)
7323 (append
7324 (loop for (command . doc) in commands
7325 for cmdname = (symbol-name command)
7326 collect
7327 (cons
7328 (format "Command: %s\n %s"
7329 (propertize cmdname 'face font-lock-function-name-face)
7330 (adoc-first-line doc))
7331 (assoc cmdname imenu--index-alist)))
7332 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7333 for (option doc default) in options
7334 for optname = (symbol-name option)
7335 collect
7336 (cons
7337 (format "Option: %s\n %s\n default = %s"
7338 (propertize optname 'face font-lock-variable-name-face)
7339 (adoc-first-line doc)
7340 (adoc-prin1-to-string default))
7341 (assoc optname
7342 var-alist)))))))
7343 anything-c-auto-document-data))
7345 ;; (anything 'anything-c-source-commands-and-options-in-file)
7348 ;;;; <Color and Face>
7351 ;;; Customize Face
7354 (defvar anything-c-source-customize-face
7355 '((name . "Customize Face")
7356 (init . (lambda ()
7357 (unless (anything-candidate-buffer)
7358 (save-selected-window
7359 (list-faces-display))
7360 (anything-candidate-buffer (get-buffer "*Faces*")))))
7361 (candidates-in-buffer)
7362 (get-line . buffer-substring)
7363 (action . (lambda (line)
7364 (customize-face (intern (car (split-string line))))))
7365 (requires-pattern . 3))
7366 "See (info \"(emacs)Faces\")")
7367 ;; (anything 'anything-c-source-customize-face)
7369 ;;; Colors browser
7372 (defvar anything-c-source-colors
7373 '((name . "Colors")
7374 (init . (lambda () (unless (anything-candidate-buffer)
7375 (save-selected-window
7376 (list-colors-display))
7377 (anything-candidate-buffer (get-buffer "*Colors*")))))
7378 (candidates-in-buffer)
7379 (get-line . buffer-substring)
7380 (action
7381 ("Copy Name" . (lambda (candidate)
7382 (kill-new (anything-c-colors-get-name candidate))))
7383 ("Copy RGB" . (lambda (candidate)
7384 (kill-new (anything-c-colors-get-rgb candidate))))
7385 ("Insert Name" . (lambda (candidate)
7386 (with-anything-current-buffer
7387 (insert (anything-c-colors-get-name candidate)))))
7388 ("Insert RGB" . (lambda (candidate)
7389 (with-anything-current-buffer
7390 (insert (anything-c-colors-get-rgb candidate))))))))
7391 ;; (anything 'anything-c-source-colors)
7393 (defun anything-c-colors-get-name (candidate)
7394 "Get color name."
7395 (replace-regexp-in-string
7396 " " ""
7397 (with-temp-buffer
7398 (insert (capitalize candidate))
7399 (goto-char (point-min))
7400 (search-forward-regexp "\\s-\\{2,\\}")
7401 (delete-region (point) (point-max))
7402 (buffer-string))))
7404 (defun anything-c-colors-get-rgb (candidate)
7405 "Get color RGB."
7406 (replace-regexp-in-string
7407 " " ""
7408 (with-temp-buffer
7409 (insert (capitalize candidate))
7410 (goto-char (point-max))
7411 (search-backward-regexp "\\s-\\{2,\\}")
7412 (delete-region (point) (point-min))
7413 (buffer-string))))
7416 ;;;; <Search Engine>
7417 ;;; Tracker desktop search
7418 (defvar anything-c-source-tracker-search
7419 '((name . "Tracker Search")
7420 (candidates . (lambda ()
7421 (start-process "tracker-search-process" nil
7422 "tracker-search"
7423 anything-pattern)))
7424 (type . file)
7425 (requires-pattern . 3)
7426 (delayed))
7427 "Source for retrieving files matching the current input pattern
7428 with the tracker desktop search.")
7429 ;; (anything 'anything-c-source-tracker-search)
7431 ;;; Spotlight (MacOS X desktop search)
7432 (defvar anything-c-source-mac-spotlight
7433 '((name . "mdfind")
7434 (candidates
7435 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7436 (type . file)
7437 (requires-pattern . 3)
7438 (delayed))
7439 "Source for retrieving files via Spotlight's command line
7440 utility mdfind.")
7441 ;; (anything 'anything-c-source-mac-spotlight)
7443 ;;; Picklist
7444 (defvar anything-c-source-picklist
7445 '((name . "Picklist")
7446 (candidates . (lambda () (mapcar 'car picklist-list)))
7447 (type . file)))
7448 ;; (anything 'anything-c-source-picklist)
7452 ;;; Kill ring
7455 (defvar anything-c-source-kill-ring
7456 '((name . "Kill Ring")
7457 (init . (lambda () (anything-attrset 'last-command last-command)))
7458 (candidates . anything-c-kill-ring-candidates)
7459 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7460 (action . anything-c-kill-ring-action)
7461 (last-command)
7462 (migemo)
7463 (multiline))
7464 "Source for browse and insert contents of kill-ring.")
7466 (defun anything-c-kill-ring-candidates ()
7467 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7468 unless (or (< (length kill) anything-kill-ring-threshold)
7469 (string-match "^[\\s\\t]+$" kill))
7470 collect kill))
7472 (defun anything-c-kill-ring-transformer (candidates source)
7473 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7474 (loop for i in candidates
7475 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7476 if (and anything-c-kill-ring-max-lines-number
7477 (> nlines anything-c-kill-ring-max-lines-number))
7478 collect (cons
7479 (with-temp-buffer
7480 (insert i)
7481 (goto-char (point-min))
7482 (concat
7483 (buffer-substring
7484 (point-min)
7485 (save-excursion
7486 (forward-line anything-c-kill-ring-max-lines-number)
7487 (point)))
7488 "[...]")) i)
7489 else collect i))
7491 (defun anything-c-kill-ring-action (str)
7492 "Insert STR in `kill-ring' and set STR to the head.
7493 If this action is executed just after `yank',
7494 replace with STR as yanked string."
7495 (setq kill-ring (delete str kill-ring))
7496 (if (not (eq (anything-attr 'last-command) 'yank))
7497 (insert-for-yank str)
7498 ;; from `yank-pop'
7499 (let ((inhibit-read-only t)
7500 (before (< (point) (mark t))))
7501 (if before
7502 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7503 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7504 (setq yank-undo-function nil)
7505 (set-marker (mark-marker) (point) (current-buffer))
7506 (insert-for-yank str)
7507 ;; Set the window start back where it was in the yank command,
7508 ;; if possible.
7509 (set-window-start (selected-window) yank-window-start t)
7510 (if before
7511 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7512 ;; It is cleaner to avoid activation, even though the command
7513 ;; loop would deactivate the mark because we inserted text.
7514 (goto-char (prog1 (mark t)
7515 (set-marker (mark-marker) (point) (current-buffer)))))))
7516 (kill-new str))
7518 ;; (anything 'anything-c-source-kill-ring)
7521 ;;;; <Mark ring>
7522 ;; DO NOT include these sources in `anything-sources' use
7523 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7524 ;; `anything-all-mark-rings' instead.
7526 (defun anything-c-source-mark-ring-candidates ()
7527 (flet ((get-marks (pos)
7528 (save-excursion
7529 (goto-char pos)
7530 (beginning-of-line)
7531 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7532 (when (string= "" line)
7533 (setq line "<EMPTY LINE>"))
7534 (format "%7d: %s" (line-number-at-pos) line)))))
7535 (with-anything-current-buffer
7536 (loop
7537 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7538 with recip = nil
7539 for i in marks
7540 for m = (get-marks i)
7541 unless (member m recip)
7542 collect m into recip
7543 finally return recip))))
7545 (defvar anything-mark-ring-cache nil)
7546 (defvar anything-c-source-mark-ring
7547 '((name . "mark-ring")
7548 (init . (lambda ()
7549 (setq anything-mark-ring-cache
7550 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7551 (candidates . (lambda ()
7552 (anything-aif anything-mark-ring-cache
7553 it)))
7554 (action . (("Goto line"
7555 . (lambda (candidate)
7556 (anything-goto-line (string-to-number candidate))))))
7557 (persistent-action . (lambda (candidate)
7558 (anything-goto-line (string-to-number candidate))
7559 (anything-match-line-color-current-line)))
7560 (persistent-help . "Show this line")))
7562 ;; (anything 'anything-c-source-mark-ring)
7564 ;;; Global-mark-ring
7565 (defvar anything-c-source-global-mark-ring
7566 '((name . "global-mark-ring")
7567 (candidates . anything-c-source-global-mark-ring-candidates)
7568 (action . (("Goto line"
7569 . (lambda (candidate)
7570 (let ((items (split-string candidate ":")))
7571 (anything-c-switch-to-buffer (second items))
7572 (anything-goto-line (string-to-number (car items))))))))
7573 (persistent-action . (lambda (candidate)
7574 (let ((items (split-string candidate ":")))
7575 (anything-c-switch-to-buffer (second items))
7576 (anything-goto-line (string-to-number (car items)))
7577 (anything-match-line-color-current-line))))
7578 (persistent-help . "Show this line")))
7580 (defun anything-c-source-global-mark-ring-candidates ()
7581 (flet ((buf-fn (m)
7582 (with-current-buffer (marker-buffer m)
7583 (goto-char m)
7584 (beginning-of-line)
7585 (let (line)
7586 (if (string= "" line)
7587 (setq line "<EMPTY LINE>")
7588 (setq line (car (split-string (thing-at-point 'line)
7589 "[\n\r]"))))
7590 (format "%7d:%s: %s"
7591 (line-number-at-pos) (marker-buffer m) line)))))
7592 (loop
7593 with marks = global-mark-ring
7594 with recip = nil
7595 for i in marks
7596 for gm = (unless (or (string-match
7597 "^ " (format "%s" (marker-buffer i)))
7598 (null (marker-buffer i)))
7599 (buf-fn i))
7600 when (and gm (not (member gm recip)))
7601 collect gm into recip
7602 finally return recip)))
7604 ;; (anything 'anything-c-source-global-mark-ring)
7607 ;;;; <Register>
7608 ;;; Insert from register
7609 (defvar anything-c-source-register
7610 '((name . "Registers")
7611 (candidates . anything-c-register-candidates)
7612 (action-transformer . anything-c-register-action-transformer)
7613 (multiline)
7614 (action))
7615 "See (info \"(emacs)Registers\")")
7617 (defun anything-c-register-candidates ()
7618 "Collecting register contents and appropriate commands."
7619 (loop for (char . val) in register-alist
7620 for key = (single-key-description char)
7621 for string-actions =
7622 (cond
7623 ((numberp val)
7624 (list (int-to-string val)
7625 'insert-register
7626 'increment-register))
7627 ((markerp val)
7628 (let ((buf (marker-buffer val)))
7629 (if (null buf)
7630 (list "a marker in no buffer")
7631 (list (concat
7632 "a buffer position:"
7633 (buffer-name buf)
7634 ", position "
7635 (int-to-string (marker-position val)))
7636 'jump-to-register
7637 'insert-register))))
7638 ((and (consp val) (window-configuration-p (car val)))
7639 (list "window configuration."
7640 'jump-to-register))
7641 ((and (consp val) (frame-configuration-p (car val)))
7642 (list "frame configuration."
7643 'jump-to-register))
7644 ((and (consp val) (eq (car val) 'file))
7645 (list (concat "file:"
7646 (prin1-to-string (cdr val))
7647 ".")
7648 'jump-to-register))
7649 ((and (consp val) (eq (car val) 'file-query))
7650 (list (concat "file:a file-query reference: file "
7651 (car (cdr val))
7652 ", position "
7653 (int-to-string (car (cdr (cdr val))))
7654 ".")
7655 'jump-to-register))
7656 ((consp val)
7657 (let ((lines (format "%4d" (length val))))
7658 (list (format "%s: %s\n" lines
7659 (truncate-string-to-width
7660 (mapconcat 'identity (list (car val))
7661 ;; (mapconcat (lambda (y) y) val
7662 "^J") (- (window-width) 15)))
7663 'insert-register)))
7664 ((stringp val)
7665 (list ;; without properties
7666 (substring-no-properties val)
7667 'insert-register
7668 'append-to-register
7669 'prepend-to-register))
7671 "GARBAGE!"))
7672 collect (cons (format "register %3s: %s" key (car string-actions))
7673 (cons char (cdr string-actions)))))
7675 (defun anything-c-register-action-transformer (actions register-and-functions)
7676 "Decide actions by the contents of register."
7677 (loop with func-actions =
7678 '((insert-register
7679 "Insert Register" .
7680 (lambda (c) (insert-register (car c))))
7681 (jump-to-register
7682 "Jump to Register" .
7683 (lambda (c) (jump-to-register (car c))))
7684 (append-to-register
7685 "Append Region to Register" .
7686 (lambda (c) (append-to-register
7687 (car c) (region-beginning) (region-end))))
7688 (prepend-to-register
7689 "Prepend Region to Register" .
7690 (lambda (c) (prepend-to-register
7691 (car c) (region-beginning) (region-end))))
7692 (increment-register
7693 "Increment Prefix Arg to Register" .
7694 (lambda (c) (increment-register
7695 anything-current-prefix-arg (car c)))))
7696 for func in (cdr register-and-functions)
7697 for cell = (assq func func-actions)
7698 when cell
7699 collect (cdr cell)))
7701 ;; (anything 'anything-c-source-register)
7704 ;;; Latex completion
7705 (defun anything-c-latex-math-candidates ()
7706 "Collect candidates for latex math completion."
7707 (declare (special LaTeX-math-menu))
7708 (loop for i in (cddr LaTeX-math-menu)
7709 for elm = (loop for s in i when (vectorp s)
7710 collect (cons (aref s 0) (aref s 1)))
7711 append elm))
7713 (defvar anything-c-source-latex-math
7714 '((name . "Latex Math Menu")
7715 (init . (lambda ()
7716 (with-anything-current-buffer
7717 (LaTeX-math-mode 1))))
7718 (candidate-number-limit . 9999)
7719 (candidates . anything-c-latex-math-candidates)
7720 (action . (lambda (candidate)
7721 (call-interactively candidate)))))
7724 ;;;; <Headline Extraction>
7725 (defvar anything-c-source-fixme
7726 '((name . "TODO/FIXME/DRY comments")
7727 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7728 (adjust)
7729 (recenter))
7730 "Show TODO/FIXME/DRY comments in current file.")
7731 ;; (anything 'anything-c-source-fixme)
7733 (defvar anything-c-source-rd-headline
7734 '((name . "RD HeadLine")
7735 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7736 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7737 (migemo)
7738 (subexp . 1))
7739 "Show RD headlines.
7741 RD is Ruby's POD.
7742 http://en.wikipedia.org/wiki/Ruby_Document_format")
7743 ;; (anything 'anything-c-source-rd-headline)
7745 (defvar anything-c-source-oddmuse-headline
7746 '((name . "Oddmuse HeadLine")
7747 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7748 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7749 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7750 (migemo)
7751 (subexp . 1))
7752 "Show Oddmuse headlines, such as EmacsWiki.")
7753 ;; (anything 'anything-c-source-oddmuse-headline)
7755 (defvar anything-c-source-emacs-source-defun
7756 '((name . "Emacs Source DEFUN")
7757 (headline . "DEFUN\\|DEFVAR")
7758 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7759 (or buffer-file-name ""))))
7760 "Show DEFUN/DEFVAR in Emacs C source file.")
7761 ;; (anything 'anything-c-source-emacs-source-defun)
7763 (defvar anything-c-source-emacs-lisp-expectations
7764 '((name . "Emacs Lisp Expectations")
7765 (headline . "(desc[ ]\\|(expectations")
7766 (condition . (eq major-mode 'emacs-lisp-mode)))
7767 "Show descriptions (desc) in Emacs Lisp Expectations.
7769 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7770 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7772 (defvar anything-c-source-emacs-lisp-toplevels
7773 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7774 (headline . "^(\\|(@\\*\\|^;;;;")
7775 (get-line . buffer-substring)
7776 (condition . (eq major-mode 'emacs-lisp-mode))
7777 (adjust))
7778 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7779 linkd.el is optional because linkd stars are extracted by regexp.
7780 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7781 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7784 ;;; Anything yaoddmuse
7786 ;; Be sure to have yaoddmuse.el installed
7787 ;; install-elisp may be required if you want to install elisp file from here.
7788 (defvar anything-yaoddmuse-use-cache-file nil)
7789 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7790 (defvar anything-c-yaoddmuse-ew-cache nil)
7792 (defun anything-yaoddmuse-get-candidates ()
7793 (declare (special yaoddmuse-pages-hash))
7794 (if anything-yaoddmuse-use-cache-file
7795 (ignore-errors
7796 (unless anything-c-yaoddmuse-ew-cache
7797 (load anything-c-yaoddmuse-cache-file)
7798 (setq anything-c-yaoddmuse-ew-cache
7799 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7800 anything-c-yaoddmuse-ew-cache)
7801 (yaoddmuse-update-pagename t)
7802 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7804 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7805 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7806 (candidates . anything-yaoddmuse-get-candidates)
7807 (action . (("Edit page" . (lambda (candidate)
7808 (yaoddmuse-edit "EmacsWiki" candidate)))
7809 ("Browse page"
7810 . (lambda (candidate)
7811 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7812 ("Browse page other window"
7813 . (lambda (candidate)
7814 (if (one-window-p)
7815 (split-window-vertically))
7816 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7817 ("Browse diff"
7818 . (lambda (candidate)
7819 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7820 ("Copy URL"
7821 . (lambda (candidate)
7822 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7823 (message "Have copy page %s's URL to yank." candidate)))
7824 ("Create page"
7825 . (lambda (candidate)
7826 (yaoddmuse-edit "EmacsWiki" anything-input)))
7827 ("Update cache"
7828 . (lambda (candidate)
7829 (if anything-yaoddmuse-use-cache-file
7830 (progn
7831 (anything-yaoddmuse-cache-pages t)
7832 (setq anything-c-yaoddmuse-ew-cache
7833 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7834 (yaoddmuse-update-pagename))))))
7835 (action-transformer anything-c-yaoddmuse-action-transformer))
7836 "Needs yaoddmuse.el.
7838 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7840 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7842 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7843 '((name . "Yaoddmuse Post library (EmacsWiki)")
7844 (init . (anything-yaoddmuse-init))
7845 (candidates-in-buffer)
7846 (action . (("Post library and Browse"
7847 . (lambda (candidate)
7848 (yaoddmuse-post-file
7849 (find-library-name candidate)
7850 "EmacsWiki"
7851 (file-name-nondirectory (find-library-name candidate))
7852 nil t)))
7853 ("Post library"
7854 . (lambda (candidate)
7855 (yaoddmuse-post-file
7856 (find-library-name candidate)
7857 "EmacsWiki"
7858 (file-name-nondirectory
7859 (find-library-name candidate))))))))
7860 "Needs yaoddmuse.el.
7862 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7864 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7866 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7867 "Allow the use of `install-elisp' only on elisp files."
7868 (if (string-match "\.el$" candidate)
7869 (append actions '(("Install Elisp"
7870 . (lambda (elm)
7871 (install-elisp-from-emacswiki elm)))))
7872 actions))
7874 ;;;###autoload
7875 (defun anything-yaoddmuse-cache-pages (&optional load)
7876 "Fetch the list of files on emacswiki and create cache file.
7877 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7878 (interactive)
7879 (declare (special yaoddmuse-pages-hash))
7880 (yaoddmuse-update-pagename)
7881 (save-excursion
7882 (find-file anything-c-yaoddmuse-cache-file)
7883 (erase-buffer)
7884 (insert "(puthash \"EmacsWiki\" '(")
7885 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7887 (insert (concat "(\"" (car i) "\") ")))
7888 (insert ") yaoddmuse-pages-hash)\n")
7889 (save-buffer)
7890 (kill-buffer (current-buffer))
7891 (when (or current-prefix-arg
7892 load)
7893 (load anything-c-yaoddmuse-cache-file))))
7895 (defun anything-yaoddmuse-init ()
7896 "Init anything buffer status."
7897 (let ((anything-buffer (anything-candidate-buffer 'global))
7898 (library-list (yaoddmuse-get-library-list)))
7899 (with-current-buffer anything-buffer
7900 ;; Insert library name.
7901 (dolist (library library-list)
7902 (insert (format "%s\n" library)))
7903 ;; Sort lines.
7904 (sort-lines nil (point-min) (point-max)))))
7907 ;;; Eev anchors
7908 (defvar anything-c-source-eev-anchor
7909 '((name . "Anchors")
7910 (candidates
7911 . (lambda ()
7912 (ignore-errors
7913 (with-anything-current-buffer
7914 (loop initially (goto-char (point-min))
7915 while (re-search-forward
7916 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7917 for anchor = (match-string-no-properties 1)
7918 collect (cons (format "%5d:%s"
7919 (line-number-at-pos (match-beginning 0))
7920 (format ee-anchor-format anchor))
7921 anchor))))))
7922 (persistent-action . (lambda (item)
7923 (ee-to item)
7924 (anything-match-line-color-current-line)))
7925 (persistent-help . "Show this entry")
7926 (action . (("Goto link" . ee-to)))))
7927 ;; (anything 'anything-c-source-eev-anchor)
7930 ;;; Org headlines
7933 (defvar anything-c-source-org-headline
7934 `((name . "Org HeadLine")
7935 (headline
7936 ,@(mapcar
7937 (lambda (num)
7938 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7939 num))
7940 (number-sequence 1 8)))
7941 (condition . (eq major-mode 'org-mode))
7942 (migemo)
7943 (subexp . 1)
7944 (persistent-action . (lambda (elm)
7945 (anything-c-action-line-goto elm)
7946 (org-cycle)))
7947 (action-transformer
7948 . (lambda (actions candidate)
7949 '(("Go to Line" . anything-c-action-line-goto)
7950 ("Refile to this Headline" . anything-c-org-headline-refile)
7951 ("Insert Link to This Headline"
7952 . anything-c-org-headline-insert-link-to-headline)))))
7953 "Show Org headlines.
7954 org-mode is very very much extended text-mode/outline-mode.
7956 See (find-library \"org.el\")
7957 See http://orgmode.org for the latest version.")
7958 ;; (anything 'anything-c-source-org-headline)
7960 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7961 (insert
7962 (save-excursion
7963 (anything-goto-line (car lineno-and-content))
7964 (and (looking-at org-complex-heading-regexp)
7965 (org-make-link-string (concat "*" (match-string 4)))))))
7967 (defun anything-c-org-headline-refile (lineno-and-content)
7968 "Refile current org entry to LINENO-AND-CONTENT."
7969 (with-anything-current-buffer
7970 (org-cut-subtree)
7971 (anything-goto-line (car lineno-and-content))
7972 (org-end-of-subtree t t)
7973 (let ((org-yank-adjusted-subtrees t))
7974 (org-yank))))
7977 ;;; Org keywords
7980 (defvar anything-c-source-org-keywords
7981 '((name . "Org Keywords")
7982 (init . anything-c-org-keywords-init)
7983 (candidates . anything-c-org-keywords-candidates)
7984 (action . anything-c-org-keywords-insert)
7985 (persistent-action . anything-c-org-keywords-show-help)
7986 (persistent-help . "Show an example and info page to describe this keyword.")
7987 (keywords-examples)
7988 (keywords)))
7989 ;; (anything 'anything-c-source-org-keywords)
7991 (defvar anything-c-org-keywords-info-location
7992 '(("#+TITLE:" . "(org)Export options")
7993 ("#+AUTHOR:" . "(org)Export options")
7994 ("#+DATE:" . "(org)Export options")
7995 ("#+EMAIL:" . "(org)Export options")
7996 ("#+DESCRIPTION:" . "(org)Export options")
7997 ("#+KEYWORDS:" . "(org)Export options")
7998 ("#+LANGUAGE:" . "(org)Export options")
7999 ("#+TEXT:" . "(org)Export options")
8000 ("#+TEXT:" . "(org)Export options")
8001 ("#+OPTIONS:" . "(org)Export options")
8002 ("#+BIND:" . "(org)Export options")
8003 ("#+LINK_UP:" . "(org)Export options")
8004 ("#+LINK_HOME:" . "(org)Export options")
8005 ("#+LATEX_HEADER:" . "(org)Export options")
8006 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
8007 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
8008 ("#+INFOJS_OPT" . "(org)Javascript support")
8009 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
8010 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
8011 ("#+ORGTBL" . "(org)Radio tables")
8012 ("#+HTML:" . "(org)Quoting HTML tags")
8013 ("#+LaTeX:" . "(org)Quoting LaTeX code")
8014 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
8015 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
8016 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
8017 ("#+BEGIN_VERSE" . "(org)Paragraphs")
8018 ("#+BEGIN_SRC" . "(org)Literal examples")
8019 ("#+CAPTION" . "(org)Tables in HTML export")
8020 ("#+LABEL" . "(org)Tables in LaTeX export")
8021 ("#+ATTR_HTML" . "(org)Links")
8022 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
8024 (defun anything-c-org-keywords-init ()
8025 (unless (anything-attr 'keywords-examples)
8026 (require 'org)
8027 (anything-attrset 'keywords-examples
8028 (append
8029 (mapcar
8030 (lambda (x)
8031 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8032 (cons (match-string 2 x) (match-string 1 x)))
8033 (org-split-string (org-get-current-options) "\n"))
8034 (mapcar 'list org-additional-option-like-keywords)))
8035 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
8037 (defun anything-c-org-keywords-candidates ()
8038 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
8039 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
8040 (anything-attr 'keywords)))
8042 (defun anything-c-org-keywords-insert (keyword)
8043 (cond ((and (string-match "BEGIN" keyword)
8044 (anything-region-active-p))
8045 (let ((beg (region-beginning))
8046 (end (region-end)))
8047 (goto-char end)
8048 (insert "\n#+" (replace-regexp-in-string
8049 "BEGIN" "END" keyword) "\n")
8050 (goto-char beg)
8051 (insert "#+" keyword " ")
8052 (save-excursion (insert "\n"))))
8053 ((string-match "BEGIN" keyword)
8054 (insert "#+" keyword " ")
8055 (save-excursion
8056 (insert "\n#+" (replace-regexp-in-string
8057 "BEGIN" "END" keyword) "\n")))
8058 (t (insert "#+" keyword " "))))
8060 (defun anything-c-org-keywords-show-help (keyword)
8061 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
8062 "(org)In-buffer settings"))
8063 (search-forward (concat "#+" keyword) nil t)
8064 (anything-persistent-highlight-point)
8065 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8069 ;;; bbdb
8072 (defvar bbdb-records)
8073 (defvar bbdb-buffer-name)
8075 (defun anything-c-bbdb-candidates ()
8076 "Return a list of all names in the bbdb database. The format
8077 is \"Firstname Lastname\"."
8078 (mapcar (lambda (bbdb-record)
8079 (replace-regexp-in-string
8080 "\\s-+$" ""
8081 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8082 (bbdb-records)))
8084 (defun anything-c-bbdb-create-contact (actions candidate)
8085 "Action transformer that returns only an entry to add the
8086 current `anything-pattern' as new contact. All other actions are
8087 removed."
8088 (if (string= candidate "*Add to contacts*")
8089 '(("Add to contacts" . (lambda (actions)
8090 (bbdb-create-internal
8091 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8092 (read-from-minibuffer "Company: ")
8093 (read-from-minibuffer "Email: ")
8096 (read-from-minibuffer "Note: ")))))
8097 actions))
8099 (defun anything-c-bbdb-get-record (candidate)
8100 "Return record that match CANDIDATE."
8101 (bbdb candidate nil)
8102 (set-buffer "*BBDB*")
8103 (bbdb-current-record))
8105 (defvar anything-c-bbdb-name nil
8106 "Only for internal use.")
8108 (defvar anything-c-source-bbdb
8109 '((name . "BBDB")
8110 (candidates . anything-c-bbdb-candidates)
8111 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8112 ("View person's data" . anything-c-bbdb-view-person-action))
8113 (filtered-candidate-transformer . (lambda (candidates source)
8114 (setq anything-c-bbdb-name anything-pattern)
8115 (if (not candidates)
8116 (list "*Add to contacts*")
8117 candidates)))
8118 (action-transformer . (lambda (actions candidate)
8119 (anything-c-bbdb-create-contact actions candidate))))
8120 "Needs BBDB.
8122 http://bbdb.sourceforge.net/")
8123 ;; (anything 'anything-c-source-bbdb)
8125 (defun anything-c-bbdb-view-person-action (candidate)
8126 "View BBDB data of single CANDIDATE or marked candidates."
8127 (anything-aif (anything-marked-candidates)
8128 (let ((bbdb-append-records (length it)))
8129 (dolist (i it)
8130 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8131 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8133 (defun anything-c-bbdb-collect-mail-addresses ()
8134 "Return a list of all mail addresses of records in bbdb buffer."
8135 (with-current-buffer bbdb-buffer-name
8136 (loop for i in bbdb-records
8137 if (bbdb-record-net (car i))
8138 collect (bbdb-dwim-net-address (car i)))))
8140 (defun anything-c-bbdb-compose-mail (candidate)
8141 "Compose a mail with all records of bbdb buffer."
8142 (anything-c-bbdb-view-person-action candidate)
8143 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8144 (address-str (mapconcat 'identity address-list ",\n ")))
8145 (compose-mail address-str)))
8148 ;;; Evaluation Result
8151 ;; Internal
8152 (defvar anything-eldoc-active-minibuffers-list nil)
8153 (defvar anything-eval-expression-input-history nil)
8155 (defvar anything-c-source-evaluation-result
8156 '((name . "Evaluation Result")
8157 (disable-shortcuts)
8158 (dummy)
8159 (multiline)
8160 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8161 (filtered-candidate-transformer . (lambda (candidates source)
8162 (list
8163 (condition-case nil
8164 (with-anything-current-buffer
8165 (pp-to-string
8166 (eval (read anything-pattern))))
8167 (error "Error")))))
8168 (action . (("Copy result to kill-ring" . (lambda (candidate)
8169 (with-current-buffer anything-buffer
8170 (let ((end (save-excursion
8171 (goto-char (point-max))
8172 (search-backward "\n")
8173 (point))))
8174 (kill-region (point) end)))))
8175 ("copy sexp to kill-ring" . (lambda (candidate)
8176 (kill-new anything-input)))))))
8177 ;; (anything 'anything-c-source-evaluation-result)
8179 (defun anything-eval-new-line-and-indent ()
8180 (interactive)
8181 (newline) (lisp-indent-line))
8183 (defun anything-eldoc-store-minibuffer ()
8184 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8185 (with-selected-window (minibuffer-window)
8186 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8188 (defun anything-eldoc-show-in-eval ()
8189 "Return eldoc in mode-line for current minibuffer input."
8190 (let ((buf (with-selected-window (minibuffer-window)
8191 (buffer-name))))
8192 (when (member buf anything-eldoc-active-minibuffers-list)
8193 (let* ((str-all (with-current-buffer buf
8194 (minibuffer-completion-contents)))
8195 (sym (when str-all
8196 (with-temp-buffer
8197 (insert str-all)
8198 (goto-char (point-max))
8199 (unless (looking-back ")\\|\"") (forward-char -1))
8200 (eldoc-current-symbol))))
8201 (info-fn (eldoc-fnsym-in-current-sexp))
8202 (doc (or (eldoc-get-var-docstring sym)
8203 (eldoc-get-fnsym-args-string
8204 (car info-fn) (cadr info-fn)))))
8205 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8207 (defun anything-c-show-info-in-mode-line (str)
8208 "Display string STR in mode-line."
8209 (save-selected-window
8210 (with-current-buffer anything-buffer
8211 (let ((mode-line-format (concat " " str)))
8212 (force-mode-line-update)
8213 (sit-for anything-c-show-info-in-mode-line-delay))
8214 (force-mode-line-update))))
8216 ;;; Calculation Result
8219 (defvar anything-c-source-calculation-result
8220 '((name . "Calculation Result")
8221 (dummy)
8222 (filtered-candidate-transformer . (lambda (candidates source)
8223 (list
8224 (condition-case nil
8225 (calc-eval anything-pattern)
8226 (error "error")))))
8227 (action ("Copy result to kill-ring" . kill-new))))
8228 ;; (anything 'anything-c-source-calculation-result)
8231 ;;; Google Suggestions
8234 ;; Internal
8235 (defvar anything-ggs-max-length-real-flag 0)
8236 (defvar anything-ggs-max-length-num-flag 0)
8238 (defun anything-c-google-suggest-fetch (input)
8239 "Fetch suggestions for INPUT from XML buffer.
8240 Return an alist with elements like (data . number_results)."
8241 (setq anything-ggs-max-length-real-flag 0
8242 anything-ggs-max-length-num-flag 0)
8243 (let ((request (concat anything-c-google-suggest-url
8244 (url-hexify-string input))))
8245 (flet ((fetch ()
8246 (loop
8247 with result-alist = (xml-get-children
8248 (car (xml-parse-region
8249 (point-min) (point-max)))
8250 'CompleteSuggestion)
8251 for i in result-alist
8252 for data = (cdr (caadr (assoc 'suggestion i)))
8253 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8254 for lqueries = (length (anything-c-ggs-set-number-result
8255 nqueries))
8256 for ldata = (length data)
8258 (progn
8259 (when (> ldata anything-ggs-max-length-real-flag)
8260 (setq anything-ggs-max-length-real-flag ldata))
8261 (when (> lqueries anything-ggs-max-length-num-flag)
8262 (setq anything-ggs-max-length-num-flag lqueries)))
8263 collect (cons data nqueries) into cont
8264 finally return cont)))
8265 (if anything-google-suggest-use-curl-p
8266 (with-temp-buffer
8267 (call-process "curl" nil t nil request)
8268 (fetch))
8269 (with-current-buffer
8270 (url-retrieve-synchronously request)
8271 (fetch))))))
8273 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8274 "Set candidates with result and number of google results found."
8275 (let ((suggestions
8276 (loop with suggested-results = (anything-c-google-suggest-fetch
8277 (or (and request-prefix
8278 (concat request-prefix " " anything-pattern))
8279 anything-pattern))
8280 for (real . numresult) in suggested-results
8281 ;; Prepare number of results with ","
8282 for fnumresult = (anything-c-ggs-set-number-result numresult)
8283 ;; Calculate number of spaces to add before fnumresult
8284 ;; if it is smaller than longest result
8285 ;; `anything-ggs-max-length-num-flag'.
8286 ;; e.g 1,234,567
8287 ;; 345,678
8288 ;; To be sure it is aligned properly.
8289 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8290 (- anything-ggs-max-length-num-flag (length fnumresult))
8292 ;; Add now the spaces before fnumresult.
8293 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8294 for interval = (- anything-ggs-max-length-real-flag (length real))
8295 for spaces = (make-string (+ 2 interval) ? )
8296 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8297 collect (cons display real))))
8298 (if (loop for (disp . dat) in suggestions
8299 thereis (equal dat anything-pattern))
8300 suggestions
8301 ;; if there is no suggestion exactly matching the input then
8302 ;; prepend a Search on Google item to the list
8303 (append
8304 suggestions
8305 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8306 anything-input))))))
8308 (defun anything-c-ggs-set-number-result (num)
8309 (if num
8310 (progn
8311 (and (numberp num) (setq num (number-to-string num)))
8312 (loop for i in (reverse (split-string num "" t))
8313 for count from 1
8314 append (list i) into C
8315 when (= count 3)
8316 append (list ",") into C
8317 and do (setq count 0)
8318 finally return
8319 (replace-regexp-in-string
8320 "^," "" (mapconcat 'identity (reverse C) ""))))
8321 "?"))
8323 (defvar anything-c-google-suggest-default-browser-function nil
8324 "*The browse url function you prefer to use with google suggest.
8325 When nil, use the first browser function available
8326 See `anything-browse-url-default-browser-alist'.")
8328 (defun anything-c-google-suggest-action (candidate)
8329 "Default action to jump to a google suggested candidate."
8330 (let ((arg (concat anything-c-google-suggest-search-url
8331 (url-hexify-string candidate))))
8332 (anything-aif anything-c-google-suggest-default-browser-function
8333 (funcall it arg)
8334 (anything-c-browse-url arg))))
8336 (defvar anything-c-google-suggest-default-function
8337 'anything-c-google-suggest-set-candidates
8338 "Default function to use in anything google suggest.")
8340 (defvar anything-c-source-google-suggest
8341 '((name . "Google Suggest")
8342 (candidates . (lambda ()
8343 (funcall anything-c-google-suggest-default-function)))
8344 (action . (("Google Search" . anything-c-google-suggest-action)))
8345 (volatile)
8346 (requires-pattern . 3)
8347 (delayed)))
8349 (defun anything-c-google-suggest-emacs-lisp ()
8350 "Try to emacs lisp complete with google suggestions."
8351 (anything-c-google-suggest-set-candidates "emacs lisp"))
8353 ;; (anything 'anything-c-source-google-suggest)
8355 ;;; Yahoo suggestions
8358 (defun anything-c-yahoo-suggest-fetch (input)
8359 "Fetch Yahoo suggestions for INPUT from XML buffer.
8360 Return an alist with elements like (data . number_results)."
8361 (let ((request (concat anything-c-yahoo-suggest-url
8362 (url-hexify-string input))))
8363 (flet ((fetch ()
8364 (loop
8365 with result-alist = (xml-get-children
8366 (car (xml-parse-region (point-min) (point-max)))
8367 'Result)
8368 for i in result-alist
8369 collect (caddr i))))
8370 (with-current-buffer
8371 (url-retrieve-synchronously request)
8372 (fetch)))))
8374 (defun anything-c-yahoo-suggest-set-candidates ()
8375 "Set candidates with Yahoo results found."
8376 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8377 (or suggestions
8378 (append
8379 suggestions
8380 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8381 anything-input))))))
8383 (defun anything-c-yahoo-suggest-action (candidate)
8384 "Default action to jump to a Yahoo suggested candidate."
8385 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8386 (url-hexify-string candidate))))
8388 (defvar anything-c-source-yahoo-suggest
8389 '((name . "Yahoo Suggest")
8390 (candidates . anything-c-yahoo-suggest-set-candidates)
8391 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8392 (volatile)
8393 (requires-pattern . 3)
8394 (delayed)))
8396 ;; (anything 'anything-c-source-yahoo-suggest)
8399 ;;; Web browser functions.
8402 (require 'browse-url)
8403 ;; If default setting of `w3m-command' is not
8404 ;; what you want you and you modify it, you will have to reeval
8405 ;; also `anything-browse-url-default-browser-alist'.
8406 (defvar w3m-command "/usr/bin/w3m")
8407 (defvar anything-c-home-url "http://www.google.fr"
8408 "*Default url to use as home url.")
8410 (defvar ac-browse-url-chromium-program "chromium-browser")
8411 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8412 (defvar anything-browse-url-default-browser-alist
8413 `((,w3m-command . w3m-browse-url)
8414 (,browse-url-firefox-program . browse-url-firefox)
8415 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8416 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8417 (,browse-url-kde-program . browse-url-kde)
8418 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8419 (,browse-url-mozilla-program . browse-url-mozilla)
8420 (,browse-url-galeon-program . browse-url-galeon)
8421 (,browse-url-netscape-program . browse-url-netscape)
8422 (,browse-url-mosaic-program . browse-url-mosaic)
8423 (,browse-url-xterm-program . browse-url-text-xterm))
8424 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8426 (defun* anything-c-generic-browser (url name &rest args)
8427 "Browse URL with NAME browser."
8428 (let ((proc (concat name " " url)))
8429 (message "Starting %s..." name)
8430 (apply 'start-process proc nil name
8431 (append args (list url)))
8432 (set-process-sentinel
8433 (get-process proc)
8434 #'(lambda (process event)
8435 (when (string= event "finished\n")
8436 (message "%s process %s" process event))))))
8438 (defun ac-browse-url-chromium (url)
8439 "Browse URL with google chrome browser."
8440 (interactive "sURL: ")
8441 (anything-c-generic-browser
8442 url ac-browse-url-chromium-program))
8444 (defun ac-browse-url-uzbl (url &optional ignore)
8445 "Browse URL with uzbl browser."
8446 (interactive "sURL: ")
8447 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8449 (defun anything-browse-url-default-browser (url &rest args)
8450 "Find the first available browser and ask it to load URL."
8451 (let ((default-browser-fn
8452 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8453 thereis (and exe (executable-find exe) fn))))
8454 (if default-browser-fn
8455 (apply default-browser-fn url args)
8456 (error "No usable browser found"))))
8458 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8459 "Default command to browse URL."
8460 (if browse-url-browser-function
8461 (browse-url url)
8462 (anything-browse-url-default-browser url)))
8465 ;;; Surfraw
8467 ;; Need external program surfraw.
8468 ;; <http://surfraw.alioth.debian.org/>
8470 (defvar anything-surfraw-default-browser-function nil
8471 "*The browse url function you prefer to use with surfraw.
8472 When nil, fallback to `browse-url-browser-function'.")
8474 ;; Internal
8475 (defvar anything-surfraw-engines-history nil)
8476 (defvar anything-surfraw-input-history nil)
8478 (defun anything-c-build-elvi-list ()
8479 "Return list of all engines and descriptions handled by surfraw."
8480 (cdr
8481 (with-temp-buffer
8482 (call-process "surfraw" nil t nil
8483 "-elvi")
8484 (split-string (buffer-string) "\n"))))
8487 ;;; Emms
8490 (defun anything-emms-stream-edit-bookmark (elm)
8491 "Change the information of current emms-stream bookmark from anything."
8492 (declare (special emms-stream-list))
8493 (let* ((cur-buf anything-current-buffer)
8494 (bookmark (assoc elm emms-stream-list))
8495 (name (read-from-minibuffer "Description: "
8496 (nth 0 bookmark)))
8497 (url (read-from-minibuffer "URL: "
8498 (nth 1 bookmark)))
8499 (fd (read-from-minibuffer "Feed Descriptor: "
8500 (int-to-string (nth 2 bookmark))))
8501 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8502 (format "%s" (car (last bookmark))))))
8503 (save-excursion
8504 (emms-streams)
8505 (when (re-search-forward (concat "^" name) nil t)
8506 (beginning-of-line)
8507 (emms-stream-delete-bookmark)
8508 (emms-stream-add-bookmark name url (string-to-number fd) type)
8509 (emms-stream-save-bookmarks-file)
8510 (emms-stream-quit)
8511 (anything-c-switch-to-buffer cur-buf)))))
8513 (defun anything-emms-stream-delete-bookmark (elm)
8514 "Delete an emms-stream bookmark from anything."
8515 (let* ((cur-buf anything-current-buffer)
8516 (bookmark (assoc elm emms-stream-list))
8517 (name (nth 0 bookmark)))
8518 (save-excursion
8519 (emms-streams)
8520 (when (re-search-forward (concat "^" name) nil t)
8521 (beginning-of-line)
8522 (emms-stream-delete-bookmark)
8523 (emms-stream-save-bookmarks-file)
8524 (emms-stream-quit)
8525 (anything-c-switch-to-buffer cur-buf)))))
8527 (defvar anything-c-source-emms-streams
8528 '((name . "Emms Streams")
8529 (init . (lambda ()
8530 (emms-stream-init)))
8531 (candidates . (lambda ()
8532 (declare (special emms-stream-list))
8533 (mapcar 'car emms-stream-list)))
8534 (action . (("Play" . (lambda (elm)
8535 (declare (special emms-stream-list))
8536 (let* ((stream (assoc elm emms-stream-list))
8537 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8538 (url (second stream)))
8539 (funcall fn url))))
8540 ("Delete" . anything-emms-stream-delete-bookmark)
8541 ("Edit" . anything-emms-stream-edit-bookmark)))
8542 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8543 ;; (anything 'anything-c-source-emms-streams)
8545 ;; Don't forget to set `emms-source-file-default-directory'
8546 (defvar anything-c-source-emms-dired
8547 '((name . "Music Directory")
8548 (candidates . (lambda ()
8549 (cddr (directory-files emms-source-file-default-directory))))
8550 (action .
8551 (("Play Directory" . (lambda (item)
8552 (emms-play-directory
8553 (expand-file-name
8554 item
8555 emms-source-file-default-directory))))
8556 ("Open dired in file's directory" . (lambda (item)
8557 (anything-c-open-dired
8558 (expand-file-name
8559 item
8560 emms-source-file-default-directory))))))
8561 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8562 ;; (anything 'anything-c-source-emms-dired)
8565 (defun anything-c-emms-files-modifier (candidates source)
8566 (let ((current-playlist (with-current-emms-playlist
8567 (loop
8568 with cur-list = (emms-playlist-tracks-in-region
8569 (point-min) (point-max))
8570 for i in cur-list
8571 collect (assoc-default 'name i)))))
8572 (loop for i in candidates
8573 if (member (cdr i) current-playlist)
8574 collect (cons (propertize (car i)
8575 'face 'anything-emms-playlist)
8576 (cdr i)) into lis
8577 else collect i into lis
8578 finally return lis)))
8580 (defun anything-c-emms-play-current-playlist ()
8581 "Play current playlist."
8582 (with-current-emms-playlist
8583 (emms-playlist-first)
8584 (emms-playlist-mode-play-smart)))
8586 (defvar anything-c-source-emms-files
8587 '((name . "Emms files")
8588 (candidates . (lambda ()
8589 (loop for v being the hash-values in emms-cache-db
8590 for name = (assoc-default 'name v)
8591 for artist = (or (assoc-default 'info-artist v) "unknown")
8592 for genre = (or (assoc-default 'info-genre v) "unknown")
8593 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8594 for song = (or (assoc-default 'info-title v) "unknown")
8595 for info = (concat artist " - " genre " - " tracknum ": " song)
8596 unless (string-match "^http:" name) collect (cons info name))))
8597 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8598 (action . (("Play file" . emms-play-file)
8599 ("Add to Playlist and play (C-u clear current)"
8600 . (lambda (candidate)
8601 (when anything-current-prefix-arg
8602 (emms-playlist-current-clear))
8603 (emms-playlist-new)
8604 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8605 (unless emms-player-playing-p
8606 (anything-c-emms-play-current-playlist))))))))
8608 ;; (anything 'anything-c-source-emms-files)
8611 ;;; Jabber Contacts (jabber.el)
8612 (defun anything-c-jabber-online-contacts ()
8613 "List online Jabber contacts."
8614 (with-no-warnings
8615 (let (jids)
8616 (dolist (item (jabber-concat-rosters) jids)
8617 (when (get item 'connected)
8618 (push (if (get item 'name)
8619 (cons (get item 'name) item)
8620 (cons (symbol-name item) item)) jids))))))
8622 (defvar anything-c-source-jabber-contacts
8623 '((name . "Jabber Contacts")
8624 (init . (lambda () (require 'jabber)))
8625 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8626 (action . (lambda (x)
8627 (jabber-chat-with
8628 (jabber-read-account)
8629 (symbol-name
8630 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8631 ;; (anything 'anything-c-source-jabber-contacts)
8635 ;;; Call source.
8636 (defvar anything-source-select-buffer "*anything source select*")
8637 (defvar anything-c-source-call-source
8638 `((name . "Call anything source")
8639 (candidate-number-limit)
8640 (candidates
8641 . (lambda ()
8642 (loop for vname in (all-completions "anything-c-source-" obarray)
8643 for var = (intern vname)
8644 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8645 if name collect
8646 (cons (format "%s `%s'"
8647 name (propertize vname 'face 'font-lock-variable-name-face))
8648 var))))
8649 (action
8650 . (("Invoke anything with selected source"
8652 (lambda (candidate)
8653 (setq anything-candidate-number-limit 9999)
8654 (anything candidate nil nil nil nil
8655 anything-source-select-buffer)))
8656 ("Describe variable" . describe-variable)
8657 ("Find variable" . find-variable)))
8658 (persistent-action . describe-variable)
8659 (persistent-help . "Show description of this source")))
8660 ;; (anything 'anything-c-source-call-source)
8662 (defun anything-call-source-from-anything ()
8663 "Call anything source within `anything' session."
8664 (interactive)
8665 (setq anything-input-idle-delay 0)
8666 (anything-set-sources '(anything-c-source-call-source)))
8668 ;;; Execute Preconfigured anything.
8669 (defvar anything-c-source-anything-commands
8670 '((name . "Preconfigured Anything")
8671 (candidates . anything-c-anything-commands-candidates)
8672 (type . command)
8673 (candidate-number-limit)))
8674 ;; (anything 'anything-c-source-anything-commands)
8676 (defun anything-c-anything-commands-candidates ()
8677 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8678 collect (cons (if (where-is-internal cmd nil t)
8679 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8680 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8681 cmd)))
8684 ;;; Occur
8687 (defun anything-c-occur-init ()
8688 "Create the initial anything occur buffer.
8689 If region is active use region as buffer contents
8690 instead of whole buffer."
8691 (with-current-buffer (anything-candidate-buffer 'global)
8692 (erase-buffer)
8693 (let ((buf-contents
8694 (with-anything-current-buffer
8695 (if (anything-region-active-p)
8696 (buffer-substring (region-beginning) (region-end))
8697 (buffer-substring (point-min) (point-max))))))
8698 (insert buf-contents))))
8700 (defun anything-c-occur-get-line (s e)
8701 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8703 (defun anything-c-occur-query-replace-regexp (candidate)
8704 "Query replace regexp starting from CANDIDATE.
8705 If region is active ignore CANDIDATE and replace only in region.
8706 With a prefix arg replace only matches surrounded by word boundaries,
8707 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8708 (let ((regexp anything-input))
8709 (unless (anything-region-active-p)
8710 (anything-c-action-line-goto candidate))
8711 (apply 'query-replace-regexp
8712 (anything-c-query-replace-args regexp))))
8714 (defvar anything-c-source-occur
8715 '((name . "Occur")
8716 (init . anything-c-occur-init)
8717 (candidates-in-buffer)
8718 (migemo)
8719 (get-line . anything-c-occur-get-line)
8720 (display-to-real . anything-c-display-to-real-line)
8721 (action . (("Go to Line" . anything-c-action-line-goto)
8722 ("Query replace regexp (C-u Not inside word.)"
8723 . anything-c-occur-query-replace-regexp)))
8724 (recenter)
8725 (requires-pattern . 1)
8726 (delayed)
8727 (volatile)))
8728 ;; (anything 'anything-c-source-occur)
8731 ;;; Anything browse code.
8732 (defun anything-c-browse-code-get-line (beg end)
8733 "Select line if it match the regexp corresponding to current `major-mode'.
8734 Line is parsed for BEG position to END position."
8735 (let ((str-line (buffer-substring beg end))
8736 (regexp (assoc-default major-mode
8737 anything-c-browse-code-regexp-alist))
8738 (num-line (if (string= anything-pattern "") beg (1- beg))))
8739 (when (and regexp (string-match regexp str-line))
8740 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8743 (defvar anything-c-source-browse-code
8744 '((name . "Browse code")
8745 (init . (lambda ()
8746 (anything-candidate-buffer anything-current-buffer)
8747 (with-anything-current-buffer
8748 (jit-lock-fontify-now))))
8749 (candidate-number-limit . 9999)
8750 (candidates-in-buffer)
8751 (get-line . anything-c-browse-code-get-line)
8752 (type . line)
8753 (recenter)))
8756 ;; Do many actions for input
8757 (defvar anything-c-source-create
8758 '((name . "Create")
8759 (dummy)
8760 (action)
8761 (action-transformer . anything-create--actions))
8762 "Do many create actions from `anything-pattern'.
8763 See also `anything-create--actions'.")
8764 ;; (anything 'anything-c-source-create)
8766 (defun anything-create-from-anything ()
8767 "Run `anything-create' from `anything' as a fallback."
8768 (interactive)
8769 (anything-run-after-quit 'anything-create nil anything-pattern))
8771 (defun anything-create--actions (&rest ignored)
8772 "Default actions for `anything-create' / `anything-c-source-create'."
8773 (remove-if-not
8774 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8775 (append anything-create--actions-private
8776 '(("find-file" . find-file)
8777 ("find-file other window" . find-file-other-window)
8778 ("New buffer" . anything-c-switch-to-buffer)
8779 ("New buffer other window" . switch-to-buffer-other-window)
8780 ("Bookmark Set" . bookmark-set)
8781 ("Set Register" .
8782 (lambda (x) (set-register (read-char "Register: ") x)))
8783 ("Insert Linkd star" . linkd-insert-star)
8784 ("Insert Linkd Tag" . linkd-insert-tag)
8785 ("Insert Linkd Link" . linkd-insert-link)
8786 ("Insert Linkd Lisp" . linkd-insert-lisp)
8787 ("Insert Linkd Wiki" . linkd-insert-wiki)
8788 ("Google Search" . google)))))
8791 ;; Minibuffer History
8794 (defvar anything-c-source-minibuffer-history
8795 '((name . "Minibuffer History")
8796 (header-name . (lambda (name)
8797 (format "%s (%s)" name minibuffer-history-variable)))
8798 (candidates
8799 . (lambda ()
8800 (let ((history (loop for i in
8801 (symbol-value minibuffer-history-variable)
8802 unless (string= "" i) collect i)))
8803 (if (consp (car history))
8804 (mapcar 'prin1-to-string history)
8805 history))))
8806 (migemo)
8807 (action . insert)))
8808 ;; (anything 'anything-c-source-minibuffer-history)
8811 ;;; Elscreen
8814 (defvar anything-c-source-elscreen
8815 '((name . "Elscreen")
8816 (candidates
8817 . (lambda ()
8818 (if (cdr (elscreen-get-screen-to-name-alist))
8819 (sort
8820 (loop for sname in (elscreen-get-screen-to-name-alist)
8821 append (list (format "[%d] %s" (car sname) (cdr sname))))
8822 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8823 (action
8824 . (("Change Screen" .
8825 (lambda (candidate)
8826 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8827 ("Kill Screen(s)" .
8828 (lambda (candidate)
8829 (dolist (i (anything-marked-candidates))
8830 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8831 (elscreen-kill))))
8832 ("Only Screen" .
8833 (lambda (candidate)
8834 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8835 (elscreen-kill-others)))))))
8836 ;; (anything 'anything-c-source-elscreen)
8839 ;;;; <System>
8841 ;;; Top (process)
8842 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8843 "Top command (batch mode). %s is replaced with `frame-width'.")
8844 (defvar anything-c-source-top
8845 '((name . "Top (Press C-c C-u to refresh)")
8846 (init . anything-c-top-init)
8847 (candidates-in-buffer)
8848 (display-to-real . anything-c-top-display-to-real)
8849 (persistent-action . anything-c-top-sh-persistent-action)
8850 (persistent-help . "SIGTERM")
8851 (action
8852 ("kill (TERM)" . (lambda (pid)
8853 (anything-c-top-sh (format "kill -TERM %s" pid))))
8854 ("kill (KILL)" . (lambda (pid)
8855 (anything-c-top-sh (format "kill -KILL %s" pid))))
8856 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8857 ;; (anything 'anything-c-source-top)
8859 (defun anything-c-top-sh (cmd)
8860 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8862 (defun anything-c-top-sh-persistent-action (pid)
8863 (delete-other-windows)
8864 (anything-c-top-sh (format "kill -TERM %s" pid))
8865 (anything-force-update))
8867 (defun anything-c-top-init ()
8868 (with-current-buffer (anything-candidate-buffer 'global)
8869 (call-process-shell-command
8870 (format anything-c-top-command
8871 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8872 nil (current-buffer))))
8874 (defun anything-c-top-display-to-real (line)
8875 (car (split-string line)))
8877 ;;; Timers
8878 (defvar anything-c-source-absolute-time-timers
8879 '((name . "Absolute Time Timers")
8880 (candidates . timer-list)
8881 (type . timer)))
8882 ;; (anything 'anything-c-source-absolute-time-timers)
8884 (defvar anything-c-source-idle-time-timers
8885 '((name . "Idle Time Timers")
8886 (candidates . timer-idle-list)
8887 (type . timer)))
8888 ;; (anything 'anything-c-source-idle-time-timers)
8890 (defun anything-c-timer-real-to-display (timer)
8891 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8892 (append timer nil) ;use `append' to convert vector->list
8893 (format "%s repeat=%5S %s(%s)"
8894 (let ((time (list t1 t2 t3)))
8895 (if idle-delay
8896 (format-time-string "idle-for=%5s" time)
8897 (format-time-string "%m/%d %T" time)))
8898 repeat-delay
8899 func
8900 (mapconcat 'prin1-to-string args " "))))
8902 ;;; X RandR resolution change
8903 ;;; FIXME I do not care multi-display.
8904 (defvar anything-c-xrandr-output "VGA")
8905 (defvar anything-c-xrandr-screen "0")
8906 (defvar anything-c-source-xrandr-change-resolution
8907 '((name . "Change Resolution")
8908 (candidates
8909 . (lambda ()
8910 (with-temp-buffer
8911 (call-process "xrandr" nil (current-buffer) nil
8912 "--screen" anything-c-xrandr-screen "-q")
8913 (goto-char 1)
8914 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8915 collect (match-string 1)))))
8916 (action
8917 ("Change Resolution" . (lambda (mode)
8918 (call-process "xrandr" nil nil nil
8919 "--screen" anything-c-xrandr-screen
8920 "--output" anything-c-xrandr-output
8921 "--mode" mode))))))
8922 ;; (anything 'anything-c-source-xrandr-change-resolution)
8924 ;;; Xfont selection
8927 (defun anything-c-persistent-xfont-action (elm)
8928 "Show current font temporarily"
8929 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8930 (default-font elm))
8931 (unwind-protect
8932 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8933 (set-frame-font current-font))))
8935 (defvar anything-c-xfonts-cache nil)
8936 (defvar anything-c-source-xfonts
8937 '((name . "X Fonts")
8938 (init . (lambda ()
8939 (unless anything-c-xfonts-cache
8940 (setq anything-c-xfonts-cache
8941 (x-list-fonts "*")))))
8942 (candidates . anything-c-xfonts-cache)
8943 (action . (("Copy to kill ring" . (lambda (elm)
8944 (kill-new elm)))
8945 ("Set Font" . (lambda (elm)
8946 (kill-new elm)
8947 (set-frame-font elm 'keep-size)
8948 (message "New font have been copied to kill ring")))))
8949 (persistent-action . anything-c-persistent-xfont-action)
8950 (persistent-help . "Switch to this font temporarily")))
8951 ;; (anything 'anything-c-source-xfonts)
8953 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8956 (defvar anything-c-ucs-max-len 0)
8957 (defun anything-c-calculate-ucs-max-len ()
8958 "Calculate the length of longest `ucs-names' candidate."
8959 (loop with count = 0
8960 for (n . v) in (ucs-names)
8961 for len = (length n)
8962 if (> len count)
8963 do (setq count len)
8964 finally return count))
8966 (defun anything-c-ucs-init ()
8967 "Initialize an anything buffer with ucs symbols.
8968 Only math* symbols are collected."
8969 (unless (> anything-c-ucs-max-len 0)
8970 (setq anything-c-ucs-max-len
8971 (anything-c-calculate-ucs-max-len)))
8972 (with-current-buffer (anything-candidate-buffer
8973 (get-buffer-create "*anything ucs*"))
8974 ;; `ucs-names' fn will not run again, data is cached in
8975 ;; var `ucs-names'.
8976 (loop for (n . v) in (ucs-names)
8977 for len = (length n)
8978 for diff = (+ (- anything-c-ucs-max-len len) 2)
8979 unless (string= "" n)
8980 do (progn (insert (concat
8981 n ":"
8982 (make-string
8983 diff ? )))
8984 (ucs-insert v)
8985 (insert "\n")))))
8987 (defun anything-c-ucs-forward-char (candidate)
8988 (with-anything-current-buffer
8989 (forward-char 1)))
8991 (defun anything-c-ucs-backward-char (candidate)
8992 (with-anything-current-buffer
8993 (forward-char -1)))
8995 (defun anything-c-ucs-delete-backward (candidate)
8996 (with-anything-current-buffer
8997 (delete-char -1)))
8999 (defun anything-c-ucs-insert-char (candidate)
9000 (with-anything-current-buffer
9001 (insert
9002 (replace-regexp-in-string
9003 " " ""
9004 (cadr (split-string candidate ":"))))))
9006 (defun anything-c-ucs-persistent-insert ()
9007 (interactive)
9008 (anything-attrset 'action-insert 'anything-c-ucs-insert-char)
9009 (anything-execute-persistent-action 'action-insert))
9011 (defun anything-c-ucs-persistent-forward ()
9012 (interactive)
9013 (anything-attrset 'action-forward 'anything-c-ucs-forward-char)
9014 (anything-execute-persistent-action 'action-forward))
9016 (defun anything-c-ucs-persistent-backward ()
9017 (interactive)
9018 (anything-attrset 'action-back 'anything-c-ucs-backward-char)
9019 (anything-execute-persistent-action 'action-back))
9021 (defun anything-c-ucs-persistent-delete ()
9022 (interactive)
9023 (anything-attrset 'action-delete 'anything-c-ucs-delete-backward)
9024 (anything-execute-persistent-action 'action-delete))
9026 (defvar anything-c-source-ucs
9027 '((name . "Ucs names")
9028 (init . anything-c-ucs-init)
9029 (candidate-number-limit . 9999)
9030 (candidates-in-buffer)
9031 (mode-line . anything-c-ucs-mode-line-string)
9032 (action . (("Insert" . anything-c-ucs-insert-char)
9033 ("Forward char" . anything-c-ucs-forward-char)
9034 ("Backward char" . anything-c-ucs-backward-char)
9035 ("Delete char backward" . anything-c-ucs-delete-backward))))
9036 "Source for collecting `ucs-names' math symbols.")
9039 ;;; Emacs process
9042 (defvar anything-c-source-emacs-process
9043 '((name . "Emacs Process")
9044 (candidates . (lambda () (mapcar #'process-name (process-list))))
9045 (persistent-action . (lambda (elm)
9046 (delete-process (get-process elm))
9047 (anything-delete-current-selection)))
9048 (persistent-help . "Kill Process")
9049 (action ("Kill Process" . (lambda (elm)
9050 (delete-process (get-process elm)))))))
9051 ;; (anything 'anything-c-source-emacs-process)
9053 ;;; World time
9056 (defvar anything-c-source-time-world
9057 '((name . "Time World List")
9058 (init . (lambda ()
9059 (let ((anything-buffer (anything-candidate-buffer 'global)))
9060 (with-current-buffer anything-buffer
9061 (display-time-world-display display-time-world-list)))))
9062 (candidates-in-buffer)))
9066 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9069 (defvar anything-c-source-apt
9070 '((name . "APT")
9071 (init . anything-c-apt-init)
9072 (candidates-in-buffer)
9073 (candidate-transformer anything-c-apt-candidate-transformer)
9074 (display-to-real . anything-c-apt-display-to-real)
9075 (requires-pattern . 2)
9076 (update . anything-c-apt-refresh)
9077 (action
9078 ("Show package description" . anything-c-apt-cache-show)
9079 ("Install package" . anything-c-apt-install)
9080 ("Remove package" . anything-c-apt-uninstall)
9081 ("Purge package" . anything-c-apt-purge))
9082 (persistent-action . anything-c-apt-persistent-action)
9083 (persistent-help . "Show package description")))
9084 ;; (anything 'anything-c-source-apt)
9086 (defvar anything-c-apt-query "emacs")
9087 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9088 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9089 (defvar anything-c-apt-installed-packages nil)
9090 (defvar anything-c-apt-all-packages nil)
9091 (defvar anything-c-apt-input-history nil)
9093 (defun anything-c-apt-refresh ()
9094 "Refresh installed candidates list."
9095 (setq anything-c-apt-installed-packages nil)
9096 (setq anything-c-apt-all-packages nil))
9098 (defun anything-c-apt-persistent-action (candidate)
9099 "Persistent action for APT source."
9100 (anything-c-apt-cache-show candidate))
9102 (defun anything-c-apt-candidate-transformer (candidates)
9103 "Show installed candidates in a different color."
9104 (loop
9105 with all
9106 for cand in candidates
9107 for name = (anything-c-apt-display-to-real cand)
9108 if (member name anything-c-apt-installed-packages)
9109 collect (propertize cand 'face 'anything-apt-installed) into all
9110 else collect cand into all finally return all))
9112 (defun anything-c-apt-init ()
9113 "Initialize list of debian packages."
9114 (let ((query ""))
9115 (unless (and anything-c-apt-installed-packages
9116 anything-c-apt-all-packages)
9117 (message "Loading package list...")
9118 (setq anything-c-apt-installed-packages
9119 (with-temp-buffer
9120 (call-process-shell-command "dpkg --get-selections"
9121 nil (current-buffer))
9122 (loop for i in (split-string (buffer-string) "\n" t)
9123 collect (car (split-string i)))))
9124 (setq anything-c-apt-all-packages
9125 (with-current-buffer
9126 (anything-candidate-buffer
9127 (get-buffer-create (format "*anything-apt*")))
9128 (erase-buffer)
9129 (call-process-shell-command
9130 (format anything-c-apt-search-command query)
9131 nil (current-buffer))))
9132 (message "Loading package list done")
9133 (sit-for 0.5))))
9135 (defun anything-c-apt-display-to-real (line)
9136 "Return only name of a debian package.
9137 LINE is displayed like:
9138 package name - description."
9139 (car (split-string line " - ")))
9141 (defun anything-c-shell-command-if-needed (command)
9142 "Run shell command COMMAND to describe package.
9143 If a buffer named COMMAND already exists, just switch to it."
9144 (let ((buf (get-buffer command)))
9145 (anything-c-switch-to-buffer (get-buffer-create command))
9146 (unless buf (insert (shell-command-to-string command)))))
9148 (defun anything-c-apt-cache-show (package)
9149 "Show information on apt package PACKAGE."
9150 (anything-c-shell-command-if-needed
9151 (format anything-c-apt-show-command package)))
9153 (defun anything-c-apt-install (package)
9154 "Run 'apt-get install' shell command on PACKAGE."
9155 (anything-c-apt-generic-action :action 'install))
9157 (defun anything-c-apt-uninstall (package)
9158 "Run 'apt-get remove' shell command on PACKAGE."
9159 (anything-c-apt-generic-action :action 'uninstall))
9161 (defun anything-c-apt-purge (package)
9162 "Run 'apt-get purge' shell command on PACKAGE."
9163 (anything-c-apt-generic-action :action 'purge))
9165 (defun* anything-c-apt-generic-action (&key action)
9166 "Run 'apt-get ACTION'.
9167 Support install, remove and purge actions."
9168 (ansi-term (getenv "SHELL") "anything apt")
9169 (term-line-mode)
9170 (let ((command (case action
9171 ('install "sudo apt-get install ")
9172 ('uninstall "sudo apt-get remove ")
9173 ('purge "sudo apt-get purge ")
9174 (t (error "Unknow action"))))
9175 (beg (point))
9177 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9178 (anything-marked-candidates) " ")))
9179 (goto-char (point-max))
9180 (insert (concat command cand-list))
9181 (setq end (point))
9182 (if (y-or-n-p (format "%s package" (symbol-name action)))
9183 (progn
9184 (setq anything-c-external-commands-list nil)
9185 (setq anything-c-apt-installed-packages nil)
9186 (term-char-mode) (term-send-input))
9187 (delete-region beg end) (term-send-eof) (kill-buffer))))
9189 ;; (anything-c-apt-install "jed")
9192 ;;; Anything UI for gentoo portage.
9195 (defvar anything-c-gentoo-use-flags nil)
9196 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9197 (defvar anything-c-cache-gentoo nil)
9198 (defvar anything-c-cache-world nil)
9199 (defvar anything-c-source-gentoo
9200 '((name . "Portage sources")
9201 (init . (lambda ()
9202 (get-buffer-create anything-c-gentoo-buffer)
9203 (unless anything-c-cache-gentoo
9204 (anything-c-gentoo-setup-cache))
9205 (unless anything-c-cache-world
9206 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9207 (anything-c-gentoo-init-list)))
9208 (candidates-in-buffer)
9209 (match . identity)
9210 (candidate-transformer anything-c-highlight-world)
9211 (action . (("Show package" . (lambda (elm)
9212 (anything-c-gentoo-eshell-action elm "eix")))
9213 ("Show history" . (lambda (elm)
9214 (if (member elm anything-c-cache-world)
9215 (anything-c-gentoo-eshell-action elm "genlop -qe")
9216 (message "No infos on packages not yet installed"))))
9217 ("Copy in kill-ring" . kill-new)
9218 ("insert at point" . insert)
9219 ("Browse HomePage" . (lambda (elm)
9220 (let ((urls (anything-c-gentoo-get-url elm)))
9221 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9222 ("Show extra infos" . (lambda (elm)
9223 (if (member elm anything-c-cache-world)
9224 (anything-c-gentoo-eshell-action elm "genlop -qi")
9225 (message "No infos on packages not yet installed"))))
9226 ("Show use flags" . (lambda (elm)
9227 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9228 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9229 (font-lock-mode 1)))
9230 ("Run emerge pretend" . (lambda (elm)
9231 (anything-c-gentoo-eshell-action elm "emerge -p")))
9232 ("Emerge" . (lambda (elm)
9233 (anything-gentoo-install elm :action 'install)))
9234 ("Unmerge" . (lambda (elm)
9235 (anything-gentoo-install elm :action 'uninstall)))
9236 ("Show dependencies" . (lambda (elm)
9237 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9238 ("Show related files" . (lambda (elm)
9239 (anything-c-gentoo-default-action elm "equery" "files")))
9240 ("Refresh" . (lambda (elm)
9241 (anything-c-gentoo-setup-cache)
9242 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9244 ;; (anything 'anything-c-source-gentoo)
9246 (defun* anything-gentoo-install (candidate &key action)
9247 (setq anything-c-external-commands-list nil)
9248 (ansi-term (getenv "SHELL") "Gentoo emerge")
9249 (term-line-mode)
9250 (let ((command (case action
9251 ('install "sudo emerge -av ")
9252 ('uninstall "sudo emerge -avC ")
9253 (t (error "Unknow action"))))
9254 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9255 (beg (point)) end)
9256 (goto-char (point-max))
9257 (insert (concat command elms))
9258 (setq end (point))
9259 (term-char-mode) (term-send-input)))
9261 (defun anything-c-gentoo-default-action (elm command &rest args)
9262 "Gentoo default action that use `anything-c-gentoo-buffer'."
9263 (if (member elm anything-c-cache-world)
9264 (progn
9265 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9266 (erase-buffer)
9267 (let ((com-list (append args (list elm))))
9268 (apply #'call-process command nil t nil
9269 com-list)))
9270 (message "No infos on packages not yet installed")))
9272 (defvar anything-c-source-use-flags
9273 '((name . "Use Flags")
9274 (init . (lambda ()
9275 (unless anything-c-gentoo-use-flags
9276 (anything-c-gentoo-setup-use-flags-cache))
9277 (anything-c-gentoo-get-use)))
9278 (candidates-in-buffer)
9279 (match . identity)
9280 (candidate-transformer anything-c-highlight-local-use)
9281 (action . (("Description"
9282 . (lambda (elm)
9283 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9284 (erase-buffer)
9285 (apply #'call-process "euse" nil t nil
9286 `("-i"
9287 ,elm))
9288 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9289 (font-lock-mode 1)))
9290 ("Enable"
9291 . (lambda (elm)
9292 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9293 ("Disable"
9294 . (lambda (elm)
9295 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9296 ("Remove"
9297 . (lambda (elm)
9298 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9299 ("Show which dep use this flag"
9300 . (lambda (elm)
9301 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9302 (erase-buffer)
9303 (apply #'call-process "equery" nil t nil
9304 `("-C"
9306 ,elm))))))))
9309 ;; (anything 'anything-c-source-use-flags)
9311 (defun anything-c-gentoo-init-list ()
9312 "Initialize buffer with all packages in Portage."
9313 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9314 (buf (anything-candidate-buffer 'portage-buf)))
9315 (with-current-buffer buf
9316 (dolist (i anything-c-cache-gentoo)
9317 (insert (concat i "\n"))))))
9319 (defun anything-c-gentoo-setup-cache ()
9320 "Set up `anything-c-cache-gentoo'"
9321 (setq anything-c-cache-gentoo
9322 (split-string (with-temp-buffer
9323 (call-process "eix" nil t nil
9324 "--only-names")
9325 (buffer-string)))))
9327 (defun anything-c-gentoo-eshell-action (elm command)
9328 (when (get-buffer "*EShell Command Output*")
9329 (kill-buffer "*EShell Command Output*"))
9330 (message "Wait searching...")
9331 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9332 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9333 (progn
9334 (save-window-excursion
9335 (pop-to-buffer "*scratch*")
9336 (eshell-command (format "%s %s" command elm)))
9337 (pop-to-buffer "*EShell Command Output*"))
9338 (eshell-command (format "%s %s" command elm)))))
9340 (defun anything-c-gentoo-get-use ()
9341 "Initialize buffer with all use flags."
9342 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9343 (buf (anything-candidate-buffer 'use-buf)))
9344 (with-current-buffer buf
9345 (dolist (i anything-c-gentoo-use-flags)
9346 (insert (concat i "\n"))))))
9349 (defun anything-c-gentoo-setup-use-flags-cache ()
9350 "Setup `anything-c-gentoo-use-flags'"
9351 (setq anything-c-gentoo-use-flags
9352 (split-string (with-temp-buffer
9353 (call-process "eix" nil t nil
9354 "--print-all-useflags")
9355 (buffer-string)))))
9357 (defun anything-c-gentoo-get-url (elm)
9358 "Return a list of urls from eix output."
9359 (loop
9360 with url-list = (split-string
9361 (with-temp-buffer
9362 (call-process "eix" nil t nil
9363 elm "--format" "<homepage>\n")
9364 (buffer-string)))
9365 with all
9366 for i in url-list
9367 when (and (string-match "^http://.*" i)
9368 (not (member i all)))
9369 collect i into all
9370 finally return all))
9372 (defun anything-c-gentoo-get-world ()
9373 "Return list of all installed package on your system."
9374 (split-string (with-temp-buffer
9375 (call-process "qlist" nil t nil
9376 "-I")
9377 (buffer-string))))
9379 (defun anything-c-gentoo-get-local-use ()
9380 (split-string (with-temp-buffer
9381 (call-process "portageq" nil t nil
9382 "envvar"
9383 "USE")
9384 (buffer-string))))
9387 (defun anything-c-highlight-world (eix)
9388 "Highlight all installed package."
9389 (loop for i in eix
9390 if (member i anything-c-cache-world)
9391 collect (propertize i 'face 'anything-gentoo-match-face)
9392 else
9393 collect i))
9395 (defun anything-c-highlight-local-use (use-flags)
9396 (let ((local-uses (anything-c-gentoo-get-local-use)))
9397 (loop for i in use-flags
9398 if (member i local-uses)
9399 collect (propertize i 'face 'anything-gentoo-match-face)
9400 else
9401 collect i)))
9405 ;;; Anything ratpoison UI
9408 (defvar anything-c-source-ratpoison-commands
9409 '((name . "Ratpoison Commands")
9410 (init . anything-c-ratpoison-commands-init)
9411 (candidates-in-buffer)
9412 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9413 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9414 (candidate-number-limit)))
9415 ;; (anything 'anything-c-source-ratpoison-commands)
9417 (defun anything-c-ratpoison-commands-init ()
9418 (unless (anything-candidate-buffer)
9419 (with-current-buffer (anything-candidate-buffer 'global)
9420 ;; with ratpoison prefix key
9421 (save-excursion
9422 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9423 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9424 (replace-match "<ratpoison> \\1: \\2"))
9425 (goto-char (point-max))
9426 ;; direct binding
9427 (save-excursion
9428 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9429 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9430 (replace-match "\\1: \\2")))))
9432 (defun anything-c-ratpoison-commands-display-to-real (display)
9433 (and (string-match ": " display)
9434 (substring display (match-end 0))))
9436 (defun anything-c-ratpoison-commands-execute (candidate)
9437 (call-process "ratpoison" nil nil nil "-ic" candidate))
9441 ;;; Anything `completing-read' replacement
9444 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9445 "Convert COLLECTION to list removing elements that don't match TEST.
9446 See `anything-comp-read' about supported COLLECTION arguments.
9448 SORT-FN is a predicate to sort COLLECTION.
9450 ALISTP when non--nil will not use `all-completions' to collect
9451 candidates because it doesn't handle alists correctly for anything.
9452 i.e In `all-completions' the keys \(cars of elements\)
9453 are the possible completions. In anything we want to use the cdr instead
9454 like \(display . real\).
9458 \(setq A '((a . 1) (b . 2) (c . 3)))
9459 ==>((a . 1) (b . 2) (c . 3))
9460 \(anything-comp-read \"test: \" A :alistp nil
9461 :exec-when-only-one t
9462 :initial-input \"a\")
9463 ==>\"a\"
9464 \(anything-comp-read \"test: \" A :alistp t
9465 :exec-when-only-one t
9466 :initial-input \"1\")
9467 ==>\"1\"
9469 See docstring of `all-completions' for more info.
9471 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9472 (let ((cands
9473 (cond ((and (eq collection obarray) test)
9474 (all-completions "" collection test))
9475 ((and (vectorp collection) test)
9476 (loop for i across collection when (funcall test i) collect i))
9477 ((vectorp collection)
9478 (loop for i across collection collect i))
9479 ((and alistp test)
9480 (loop for i in collection when (funcall test i) collect i))
9481 ((and (symbolp collection) (boundp collection))
9482 (symbol-value collection))
9483 (alistp collection)
9484 ((and collection test)
9485 (all-completions "" collection test))
9486 (t (all-completions "" collection)))))
9487 (if sort-fn (sort cands sort-fn) cands)))
9489 (defun anything-cr-default-transformer (candidates source)
9490 "Default filter candidate function for `anything-comp-read'.
9491 Do nothing, just return candidate list unmodified."
9492 candidates)
9494 (defun* anything-comp-read (prompt collection
9495 &key
9496 test
9497 initial-input
9498 default
9499 preselect
9500 (buffer "*Anything Completions*")
9501 must-match
9502 (requires-pattern 0)
9503 (history nil)
9504 input-history
9505 (persistent-action nil)
9506 (persistent-help "DoNothing")
9507 (name "Anything Completions")
9508 candidates-in-buffer
9509 exec-when-only-one
9510 (volatile t)
9511 sort
9512 (fc-transformer 'anything-cr-default-transformer)
9513 (marked-candidates nil)
9514 (alistp t))
9515 "Read a string in the minibuffer, with anything completion.
9517 It is anything `completing-read' equivalent.
9519 - PROMPT is the prompt name to use.
9521 - COLLECTION can be a list, vector, obarray or hash-table.
9522 It can be also a function that receives three arguments:
9523 the values string, predicate and t. See `all-completions' for more details.
9525 Keys description:
9527 - TEST: A predicate called with one arg i.e candidate.
9529 - INITIAL-INPUT: Same as input arg in `anything'.
9531 - PRESELECT: See preselect arg of `anything'.
9533 - DEFAULT: This option is used only for compatibility with regular
9534 Emacs `completing-read'.
9536 - BUFFER: Name of anything-buffer.
9538 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9540 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9542 - HISTORY: A list containing specific history, default is nil.
9543 When it is non--nil, all elements of HISTORY are displayed in
9544 a special source before COLLECTION.
9546 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9547 stored there, if nil or not provided, `minibuffer-history'
9548 will be used instead.
9550 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9552 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9554 - NAME: The name related to this local source.
9556 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9557 to non--nil. (possibles values are t or nil).
9559 - VOLATILE: Use volatile attribute \(enabled by default\).
9561 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9563 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9565 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9567 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9569 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9570 `anything-candidates-in-buffer' which is much faster.
9571 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9573 Any prefix args passed during `anything-comp-read' invocation will be recorded
9574 in `anything-current-prefix-arg', otherwise if prefix args were given before
9575 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9576 That's mean you can pass prefix args before or after calling a command
9577 that use `anything-comp-read' See `anything-M-x' for example."
9578 (when (get-buffer anything-action-buffer)
9579 (kill-buffer anything-action-buffer))
9580 (flet ((action-fn (candidate)
9581 (if marked-candidates
9582 (anything-marked-candidates)
9583 (identity candidate))))
9584 ;; Assume completion have been already required,
9585 ;; so always use 'confirm.
9586 (when (eq must-match 'confirm-after-completion)
9587 (setq must-match 'confirm))
9588 (let* ((minibuffer-completion-confirm (unless (eq must-match t)
9589 must-match))
9590 (keymap (when must-match minibuffer-local-must-match-map))
9591 (anything-map (make-composed-keymap
9592 ;; Merge some anything bindings
9593 ;; that clash with minibuffer ones.
9594 (list '(keymap
9595 (7 . anything-keyboard-quit)
9596 (up . anything-previous-line)
9597 (down . anything-next-line))
9598 keymap)
9599 anything-map))
9600 (src-hist `((name . ,(format "%s History" name))
9601 (candidates
9602 . (lambda ()
9603 (let ((all (anything-comp-read-get-candidates
9604 history nil nil ,alistp)))
9605 (delete
9607 (anything-fast-remove-dups
9608 (if (and default (not (string= default "")))
9609 (delq nil (cons default
9610 (delete default all)))
9611 all)
9612 :test 'equal)))))
9613 (filtered-candidate-transformer
9614 . (lambda (candidates sources)
9615 (loop for i in candidates
9616 do (set-text-properties 0 (length i) nil i)
9617 collect i)))
9618 (persistent-action . ,persistent-action)
9619 (persistent-help . ,persistent-help)
9620 (action . ,'action-fn)))
9621 (src `((name . ,name)
9622 (candidates
9623 . (lambda ()
9624 (let ((cands (anything-comp-read-get-candidates
9625 collection test sort alistp)))
9626 (unless (or must-match (string= anything-pattern ""))
9627 (setq cands (append (list anything-pattern) cands)))
9628 (if (and default (not (string= default "")))
9629 (delq nil (cons default (delete default cands)))
9630 cands))))
9631 (filtered-candidate-transformer ,fc-transformer)
9632 (requires-pattern . ,requires-pattern)
9633 (persistent-action . ,persistent-action)
9634 (persistent-help . ,persistent-help)
9635 (action . ,'action-fn)))
9636 (src-1 `((name . ,name)
9637 (init
9638 . (lambda ()
9639 (let ((cands (anything-comp-read-get-candidates
9640 collection test sort alistp)))
9641 (unless (or must-match (string= anything-pattern ""))
9642 (setq cands (append (list anything-pattern) cands)))
9643 (with-current-buffer (anything-candidate-buffer 'global)
9644 (loop for i in
9645 (if (and default (not (string= default "")))
9646 (delq nil (cons default (delete default cands)))
9647 cands)
9648 do (insert (concat i "\n")))))))
9649 (candidates-in-buffer)
9650 (filtered-candidate-transformer ,fc-transformer)
9651 (requires-pattern . ,requires-pattern)
9652 (persistent-action . ,persistent-action)
9653 (persistent-help . ,persistent-help)
9654 (action . ,'action-fn)))
9655 (src-list (list src-hist
9656 (if candidates-in-buffer
9657 src-1
9658 (if volatile
9659 (append src '((volatile)))
9660 src))))
9661 (anything-execute-action-at-once-if-one exec-when-only-one))
9663 (anything
9664 :sources src-list
9665 :input initial-input
9666 :default default
9667 :preselect preselect
9668 :prompt prompt
9669 :resume 'noresume
9670 :history (and (symbolp input-history) input-history)
9671 :buffer buffer)
9672 (when (and (not (string= anything-pattern ""))
9673 (eq anything-exit-status 0)
9674 (eq must-match 'confirm))
9675 (identity anything-pattern))
9676 (unless (or (eq anything-exit-status 1) must-match)
9677 default)
9678 (keyboard-quit)))))
9680 ;; Generic completing-read
9682 ;; Support also function as collection.
9683 ;; e.g M-x man is supported.
9684 ;; Support hash-table and vectors as collection.
9685 ;; NOTE:
9686 ;; Some crap emacs functions may not be supported
9687 ;; like ffap-alternate-file (bad use of completing-read)
9688 ;; and maybe others.
9689 ;; Provide a mode `anything-completion-mode' which turn on
9690 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9692 (defvar anything-completion-mode-string " AC")
9694 (defvar anything-completion-mode-quit-message
9695 "Anything completion disabled")
9697 (defvar anything-completion-mode-start-message
9698 "Anything completion enabled")
9700 ;;; Specialized handlers
9703 (defun anything-completing-read-symbols
9704 (prompt collection test require-match init
9705 hist default inherit-input-method name buffer)
9706 "Specialized function for fast symbols completion in `ac-mode'."
9708 (anything
9709 :sources `((name . ,name)
9710 (init . (lambda ()
9711 (with-current-buffer (anything-candidate-buffer 'global)
9712 (goto-char (point-min))
9713 (when (and default (stringp default)
9714 ;; Some defaults args result as
9715 ;; (symbol-name nil) == "nil".
9716 ;; e.g debug-on-entry.
9717 (not (string= default "nil"))
9718 (not (string= default "")))
9719 (insert (concat default "\n")))
9720 (loop with all = (all-completions "" collection test)
9721 for sym in all
9722 unless (and default (eq sym default))
9723 do (insert (concat sym "\n"))))))
9724 (persistent-action . anything-lisp-completion-persistent-action)
9725 (persistent-help . "Show brief doc in mode-line")
9726 (candidates-in-buffer)
9727 (action . identity))
9728 :prompt prompt
9729 :buffer buffer
9730 :input init
9731 :history hist
9732 :resume 'noresume
9733 :default (or default ""))
9734 (keyboard-quit)))
9737 ;;; Generic completing read
9740 (defun anything-completing-read-default-1
9741 (prompt collection test require-match
9742 init hist default inherit-input-method
9743 name buffer &optional cands-in-buffer exec-when-only-one)
9744 "Call `anything-comp-read' with same args as `completing-read'.
9745 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9746 method which is faster.
9747 It should be used when candidate list don't need to rebuild dynamically."
9748 (let ((history (or (car-safe hist) hist)))
9749 (anything-comp-read
9750 prompt collection
9751 :test test
9752 :history history
9753 :input-history history
9754 :must-match require-match
9755 :alistp nil ; Be sure `all-completions' is used.
9756 :name name
9757 :candidates-in-buffer cands-in-buffer
9758 :exec-when-only-one exec-when-only-one
9759 :buffer buffer
9760 ;; If DEF is not provided, fallback to empty string
9761 ;; to avoid `thing-at-point' to be appended on top of list
9762 :default (or default "")
9763 :initial-input init)))
9765 (defun anything-completing-read-with-cands-in-buffer
9766 (prompt collection test require-match
9767 init hist default inherit-input-method
9768 name buffer)
9769 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9770 ;; Some commands like find-tag may use `read-file-name' from inside
9771 ;; the calculation of collection. in this case it clash with
9772 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9773 ;; So (re)calculate collection outside of main anything-session.
9774 (let ((cands (all-completions "" collection)))
9775 (anything-completing-read-default-1 prompt cands test require-match
9776 init hist default inherit-input-method
9777 name buffer t)))
9779 (defun* anything-completing-read-default
9780 (prompt collection &optional
9781 predicate require-match
9782 initial-input hist def
9783 inherit-input-method)
9784 "An anything replacement of `completing-read'.
9785 This function should be used only as a `completing-read-function'.
9787 Don't use it directly, use instead `anything-comp-read' in your programs.
9789 See documentation of `completing-read' and `all-completions' for details."
9790 (declare (special anything-completion-mode))
9791 (let* ((current-command this-command)
9792 (str-command (symbol-name current-command))
9793 (buf-name (format "*ac-mode-%s*" str-command))
9794 (entry (assq current-command
9795 anything-completing-read-handlers-alist))
9796 (def-com (cdr-safe entry))
9797 (str-defcom (and def-com (symbol-name def-com)))
9798 (def-args (list prompt collection predicate require-match
9799 initial-input hist def inherit-input-method))
9800 ;; Append the two extra args needed to set the buffer and source name
9801 ;; in anything specialized functions.
9802 (any-args (append def-args (list str-command buf-name)))
9803 anything-completion-mode-start-message ; Be quiet
9804 anything-completion-mode-quit-message
9805 (minibuffer-completion-table collection)
9806 (minibuffer-completion-predicate predicate)
9807 ;; Be sure this pesty *completion* buffer doesn't popup.
9808 (minibuffer-setup-hook (remove 'minibuffer-completion-help
9809 minibuffer-setup-hook)))
9810 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9811 (unless (or (not entry) def-com)
9812 ;; An entry in *read-handlers-alist exists but have
9813 ;; a nil value, so we exit from here, disable `ac-mode'
9814 ;; and run the command again with it original behavior.
9815 ;; `ac-mode' will be restored on exit.
9816 (return-from anything-completing-read-default
9817 (unwind-protect
9818 (progn
9819 (ac-mode -1)
9820 (apply completing-read-function def-args))
9821 (ac-mode 1))))
9822 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9823 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9824 (when (or (eq def-com 'completing-read)
9825 ;; All specialized functions are prefixed by "anything"
9826 (and (stringp str-defcom)
9827 (not (string-match "^anything" str-defcom))))
9828 (ac-mode -1))
9829 (unwind-protect
9830 (cond (;; An anything specialized function exists, run it.
9831 (and def-com anything-completion-mode)
9832 (apply def-com any-args))
9833 (;; Try to handle `ido-completing-read' everywhere.
9834 (and def-com (eq def-com 'ido-completing-read))
9835 (setcar (memq collection def-args)
9836 (all-completions "" collection predicate))
9837 (apply def-com def-args))
9838 (;; User set explicitely `completing-read' or something similar
9839 ;; in *read-handlers-alist, use this with exactly the same
9840 ;; args as in `completing-read'.
9841 ;; If we are here `anything-completion-mode' is now disabled.
9842 def-com
9843 (apply def-com def-args))
9844 (t ; Fall back to classic `anything-comp-read'.
9845 (anything-completing-read-default-1
9846 prompt collection predicate require-match
9847 initial-input hist def inherit-input-method
9848 str-command buf-name)))
9849 (ac-mode 1)
9850 ;; When exiting minibuffer, `this-command' is set to
9851 ;; `anything-exit-minibuffer', which is unwanted when starting
9852 ;; on another `completing-read', so restore `this-command' to
9853 ;; initial value when exiting.
9854 (setq this-command current-command))))
9856 (defun* anything-generic-read-file-name
9857 (prompt &optional dir default-filename mustmatch initial predicate)
9858 "An anything replacement of `read-file-name'."
9859 (declare (special anything-completion-mode))
9860 (let* ((default (and default-filename
9861 (if (listp default-filename)
9862 (car default-filename)
9863 default-filename)))
9864 (init (or default initial dir default-directory))
9865 (ini-input (and init (expand-file-name init)))
9866 (current-command this-command)
9867 (str-command (symbol-name current-command))
9868 (anything-file-completion-sources
9869 (cons str-command
9870 (remove str-command anything-file-completion-sources)))
9871 (buf-name (format "*ac-mode-%s*" str-command))
9872 (entry (assq current-command
9873 anything-completing-read-handlers-alist))
9874 (def-com (cdr-safe entry))
9875 (str-defcom (symbol-name def-com))
9876 (def-args (list prompt dir default-filename mustmatch initial predicate))
9877 ;; Append the two extra args needed to set the buffer and source name
9878 ;; in anything specialized functions.
9879 (any-args (append def-args (list str-command buf-name)))
9880 (ido-state ido-mode)
9881 anything-completion-mode-start-message ; Be quiet
9882 anything-completion-mode-quit-message ; Same here
9883 fname)
9884 ;; Some functions that normally call `completing-read' can switch
9885 ;; brutally to `read-file-name' (e.g find-tag), in this case
9886 ;; the anything specialized function will fail because it is build
9887 ;; for `completing-read', so set it to 'incompatible to be sure
9888 ;; we switch to `anything-c-read-file-name' and don't try to call it
9889 ;; with wrong number of args.
9890 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9891 (setq def-com 'incompatible))
9892 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9893 (unless (or (not entry) def-com)
9894 (return-from anything-generic-read-file-name
9895 (unwind-protect
9896 (progn
9897 (ac-mode -1)
9898 (apply read-file-name-function def-args))
9899 (ac-mode 1))))
9900 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9901 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9902 (when (or (eq def-com 'read-file-name)
9903 (eq def-com 'ido-read-file-name)
9904 (and (stringp str-defcom)
9905 (not (string-match "^anything" str-defcom))))
9906 (ac-mode -1))
9907 (unwind-protect
9908 (setq fname
9909 (cond (;; A specialized function exists, run it
9910 ;; with the two extra args specific to anything..
9911 (and def-com anything-completion-mode
9912 (not (eq def-com 'ido-read-file-name))
9913 (not (eq def-com 'incompatible)))
9914 (apply def-com any-args))
9915 (;; Def-com value is `ido-read-file-name'
9916 ;; run it with default args.
9917 (and def-com (eq def-com 'ido-read-file-name))
9918 (ido-mode 1)
9919 (apply def-com def-args))
9920 (;; Def-com value is `read-file-name'
9921 ;; run it with default args.
9922 (eq def-com 'read-file-name)
9923 (apply def-com def-args))
9924 (t ; Fall back to classic `anything-c-read-file-name'.
9925 (anything-c-read-file-name
9926 prompt
9927 :name str-command
9928 :buffer buf-name
9929 :initial-input (expand-file-name init dir)
9930 :alistp nil
9931 :must-match mustmatch
9932 :test predicate))))
9933 (ac-mode 1)
9934 (ido-mode (if ido-state 1 -1))
9935 ;; Same comment as in `anything-completing-read-default'.
9936 (setq this-command current-command))
9937 (if (and mustmatch (not (file-exists-p fname)))
9938 (if (y-or-n-p "File does not exists, create buffer?")
9939 fname (error "Abort file does not exists"))
9940 fname)))
9942 ;;;###autoload
9943 (define-minor-mode anything-completion-mode
9944 "Toggle generic anything completion.
9946 All functions in Emacs that use `completing-read'
9947 or `read-file-name' and friends will use anything interface
9948 when this mode is turned on.
9949 However you can modify this behavior for functions of your choice
9950 with `anything-completing-read-handlers-alist'.
9952 Called with a positive arg, turn on unconditionally, with a
9953 negative arg turn off.
9954 You can turn it on with `ac-mode'.
9956 Some crap emacs functions may not be supported,
9957 e.g `ffap-alternate-file' and maybe others
9958 You can add such functions to `anything-completing-read-handlers-alist'
9959 with a nil value.
9961 Note: This mode will work only partially on Emacs23."
9962 :group 'anything
9963 :global t
9964 :lighter anything-completion-mode-string
9965 (declare (special completing-read-function))
9966 (if anything-completion-mode
9967 (progn
9968 (setq completing-read-function 'anything-completing-read-default
9969 read-file-name-function 'anything-generic-read-file-name)
9970 (message anything-completion-mode-start-message))
9971 (setq completing-read-function (and (fboundp 'completing-read-default)
9972 'completing-read-default)
9973 read-file-name-function (and (fboundp 'read-file-name-default)
9974 'read-file-name-default))
9975 (message anything-completion-mode-quit-message)))
9977 (defalias 'ac-mode 'anything-completion-mode)
9981 ;;; Eshell completion.
9983 ;; Enable like this in .emacs:
9985 ;; (add-hook 'eshell-mode-hook
9986 ;; #'(lambda ()
9987 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9989 (defvar anything-c-source-esh
9990 '((name . "Eshell completions")
9991 (init . (lambda ()
9992 (setq pcomplete-current-completions nil
9993 pcomplete-last-completion-raw nil)
9994 ;; Eshell-command add this hook in all minibuffers
9995 ;; Remove it for the anything one. (Fixed in Emacs24)
9996 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9997 (candidates . anything-esh-get-candidates)
9998 (action . anything-ec-insert))
9999 "Anything source for Eshell completion.")
10001 ;; Internal.
10002 (defvar anything-ec-target "")
10003 (defun anything-ec-insert (candidate)
10004 "Insert CANDIDATE at point.
10005 This is the same as `ac-insert', just inlined here for compatibility."
10006 (let ((pt (point)))
10007 (when (and anything-ec-target
10008 (search-backward anything-ec-target nil t)
10009 (string= (buffer-substring (point) pt) anything-ec-target))
10010 (delete-region (point) pt)))
10011 (insert candidate))
10013 (defun anything-esh-get-candidates ()
10014 "Get candidates for eshell completion using `pcomplete'."
10015 (catch 'pcompleted
10016 (let* ((pcomplete-stub)
10017 pcomplete-seen pcomplete-norm-func
10018 pcomplete-args pcomplete-last pcomplete-index
10019 (pcomplete-autolist pcomplete-autolist)
10020 (pcomplete-suffix-list pcomplete-suffix-list))
10021 (with-anything-current-buffer
10022 (loop
10023 with table = (pcomplete-completions)
10024 with entry = (condition-case nil
10025 ;; For Emacs24
10026 (try-completion anything-pattern (pcomplete-entries))
10027 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10028 (error
10030 (let ((fc (car (last (pcomplete-parse-arguments)))))
10031 ;; Check if last arg require fname completion.
10032 (and (file-name-directory fc) fc))))
10033 for i in (if (listp table) table ; Emacs23 or commands.
10034 (all-completions pcomplete-stub table)) ; Emacs24
10035 for file-cand = (and entry
10036 (if (file-remote-p i) i
10037 (expand-file-name i (file-name-directory entry))))
10038 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
10039 collect file-cand into ls
10040 else collect i into ls
10041 finally return
10042 (if (and entry (not (string= entry "")) (file-exists-p entry))
10043 (append (list (expand-file-name entry default-directory)) ls) ls))))))
10045 ;;; Eshell history.
10048 (defvar anything-c-source-eshell-history
10049 '((name . "Eshell history")
10050 (init . (lambda ()
10051 (let (eshell-hist-ignoredups)
10052 ;; Write the content's of ring to file.
10053 (eshell-write-history eshell-history-file-name t)
10054 (with-current-buffer (anything-candidate-buffer 'global)
10055 (insert-file-contents eshell-history-file-name)))
10056 ;; Same comment as in `anything-c-source-esh'
10057 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
10058 (candidates-in-buffer)
10059 (filtered-candidate-transformer . (lambda (candidates sources)
10060 (reverse candidates)))
10061 (candidate-number-limit . 9999)
10062 (action . (lambda (candidate)
10063 (eshell-kill-input)
10064 (insert candidate))))
10065 "Anything source for Eshell history.")
10068 ;;; Show completion - an alternative of anything-show-completion.el.
10070 ;; Provide show completion with macro `with-anything-show-completion'.
10073 ;; Called each time cursor move in anything-buffer.
10074 (defun anything-c-show-completion ()
10075 (with-anything-current-buffer
10076 (overlay-put anything-c-show-completion-overlay
10077 'display (anything-get-selection))))
10079 (defun anything-c-show-completion-init-overlay (beg end)
10080 (and anything-c-turn-on-show-completion
10081 (setq anything-c-show-completion-overlay (make-overlay beg end))
10082 (overlay-put anything-c-show-completion-overlay
10083 'face 'anything-lisp-show-completion)))
10085 (defmacro with-anything-show-completion (beg end &rest body)
10086 "Show anything candidate in an overlay at point.
10087 BEG and END are the beginning and end position of the current completion
10088 in `anything-current-buffer'.
10089 BODY is an anything call where we want to enable show completion.
10090 If `anything-c-turn-on-show-completion' is nil just do nothing."
10091 (declare (indent 2) (debug t))
10092 `(let ((anything-move-selection-after-hook
10093 (and anything-c-turn-on-show-completion
10094 (append (list 'anything-c-show-completion)
10095 anything-move-selection-after-hook))))
10096 (unwind-protect
10097 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10098 ,@body)
10099 (and anything-c-turn-on-show-completion
10100 (delete-overlay anything-c-show-completion-overlay)))))
10103 ;;; Lisp symbol completion.
10106 ;;;###autoload
10107 (defun anything-lisp-completion-at-point ()
10108 "Anything lisp symbol completion at point."
10109 (interactive)
10110 (let* ((data (lisp-completion-at-point))
10111 (beg (car data))
10112 (end (point)) ; 'cadr data' is wrong when no space after point.
10113 (plist (nthcdr 3 data))
10114 (pred (plist-get plist :predicate))
10115 (lgst-len 0)
10116 (target (and beg end (buffer-substring-no-properties beg end)))
10117 (candidates (all-completions target (nth 2 data) pred))
10118 (anything-quit-if-no-candidate t)
10119 (anything-execute-action-at-once-if-one t)
10120 (anything-match-plugin-enabled
10121 (member 'anything-compile-source--match-plugin
10122 anything-compile-source-functions)))
10123 (if candidates
10124 (with-anything-show-completion beg end
10125 ;; Overlay is initialized now in anything-current-buffer.
10126 (anything
10127 :sources
10128 '((name . "Lisp completion")
10129 (init . (lambda ()
10130 (with-current-buffer (anything-candidate-buffer 'global)
10131 (loop for sym in candidates
10132 for len = (length sym)
10133 when (> len lgst-len) do (setq lgst-len len)
10134 do (insert (concat sym "\n"))))))
10135 (candidates-in-buffer)
10136 (persistent-action . anything-lisp-completion-persistent-action)
10137 (persistent-help . "Show brief doc in mode-line")
10138 (filtered-candidate-transformer anything-lisp-completion-transformer)
10139 (action . (lambda (candidate)
10140 (delete-region beg end)
10141 (insert candidate))))
10142 :input (if anything-match-plugin-enabled (concat target " ") target)))
10143 (message "[No Match]"))))
10145 (defun anything-lisp-completion-persistent-action (candidate)
10146 (let ((cursor-in-echo-area t)
10147 mode-line-in-non-selected-windows)
10148 (anything-c-show-info-in-mode-line
10149 (propertize
10150 (anything-c-get-first-line-documentation
10151 (intern candidate))
10152 'face 'anything-lisp-completion-info))))
10154 (defun anything-lisp-completion-transformer (candidates source)
10155 "Anything candidates transformer for lisp completion."
10156 (declare (special lgst-len))
10157 (loop for c in candidates
10158 for sym = (intern c)
10159 for annot = (cond ((commandp sym) " (Com)")
10160 ((fboundp sym) " (Fun)")
10161 ((boundp sym) " (Var)")
10162 ((facep sym) " (Face)"))
10163 for spaces = (make-string (- lgst-len (length c)) ? )
10164 collect (cons (concat c spaces annot) c)))
10166 (defun anything-c-get-first-line-documentation (sym)
10167 "Return first line documentation of symbol SYM.
10168 If SYM is not documented, return \"Not documented\"."
10169 (let ((doc (cond ((fboundp sym)
10170 (documentation sym t))
10171 ((boundp sym)
10172 (documentation-property sym 'variable-documentation t))
10173 ((facep sym)
10174 (face-documentation sym))
10175 (t nil))))
10176 (if (and doc (not (string= doc ""))
10177 ;; `documentation' return "\n\n(args...)"
10178 ;; for CL-style functions.
10179 (not (string-match-p "^\n\n" doc)))
10180 (car (split-string doc "\n"))
10181 "Not documented")))
10183 ;;; File completion.
10185 ;; Complete file name at point.
10186 (defun anything-c-thing-before-point ()
10187 "Get symbol name before point.
10188 Borrowed from anything-complete.el, inlined here for compatibility."
10189 (save-excursion
10190 (let ((beg (point)))
10191 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10192 (when (re-search-backward
10193 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10194 (buffer-substring-no-properties beg (match-end 0))))))
10196 ;;;###autoload
10197 (defun anything-c-complete-file-name-at-point ()
10198 "Complete file name at point."
10199 (interactive)
10200 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10201 (end (point))
10202 (beg (- (point) (length init)))
10203 (anything-quit-if-no-candidate t)
10204 (anything-execute-action-at-once-if-one t)
10205 completion)
10206 (with-anything-show-completion beg end
10207 (setq completion (anything-c-read-file-name "FileName: "
10208 :initial-input init)))
10209 (anything-c-insert-file-name-completion-at-point completion)))
10211 ;; Internal
10212 (defvar anything-lisp-completion-counter 0)
10213 ;;;###autoload
10214 (defun anything-lisp-completion-at-point-or-indent (arg)
10215 "First call indent and second call complete lisp symbol.
10216 The second call should happen before `anything-lisp-completion-or-indent-delay',
10217 after this delay, next call will indent again.
10218 After completion, next call is always indent.
10219 See that like click and double mouse click.
10220 One hit indent, two quick hits maybe indent and complete."
10221 (interactive "P")
10222 ;; Be sure `indent-for-tab-command' will not try
10223 ;; to use `completion-at-point'.
10224 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10225 t tab-always-indent)))
10226 (incf anything-lisp-completion-counter)
10227 (unwind-protect
10228 (if (> anything-lisp-completion-counter 1)
10229 (anything-lisp-completion-or-file-name-at-point)
10230 (indent-for-tab-command arg))
10231 ;; After `anything-lisp-completion-or-indent-delay' seconds
10232 ;; reset to 0.
10233 (run-with-timer anything-lisp-completion-or-indent-delay nil
10234 #'(lambda ()
10235 (setq anything-lisp-completion-counter 0)))
10236 ;; Always reset to 0 at second hit.
10237 (when (eq anything-lisp-completion-counter 2)
10238 (setq anything-lisp-completion-counter 0)))))
10240 ;;;###autoload
10241 (defun anything-lisp-completion-or-file-name-at-point ()
10242 "Complete lisp symbol or filename at point.
10243 Filename completion happen if filename is started in
10244 or between double quotes."
10245 (interactive)
10246 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10247 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10248 (save-excursion (search-backward "\"" (point-at-bol) t)))
10249 (anything-c-complete-file-name-at-point)
10250 (anything-lisp-completion-at-point))))
10252 (defun anything-c-apropos-init (test default)
10253 "Init candidates buffer for `anything-c-apropos' sources."
10254 (with-current-buffer (anything-candidate-buffer 'global)
10255 (goto-char (point-min))
10256 (when (and default (stringp default)
10257 ;; Some defaults args result as
10258 ;; (symbol-name nil) == "nil".
10259 ;; e.g debug-on-entry.
10260 (not (string= default "nil"))
10261 (funcall test (intern default)))
10262 (insert (concat default "\n")))
10263 (loop with all = (all-completions "" obarray test)
10264 for sym in all
10265 unless (and default (eq sym default))
10266 do (insert (concat sym "\n")))))
10269 ;;; Run Externals commands within Emacs with anything completion
10272 (defvar anything-external-command-history nil)
10274 (defun anything-c-external-commands-list-1 (&optional sort)
10275 "Returns a list of all external commands the user can execute.
10276 If `anything-c-external-commands-list' is non-nil it will
10277 return its contents. Else it calculates all external commands
10278 and sets `anything-c-external-commands-list'."
10279 (if anything-c-external-commands-list
10280 anything-c-external-commands-list
10281 (setq anything-c-external-commands-list
10282 (loop
10283 with paths = (split-string (getenv "PATH") path-separator)
10284 with completions = ()
10285 for dir in paths
10286 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10287 for lsdir = (loop for i in (directory-files dir t)
10288 for bn = (file-name-nondirectory i)
10289 when (and (not (member bn completions))
10290 (not (file-directory-p i))
10291 (file-executable-p i))
10292 collect bn)
10293 append lsdir into completions
10294 finally return (if sort (sort completions 'string-lessp) completions)))))
10296 (defun anything-run-or-raise (exe &optional file)
10297 "Generic command that run asynchronously EXE.
10298 If EXE is already running just jump to his window if `anything-raise-command'
10299 is non--nil.
10300 When FILE argument is provided run EXE with FILE.
10301 In this case EXE must be provided as \"EXE %s\"."
10302 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10303 "%s" "" exe))))
10304 (proc (if file (concat real-com " " file) real-com)))
10305 (if (get-process proc)
10306 (if anything-raise-command
10307 (shell-command (format anything-raise-command real-com))
10308 (error "Error: %s is already running" real-com))
10309 (when (loop for i in anything-c-external-commands-list thereis real-com)
10310 (message "Starting %s..." real-com)
10311 (if file
10312 (start-process-shell-command
10313 proc nil (format exe (shell-quote-argument
10314 (if (eq system-type 'windows-nt)
10315 (anything-w32-prepare-filename file)
10316 file))))
10317 (start-process-shell-command proc nil real-com))
10318 (set-process-sentinel
10319 (get-process proc)
10320 #'(lambda (process event)
10321 (when (and (string= event "finished\n")
10322 anything-raise-command
10323 (not (anything-c-get-pid-from-process-name real-com)))
10324 (shell-command (format anything-raise-command "emacs")))
10325 (message "%s process...Finished." process))))
10326 (setq anything-c-external-commands-list
10327 (cons real-com
10328 (delete real-com anything-c-external-commands-list))))))
10332 ;;; Generic action functions
10335 (defun anything-c-file-buffers (filename)
10336 "Returns a list of buffer names corresponding to FILENAME."
10337 (let ((name (expand-file-name filename))
10338 (buf-list ()))
10339 (dolist (buf (buffer-list) buf-list)
10340 (let ((bfn (buffer-file-name buf)))
10341 (when (and bfn (string= name bfn))
10342 (push (buffer-name buf) buf-list))))))
10344 (defun anything-revert-buffer (candidate)
10345 (with-current-buffer candidate
10346 (when (or (buffer-modified-p)
10347 (not (verify-visited-file-modtime
10348 (get-buffer candidate))))
10349 (revert-buffer t t))))
10351 (defun anything-revert-marked-buffers (ignore)
10352 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10354 (defun anything-kill-marked-buffers (ignore)
10355 (mapc 'kill-buffer (anything-marked-candidates)))
10357 (defun anything-c-delete-file (file &optional error-if-dot-file-p)
10358 "Delete the given file after querying the user.
10359 Ask to kill buffers associated with that file, too."
10360 (when (and error-if-dot-file-p
10361 (anything-ff-dot-file-p file))
10362 (error "Error: Cannot operate on `.' or `..'"))
10363 (let ((buffers (anything-c-file-buffers file)))
10364 (if (< emacs-major-version 24)
10365 ;; `dired-delete-file' in Emacs versions < 24
10366 ;; doesn't support delete-by-moving-to-trash
10367 ;; so use `delete-directory' and `delete-file'
10368 ;; that handle it.
10369 (cond ((and (not (file-symlink-p file))
10370 (file-directory-p file)
10371 (directory-files file t dired-re-no-dot))
10372 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10373 (delete-directory file 'recursive)))
10374 ((and (not (file-symlink-p file))
10375 (file-directory-p file))
10376 (delete-directory file))
10377 (t (delete-file file)))
10378 (dired-delete-file
10379 file 'dired-recursive-deletes delete-by-moving-to-trash))
10380 (when buffers
10381 (dolist (buf buffers)
10382 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10383 (kill-buffer buf))))))
10385 (defun anything-get-mailcap-for-file (filename)
10386 "Get the command to use for FILENAME from mailcap files.
10387 The command is like <command %s> and is meant to use with `format'."
10388 (mailcap-parse-mailcaps)
10389 (let* ((ext (file-name-extension filename))
10390 (mime (when ext (mailcap-extension-to-mime ext)))
10391 (result (when mime (mailcap-mime-info mime))))
10392 ;; If elisp file have no associations in .mailcap
10393 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10394 (when (stringp result) result)))
10396 (defun anything-get-default-program-for-file (filename)
10397 "Try to find a default program to open FILENAME.
10398 Try first in `anything-c-external-programs-associations' and then in mailcap file
10399 if nothing found return nil."
10400 (let* ((ext (file-name-extension filename))
10401 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10402 (cond ((and def-prog (not (string= def-prog "")))
10403 (concat def-prog " %s"))
10404 ((and anything-c-default-external-file-browser
10405 (file-directory-p filename))
10406 (concat anything-c-default-external-file-browser " %s"))
10407 (t (anything-get-mailcap-for-file filename)))))
10409 (defun anything-c-open-file-externally (file)
10410 "Open FILE with an external program.
10411 Try to guess which program to use with `anything-get-default-program-for-file'.
10412 If not found or a prefix arg is given query the user which tool to use."
10413 (let* ((fname (expand-file-name file))
10414 (collection (anything-c-external-commands-list-1 'sort))
10415 (def-prog (anything-get-default-program-for-file fname))
10416 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10417 ;; Prefix arg or no default program.
10418 (prog1
10419 (anything-comp-read
10420 "Program: " collection
10421 :must-match t
10422 :name "Open file Externally"
10423 :history anything-external-command-history)
10424 ;; Always prompt to set this program as default.
10425 (setq def-prog nil))
10426 ;; No prefix arg or default program exists.
10427 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10428 (program (concat real-prog-name " %s")))
10429 (unless (or def-prog ; Association exists, no need to record it.
10430 ;; Don't try to record non--filenames associations (e.g urls).
10431 (not (file-exists-p fname)))
10432 (when
10433 (y-or-n-p
10434 (format
10435 "Do you want to make `%s' the default program for this kind of files? "
10436 real-prog-name))
10437 (anything-aif (assoc (file-name-extension fname)
10438 anything-c-external-programs-associations)
10439 (setq anything-c-external-programs-associations
10440 (delete it anything-c-external-programs-associations)))
10441 (push (cons (file-name-extension fname)
10442 (read-string
10443 "Program (Add args maybe and confirm): " real-prog-name))
10444 anything-c-external-programs-associations)
10445 (customize-save-variable 'anything-c-external-programs-associations
10446 anything-c-external-programs-associations)))
10447 (anything-run-or-raise program file)
10448 (setq anything-external-command-history
10449 (cons real-prog-name
10450 (delete real-prog-name
10451 (loop for i in anything-external-command-history
10452 when (executable-find i) collect i))))))
10454 (defun anything-c-find-file-or-marked (candidate)
10455 "Open file CANDIDATE or open anything marked files in background."
10456 (let ((marked (anything-marked-candidates))
10457 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10458 (find-file-wildcards nil))
10459 (if (> (length marked) 1)
10460 ;; Open all marked files in background and display
10461 ;; the first one.
10462 (progn (mapc 'find-file-noselect (cdr marked))
10463 (find-file (car marked)))
10464 (if (and (not (file-exists-p candidate))
10465 (and ffap-url-regexp
10466 (not (string-match ffap-url-regexp candidate)))
10467 (string-match "/$" candidate))
10468 ;; A a non--existing filename ending with /
10469 ;; Create a directory and jump to it.
10470 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10471 (let ((dirfname (directory-file-name candidate)))
10472 (if (file-exists-p dirfname)
10473 (error "Mkdir: Unable to create directory `%s': file exists."
10474 (anything-c-basename dirfname))
10475 (make-directory candidate 'parent)))
10476 (anything-find-files-1 candidate))
10477 ;; A non--existing filename NOT ending with / or
10478 ;; an existing filename, create or jump to it.
10479 (find-file-at-point (car marked))))))
10481 (defun anything-delete-marked-files (ignore)
10482 (let* ((files (anything-marked-candidates))
10483 (len (length files)))
10484 (if (not (y-or-n-p
10485 (format "Delete *%s File(s):\n%s"
10487 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10488 (message "(No deletions performed)")
10489 (dolist (i files)
10490 (set-text-properties 0 (length i) nil i)
10491 (anything-c-delete-file i anything-ff-signal-error-on-dot-files))
10492 (message "%s File(s) deleted" len))))
10494 (defun anything-ediff-marked-buffers (candidate &optional merge)
10495 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10496 With optional arg MERGE call `ediff-merge-buffers'."
10497 (let ((lg-lst (length (anything-marked-candidates)))
10498 buf1 buf2)
10499 (case lg-lst
10501 (error "Error:You have to mark at least 1 buffer"))
10503 (setq buf1 anything-current-buffer
10504 buf2 (first (anything-marked-candidates))))
10506 (setq buf1 (first (anything-marked-candidates))
10507 buf2 (second (anything-marked-candidates))))
10509 (error "Error:To much buffers marked!")))
10510 (if merge
10511 (ediff-merge-buffers buf1 buf2)
10512 (ediff-buffers buf1 buf2))))
10514 (defun anything-ediff-marked-buffers-merge (candidate)
10515 "Ediff merge `anything-current-buffer' with CANDIDATE.
10516 See `anything-ediff-marked-buffers'."
10517 (anything-ediff-marked-buffers candidate t))
10519 (defun anything-bookmark-get-bookmark-from-name (bmk)
10520 "Return bookmark name even if it is a bookmark with annotation.
10521 e.g prepended with *.
10522 Return nil if bmk is not a valid bookmark."
10523 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10524 (if (assoc bookmark bookmark-alist)
10525 bookmark
10526 (when (assoc bmk bookmark-alist)
10527 bmk))))
10529 (defun anything-delete-marked-bookmarks (ignore)
10530 "Delete this bookmark or all marked bookmarks."
10531 (dolist (i (anything-marked-candidates))
10532 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10533 'batch)))
10535 (defun anything-require-or-error (feature function)
10536 (or (require feature nil t)
10537 (error "Need %s to use `%s'." feature function)))
10539 (defun anything-find-buffer-on-elscreen (candidate)
10540 "Open buffer in new screen, if marked buffers open all in elscreens."
10541 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10542 (anything-aif (anything-marked-candidates)
10543 (dolist (i it)
10544 (let ((target-screen (elscreen-find-screen-by-buffer
10545 (get-buffer i) 'create)))
10546 (elscreen-goto target-screen)))
10547 (let ((target-screen (elscreen-find-screen-by-buffer
10548 (get-buffer candidate) 'create)))
10549 (elscreen-goto target-screen))))
10551 (defun anything-elscreen-find-file (file)
10552 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10553 (elscreen-find-file file))
10555 (defun anything-w32-prepare-filename (file)
10556 "Convert filename FILE to something usable by external w32 executables."
10557 (replace-regexp-in-string ; For UNC paths
10558 "/" "\\"
10559 (replace-regexp-in-string ; Strip cygdrive paths
10560 "/cygdrive/\\(.\\)" "\\1:"
10561 file nil nil) nil t))
10563 ;;;###autoload
10564 (defun anything-w32-shell-execute-open-file (file)
10565 (interactive "fOpen file:")
10566 (with-no-warnings
10567 (w32-shell-execute "open" (anything-w32-prepare-filename file))))
10569 (defun anything-c-open-file-with-default-tool (file)
10570 "Open FILE with the default tool on this platform."
10571 (if (eq system-type 'windows-nt)
10572 (anything-w32-shell-execute-open-file file)
10573 (start-process "anything-c-open-file-with-default-tool"
10575 (cond ((eq system-type 'gnu/linux)
10576 "xdg-open")
10577 ((or (eq system-type 'darwin) ;; Mac OS X
10578 (eq system-type 'macos)) ;; Mac OS 9
10579 "open"))
10580 file)))
10582 (defun anything-c-open-dired (file)
10583 "Opens a dired buffer in FILE's directory. If FILE is a
10584 directory, open this directory."
10585 (if (file-directory-p file)
10586 (dired file)
10587 (dired (file-name-directory file))
10588 (dired-goto-file file)))
10590 (defun anything-c-display-to-real-line (candidate)
10591 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10592 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10593 (error "Line number not found")))
10595 (defun anything-c-action-line-goto (lineno-and-content)
10596 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10597 (append lineno-and-content
10598 (list (if (and (anything-attr-defined 'target-file)
10599 (not anything-in-persistent-action))
10600 'find-file-other-window
10601 'find-file)))))
10603 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10604 (apply #'anything-goto-file-line
10605 (if (stringp file-line-content)
10606 ;; Case: filtered-candidate-transformer is skipped
10607 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10608 file-line-content)))
10610 (require 'compile)
10611 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10612 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10614 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10615 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10616 (let ((filename (match-string 1 candidate))
10617 (lineno (match-string 2 candidate))
10618 (content (match-string 3 candidate)))
10619 (cons (format "%s:%s\n %s"
10620 (propertize filename 'face compilation-info-face)
10621 (propertize lineno 'face compilation-line-face)
10622 content)
10623 (list (expand-file-name
10624 filename
10625 (or (anything-interpret-value (anything-attr 'default-directory))
10626 (and (anything-candidate-buffer)
10627 (buffer-local-value
10628 'default-directory (anything-candidate-buffer)))))
10629 (string-to-number lineno) content)))))
10631 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10632 (anything-aif (anything-attr 'before-jump-hook)
10633 (funcall it))
10634 (when file (funcall find-file-function file))
10635 (if (anything-attr-defined 'adjust)
10636 (anything-c-goto-line-with-adjustment lineno content)
10637 (anything-goto-line lineno))
10638 (unless (anything-attr-defined 'recenter)
10639 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10640 (anything-aif (anything-attr 'after-jump-hook)
10641 (funcall it))
10642 (when anything-in-persistent-action
10643 (anything-match-line-color-current-line)))
10645 (defun anything-find-file-as-root (candidate)
10646 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10648 (defun anything-find-many-files (ignore)
10649 (mapc 'find-file (anything-marked-candidates)))
10651 ;; borrowed from etags.el
10652 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10653 (defun anything-c-goto-line-with-adjustment (line line-content)
10654 (let ((startpos)
10655 offset found pat)
10656 ;; This constant is 1/2 the initial search window.
10657 ;; There is no sense in making it too small,
10658 ;; since just going around the loop once probably
10659 ;; costs about as much as searching 2000 chars.
10660 (setq offset 1000
10661 found nil
10662 pat (concat (if (eq selective-display t)
10663 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10664 (regexp-quote line-content)))
10665 ;; If no char pos was given, try the given line number.
10666 (setq startpos (progn (anything-goto-line line) (point)))
10667 (or startpos (setq startpos (point-min)))
10668 ;; First see if the tag is right at the specified location.
10669 (goto-char startpos)
10670 (setq found (looking-at pat))
10671 (while (and (not found)
10672 (progn
10673 (goto-char (- startpos offset))
10674 (not (bobp))))
10675 (setq found
10676 (re-search-forward pat (+ startpos offset) t)
10677 offset (* 3 offset))) ; expand search window
10678 (or found
10679 (re-search-forward pat nil t)
10680 (error "not found")))
10681 ;; Position point at the right place
10682 ;; if the search string matched an extra Ctrl-m at the beginning.
10683 (and (eq selective-display t)
10684 (looking-at "\^m")
10685 (forward-char 1))
10686 (beginning-of-line))
10688 (anything-document-attribute 'default-directory "type . file-line"
10689 "`default-directory' to interpret file.")
10690 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10691 "Function to call before jumping to the target location.")
10692 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10693 "Function to call after jumping to the target location.")
10694 (anything-document-attribute 'adjust "type . file-line"
10695 "Search around line matching line contents.")
10696 (anything-document-attribute 'recenter "type . file-line / line"
10697 "`recenter' after jumping.")
10698 (anything-document-attribute 'target-file "type . line"
10699 "Goto line of target-file.")
10701 ;;;###autoload
10702 (defun anything-c-call-interactively (cmd-or-name)
10703 "Execute CMD-OR-NAME as Emacs command.
10704 It is added to `extended-command-history'.
10705 `anything-current-prefix-arg' is used as the command's prefix argument."
10706 (setq extended-command-history
10707 (cons (anything-c-stringify cmd-or-name)
10708 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10709 (let ((current-prefix-arg anything-current-prefix-arg)
10710 (cmd (anything-c-symbolify cmd-or-name)))
10711 (if (stringp (symbol-function cmd))
10712 (execute-kbd-macro (symbol-function cmd))
10713 (setq this-command cmd)
10714 (call-interactively cmd))))
10716 ;;;###autoload
10717 (defun anything-c-set-variable (var)
10718 "Set value to VAR interactively."
10719 (interactive)
10720 (let ((sym (anything-c-symbolify var)))
10721 (set sym (eval-minibuffer (format "Set %s: " var)
10722 (prin1-to-string (symbol-value sym))))))
10723 ;; (setq hh 12)
10724 ;; (anything-c-set-variable 'hh)
10728 ;;; Persistent Action Helpers
10731 (defvar anything-match-line-overlay-face nil)
10732 (defvar anything-match-line-overlay nil)
10734 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10735 "Highlight and underline current position"
10736 (let ((args (list (or start (line-beginning-position))
10737 (or end (1+ (line-end-position)))
10738 buf)))
10739 (if (not anything-match-line-overlay)
10740 (setq anything-match-line-overlay (apply 'make-overlay args))
10741 (apply 'move-overlay anything-match-line-overlay args)))
10742 (overlay-put anything-match-line-overlay
10743 'face (or face anything-match-line-overlay-face))
10744 (when rec
10745 (goto-char start)
10746 (recenter)))
10748 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10751 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10753 (defun anything-match-line-cleanup ()
10754 (when anything-match-line-overlay
10755 (delete-overlay anything-match-line-overlay)
10756 (setq anything-match-line-overlay nil)))
10758 (defun anything-match-line-update ()
10759 (when anything-match-line-overlay
10760 (delete-overlay anything-match-line-overlay)
10761 (anything-match-line-color-current-line)))
10763 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10764 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10767 ;;; Actions Transformers
10770 ;;; Files
10771 (defun anything-c-transform-file-load-el (actions candidate)
10772 "Add action to load the file CANDIDATE if it is an emacs lisp
10773 file. Else return ACTIONS unmodified."
10774 (if (member (file-name-extension candidate) '("el" "elc"))
10775 (append actions '(("Load Emacs Lisp File" . load-file)))
10776 actions))
10778 (defun anything-c-transform-file-browse-url (actions candidate)
10779 "Add an action to browse the file CANDIDATE if it in a html
10780 file or URL. Else return ACTIONS unmodified."
10781 (let ((browse-action '("Browse with Browser" . browse-url)))
10782 (cond ((string-match "^http\\|^ftp" candidate)
10783 (cons browse-action actions))
10784 ((string-match "\\.html?$" candidate)
10785 (append actions (list browse-action)))
10786 (t actions))))
10788 ;;; Function
10789 (defun anything-c-transform-function-call-interactively (actions candidate)
10790 "Add an action to call the function CANDIDATE interactively if
10791 it is a command. Else return ACTIONS unmodified."
10792 (if (commandp (intern-soft candidate))
10793 (append actions '(("Call Interactively"
10795 anything-c-call-interactively)))
10796 actions))
10798 ;;;; S-Expressions
10799 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10800 "If CANDIDATE's `car' is a command, then add an action to
10801 evaluate it and put it onto the `command-history'."
10802 (if (commandp (car (read candidate)))
10803 ;; Make it first entry
10804 (cons '("Eval and put onto command-history" .
10805 (lambda (sexp)
10806 (let ((sym (read sexp)))
10807 (eval sym)
10808 (setq command-history
10809 (cons sym command-history)))))
10810 actions)
10811 actions))
10814 ;;; Candidate Transformers
10817 ;;; Buffers
10818 (defun anything-c-skip-boring-buffers (buffers)
10819 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10821 (defun anything-c-skip-current-buffer (buffers)
10822 (if anything-allow-skipping-current-buffer
10823 (remove (buffer-name anything-current-buffer) buffers)
10824 buffers))
10826 (defun anything-c-shadow-boring-buffers (buffers)
10827 "Buffers matching `anything-c-boring-buffer-regexp' will be
10828 displayed with the `file-name-shadow' face if available."
10829 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10831 (defvar anything-c-buffer-display-string-functions
10832 '(anything-c-buffer-display-string--compilation
10833 anything-c-buffer-display-string--shell
10834 anything-c-buffer-display-string--eshell)
10835 "Functions to setup display string for buffer.
10837 Function has one argument, buffer name.
10838 If it returns string, use it.
10839 If it returns nil, display buffer name.
10840 See `anything-c-buffer-display-string--compilation' for example.")
10842 (defun anything-c-transform-buffer-display-string (buffers)
10843 "Setup display string for buffer candidates
10844 using `anything-c-buffer-display-string-functions'."
10845 (loop for buf in buffers
10846 if (consp buf)
10847 collect buf
10848 else
10849 for disp = (progn (set-buffer buf)
10850 (run-hook-with-args-until-success
10851 'anything-c-buffer-display-string-functions buf))
10852 collect (if disp (cons disp buf) buf)))
10854 (defun anything-c-buffer-display-string--compilation (buf)
10855 (anything-aif (car compilation-arguments)
10856 (format "%s: %s [%s]" buf it default-directory)))
10858 (defun anything-c-buffer-display-string--eshell (buf)
10859 (declare (special eshell-history-ring))
10860 (when (eq major-mode 'eshell-mode)
10861 (format "%s: %s [%s]" buf
10862 (ignore-errors (ring-ref eshell-history-ring 0))
10863 default-directory)))
10865 (defun anything-c-buffer-display-string--shell (buf)
10866 (when (eq major-mode 'shell-mode)
10867 (format "%s: %s [%s]" buf
10868 (ignore-errors (ring-ref comint-input-ring 0))
10869 default-directory)))
10871 ;;; Files
10872 (defun anything-c-shadow-boring-files (files)
10873 "Files matching `anything-c-boring-file-regexp' will be
10874 displayed with the `file-name-shadow' face if available."
10875 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10877 (defun anything-c-skip-boring-files (files)
10878 "Files matching `anything-c-boring-file-regexp' will be skipped."
10879 (anything-c-skip-entries files anything-c-boring-file-regexp))
10880 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10882 (defun anything-c-skip-current-file (files)
10883 "Current file will be skipped."
10884 (remove (buffer-file-name anything-current-buffer) files))
10886 (defun anything-c-w32-pathname-transformer (args)
10887 "Change undesirable features of windows pathnames to ones more acceptable to
10888 other candidate transformers."
10889 (if (eq system-type 'windows-nt)
10890 (mapcar (lambda (x)
10891 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10892 (mapcar (lambda (y)
10893 (replace-regexp-in-string "\\\\" "/" y)) args))
10894 args))
10896 (defun anything-c-shorten-home-path (files)
10897 "Replaces /home/user with ~."
10898 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10899 (getenv "HOME"))))
10900 (mapcar (lambda (file)
10901 (if (and (stringp file) (string-match home file))
10902 (cons (replace-match "~" nil nil file) file)
10903 file))
10904 files)))
10906 ;;; Functions
10907 (defun anything-c-mark-interactive-functions (functions)
10908 "Mark interactive functions (commands) with (i) after the function name."
10909 (let (list)
10910 (loop for function in functions
10911 do (push (cons (concat function
10912 (when (commandp (intern-soft function)) " (i)"))
10913 function)
10914 list)
10915 finally (return (nreverse list)))))
10918 ;;; Adaptive Sorting of Candidates
10921 ;; Internal
10922 (defvar anything-c-adaptive-done nil
10923 "nil if history information is not yet stored for the current
10924 selection.")
10926 (defvar anything-c-adaptive-history nil
10927 "Contains the stored history information.
10928 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10930 ;; Should run at beginning of `anything-initial-setup'.
10931 (add-hook 'anything-before-initialize-hook #'(lambda ()
10932 (when anything-c-use-adaptative-sorting
10933 (setq anything-c-adaptive-done nil))))
10935 ;; Should run at beginning of `anything-exit-minibuffer'.
10936 (add-hook 'anything-before-action-hook #'(lambda ()
10937 (when anything-c-use-adaptative-sorting
10938 (anything-c-adaptive-store-selection))))
10940 ;; Should run at beginning of `anything-select-action'.
10941 (add-hook 'anything-select-action-hook #'(lambda ()
10942 (when anything-c-use-adaptative-sorting
10943 (anything-c-adaptive-store-selection))))
10945 (defun anything-c-source-use-adaptative-p (&optional source-name)
10946 "Return current source only if it use adaptative history, nil otherwise."
10947 (when anything-c-use-adaptative-sorting
10948 (let* ((source (or source-name (anything-get-current-source)))
10949 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10950 (assoc (assoc-default 'type source)
10951 anything-type-attributes))
10952 (assoc-default 'candidate-transformer
10953 (assoc (assoc-default 'type source)
10954 anything-type-attributes))
10955 (assoc-default 'filtered-candidate-transformer source)
10956 (assoc-default 'candidate-transformer source))))
10957 (if (listp adapt-source)
10958 (when (member 'anything-c-adaptive-sort adapt-source) source)
10959 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10961 (defun anything-c-adaptive-store-selection ()
10962 "Store history information for the selected candidate."
10963 (unless anything-c-adaptive-done
10964 (setq anything-c-adaptive-done t)
10965 (let ((source (anything-c-source-use-adaptative-p)))
10966 (when source
10967 (let* ((source-name (or (assoc-default 'type source)
10968 (assoc-default 'name source)))
10969 (source-info (or (assoc source-name anything-c-adaptive-history)
10970 (progn
10971 (push (list source-name) anything-c-adaptive-history)
10972 (car anything-c-adaptive-history))))
10973 (selection (anything-get-selection))
10974 (selection-info (progn
10975 (setcdr source-info
10976 (cons
10977 (let ((found (assoc selection (cdr source-info))))
10978 (if (not found)
10979 ;; new entry
10980 (list selection)
10982 ;; move entry to the beginning of the
10983 ;; list, so that it doesn't get
10984 ;; trimmed when the history is
10985 ;; truncated
10986 (setcdr source-info
10987 (delete found (cdr source-info)))
10988 found))
10989 (cdr source-info)))
10990 (cadr source-info)))
10991 (pattern-info (progn
10992 (setcdr selection-info
10993 (cons
10994 (let ((found (assoc anything-pattern (cdr selection-info))))
10995 (if (not found)
10996 ;; new entry
10997 (cons anything-pattern 0)
10999 ;; move entry to the beginning of the
11000 ;; list, so if two patterns used the
11001 ;; same number of times then the one
11002 ;; used last appears first in the list
11003 (setcdr selection-info
11004 (delete found (cdr selection-info)))
11005 found))
11006 (cdr selection-info)))
11007 (cadr selection-info))))
11009 ;; increase usage count
11010 (setcdr pattern-info (1+ (cdr pattern-info)))
11012 ;; truncate history if needed
11013 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
11014 (setcdr selection-info
11015 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
11017 (defun anything-c-adaptative-maybe-load-history ()
11018 (when (and anything-c-use-adaptative-sorting
11019 (file-readable-p anything-c-adaptive-history-file))
11020 (load-file anything-c-adaptive-history-file)))
11022 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
11023 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
11025 (defun anything-c-adaptive-save-history (&optional arg)
11026 "Save history information to file given by `anything-c-adaptive-history-file'."
11027 (interactive "p")
11028 (when anything-c-use-adaptative-sorting
11029 (with-temp-buffer
11030 (insert
11031 ";; -*- mode: emacs-lisp -*-\n"
11032 ";; History entries used for anything adaptive display.\n")
11033 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
11034 (current-buffer))
11035 (insert ?\n)
11036 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11037 (unless arg 'quiet)))))
11039 (defun anything-c-adaptive-sort (candidates source)
11040 "Sort the CANDIDATES for SOURCE by usage frequency.
11041 This is a filtered candidate transformer you can use for the
11042 attribute `filtered-candidate-transformer' of a source in
11043 `anything-sources' or a type in `anything-type-attributes'."
11044 (let* ((source-name (or (assoc-default 'type source)
11045 (assoc-default 'name source)))
11046 (source-info (assoc source-name anything-c-adaptive-history)))
11047 (if source-info
11048 (let ((usage
11049 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11050 ;; pairs
11051 (mapcar (lambda (candidate-info)
11052 (let ((count 0))
11053 (dolist (pattern-info (cdr candidate-info))
11054 (if (not (equal (car pattern-info)
11055 anything-pattern))
11056 (incf count (cdr pattern-info))
11058 ;; if current pattern is equal to the previously
11059 ;; used one then this candidate has priority
11060 ;; (that's why its count is boosted by 10000) and
11061 ;; it only has to compete with other candidates
11062 ;; which were also selected with the same pattern
11063 (setq count (+ 10000 (cdr pattern-info)))
11064 (return)))
11065 (cons (car candidate-info) count)))
11066 (cdr source-info)))
11067 sorted)
11068 (if (and usage (consp usage))
11069 ;; sort the list in descending order, so candidates with highest
11070 ;; priorty come first
11071 (progn
11072 (setq usage (sort usage (lambda (first second)
11073 (> (cdr first) (cdr second)))))
11075 ;; put those candidates first which have the highest usage count
11076 (dolist (info usage)
11077 (when (member* (car info) candidates
11078 :test 'anything-c-adaptive-compare)
11079 (push (car info) sorted)
11080 (setq candidates (remove* (car info) candidates
11081 :test 'anything-c-adaptive-compare))))
11083 ;; and append the rest
11084 (append (reverse sorted) candidates nil))
11085 (message "Your `%s' is maybe corrupted or too old, \
11086 you should reinitialize it with `anything-c-reset-adaptative-history'"
11087 anything-c-adaptive-history-file)
11088 (sit-for 1)
11089 candidates))
11090 ;; if there is no information stored for this source then do nothing
11091 candidates)))
11093 ;;;###autoload
11094 (defun anything-c-reset-adaptative-history ()
11095 "Delete all `anything-c-adaptive-history' and his file.
11096 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11097 (interactive)
11098 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11099 (setq anything-c-adaptive-history nil)
11100 (delete-file anything-c-adaptive-history-file)))
11102 (defun anything-c-adaptive-compare (x y)
11103 "Compare candidates X and Y taking into account that the
11104 candidate can be in (DISPLAY . REAL) format."
11105 (equal (if (listp x)
11106 (cdr x)
11108 (if (listp y)
11109 (cdr y)
11110 y)))
11114 ;;; Outliner
11117 (defvar anything-outline-goto-near-line-flag t)
11118 (defvar anything-outline-using nil)
11119 (defun anything-after-update-hook--outline ()
11120 (if (and (eq anything-outline-using t)
11121 (eq anything-outline-goto-near-line-flag t))
11122 (anything-outline-goto-near-line)))
11123 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11125 (defun anything-outline-goto-near-line ()
11126 (with-anything-window
11127 ;; TODO need consideration whether to update position by every input.
11128 (when t ; (equal anything-pattern "")
11129 (anything-goto-line 2)
11130 (let ((lineno (with-anything-current-buffer
11131 (line-number-at-pos (car anything-current-position)))))
11132 (block exit
11133 (while (<= (progn (skip-chars-forward " ")
11134 (or (number-at-point) lineno))
11135 lineno)
11136 (forward-line 1)
11137 (when (eobp)
11138 (forward-line -1)
11139 (return-from exit))))
11140 (forward-line -1)
11141 (and (bobp) (forward-line 1))
11142 (and (anything-pos-header-line-p) (forward-line -2))
11143 (anything-mark-current-line)))))
11147 ;;; Plug-in
11150 ;; Plug-in: info-index
11151 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11152 (let (result)
11153 (unless (anything-candidate-buffer)
11154 (save-window-excursion
11155 (info file)
11156 (let (Info-history
11157 (tobuf (anything-candidate-buffer 'global))
11158 (infobuf (current-buffer))
11159 s e)
11160 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11161 (Info-goto-node node)
11162 (goto-char (point-min))
11163 (while (search-forward "\n* " nil t)
11164 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11165 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11166 (setq s (point-at-bol)
11167 e (point-at-eol))
11168 (with-current-buffer tobuf
11169 (insert-buffer-substring infobuf s e)
11170 (insert "\n"))))))))))
11172 (defun anything-c-info-goto (node-line)
11173 (Info-goto-node (car node-line))
11174 (anything-goto-line (cdr node-line)))
11176 (defun anything-c-info-display-to-real (line)
11177 (and (string-match
11178 ;; This regexp is stolen from Info-apropos-matches
11179 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11180 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11181 (string-to-number (or (match-string 3 line) "1")))))
11183 (defun anything-c-make-info-source (source file)
11184 `(,@source
11185 (name . ,(concat "Info Index: " file))
11186 (info-file . ,file)
11187 (init . anything-c-info-init)
11188 (display-to-real . anything-c-info-display-to-real)
11189 (get-line . buffer-substring)
11190 (candidates-in-buffer)
11191 (action ("Goto node" . anything-c-info-goto))))
11193 (defun anything-compile-source--info-index (source)
11194 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11195 (anything-c-make-info-source source it)
11196 source))
11197 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11199 (anything-document-attribute 'info-index "info-index plugin"
11200 "Create a source of info index very easily.
11202 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11204 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11205 "Index nodes of info file.
11207 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11208 Some info files are missing index specification.
11210 ex. See `anything-c-source-info-screen'.")
11212 ;; Plug-in: candidates-file
11213 (defun anything-compile-source--candidates-file (source)
11214 (if (assoc-default 'candidates-file source)
11215 `((init anything-p-candidats-file-init
11216 ,@(let ((orig-init (assoc-default 'init source)))
11217 (cond ((null orig-init) nil)
11218 ((functionp orig-init) (list orig-init))
11219 (t orig-init))))
11220 (candidates-in-buffer)
11221 ,@source)
11222 source))
11223 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11225 (defun anything-p-candidats-file-init ()
11226 (destructuring-bind (file &optional updating)
11227 (anything-mklist (anything-attr 'candidates-file))
11228 (setq file (anything-interpret-value file))
11229 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11230 (when updating
11231 (buffer-disable-undo)
11232 (font-lock-mode -1)
11233 (auto-revert-mode 1)))))
11235 (anything-document-attribute 'candidates-file "candidates-file plugin"
11236 "Use a file as the candidates buffer.
11238 1st argument is a filename, string or function name or variable name.
11239 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11241 ;; Plug-in: headline
11242 (defun anything-compile-source--anything-headline (source)
11243 (if (assoc-default 'headline source)
11244 (append '((init . anything-headline-init)
11245 (get-line . buffer-substring)
11246 (type . line))
11247 source
11248 '((candidates-in-buffer)
11249 (persistent-help . "Show this line")))
11250 source))
11251 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11253 (defun anything-headline-init ()
11254 (when (and (anything-current-buffer-is-modified)
11255 (with-anything-current-buffer
11256 (eval (or (anything-attr 'condition) t))))
11257 (anything-headline-make-candidate-buffer
11258 (anything-interpret-value (anything-attr 'headline))
11259 (anything-interpret-value (anything-attr 'subexp)))))
11261 (anything-document-attribute 'headline "Headline plug-in"
11262 "Regexp string for anything-headline to scan.")
11263 (anything-document-attribute 'condition "Headline plug-in"
11264 "A sexp representing the condition to use anything-headline.")
11265 (anything-document-attribute 'subexp "Headline plug-in"
11266 "Display (match-string-no-properties subexp).")
11268 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11269 ;; of regexps.
11271 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11272 ;; 2. Sort this list by start-of-match.
11273 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11275 ;; It's quite brilliantly written.
11279 (defun anything-headline-get-candidates (regexp subexp)
11280 (with-anything-current-buffer
11281 (save-excursion
11282 (goto-char (point-min))
11283 (if (functionp regexp) (setq regexp (funcall regexp)))
11284 (let (hierarchy curhead)
11285 (flet ((matched ()
11286 (if (numberp subexp)
11287 (cons (match-string-no-properties subexp) (match-beginning subexp))
11288 (cons (buffer-substring (point-at-bol) (point-at-eol))
11289 (point-at-bol))))
11290 (hierarchies (headlines)
11291 (1+ (loop for (_ . hierarchy) in headlines
11292 maximize hierarchy)))
11293 (vector-0-n (v n)
11294 (loop for i from 0 to hierarchy
11295 collecting (aref curhead i)))
11296 (arrange (headlines)
11297 (unless (null headlines) ; FIX headlines empty bug!
11298 (loop with curhead = (make-vector (hierarchies headlines) "")
11299 for ((str . pt) . hierarchy) in headlines
11300 do (aset curhead hierarchy str)
11301 collecting
11302 (cons
11303 (format "H%d:%s" (1+ hierarchy)
11304 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11305 pt)))))
11306 (if (listp regexp)
11307 (arrange
11308 (sort
11309 (loop for re in regexp
11310 for hierarchy from 0
11311 do (goto-char (point-min))
11312 appending
11313 (loop
11314 while (re-search-forward re nil t)
11315 collect (cons (matched) hierarchy)))
11316 (lambda (a b) (> (cdar b) (cdar a)))))
11317 (loop while (re-search-forward regexp nil t)
11318 collect (matched))))))))
11321 (defun anything-headline-make-candidate-buffer (regexp subexp)
11322 (with-current-buffer (anything-candidate-buffer 'local)
11323 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11324 do (insert
11325 (format "%5d:%s\n"
11326 (with-anything-current-buffer
11327 (line-number-at-pos pos))
11328 content)))))
11330 (defun anything-headline-goto-position (pos recenter)
11331 (goto-char pos)
11332 (unless recenter
11333 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11336 ;; Plug-in: persistent-help
11337 (defun anything-compile-source--persistent-help (source)
11338 (append source '((header-line . anything-persistent-help-string))))
11339 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11341 (defun anything-persistent-help-string ()
11342 (substitute-command-keys
11343 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11344 (or (anything-interpret-value (anything-attr 'persistent-help))
11345 (anything-aif (or (assoc-default 'persistent-action
11346 (anything-get-current-source))
11347 (assoc-default 'action
11348 (anything-get-current-source)))
11349 (cond ((symbolp it) (symbol-name it))
11350 ((listp it) (or (ignore-errors (caar it)) ""))))
11352 " (keeping session)")))
11354 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11355 "A string to explain persistent-action of this source.
11356 It also accepts a function or a variable name.")
11358 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11360 ;; Plug-in: Type customize
11361 (defun anything-c-uniq-list (lst)
11362 "Like `remove-duplicates' in CL.
11363 But cut deeper duplicates and test by `equal'. "
11364 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11365 (defvar anything-additional-type-attributes nil)
11366 (defun anything-c-arrange-type-attribute (type spec)
11367 "Override type attributes by `define-anything-type-attribute'.
11369 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11371 Example: Set `play-sound-file' as default action
11372 (anything-c-arrange-type-attribute 'file
11373 '((action (\"Play sound\" . play-sound-file)
11374 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11377 (add-to-list 'anything-additional-type-attributes
11378 (cons type
11379 (loop with typeattr = (assoc-default type anything-type-attributes)
11380 for (attr . value) in spec
11381 if (listp value)
11382 collect (cons attr
11383 (anything-c-uniq-list
11384 (loop for v in value
11385 if (eq v 'REST)
11386 append (assoc-default attr typeattr)
11387 else
11388 collect v)))
11389 else
11390 collect (cons attr value)))))
11391 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11393 (defun anything-compile-source--type-customize (source)
11394 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11395 (append it source)
11396 source))
11397 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11399 ;; Plug-in: default-action
11400 (defun anything-compile-source--default-action (source)
11401 (anything-aif (assoc-default 'default-action source)
11402 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11403 source)
11404 source))
11405 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11406 (anything-document-attribute 'default-action "default-action plug-in"
11407 "Default action.")
11410 ;;; Toggle anything-match-plugin
11413 (defvar anything-mp-initial-highlight-delay nil)
11415 ;;;###autoload
11416 (defun anything-c-toggle-match-plugin ()
11417 "Toggle anything-match-plugin."
11418 (interactive)
11419 (let ((anything-match-plugin-enabled
11420 (member 'anything-compile-source--match-plugin
11421 anything-compile-source-functions)))
11422 (flet ((disable-match-plugin ()
11423 (setq anything-compile-source-functions
11424 (delq 'anything-compile-source--match-plugin
11425 anything-compile-source-functions))
11426 (setq anything-mp-initial-highlight-delay
11427 anything-mp-highlight-delay)
11428 (setq anything-mp-highlight-delay nil))
11429 (enable-match-plugin ()
11430 (require 'anything-match-plugin)
11431 (unless anything-mp-initial-highlight-delay
11432 (setq anything-mp-initial-highlight-delay
11433 anything-mp-highlight-delay))
11434 (setq anything-compile-source-functions
11435 (cons 'anything-compile-source--match-plugin
11436 anything-compile-source-functions))
11437 (unless anything-mp-highlight-delay
11438 (setq anything-mp-highlight-delay
11439 anything-mp-initial-highlight-delay))))
11440 (if anything-match-plugin-enabled
11441 (when (y-or-n-p "Really disable match-plugin? ")
11442 (disable-match-plugin)
11443 (message "Anything-match-plugin disabled"))
11444 (when (y-or-n-p "Really enable match-plugin? ")
11445 (enable-match-plugin)
11446 (message "Anything-match-plugin enabled"))))))
11450 ;;; Type Attributes
11453 (define-anything-type-attribute 'buffer
11454 `((action
11455 ("Switch to buffer" . anything-c-switch-to-buffer)
11456 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11457 ("Switch to buffer other window" . switch-to-buffer-other-window)
11458 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11459 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11460 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11461 ("Query replace" . anything-c-buffer-query-replace)
11462 ("View buffer" . view-buffer)
11463 ("Display buffer" . display-buffer)
11464 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11465 ("Revert buffer(s)" . anything-revert-marked-buffers)
11466 ("Insert buffer" . insert-buffer)
11467 ("Kill buffer(s)" . anything-kill-marked-buffers)
11468 ("Diff with file" . diff-buffer-with-file)
11469 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11470 ("Ediff Merge marked buffers" . (lambda (candidate)
11471 (anything-ediff-marked-buffers candidate t))))
11472 (persistent-help . "Show this buffer")
11473 (candidate-transformer anything-c-skip-current-buffer
11474 anything-c-skip-boring-buffers
11475 anything-c-transform-buffer-display-string))
11476 "Buffer or buffer name.")
11478 (define-anything-type-attribute 'file
11479 `((action
11480 ("Find file" . anything-find-many-files)
11481 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11482 ("Find file as root" . anything-find-file-as-root)
11483 ("Find file other window" . find-file-other-window)
11484 ("Find file other frame" . find-file-other-frame)
11485 ("Open dired in file's directory" . anything-c-open-dired)
11486 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11487 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11488 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11489 ("Checksum File" . anything-ff-checksum)
11490 ("Ediff File" . anything-find-files-ediff-files)
11491 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11492 ("View file" . view-file)
11493 ("Insert file" . insert-file)
11494 ("Delete file(s)" . anything-delete-marked-files)
11495 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11496 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11497 ("Find file in hex dump" . hexl-find-file))
11498 (persistent-help . "Show this file")
11499 (action-transformer anything-c-transform-file-load-el
11500 anything-c-transform-file-browse-url)
11501 (candidate-transformer anything-c-w32-pathname-transformer
11502 anything-c-skip-current-file
11503 anything-c-skip-boring-files
11504 anything-c-shorten-home-path))
11505 "File name.")
11507 (let ((actions '(("Describe command" . describe-function)
11508 ("Add command to kill ring" . anything-c-kill-new)
11509 ("Go to command's definition" . find-function)
11510 ("Debug on entry" . debug-on-entry)
11511 ("Cancel debug on entry" . cancel-debug-on-entry)
11512 ("Trace function" . trace-function)
11513 ("Trace function (background)" . trace-function-background)
11514 ("Untrace function" . untrace-function))))
11515 (define-anything-type-attribute 'command
11516 `((action ("Call interactively" . anything-c-call-interactively)
11517 ,@actions)
11518 ;; Sort commands according to their usage count.
11519 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11520 (coerce . anything-c-symbolify)
11521 (persistent-action . describe-function))
11522 "Command. (string or symbol)")
11524 (define-anything-type-attribute 'function
11525 `((action . ,actions)
11526 (action-transformer anything-c-transform-function-call-interactively)
11527 (candidate-transformer anything-c-mark-interactive-functions)
11528 (coerce . anything-c-symbolify))
11529 "Function. (string or symbol)"))
11531 (define-anything-type-attribute 'variable
11532 '((action ("Describe variable" . describe-variable)
11533 ("Add variable to kill ring" . anything-c-kill-new)
11534 ("Go to variable's definition" . find-variable)
11535 ("Set variable" . anything-c-set-variable))
11536 (coerce . anything-c-symbolify))
11537 "Variable.")
11539 (define-anything-type-attribute 'sexp
11540 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11541 ("Add s-expression to kill ring" . kill-new))
11542 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11543 "String representing S-Expressions.")
11545 (define-anything-type-attribute 'bookmark
11546 `((coerce . anything-bookmark-get-bookmark-from-name)
11547 (action
11548 ("Jump to bookmark" . (lambda (bookmark)
11549 (let ((current-prefix-arg anything-current-prefix-arg))
11550 (bookmark-jump bookmark))
11551 (anything-update)))
11552 ("Jump to BM other window" . (lambda (bookmark)
11553 (bookmark-jump-other-window bookmark)
11554 (anything-update)))
11555 ("Bookmark edit annotation" . bookmark-edit-annotation)
11556 ("Bookmark show annotation" . bookmark-show-annotation)
11557 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11558 ,@(and (locate-library "bookmark-extensions")
11559 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11560 ("Rename bookmark" . bookmark-rename)
11561 ("Relocate bookmark" . bookmark-relocate)))
11562 "Bookmark name.")
11564 (define-anything-type-attribute 'line
11565 '((display-to-real . anything-c-display-to-real-line)
11566 (action ("Go to Line" . anything-c-action-line-goto)))
11567 "LINENO:CONTENT string, eg. \" 16:foo\".
11569 Optional `target-file' attribute is a name of target file.
11571 Optional `before-jump-hook' attribute is a function with no
11572 arguments which is called before jumping to position.
11574 Optional `after-jump-hook' attribute is a function with no
11575 arguments which is called after jumping to position.
11577 If `adjust' attribute is specified, searches the line whose
11578 content is CONTENT near the LINENO.
11580 If `recenter' attribute is specified, the line is displayed at
11581 the center of window, otherwise at the top of window.
11584 (define-anything-type-attribute 'file-line
11585 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11586 (multiline)
11587 (action ("Go to" . anything-c-action-file-line-goto)))
11588 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11590 Optional `default-directory' attribute is a default-directory
11591 FILENAME is interpreted.
11593 Optional `before-jump-hook' attribute is a function with no
11594 arguments which is called before jumping to position.
11596 Optional `after-jump-hook' attribute is a function with no
11597 arguments which is called after jumping to position.
11599 If `adjust' attribute is specified, searches the line whose
11600 content is CONTENT near the LINENO.
11602 If `recenter' attribute is specified, the line is displayed at
11603 the center of window, otherwise at the top of window.
11606 (define-anything-type-attribute 'timer
11607 '((real-to-display . anything-c-timer-real-to-display)
11608 (action ("Cancel Timer" . cancel-timer)
11609 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11610 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11611 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11612 (persistent-help . "Describe Function"))
11613 "Timer.")
11616 ;;; Default `anything-sources'
11617 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11618 ;; tend to invoke M-x anything directly. So I offer default setting.
11619 (setq anything-sources
11620 '(anything-c-source-buffers-list
11621 anything-c-source-recentf
11622 anything-c-source-files-in-current-dir+))
11625 ;;; Preconfigured Anything
11628 ;;;###autoload
11629 (defun anything-mini ()
11630 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11631 (interactive)
11632 (anything-other-buffer '(anything-c-source-buffers-list
11633 anything-c-source-recentf
11634 anything-c-source-buffer-not-found)
11635 "*anything mini*"))
11636 ;;;###autoload
11637 (defun anything-for-files ()
11638 "Preconfigured `anything' for opening files.
11639 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11640 (interactive)
11641 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11643 ;;;###autoload
11644 (defun anything-recentf ()
11645 "Preconfigured `anything' for `recentf'."
11646 (interactive)
11647 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11649 ;;;###autoload
11650 (defun anything-info-at-point (arg)
11651 "Preconfigured `anything' for searching info at point.
11652 With a prefix-arg insert symbol at point."
11653 (interactive "P")
11654 (let ((anything-c-google-suggest-default-function
11655 'anything-c-google-suggest-emacs-lisp))
11656 (anything :sources '(anything-c-source-info-elisp
11657 anything-c-source-info-cl
11658 anything-c-source-info-pages
11659 anything-c-source-google-suggest)
11660 :input (and arg (thing-at-point 'symbol))
11661 :buffer "*anything info*")))
11663 ;;;###autoload
11664 (defun anything-info-emacs ()
11665 "Preconfigured anything for Emacs manual index."
11666 (interactive)
11667 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11669 ;;;###autoload
11670 (defun anything-show-kill-ring ()
11671 "Preconfigured `anything' for `kill-ring'.
11672 It is drop-in replacement of `yank-pop'.
11673 You may bind this command to M-y.
11674 First call open the kill-ring browser, next calls move to next line."
11675 (interactive)
11676 (let ((buf "*anything kill-ring*"))
11677 (if (get-buffer-window buf)
11678 (with-anything-window
11679 (if (eq (overlay-end anything-selection-overlay) (point-max))
11680 (anything-beginning-of-buffer)
11681 (anything-next-line)))
11682 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11684 ;;;###autoload
11685 (defun anything-minibuffer-history ()
11686 "Preconfigured `anything' for `minibuffer-history'."
11687 (interactive)
11688 (let ((enable-recursive-minibuffers t))
11689 (anything-other-buffer 'anything-c-source-minibuffer-history
11690 "*anything minibuffer-history*")))
11692 ;;;###autoload
11693 (defun anything-gentoo ()
11694 "Preconfigured `anything' for gentoo linux."
11695 (interactive)
11696 (anything-other-buffer '(anything-c-source-gentoo
11697 anything-c-source-use-flags)
11698 "*anything gentoo*"))
11700 ;;;###autoload
11701 (defun anything-imenu ()
11702 "Preconfigured `anything' for `imenu'."
11703 (interactive)
11704 (anything :sources 'anything-c-source-imenu
11705 :buffer "*anything imenu*"))
11707 ;;;###autoload
11708 (defun anything-google-suggest ()
11709 "Preconfigured `anything' for google search with google suggest."
11710 (interactive)
11711 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11713 ;;;###autoload
11714 (defun anything-yahoo-suggest ()
11715 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11716 (interactive)
11717 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11719 ;;; Converted from anything-show-*-only
11720 ;;;###autoload
11721 (defun anything-for-buffers ()
11722 "Preconfigured `anything' for buffer."
11723 (interactive)
11724 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11726 ;;;###autoload
11727 (defun anything-buffers-list ()
11728 "Enhanced preconfigured `anything' for buffer."
11729 (interactive)
11730 (anything :sources '(anything-c-source-buffers-list
11731 anything-c-source-buffer-not-found)
11732 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11733 (defalias 'anything-buffers+ 'anything-buffer-list)
11734 ;;;###autoload
11735 (defun anything-bbdb ()
11736 "Preconfigured `anything' for BBDB.
11738 Needs BBDB.
11740 http://bbdb.sourceforge.net/"
11741 (interactive)
11742 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11744 ;;;###autoload
11745 (defun anything-locate (arg)
11746 "Preconfigured `anything' for Locate.
11747 Note: you can add locate options after entering pattern.
11748 See 'man locate' for valid options.
11750 You can specify a specific database with prefix argument ARG \(C-u\).
11751 Many databases can be used: navigate and mark them.
11752 See also `anything-locate-with-db'.
11754 To create a user specific db, use
11755 \"updatedb -l 0 -o db_path -U directory\".
11756 Where db_path is a filename matched by
11757 `anything-locate-db-file-regexp'."
11758 (interactive "P")
11759 (anything-locate-1 arg))
11761 ;;;###autoload
11762 (defun anything-w3m-bookmarks ()
11763 "Preconfigured `anything' for w3m bookmark.
11765 Needs w3m and emacs-w3m.
11767 http://w3m.sourceforge.net/
11768 http://emacs-w3m.namazu.org/"
11769 (interactive)
11770 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11771 "*anything w3m bookmarks*"))
11773 ;;;###autoload
11774 (defun anything-firefox-bookmarks ()
11775 "Preconfigured `anything' for firefox bookmark.
11776 You will have to enable html bookmarks in firefox:
11777 open about:config in firefox and double click on this line to enable value \
11778 to true:
11780 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11782 You should have now:
11784 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11786 After closing firefox, you will be able to browse you bookmarks.
11788 (interactive)
11789 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11790 "*Anything Firefox*"))
11792 ;;;###autoload
11793 (defun anything-colors ()
11794 "Preconfigured `anything' for color."
11795 (interactive)
11796 (anything-other-buffer
11797 '(anything-c-source-colors anything-c-source-customize-face)
11798 "*anything colors*"))
11800 ;;;###autoload
11801 (defun anything-bookmarks ()
11802 "Preconfigured `anything' for bookmarks."
11803 (interactive)
11804 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11806 ;;;###autoload
11807 (defun anything-c-pp-bookmarks ()
11808 "Preconfigured `anything' for bookmarks (pretty-printed)."
11809 (interactive)
11810 (anything-other-buffer '(anything-c-source-bookmarks-local
11811 anything-c-source-bookmarks-su
11812 anything-c-source-bookmarks-ssh)
11813 "*anything pp bookmarks*"))
11815 ;;;###autoload
11816 (defun anything-c-insert-latex-math ()
11817 "Preconfigured anything for latex math symbols completion."
11818 (interactive)
11819 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11821 ;;;###autoload
11822 (defun anything-register ()
11823 "Preconfigured `anything' for Emacs registers."
11824 (interactive)
11825 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11827 ;;;###autoload
11828 (defun anything-man-woman ()
11829 "Preconfigured `anything' for Man and Woman pages."
11830 (interactive)
11831 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11833 ;;;###autoload
11834 (defun anything-org-keywords ()
11835 "Preconfigured `anything' for org keywords."
11836 (interactive)
11837 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11839 ;;;###autoload
11840 (defun anything-emms ()
11841 "Preconfigured `anything' for emms sources."
11842 (interactive)
11843 (anything :sources '(anything-c-source-emms-streams
11844 anything-c-source-emms-files
11845 anything-c-source-emms-dired)
11846 :buffer "*Anything Emms*"))
11848 ;;;###autoload
11849 (defun anything-eev-anchors ()
11850 "Preconfigured `anything' for eev anchors."
11851 (interactive)
11852 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11854 ;;;###autoload
11855 (defun anything-bm-list ()
11856 "Preconfigured `anything' for visible bookmarks.
11858 Needs bm.el
11860 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11861 (interactive)
11862 (let ((anything-outline-using t))
11863 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11865 ;;;###autoload
11866 (defun anything-timers ()
11867 "Preconfigured `anything' for timers."
11868 (interactive)
11869 (anything-other-buffer '(anything-c-source-absolute-time-timers
11870 anything-c-source-idle-time-timers)
11871 "*anything timers*"))
11873 ;;;###autoload
11874 (defun anything-list-emacs-process ()
11875 "Preconfigured `anything' for emacs process."
11876 (interactive)
11877 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11879 ;;;###autoload
11880 (defun anything-occur ()
11881 "Preconfigured Anything for Occur source.
11882 If region is active, search only in region,
11883 otherwise search in whole buffer."
11884 (interactive)
11885 (let ((anything-compile-source-functions
11886 ;; rule out anything-match-plugin because the input is one regexp.
11887 (delq 'anything-compile-source--match-plugin
11888 (copy-sequence anything-compile-source-functions))))
11889 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11891 ;;;###autoload
11892 (defun anything-browse-code ()
11893 "Preconfigured anything to browse code."
11894 (interactive)
11895 (anything :sources 'anything-c-source-browse-code
11896 :buffer "*anything browse code*"
11897 :default (thing-at-point 'symbol)))
11899 ;;;###autoload
11900 (defun anything-org-headlines ()
11901 "Preconfigured anything to show org headlines."
11902 (interactive)
11903 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11905 ;;;###autoload
11906 (defun anything-info-gnus ()
11907 "Preconfigured anything to browse Gnus Manual."
11908 (interactive)
11909 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11911 ;;;###autoload
11912 (defun anything-regexp ()
11913 "Preconfigured anything to build regexps.
11914 `query-replace-regexp' can be run from there against found regexp."
11915 (interactive)
11916 (save-restriction
11917 (let ((anything-compile-source-functions
11918 ;; rule out anything-match-plugin because the input is one regexp.
11919 (delq 'anything-compile-source--match-plugin
11920 (copy-sequence anything-compile-source-functions))))
11921 (when (and (anything-region-active-p)
11922 ;; Don't narrow to region if buffer is already narrowed.
11923 (not (anything-current-buffer-narrowed-p)))
11924 (narrow-to-region (region-beginning) (region-end)))
11925 (anything :sources anything-c-source-regexp
11926 :buffer "*anything regexp*"
11927 :prompt "Regexp: "
11928 :history 'anything-build-regexp-history))))
11930 ;;;###autoload
11931 (defun anything-c-copy-files-async ()
11932 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11933 (interactive)
11934 (let* ((flist (anything-c-read-file-name
11935 "Copy File async: "
11936 :marked-candidates t))
11937 (dest (anything-c-read-file-name
11938 "Copy File async To: "
11939 :preselect (car flist)
11940 :initial-input (car anything-ff-history)
11941 :history (anything-find-files-history :comp-read nil))))
11942 (anything-c-copy-async-with-log flist dest)))
11944 ;;;###autoload
11945 (defun anything-find-files (arg)
11946 "Preconfigured `anything' for anything implementation of `find-file'.
11947 Called with a prefix arg show history if some.
11948 Don't call it from programs, use `anything-find-files-1' instead.
11949 This is the starting point for nearly all actions you can do on files."
11950 (interactive "P")
11951 (let ((any-input (if (and arg anything-ff-history)
11952 (anything-find-files-history)
11953 (anything-find-files-initial-input)))
11954 (presel (buffer-file-name (current-buffer))))
11955 (when (and (eq major-mode 'org-agenda-mode)
11956 org-directory
11957 (not any-input))
11958 (setq any-input (expand-file-name org-directory)))
11959 (set-text-properties 0 (length any-input) nil any-input)
11960 (if any-input
11961 (anything-find-files-1 any-input)
11962 (setq any-input (expand-file-name (anything-c-current-directory)))
11963 (anything-find-files-1
11964 any-input (if anything-ff-transformer-show-only-basename
11965 (and presel (anything-c-basename presel))
11966 presel)))))
11968 ;;;###autoload
11969 (defun anything-write-file ()
11970 "Preconfigured `anything' providing completion for `write-file'."
11971 (interactive)
11972 (let ((anything-mp-highlight-delay nil))
11973 (anything :sources 'anything-c-source-write-file
11974 :input (expand-file-name default-directory)
11975 :prompt "Write buffer to file: "
11976 :buffer "*Anything write file*")))
11978 ;;;###autoload
11979 (defun anything-insert-file ()
11980 "Preconfigured `anything' providing completion for `insert-file'."
11981 (interactive)
11982 (let ((anything-mp-highlight-delay nil))
11983 (anything :sources 'anything-c-source-insert-file
11984 :input (expand-file-name default-directory)
11985 :prompt "Insert file: "
11986 :buffer "*Anything insert file*")))
11988 ;;;###autoload
11989 (defun anything-dired-rename-file ()
11990 "Preconfigured `anything' to rename files from dired."
11991 (interactive)
11992 (anything-dired-do-action-on-file :action 'rename))
11994 ;;;###autoload
11995 (defun anything-dired-copy-file ()
11996 "Preconfigured `anything' to copy files from dired."
11997 (interactive)
11998 (anything-dired-do-action-on-file :action 'copy))
12000 ;;;###autoload
12001 (defun anything-dired-symlink-file ()
12002 "Preconfigured `anything' to symlink files from dired."
12003 (interactive)
12004 (anything-dired-do-action-on-file :action 'symlink))
12006 ;;;###autoload
12007 (defun anything-dired-hardlink-file ()
12008 "Preconfigured `anything' to hardlink files from dired."
12009 (interactive)
12010 (anything-dired-do-action-on-file :action 'hardlink))
12012 ;;;###autoload
12013 (defun anything-do-grep ()
12014 "Preconfigured anything for grep.
12015 Contrarily to Emacs `grep' no default directory is given, but
12016 the full path of candidates in ONLY.
12017 That allow to grep different files not only in `default-directory' but anywhere
12018 by marking them (C-<SPACE>). If one or more directory is selected
12019 grep will search in all files of these directories.
12020 You can use also wildcard in the base name of candidate.
12021 If a prefix arg is given use the -r option of grep.
12022 The prefix arg can be passed before or after start.
12023 See also `anything-do-grep-1'."
12024 (interactive)
12025 (let ((only (anything-c-read-file-name
12026 "Search in file(s): "
12027 :marked-candidates t
12028 :preselect (or (dired-get-filename nil t)
12029 (buffer-file-name (current-buffer)))))
12030 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
12031 (anything-do-grep-1 only prefarg)))
12033 ;;;###autoload
12034 (defun anything-do-zgrep (candidate)
12035 "Preconfigured anything for zgrep."
12036 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
12037 (ls (anything-c-read-file-name
12038 "Search in file(s): "
12039 :marked-candidates t
12040 :preselect (or (dired-get-filename nil t)
12041 (buffer-file-name (current-buffer))))))
12042 (anything-ff-zgrep-1 ls prefarg)))
12044 (defun anything-c-etags-select (arg)
12045 "Preconfigured anything for etags.
12046 Called with one prefix arg use symbol at point as initial input.
12047 Called with two prefix arg reinitialize cache.
12048 If tag file have been modified reinitialize cache."
12049 (interactive "P")
12050 (let ((tag (anything-c-etags-get-tag-file))
12051 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
12052 (anything-quit-if-no-candidate t)
12053 (anything-execute-action-at-once-if-one t)
12054 (anything-compile-source-functions
12055 (if anything-c-etags-use-regexp-search
12056 ;; rule out anything-match-plugin because the input is one regexp.
12057 (delq 'anything-compile-source--match-plugin
12058 (copy-sequence anything-compile-source-functions))
12059 anything-compile-source-functions)))
12060 (when (or (equal arg '(16))
12061 (and anything-c-etags-mtime-alist
12062 (anything-c-etags-file-modified-p tag)))
12063 (remhash tag anything-c-etags-cache))
12064 (if (and tag (file-exists-p tag))
12065 (anything :sources 'anything-c-source-etags-select
12066 :keymap anything-c-etags-map
12067 :input init
12068 :buffer "*anything etags*")
12069 (message "Error: No tag file found, please create one with etags shell command."))))
12071 ;;;###autoload
12072 (defun anything-filelist ()
12073 "Preconfigured `anything' to open files instantly.
12075 See `anything-c-filelist-file-name' docstring for usage."
12076 (interactive)
12077 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
12079 ;;;###autoload
12080 (defun anything-filelist+ ()
12081 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
12083 This is a replacement for `anything-for-files'.
12084 See `anything-c-filelist-file-name' docstring for usage."
12085 (interactive)
12086 (anything-other-buffer
12087 '(anything-c-source-ffap-line
12088 anything-c-source-ffap-guesser
12089 anything-c-source-buffers-list
12090 anything-c-source-recentf
12091 anything-c-source-bookmarks
12092 anything-c-source-file-cache
12093 anything-c-source-filelist)
12094 "*anything file list*"))
12096 ;;;###autoload
12097 (defun anything-M-x ()
12098 "Preconfigured `anything' for Emacs commands.
12099 It is `anything' replacement of regular `M-x' `execute-extended-command'."
12100 (interactive)
12101 (let* (in-help
12102 help-cand
12103 special-display-buffer-names
12104 special-display-regexps
12105 anything-persistent-action-use-special-display
12106 (history (loop with hist
12107 for i in extended-command-history
12108 for com = (intern i)
12109 when (fboundp com)
12110 collect i into hist finally return hist)))
12111 (flet ((pers-help (candidate)
12112 (let ((hbuf (get-buffer (help-buffer))))
12113 (if (and in-help (string= candidate help-cand))
12114 (progn
12115 ;; When M-x is started from a help buffer,
12116 ;; Don't kill it as it is anything-current-buffer.
12117 (unless (equal hbuf anything-current-buffer)
12118 (kill-buffer hbuf))
12119 (setq in-help nil))
12120 ;; Be sure anything-current-buffer
12121 ;; have not a dedicated window.
12122 (set-window-dedicated-p
12123 (get-buffer-window anything-current-buffer) nil)
12124 (describe-function (intern candidate))
12125 (message nil) ; Erase the new stupid message Type "q"[...]
12126 (setq in-help t))
12127 (setq help-cand candidate))))
12128 (let* ((command
12130 (anything
12131 :sources
12132 `(((name . "Emacs Commands history")
12133 (candidates . ,history)
12134 (filtered-candidate-transformer
12135 . (lambda (candidates sources)
12136 (loop for i in candidates
12137 do (set-text-properties 0 (length i) nil i)
12138 collect i)))
12139 (persistent-action . pers-help)
12140 (persistent-help . "Describe this command")
12141 (action . identity))
12142 ((name . "Emacs Commands")
12143 (init
12144 . (lambda ()
12145 (with-current-buffer (anything-candidate-buffer 'global)
12146 (goto-char (point-min))
12147 (loop for sym in
12148 (all-completions "" obarray 'commandp)
12149 do (insert (concat sym "\n"))))))
12150 (persistent-action . pers-help)
12151 (persistent-help . "Describe this command")
12152 (filtered-candidate-transformer . anything-M-x-transformer)
12153 (candidates-in-buffer)
12154 (action . identity)))
12155 :resume 'noresume
12156 :prompt "M-x "
12157 :history 'anything-M-x-input-history
12158 :buffer "*anything M-x*")
12159 (keyboard-quit)))
12160 (sym-com (intern command)))
12161 (unless current-prefix-arg
12162 (setq current-prefix-arg anything-current-prefix-arg))
12163 ;; Avoid having `this-command' set to *exit-minibuffer.
12164 (setq this-command sym-com)
12165 (call-interactively sym-com)
12166 (setq extended-command-history
12167 (cons command (delete command history)))))))
12169 ;;;###autoload
12170 (defun anything-manage-advice ()
12171 "Preconfigured `anything' to disable/enable function advices."
12172 (interactive)
12173 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12175 ;;;###autoload
12176 (defun anything-bookmark-ext ()
12177 "Preconfigured `anything' for bookmark-extensions sources.
12178 Needs bookmark-ext.el:
12179 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12180 Contain also `anything-c-source-google-suggest'."
12181 (interactive)
12182 (anything
12183 :sources
12184 '(anything-c-source-bookmark-files&dirs
12185 anything-c-source-bookmark-w3m
12186 anything-c-source-google-suggest
12187 anything-c-source-bmkext-addressbook
12188 anything-c-source-bookmark-gnus
12189 anything-c-source-bookmark-info
12190 anything-c-source-bookmark-man
12191 anything-c-source-bookmark-images
12192 anything-c-source-bookmark-su-files&dirs
12193 anything-c-source-bookmark-ssh-files&dirs)
12194 :prompt "SearchBookmark: "
12195 :buffer "*anything bmkext*"))
12197 ;;;###autoload
12198 (defun anything-simple-call-tree ()
12199 "Preconfigured `anything' for simple-call-tree. List function relationships.
12201 Needs simple-call-tree.el.
12202 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12203 (interactive)
12204 (anything-other-buffer
12205 '(anything-c-source-simple-call-tree-functions-callers
12206 anything-c-source-simple-call-tree-callers-functions)
12207 "*anything simple-call-tree*"))
12209 ;;;###autoload
12210 (defun anything-mark-ring ()
12211 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12212 (interactive)
12213 (anything :sources 'anything-c-source-mark-ring))
12215 ;;;###autoload
12216 (defun anything-global-mark-ring ()
12217 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12218 (interactive)
12219 (anything :sources 'anything-c-source-global-mark-ring))
12221 ;;;###autoload
12222 (defun anything-all-mark-rings ()
12223 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12224 `anything-c-source-mark-ring'."
12225 (interactive)
12226 (anything :sources '(anything-c-source-mark-ring
12227 anything-c-source-global-mark-ring)))
12229 ;;;###autoload
12230 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12231 "Preconfigured `anything' to edit or view EmacsWiki page.
12233 Needs yaoddmuse.el.
12235 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12236 (interactive)
12237 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12239 ;;;###autoload
12240 (defun anything-yaoddmuse-emacswiki-post-library ()
12241 "Preconfigured `anything' to post library to EmacsWiki.
12243 Needs yaoddmuse.el.
12245 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12246 (interactive)
12247 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12249 ;;;###autoload
12250 (defun anything-eval-expression (arg)
12251 "Preconfigured anything for `anything-c-source-evaluation-result'."
12252 (interactive "P")
12253 (anything :sources 'anything-c-source-evaluation-result
12254 :input (when arg (thing-at-point 'sexp))
12255 :buffer "*anything eval*"
12256 :history 'anything-eval-expression-input-history
12257 :keymap anything-eval-expression-map))
12259 ;;;###autoload
12260 (defun anything-eval-expression-with-eldoc ()
12261 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12262 (interactive)
12263 (declare (special eldoc-idle-delay))
12264 (let ((timer (run-with-idle-timer eldoc-idle-delay
12265 'repeat 'anything-eldoc-show-in-eval))
12266 (minibuffer-completing-symbol t) ; Enable lisp completion.
12267 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12268 (unwind-protect
12269 (minibuffer-with-setup-hook
12270 'anything-eldoc-store-minibuffer
12271 (call-interactively 'anything-eval-expression))
12272 (and timer (cancel-timer timer))
12273 (setq anything-eldoc-active-minibuffers-list
12274 (cdr anything-eldoc-active-minibuffers-list)))))
12276 ;;;###autoload
12277 (defun anything-calcul-expression ()
12278 "Preconfigured anything for `anything-c-source-calculation-result'."
12279 (interactive)
12280 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12282 ;;;###autoload
12283 (defun anything-surfraw (pattern engine)
12284 "Preconfigured `anything' to search PATTERN with search ENGINE."
12285 (interactive (list (read-string "SearchFor: "
12286 nil 'anything-surfraw-input-history)
12287 (anything-comp-read
12288 "Engine: "
12289 (anything-c-build-elvi-list)
12290 :must-match t
12291 :name "Surfraw Search Engines"
12292 :history anything-surfraw-engines-history)))
12293 (let* ((engine-nodesc (car (split-string engine)))
12294 (url (with-temp-buffer
12295 (apply 'call-process "surfraw" nil t nil
12296 ;;JAVE
12297 (append (list engine-nodesc "-p") (split-string pattern)))
12298 (replace-regexp-in-string
12299 "\n" "" (buffer-string))))
12300 (browse-url-browser-function (or anything-surfraw-default-browser-function
12301 browse-url-browser-function)))
12302 (if (string= engine-nodesc "W")
12303 (anything-c-browse-url)
12304 (anything-c-browse-url url)
12305 (setq anything-surfraw-engines-history
12306 (cons engine (delete engine anything-surfraw-engines-history))))))
12308 ;;;###autoload
12309 (defun anything-call-source ()
12310 "Preconfigured `anything' to call anything source."
12311 (interactive)
12312 (anything :sources 'anything-c-source-call-source
12313 :buffer anything-source-select-buffer))
12315 ;;;###autoload
12316 (defun anything-execute-anything-command ()
12317 "Preconfigured `anything' to execute preconfigured `anything'."
12318 (interactive)
12319 (anything-other-buffer 'anything-c-source-anything-commands
12320 "*anything commands*"))
12322 ;;;###autoload
12323 (defun anything-create (&optional string initial-input)
12324 "Preconfigured `anything' to do many create actions from STRING.
12325 See also `anything-create--actions'."
12326 (interactive)
12327 (setq string (or string (read-string "Create Anything: " initial-input)))
12328 (anything :sources '(((name . "Anything Create")
12329 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12330 (candidates . anything-create--actions)
12331 (candidate-number-limit)
12332 (action . (lambda (func) (funcall func string)))))))
12334 ;;;###autoload
12335 (defun anything-top ()
12336 "Preconfigured `anything' for top command."
12337 (interactive)
12338 (let ((anything-samewindow t)
12339 (anything-enable-shortcuts)
12340 (anything-display-function 'anything-default-display-buffer)
12341 (anything-candidate-number-limit 9999))
12342 (save-window-excursion
12343 (delete-other-windows)
12344 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12346 ;;;###autoload
12347 (defun anything-select-xfont ()
12348 "Preconfigured `anything' to select Xfont."
12349 (interactive)
12350 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12352 ;;;###autoload
12353 (defun anything-world-time ()
12354 "Preconfigured `anything' to show world time."
12355 (interactive)
12356 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12358 ;;;###autoload
12359 (defun anything-apt (arg)
12360 "Preconfigured `anything' : frontend of APT package manager.
12361 With a prefix arg reload cache."
12362 (interactive "P")
12363 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12364 (when arg (anything-c-apt-refresh))
12365 (anything :sources 'anything-c-source-apt
12366 :prompt "Search Package: "
12367 :input query
12368 :history 'anything-c-apt-input-history)))
12370 ;;;###autoload
12371 (defun anything-esh-pcomplete ()
12372 "Preconfigured anything to provide anything completion in eshell."
12373 (interactive)
12374 (let* ((anything-quit-if-no-candidate t)
12375 (anything-execute-action-at-once-if-one t)
12376 (target (thing-at-point 'symbol))
12377 (end (point))
12378 (beg (or (and target (- end (length target)))
12379 ;; Nothing at point.
12380 (progn (insert " ") (point)))))
12381 (setq anything-ec-target (or target " "))
12382 (with-anything-show-completion beg end
12383 (anything :sources 'anything-c-source-esh
12384 :input (anything-ff-set-pattern ; Handle tramp filenames.
12385 (car (last (ignore-errors ; Needed in lisp symbols completion.
12386 (pcomplete-parse-arguments)))))))))
12388 ;;;###autoload
12389 (defun anything-eshell-history ()
12390 "Preconfigured anything for eshell history."
12391 (interactive)
12392 (let* ((end (point))
12393 (beg (save-excursion (eshell-bol) (point)))
12394 flag-empty)
12395 (when (eq beg end)
12396 (insert " ")
12397 (setq flag-empty t)
12398 (setq end (point)))
12399 (unwind-protect
12400 (with-anything-show-completion beg end
12401 (anything :sources 'anything-c-source-eshell-history
12402 :buffer "*Eshell history*"))
12403 (when (and flag-empty
12404 (looking-back " "))
12405 (delete-char -1)))))
12407 ;;;###autoload
12408 (defun anything-c-run-external-command (program)
12409 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12410 If program is already running exit with error.
12411 You can set your own list of commands with
12412 `anything-c-external-commands-list'."
12413 (interactive (list
12414 (anything-comp-read
12415 "RunProgram: "
12416 (anything-c-external-commands-list-1 'sort)
12417 :must-match t
12418 :name "External Commands"
12419 :history anything-external-command-history)))
12420 (anything-run-or-raise program)
12421 (setq anything-external-command-history
12422 (cons program (delete program
12423 (loop for i in anything-external-command-history
12424 when (executable-find i) collect i)))))
12426 ;;;###autoload
12427 (defun anything-ratpoison-commands ()
12428 "Preconfigured `anything' to execute ratpoison commands."
12429 (interactive)
12430 (anything-other-buffer 'anything-c-source-ratpoison-commands
12431 "*anything ratpoison commands*"))
12433 ;;;###autoload
12434 (defun anything-ucs ()
12435 "Preconfigured anything for `ucs-names' math symbols."
12436 (interactive)
12437 (anything :sources 'anything-c-source-ucs
12438 :keymap anything-c-ucs-map))
12440 ;;;###autoload
12441 (defun anything-c-apropos ()
12442 "Preconfigured anything to describe commands, functions, variables and faces."
12443 (interactive)
12444 (let ((default (thing-at-point 'symbol)))
12445 (anything :sources
12446 `(((name . "Commands")
12447 (init . (lambda ()
12448 (anything-c-apropos-init 'commandp ,default)))
12449 (persistent-action . anything-lisp-completion-persistent-action)
12450 (persistent-help . "Show brief doc in mode-line")
12451 (candidates-in-buffer)
12452 (action . (lambda (candidate)
12453 (describe-function (intern candidate)))))
12454 ((name . "Functions")
12455 (init . (lambda ()
12456 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12457 (not (commandp x))))
12458 ,default)))
12459 (persistent-action . anything-lisp-completion-persistent-action)
12460 (persistent-help . "Show brief doc in mode-line")
12461 (candidates-in-buffer)
12462 (action . (lambda (candidate)
12463 (describe-function (intern candidate)))))
12464 ((name . "Variables")
12465 (init . (lambda ()
12466 (anything-c-apropos-init 'boundp ,default)))
12467 (persistent-action . anything-lisp-completion-persistent-action)
12468 (persistent-help . "Show brief doc in mode-line")
12469 (candidates-in-buffer)
12470 (action . (lambda (candidate)
12471 (describe-variable (intern candidate)))))
12472 ((name . "Faces")
12473 (init . (lambda ()
12474 (anything-c-apropos-init 'facep ,default)))
12475 (persistent-action . anything-lisp-completion-persistent-action)
12476 (persistent-help . "Show brief doc in mode-line")
12477 (candidates-in-buffer)
12478 (filtered-candidate-transformer . (lambda (candidates source)
12479 (loop for c in candidates
12480 collect (propertize c 'face (intern c)))))
12481 (action . (lambda (candidate)
12482 (describe-face (intern candidate)))))
12483 ((name . "Anything attributes")
12484 (candidates . (lambda ()
12485 (mapcar 'symbol-name anything-additional-attributes)))
12486 (action . (lambda (candidate)
12487 (with-output-to-temp-buffer "*Help*"
12488 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12491 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12494 (provide 'anything-config)
12496 ;;; Local Variables:
12497 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12498 ;;; End:
12500 ;; How to save (DO NOT REMOVE!!)
12501 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12502 ;;; anything-config.el ends here
12504 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12505 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12506 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12507 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12508 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12509 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12510 ;;; LocalWords: dotimes Thierry online vname
12511 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12512 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12513 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12514 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12515 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12516 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12517 ;;; LocalWords: startpos noselect dont desc