* anything-config.el Use anything-attrset in many places.
[anything-config.git] / anything-config.el
blob277fe1b8978871066bdc1af7299941b724749268
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))
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.
1126 Set to nil if you do not have external file browser
1127 or do not want to use it."
1128 :group 'anything-config
1129 :type 'string)
1131 (defcustom anything-c-use-adaptative-sorting nil
1132 "*Wheter to use or not adaptative sorting.
1133 Even if a source use it, it will have no effect when set to nil."
1134 :type 'boolean
1135 :group 'anything-config)
1137 (defcustom anything-ff-newfile-prompt-p t
1138 "Whether Prompt or not when creating new file.
1139 This set `ffap-newfile-prompt'."
1140 :type 'boolean
1141 :group 'anything-config)
1144 (defcustom anything-ff-avfs-directory nil
1145 "*The default avfs directory, usually '.avfs'.
1146 When this is set you will be able to expand archive filenames with `C-z'
1147 inside an avfs directory mounted with mountavfs.
1148 See <http://sourceforge.net/projects/avf/>."
1149 :type 'boolean
1150 :group 'anything-config)
1152 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1153 "*Minimal list of compressed files extension."
1154 :type 'list
1155 :group 'anything-config)
1157 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1158 "Default regexp to match locate database.
1159 If nil Search in all files."
1160 :type 'string
1161 :group 'anything-config)
1163 (defcustom anything-c-show-info-in-mode-line-delay 12
1164 "Eldoc will show info in mode-line during this delay if user is idle."
1165 :type 'integer
1166 :group 'anything-config)
1168 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1169 "The file used to communicate with two emacs when copying files async."
1170 :type 'string
1171 :group 'anything-config)
1173 (defcustom anything-ff-printer-list nil
1174 "A list of available printers on your system.
1175 When non--nil let you choose a printer to print file.
1176 Otherwise when nil the variable `printer-name' will be used.
1177 On Unix based systems (lpstat command needed) you don't need to set this,
1178 `anything-ff-find-printers' will find a list of available printers for you."
1179 :type 'list
1180 :group 'anything-config)
1182 (defcustom anything-ff-transformer-show-only-basename nil
1183 "Show only basename of candidates in `anything-find-files'.
1184 This can be toggled at anytime from `anything-find-files' with \
1185 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1186 :type 'boolean
1187 :group 'anything-config)
1189 (defcustom anything-ff-quick-delete-dont-prompt-for-deletion nil
1190 "Don't ask in persistent deletion of files when non--nil."
1191 :group 'anything-config
1192 :type 'boolean)
1194 (defcustom anything-completing-read-handlers-alist
1195 '((describe-function . anything-completing-read-symbols)
1196 (describe-variable . anything-completing-read-symbols)
1197 (debug-on-entry . anything-completing-read-symbols)
1198 (find-function . anything-completing-read-symbols)
1199 (trace-function . anything-completing-read-symbols)
1200 (trace-function-background . anything-completing-read-symbols)
1201 (find-tag . anything-completing-read-with-cands-in-buffer)
1202 (ffap-alternate-file . nil))
1203 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1204 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1205 where key and value are symbols.
1207 Each key is an Emacs command that use originaly `completing-read'.
1209 Each value maybe an anything function that take same arguments as
1210 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1211 anything source and BUFFER the name of the buffer we will use.
1212 This function prefix name must start by \"anything\".
1214 See `anything-completing-read-symbols' for example.
1216 If the value of an entry is nil completion will fall back to
1217 emacs vanilla behavior.
1218 e.g If you want to disable anything completion for `describe-function':
1219 \(describe-function . nil\).
1221 Ido is also supported, you can use `ido-completing-read' and
1222 `ido-read-file-name' as value of an entry or just 'ido.
1223 e.g ido completion for `find-file':
1224 \(find-file . ido\)
1225 same as
1226 \(find-file . ido-read-file-name\)
1227 Note that you don't need to enable `ido-mode' for this to work."
1228 :group 'anything-config
1229 :type '(alist :key-type symbol :value-type symbol))
1233 ;;; General internal variables
1235 ;; Some internals variable that need to be loaded
1236 ;; here to avoid compiler warnings.
1237 (defvar anything-c-external-commands-list nil
1238 "A list of all external commands the user can execute. If this
1239 variable is not set by the user, it will be calculated
1240 automatically.")
1242 (defvar anything-c-show-completion-overlay nil)
1244 (defvar anything-c-locate-command
1245 (case system-type
1246 ('gnu/linux "locate -i -r %s")
1247 ('berkeley-unix "locate -i %s")
1248 ('windows-nt "es -i -r %s")
1249 (t "locate %s"))
1250 "A list of arguments for locate program.
1251 The \"-r\" option must be the last option.")
1254 ;;; Faces
1257 (defface anything-buffer-saved-out
1258 '((t (:foreground "red")))
1259 "*Face used for buffer files modified outside of emacs."
1260 :group 'anything-config)
1262 (defface anything-buffer-not-saved
1263 '((t (:foreground "Indianred2")))
1264 "*Face used for buffer files not already saved on disk."
1265 :group 'anything-config)
1267 (defface anything-ff-prefix
1268 '((t (:background "yellow" :foreground "black")))
1269 "*Face used to prefix new file or url paths in `anything-find-files'."
1270 :group 'anything-config)
1272 (defface anything-ff-executable
1273 '((t (:foreground "green")))
1274 "*Face used for executable files in `anything-find-files'."
1275 :group 'anything-config)
1277 (defface anything-ff-directory
1278 '((t (:foreground "DarkRed" :background "LightGray")))
1279 "*Face used for directories in `anything-find-files'."
1280 :group 'anything-config)
1282 (defface anything-ff-symlink
1283 '((t (:foreground "DarkOrange")))
1284 "*Face used for symlinks in `anything-find-files'."
1285 :group 'anything-config)
1287 (defface anything-ff-invalid-symlink
1288 '((t (:foreground "black" :background "red")))
1289 "*Face used for invalid symlinks in `anything-find-files'."
1290 :group 'anything-config)
1292 (defface anything-ff-file
1293 '((t (:foreground "CadetBlue" :underline t)))
1294 "*Face used for file names in `anything-find-files'."
1295 :group 'anything-config)
1297 (defface anything-grep-match
1298 '((t (:inherit match)))
1299 "Face used to highlight grep matches."
1300 :group 'anything-config)
1302 (defface anything-grep-file
1303 '((t (:foreground "BlueViolet" :underline t)))
1304 "Face used to highlight grep results filenames."
1305 :group 'anything-config)
1307 (defface anything-grep-lineno
1308 '((t (:foreground "Darkorange1")))
1309 "Face used to highlight grep number lines."
1310 :group 'anything-config)
1312 (defface anything-grep-running
1313 '((t (:foreground "Red")))
1314 "Face used in mode line when grep is running."
1315 :group 'anything-config)
1317 (defface anything-grep-finish
1318 '((t (:foreground "Green")))
1319 "Face used in mode line when grep is finish."
1320 :group 'anything-config)
1322 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1323 "*Face used in anything-M-x to show keybinding."
1324 :group 'anything)
1326 (defface anything-bmkext-info
1327 '((t (:foreground "green")))
1328 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1329 :group 'anything)
1331 (defface anything-bmkext-w3m
1332 '((t (:foreground "yellow")))
1333 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1334 :group 'anything)
1336 (defface anything-bmkext-gnus
1337 '((t (:foreground "magenta")))
1338 "*Face used for Gnus bookmarks."
1339 :group 'anything)
1341 (defface anything-bmkext-man
1342 '((t (:foreground "Orange4")))
1343 "*Face used for Woman/man bookmarks."
1344 :group 'anything)
1346 (defface anything-bmkext-no--file
1347 '((t (:foreground "grey")))
1348 "*Face used for non--file bookmarks."
1349 :group 'anything)
1351 (defface anything-bmkext-file
1352 '((t (:foreground "Deepskyblue2")))
1353 "*Face used for non--file bookmarks."
1354 :group 'anything)
1356 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1357 "Face for su/sudo bookmarks."
1358 :group 'anything)
1360 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1361 "Face for w3m bookmarks" :group 'anything)
1363 (defface anything-emms-playlist
1364 '((t (:foreground "Springgreen4" :underline t)))
1365 "*Face used for tracks in current emms playlist."
1366 :group 'anything)
1368 (defface anything-apt-installed
1369 '((t (:foreground "green")))
1370 "*Face used for apt installed candidates."
1371 :group 'anything)
1373 (defface anything-gentoo-match-face '((t (:foreground "red")))
1374 "Face for anything-gentoo installed packages."
1375 :group 'traverse-faces)
1377 (defface anything-lisp-show-completion
1378 '((t (:background "DarkSlateGray")))
1379 "*Face used for showing candidates in `anything-lisp-completion'."
1380 :group 'anything-config)
1382 (defface anything-lisp-completion-info
1383 '((t (:foreground "red")))
1384 "*Face used for showing info in `anything-lisp-completion'."
1385 :group 'anything-config)
1387 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1388 "Face for source header in the anything buffer." :group 'anything)
1390 ;;;###autoload
1391 (defun anything-configuration ()
1392 "Customize `anything'."
1393 (interactive)
1394 (customize-group "anything-config"))
1398 ;;; Anything-command-map
1401 ;;;###autoload
1402 (defvar anything-command-map)
1403 (define-prefix-command 'anything-command-map)
1406 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1407 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1408 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1409 (define-key anything-command-map (kbd "l") 'anything-locate)
1410 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1411 (define-key anything-command-map (kbd "r") 'anything-regexp)
1412 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1413 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1414 (define-key anything-command-map (kbd "#") 'anything-emms)
1415 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1416 (define-key anything-command-map (kbd "t") 'anything-top)
1417 (define-key anything-command-map (kbd "i") 'anything-imenu)
1418 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1419 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1420 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1421 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1422 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1423 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1424 (define-key anything-command-map (kbd "f") 'anything-for-files)
1425 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1426 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1427 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1428 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1429 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1430 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1431 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1432 (define-key anything-command-map (kbd "c") 'anything-colors)
1433 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1434 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1435 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1436 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1437 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1438 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1439 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1440 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1441 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1442 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1444 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1445 ;; minibuffer-local-filename-must-match-map.
1446 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1447 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1448 (dolist (map (list minibuffer-local-filename-completion-map
1449 minibuffer-local-completion-map
1450 minibuffer-local-must-match-filename-map
1451 minibuffer-local-filename-must-match-map
1452 minibuffer-local-map
1453 minibuffer-local-isearch-map
1454 minibuffer-local-must-match-map
1455 minibuffer-local-ns-map))
1456 (define-key map "\C-r" 'anything-minibuffer-history))
1460 ;;; Menu
1463 (easy-menu-define nil global-map
1464 "`anything' menu"
1465 '("Anything"
1466 ["All anything commands" anything-execute-anything-command t]
1467 ["Find any Files/Buffers" anything-for-files t]
1468 ["Anything Everywhere (Toggle)" ac-mode t]
1469 "----"
1470 ("Files:"
1471 ["Find files" anything-find-files t]
1472 ["Recent Files" anything-recentf t]
1473 ["Locate" anything-locate t]
1474 ["Bookmarks" anything-c-pp-bookmarks t])
1475 ("Buffers:"
1476 ["Find buffers" anything-buffers-list t])
1477 ("Commands:"
1478 ["Emacs Commands" anything-M-x t]
1479 ["Externals Commands" anything-c-run-external-command t])
1480 ("Help:"
1481 ["Anything Apropos" anything-c-apropos t])
1482 ("Info:"
1483 ["Info at point" anything-info-at-point t]
1484 ["Emacs Manual index" anything-info-emacs t]
1485 ["Gnus Manual index" anything-info-gnus t])
1486 ("Org:"
1487 ["Org keywords" anything-org-keywords t]
1488 ["Org headlines" anything-org-headlines t])
1489 ("Tools:"
1490 ["Occur" anything-occur t]
1491 ["Grep" anything-do-grep t]
1492 ["Etags" anything-c-etags-select t]
1493 ["Lisp complete at point" anything-lisp-completion-at-point t]
1494 ["Browse Kill ring" anything-show-kill-ring t]
1495 ["Browse register" anything-register t]
1496 ["Browse code" anything-browse-code t]
1497 ["Mark Ring" anything-all-mark-rings t]
1498 ["Regexp handler" anything-regexp t]
1499 ["Colors & Faces" anything-colors t]
1500 ["Show xfonts" anything-select-xfont t]
1501 ["Ucs Symbols" anything-ucs t]
1502 ["Imenu" anything-imenu t]
1503 ["Google Suggest" anything-google-suggest t]
1504 ["Eval expression" anything-eval-expression-with-eldoc t]
1505 ["Calcul expression" anything-calcul-expression t]
1506 ["Man pages" anything-man-woman t]
1507 ["Top externals process" anything-top t]
1508 ["Emacs internals process" anything-list-emacs-process t])
1509 "----"
1510 ["Prefered Options" anything-configuration t]))
1512 ;;; Anything map add ons
1515 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1516 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1517 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1520 ;;; Specialized keymaps
1523 (defvar anything-c-buffer-map
1524 (let ((map (copy-keymap anything-map)))
1525 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1526 ;; No need to have separate command for grep and zgrep
1527 ;; as we don't use recursivity for buffers.
1528 ;; So use zgrep for both as it is capable to handle non--compressed files.
1529 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1530 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1531 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1532 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1533 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1534 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1535 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1536 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1537 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1538 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1539 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1540 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1541 (define-key map (kbd "M-a") 'anything-mark-all)
1542 (when (locate-library "elscreen")
1543 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1544 (delq nil map))
1545 "Keymap for buffer sources in anything.")
1547 (defvar anything-find-files-map
1548 (let ((map (copy-keymap anything-map)))
1549 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1550 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1551 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1552 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1553 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1554 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1555 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1556 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1557 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1558 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1559 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1560 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1561 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1562 (define-key map (kbd "<deletechar>") 'anything-ff-persistent-delete)
1563 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1564 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1565 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1566 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1567 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1568 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1569 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1570 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1571 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1572 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1573 (define-key map (kbd "C-c ?") 'anything-ff-help)
1574 (define-key map (kbd "C-}") 'anything-narrow-window)
1575 (define-key map (kbd "C-{") 'anything-enlarge-window)
1576 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1577 (define-key map (kbd "M-a") 'anything-mark-all)
1578 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1579 (define-key map (kbd "M-u") 'anything-unmark-all)
1580 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1581 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1582 ;; Next 2 have no effect if candidate is not an image file.
1583 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1584 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1585 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1586 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1587 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1588 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1589 (when anything-ff-lynx-style-map
1590 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1591 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1592 (delq nil map))
1593 "Keymap for `anything-find-files'.")
1595 (defvar anything-c-read-file-map
1596 (let ((map (copy-keymap anything-map)))
1597 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1598 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1599 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1600 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1601 (when anything-ff-lynx-style-map
1602 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1603 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1604 (define-key map (kbd "<M-left>") 'anything-previous-source)
1605 (define-key map (kbd "<M-right>") 'anything-next-source))
1606 (delq nil map))
1607 "Keymap for `anything-c-read-file-name'.")
1609 (defvar anything-generic-files-map
1610 (let ((map (copy-keymap anything-map)))
1611 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1612 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1613 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1614 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1615 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1616 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1617 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1618 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1619 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1620 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1621 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1622 map)
1623 "Generic Keymap for files.")
1625 (defvar anything-c-grep-map
1626 (let ((map (copy-keymap anything-map)))
1627 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1628 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1629 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1630 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1631 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1632 (when anything-c-grep-use-ioccur-style-keys
1633 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1634 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1635 (define-key map (kbd "C-c ?") 'anything-grep-help)
1636 (delq nil map))
1637 "Keymap used in Grep sources.")
1639 (defvar anything-c-pdfgrep-map
1640 (let ((map (copy-keymap anything-map)))
1641 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1642 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1643 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1644 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1645 map)
1646 "Keymap used in pdfgrep.")
1648 (defvar anything-c-etags-map
1649 (let ((map (copy-keymap anything-map)))
1650 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1651 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1652 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1653 (define-key map (kbd "C-c ?") 'anything-etags-help)
1654 map)
1655 "Keymap used in Etags.")
1657 (defvar anything-eval-expression-map
1658 (let ((map (copy-keymap anything-map)))
1659 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1660 (define-key map (kbd "<tab>") 'lisp-indent-line)
1661 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1662 (define-key map (kbd "C-p") 'previous-line)
1663 (define-key map (kbd "C-n") 'next-line)
1664 (define-key map (kbd "<up>") 'previous-line)
1665 (define-key map (kbd "<down>") 'next-line)
1666 (define-key map (kbd "<right>") 'forward-char)
1667 (define-key map (kbd "<left>") 'backward-char)
1668 map))
1670 (defvar anything-c-ucs-map
1671 (let ((map (copy-keymap anything-map)))
1672 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1673 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1674 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1675 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1676 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1677 map)
1678 "Keymap for `anything-ucs'.")
1682 ;;; Embeded documentation.
1685 (defun anything-c-list-preconfigured-anything ()
1686 "Collect preconfigured anything functions in this file."
1687 (loop with doc
1688 with sym
1689 for entry in (cdr (assoc
1690 (file-truename (locate-library "anything-config"))
1691 load-history))
1692 if (and (consp entry)
1693 (eq (car entry) 'defun)
1694 (string-match "^Preconfigured.+$"
1695 (setq doc (or (documentation (setq sym (cdr entry)))
1696 ""))))
1697 collect (cons sym (match-string 0 doc))))
1699 (defun anything-c-format-preconfigured-anything ()
1700 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1701 (anything-c-list-preconfigured-anything)))
1703 ;;; Global help message - Used by `anything-help'
1706 (setq anything-help-message
1707 (lambda ()
1708 (concat
1709 "\\<anything-map>"
1710 "`anything' is QuickSilver-like candidate-selection framework.
1712 Narrow the list by typing some pattern,
1713 Multiple patterns are allowed by splitting by space.
1714 Select with natural Emacs operations, choose with RET.
1716 If you have any problems, press C-c C-x C-b!!
1717 Feel free to send bug reports. I'll fix them.
1718 The steps are described in the beginning of anything.el file.
1720 == Basic Operations ==
1721 C-p, Up: Previous Line
1722 C-n, Down : Next Line
1723 M-v, PageUp : Previous Page
1724 C-v, PageDown : Next Page
1725 Enter : Execute first (default) action / Select
1726 M-< : First Line
1727 M-> : Last Line
1728 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1729 M-PageDown, C-M-v : Next Page (other-window)
1731 Tab, C-i : Show action list
1732 Left : Previous Source
1733 Right, C-o : Next Source
1734 C-k : Delete pattern
1735 C-z : Persistent Action (Execute action with anything session kept)
1736 C-c C-x C-b: Send a bug report
1738 == Shortcuts For 2nd/3rd Action ==
1739 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1740 \\[anything-select-3rd-action] : Execute 3rd Action
1742 == Visible Marks ==
1743 Visible marks store candidate. Some actions uses marked candidates.
1745 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1746 \\[anything-prev-visible-mark] : Previous Mark
1747 \\[anything-next-visible-mark] : Next Mark
1749 == Miscellaneous Commands ==
1750 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1751 \\[anything-quit-and-find-file] : Drop into `find-file'
1752 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1753 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1754 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1755 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1756 \\[anything-force-update] : Recalculate And Redisplay Candidates
1758 == Global Commands ==
1759 \\<global-map>\\[anything-resume] revives last `anything' session.
1760 It is very useful, so you should bind any key.
1762 Single source is executed by \\[anything-call-source].
1764 == Preconfigured `anything' ==
1765 Preconfigured `anything' is commands that uses `anything' interface.
1766 You can use them without configuration.
1769 (apply 'concat (anything-c-format-preconfigured-anything))
1771 Enjoy!")))
1773 ;;; `anything-buffer-list' help
1776 ;;;###autoload
1777 (defun anything-c-buffer-help ()
1778 "Help command for anything buffers."
1779 (interactive)
1780 (let ((anything-help-message "== Anything Buffer ==
1781 \nTips:
1782 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1783 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1784 \nSpecific commands for `anything-buffers-list':
1785 \\<anything-c-buffer-map>
1786 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1787 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1788 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1789 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1790 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1791 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1792 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1793 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1794 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1795 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1796 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1797 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1798 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1799 \\[anything-mark-all]\t\t->Mark all.
1800 \\[anything-c-buffer-help]\t\t->Display this help.
1801 \n== Anything Map ==
1802 \\{anything-map}
1804 (anything-help)))
1807 ;;; Find files help (`anything-find-files')
1810 ;;;###autoload
1811 (defun anything-ff-help ()
1812 "Help command for `anything-find-files'."
1813 (interactive)
1814 (let ((anything-help-message "== Anything Find Files ==
1815 \nTips:
1816 \n- Enter `~/' at end of pattern to quickly reach home directory.
1817 - Enter `/' at end of pattern to quickly reach root of your file system.
1818 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1819 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1820 - Use `C-u C-z' to watch an image.
1821 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1822 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1824 \nSpecific commands for `anything-find-files':
1825 \\<anything-find-files-map>
1826 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1827 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1828 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1829 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1830 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1831 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1832 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1833 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1834 \\[anything-ff-run-load-file]\t\t->Load File.
1835 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1836 \\[anything-ff-run-delete-file]\t\t->Delete File.
1837 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1838 \\[anything-ff-persistent-delete]\t->Delete file without quitting.
1839 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1840 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1841 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1842 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1843 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1844 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1845 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1846 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1847 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1848 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1849 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1850 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1851 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1852 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1853 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1854 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1855 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1856 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1857 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1858 \\[anything-narrow-window]\t\t->Narrow anything window.
1859 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1860 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1861 \\[anything-ff-help]\t\t->Display this help info.
1862 \n== Anything Map ==
1863 \\{anything-map}
1865 (anything-help)))
1867 ;;; Help for `anything-c-read-file-name'
1870 ;;;###autoload
1871 (defun anything-read-file-name-help ()
1872 (interactive)
1873 (let ((anything-help-message "== Anything read file name Map ==\
1874 \nSpecific commands for anything-c-read-file-name:
1875 \\<anything-c-read-file-map>
1876 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1877 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1878 \\[anything-next-source]\t\t->Goto next source.
1879 \\[anything-previous-source]\t->Goto previous source.
1880 \\[anything-read-file-name-help]\t\t->Display this help info.
1881 \n== Anything Map ==
1882 \\{anything-map}
1884 (anything-help)))
1886 ;;; Generic file help - Used by locate.
1889 ;;;###autoload
1890 (defun anything-generic-file-help ()
1891 (interactive)
1892 (let ((anything-help-message "== Anything Generic files Map ==\
1893 \nSpecific commands for anything locate and others files sources:
1894 \\<anything-generic-files-map>
1895 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1896 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1897 \\[anything-ff-run-delete-file]\t\t->Delete file.
1898 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1899 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1900 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1901 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1902 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1903 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1904 \nLocate tips:
1905 You can add after writing search pattern any of the locate command line options.
1906 e.g -b, -e, -n <number>...etc.
1907 See Man locate for more infos.
1908 \n== Anything Map ==
1909 \\{anything-map}"))
1910 (anything-help)))
1913 ;;; Grep help
1916 ;;;###autoload
1917 (defun anything-grep-help ()
1918 (interactive)
1919 (let ((anything-help-message "== Anything Grep Map ==\
1920 \nSpecific commands for Grep and Etags:
1921 \\<anything-c-grep-map>
1922 \\[anything-c-goto-next-file]\t->Next File.
1923 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1924 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1925 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1926 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1927 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1928 \\[anything-grep-help]\t\t->Show this help.
1929 \n== Anything Map ==
1930 \\{anything-map}"))
1931 (anything-help)))
1933 ;;; Pdf grep help
1936 ;;;###autoload
1937 (defun anything-pdfgrep-help ()
1938 (interactive)
1939 (let ((anything-help-message "== Anything PdfGrep Map ==\
1940 \nSpecific commands for Pdf Grep:
1941 \\<anything-c-pdfgrep-map>
1942 \\[anything-c-goto-next-file]\t->Next File.
1943 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1944 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1945 \\[anything-pdfgrep-help]\t\t->Show this help.
1946 \n== Anything Map ==
1947 \\{anything-map}"))
1948 (anything-help)))
1950 ;;; Etags help
1953 ;;;###autoload
1954 (defun anything-etags-help ()
1955 "The help function for etags."
1956 (interactive)
1957 (let ((anything-help-message "== Anything Etags Map ==\
1958 \nSpecific commands for Etags:
1959 \\<anything-c-etags-map>
1960 \\[anything-c-goto-next-file]\t->Next File.
1961 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1962 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1963 \\[anything-etags-help]\t\t->Show this help.
1964 \n== Anything Map ==
1965 \\{anything-map}"))
1966 (anything-help)))
1968 ;;; Ucs help
1971 (defun anything-c-ucs-help ()
1972 "Help command for `anything-ucs'."
1973 (interactive)
1974 (let ((anything-help-message "== Anything Ucs ==
1975 \nSpecific commands for `anything-ucs':
1976 \\<anything-c-ucs-map>
1977 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1978 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1979 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1980 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1981 \\[anything-c-ucs-help]\t\t->Show this help.
1983 \n== Anything Map ==
1984 \\{anything-map}
1986 (anything-help)))
1990 ;;; Mode line strings
1993 (defvar anything-buffer-mode-line-string
1994 '("Buffer(s)"
1995 "\\<anything-c-buffer-map>\
1996 \\[anything-c-buffer-help]:Help, \
1997 \\<anything-map>\
1998 \\[anything-select-action]:Acts,\
1999 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2000 \\[anything-select-3rd-action]:NthAct,\
2001 \\[anything-send-bug-report-from-anything]:BugReport."
2002 "String displayed in mode-line in `anything-c-source-buffers-list'"))
2004 (defvar anything-ff-mode-line-string
2005 "\\<anything-find-files-map>\
2006 \\[anything-ff-help]:Help, \
2007 \\[anything-send-bug-report-from-anything]:BugReport, \
2008 \\<anything-map>\
2009 \\[anything-select-action]:Acts, \
2010 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2011 \\[anything-select-3rd-action]:NthAct"
2012 "String displayed in mode-line in `anything-c-source-find-files'")
2014 (defvar anything-read-file-name-mode-line-string
2015 "\\<anything-c-read-file-map>\
2016 \\[anything-read-file-name-help]:Help, \
2017 \\<anything-map>\
2018 \\[anything-select-action]:Acts,\
2019 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2020 \\[anything-select-3rd-action]:NthAct"
2021 "String displayed in mode-line in `anything-c-source-find-files'")
2023 (defvar anything-generic-file-mode-line-string
2024 "\\<anything-generic-files-map>\
2025 \\[anything-generic-file-help]:Help, \
2026 \\<anything-map>\
2027 \\[anything-select-action]:Acts,\
2028 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2029 \\[anything-select-3rd-action]:NthAct,\
2030 \\[anything-send-bug-report-from-anything]:BugReport."
2031 "String displayed in mode-line in Locate.")
2033 (defvar anything-grep-mode-line-string
2034 "\\<anything-c-grep-map>\
2035 \\[anything-grep-help]:Help,\
2036 \\<anything-map>\
2037 \\[anything-select-action]:Acts,\
2038 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2039 \\[anything-select-3rd-action]:NthAct,\
2040 \\[anything-send-bug-report-from-anything]:BugReport."
2041 "String displayed in mode-line in `anything-do-grep'.")
2043 (defvar anything-pdfgrep-mode-line-string
2044 "\\<anything-c-pdfgrep-map>\
2045 \\[anything-pdfgrep-help]:Help,\
2046 \\<anything-map>\
2047 \\[anything-select-action]:Acts,\
2048 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2049 \\[anything-select-3rd-action]:NthAct,\
2050 \\[anything-send-bug-report-from-anything]:BugReport."
2051 "String displayed in mode-line in `anything-do-pdfgrep'.")
2053 (defvar anything-etags-mode-line-string
2054 "\\<anything-c-etags-map>\
2055 \\[anything-etags-help]:Help,\
2056 \\<anything-map>\
2057 \\[anything-select-action]:Acts,\
2058 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2059 \\[anything-select-3rd-action]:NthAct,\
2060 \\[anything-send-bug-report-from-anything]:BugReport."
2061 "String displayed in mode-line in `anything-c-etags-select'.")
2064 (defvar anything-c-ucs-mode-line-string
2065 "\\<anything-c-ucs-map>\
2066 \\[anything-c-ucs-help]:Help, \
2067 \\<anything-map>\
2068 \\[anything-select-action]:Acts,\
2069 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2070 \\[anything-select-3rd-action]:NthAct."
2071 "String displayed in mode-line in `anything-ucs'.")
2075 ;;; Utilities Functions
2078 (defun anything-ff-find-printers ()
2079 "Return a list of available printers on Unix systems."
2080 (when (executable-find "lpstat")
2081 (let ((printer-list (with-temp-buffer
2082 (call-process "lpstat" nil t nil "-a")
2083 (split-string (buffer-string) "\n"))))
2084 (loop for p in printer-list
2085 for printer = (car (split-string p))
2086 when printer
2087 collect printer))))
2089 ;; Shut up byte compiler in emacs24*.
2090 (defun anything-c-switch-to-buffer (buffer-or-name)
2091 "Same as `switch-to-buffer' whithout warnings at compile time."
2092 (with-no-warnings
2093 (switch-to-buffer buffer-or-name)))
2095 (defsubst* anything-c-position (item seq &key (test 'eq))
2096 "A simple and faster replacement of CL `position'."
2097 (loop for i in seq for index from 0
2098 when (funcall test i item) return index))
2100 (defun anything-c-get-pid-from-process-name (process-name)
2101 "Get pid from running process PROCESS-NAME."
2102 (loop with process-list = (list-system-processes)
2103 for pid in process-list
2104 for process = (assoc-default 'comm (process-attributes pid))
2105 when (and process (string-match process-name process))
2106 return pid))
2108 (defun* anything-current-buffer-narrowed-p (&optional
2109 (buffer anything-current-buffer))
2110 "Check if BUFFER is narrowed.
2111 Default is `anything-current-buffer'."
2112 (with-current-buffer buffer
2113 (let ((beg (point-min))
2114 (end (point-max))
2115 (total (buffer-size)))
2116 (or (/= beg 1) (/= end (1+ total))))))
2118 (defun anything-region-active-p ()
2119 (and transient-mark-mode mark-active (/= (mark) (point))))
2121 (defun anything-goto-line (lineno)
2122 "Goto LINENO opening only outline headline if needed."
2123 (goto-char (point-min)) (forward-line (1- lineno))
2124 (when (or (eq major-mode 'org-mode)
2125 (and (boundp 'outline-minor-mode)
2126 outline-minor-mode))
2127 (require 'org) ; On some old Emacs versions org may not be loaded.
2128 (org-reveal))
2129 (anything-match-line-color-current-line) (sit-for 0.3)
2130 (anything-match-line-cleanup))
2132 (defun anything-show-this-source-only ()
2133 "Show all candidates of this source."
2134 (interactive)
2135 (setq anything-candidate-number-limit nil)
2136 (anything-set-source-filter
2137 (list (assoc-default 'name (anything-get-current-source)))))
2139 ;;;###autoload
2140 (defun anything-test-sources ()
2141 "List all anything sources for test.
2142 The output is sexps which are evaluated by \\[eval-last-sexp]."
2143 (interactive)
2144 (with-output-to-temp-buffer "*Anything Test Sources*"
2145 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2146 (apropos-internal "^anything-c-source" #'boundp))
2147 (pop-to-buffer standard-output)))
2149 (defun anything-nest (&rest same-as-anything)
2150 "Nested `anything'. If you use `anything' within `anything', use it."
2151 (with-selected-window (anything-window)
2152 (let (anything-current-position
2153 anything-current-buffer
2154 (orig-anything-buffer anything-buffer)
2155 anything-pattern
2156 anything-buffer
2157 anything-sources
2158 anything-compiled-sources
2159 anything-buffer-chars-modified-tick
2160 (anything-samewindow t)
2161 (enable-recursive-minibuffers t))
2162 (unwind-protect
2163 (apply #'anything same-as-anything)
2164 (anything-initialize-overlays orig-anything-buffer)
2165 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2167 (defun anything-displaying-source-names ()
2168 "Display sources name."
2169 (with-current-buffer anything-buffer
2170 (goto-char (point-min))
2171 (loop with pos
2172 while (setq pos (next-single-property-change (point) 'anything-header))
2173 do (goto-char pos)
2174 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2175 do (forward-line 1))))
2177 ;; [Obsolete]
2178 (defun anything-select-source ()
2179 "[OBSOLETE] Select source."
2180 (interactive)
2181 (let ((default (assoc-default 'name (anything-get-current-source)))
2182 (source-names (anything-displaying-source-names))
2183 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2184 (anything-get-sources))))
2185 (setq anything-candidate-number-limit 9999)
2186 (anything-aif
2187 (let (anything-source-filter)
2188 (anything-nest '(((name . "Anything Source")
2189 (candidates . source-names)
2190 (action . identity))
2191 ((name . "Anything Source (ALL)")
2192 (candidates . all-source-names)
2193 (action . identity)))
2194 nil "Source: " nil
2195 default "*anything select source*"))
2196 (anything-set-source-filter (list it))
2197 (anything-set-source-filter nil))))
2199 ;; Same as anything-set-pattern but bad written, please fix.
2200 (defun anything-insert-string (str)
2201 "Insert STR."
2202 (delete-minibuffer-contents)
2203 (insert str))
2205 ;;;###autoload
2206 (defun anything-insert-buffer-name ()
2207 "Insert buffer name."
2208 (interactive)
2209 (anything-insert-string
2210 (with-anything-current-buffer
2211 (if buffer-file-name (file-name-nondirectory buffer-file-name)
2212 (buffer-name)))))
2214 ;; This is not needed because M-n do the same thing now by default
2215 ;; See `anything-read-pattern-maybe'.
2216 ;; (defun anything-insert-symbol ()
2217 ;; "Insert current symbol."
2218 ;; (interactive)
2219 ;; (anything-insert-string
2220 ;; (with-anything-current-buffer
2221 ;; (save-excursion
2222 ;; (buffer-substring (beginning-of-thing 'symbol)
2223 ;; (end-of-thing 'symbol))))))
2225 ;; Same as `anything-yank-selection' but wrong because it use
2226 ;; `anything-current-buffer' to get selection.
2227 ;; (defun anything-insert-selection ()
2228 ;; "Insert current selection."
2229 ;; (interactive)
2230 ;; (anything-insert-string
2231 ;; (with-anything-current-buffer
2232 ;; (anything-get-selection))))
2234 (defun anything-c-match-on-file-name (candidate)
2235 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2236 (string-match anything-pattern (file-name-nondirectory candidate)))
2238 (defun anything-c-match-on-directory-name (candidate)
2239 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2240 (anything-aif (file-name-directory candidate)
2241 (string-match anything-pattern it)))
2243 (defun anything-c-match-on-basename (candidate)
2244 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2245 (string-match anything-pattern (anything-c-basename candidate)))
2247 (defun anything-c-string-match (candidate)
2248 "Return non-nil if `anything-pattern' match CANDIDATE.
2249 The match is done with `string-match'."
2250 (string-match anything-pattern candidate))
2252 (defun anything-c-skip-entries (list regexp)
2253 "Remove entries which matches REGEXP from LIST."
2254 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2255 list))
2257 (defun anything-c-shadow-entries (list regexp)
2258 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2259 (mapcar (lambda (file)
2260 ;; Add shadow face property to boring files.
2261 (let ((face (if (facep 'file-name-shadow)
2262 'file-name-shadow
2263 ;; fall back to default on XEmacs
2264 'default)))
2265 (if (string-match regexp file)
2266 (setq file (propertize file 'face face))))
2267 file)
2268 list))
2270 (defsubst anything-c-stringify (str-or-sym)
2271 "Get string of STR-OR-SYM."
2272 (if (stringp str-or-sym)
2273 str-or-sym
2274 (symbol-name str-or-sym)))
2276 (defsubst anything-c-symbolify (str-or-sym)
2277 "Get symbol of STR-OR-SYM."
2278 (if (symbolp str-or-sym)
2279 str-or-sym
2280 (intern str-or-sym)))
2282 (defun anything-c-describe-function (func)
2283 "FUNC is symbol or string."
2284 (describe-function (anything-c-symbolify func)))
2286 (defun anything-c-describe-variable (var)
2287 "VAR is symbol or string."
2288 (describe-variable (anything-c-symbolify var)))
2290 (defun anything-c-find-function (func)
2291 "FUNC is symbol or string."
2292 (find-function (anything-c-symbolify func)))
2294 (defun anything-c-find-variable (var)
2295 "VAR is symbol or string."
2296 (find-variable (anything-c-symbolify var)))
2298 (defun anything-c-kill-new (candidate &optional replace)
2299 "CANDIDATE is symbol or string.
2300 See `kill-new' for argument REPLACE."
2301 (kill-new (anything-c-stringify candidate) replace))
2303 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2304 "Remove duplicates elements in list SEQ.
2305 This is same as `remove-duplicates' but with memoisation.
2306 It is much faster, especially in large lists.
2307 A test function can be provided with TEST argument key.
2308 Default is `eq'."
2309 (loop with cont = (make-hash-table :test test)
2310 for elm in seq
2311 unless (gethash elm cont)
2312 do (puthash elm elm cont)
2313 finally return
2314 (loop for i being the hash-values in cont collect i)))
2316 (defadvice eval-defun (after anything-source-hack activate)
2317 "Allow immediate execution of anything source when evaling it.
2318 See `anything-c-enable-eval-defun-hack'."
2319 (when anything-c-enable-eval-defun-hack
2320 (let ((varsym (save-excursion
2321 (beginning-of-defun)
2322 (forward-char 1)
2323 (when (memq (read (current-buffer)) '(defvar setq))
2324 (read (current-buffer))))))
2325 (when (string-match "^anything-c-source-" (symbol-name varsym))
2326 (anything varsym)))))
2327 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2330 ;; Move this function from anything.el and redefine here
2331 ;; to avoid an unneeded defadvice.
2332 (defun anything-quit-and-find-file ()
2333 "Drop into `anything-find-files' from `anything'.
2334 If current selection is a buffer or a file, `anything-find-files'
2335 from its directory."
2336 (interactive)
2337 (anything-run-after-quit
2338 (lambda (f)
2339 (if (file-exists-p f)
2340 (anything-find-files-1 (file-name-directory f)
2341 (if anything-ff-transformer-show-only-basename
2342 (anything-c-basename f) f))
2343 (anything-find-files-1 f)))
2344 (anything-aif (get-buffer (anything-get-selection))
2345 (or (buffer-file-name it)
2346 (car (rassoc it dired-buffers))
2347 (and (with-current-buffer it
2348 (eq major-mode 'org-agenda-mode))
2349 org-directory
2350 (expand-file-name org-directory))
2351 default-directory)
2352 (let ((sel (anything-get-selection)))
2353 (if (file-exists-p sel)
2354 (expand-file-name sel)
2355 default-directory)))))
2358 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2359 "Walk through DIRECTORY tree.
2360 PATH can be one of basename, relative, or full.
2361 DIRECTORIES when non--nil (default) return also directories names, otherwise
2362 skip directories names.
2363 MATCH match only filenames matching regexp MATCH."
2364 `(let (result
2365 (fn (case ,path
2366 (basename 'file-name-nondirectory)
2367 (relative 'file-relative-name)
2368 (full 'identity)
2369 (t 'file-name-nondirectory))))
2370 (labels ((ls-R (dir)
2371 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2372 for f in ls
2373 if (file-directory-p f)
2374 do (progn (when ,directories
2375 (push (funcall fn f) result))
2376 ;; Don't recurse in directory symlink.
2377 (unless (file-symlink-p f)
2378 (ls-R f)))
2379 else do
2380 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2381 (push (funcall fn f) result)))))
2382 (ls-R ,directory)
2383 (nreverse result))))
2385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2387 ;;; Anything regexp.
2390 (defvar anything-build-regexp-history nil)
2391 (defun anything-c-query-replace-regexp (candidate)
2392 "Query replace regexp from `anything-regexp'.
2393 With a prefix arg replace only matches surrounded by word boundaries,
2394 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2395 (let ((regexp (funcall (anything-attr 'regexp))))
2396 (apply 'query-replace-regexp
2397 (anything-c-query-replace-args regexp))))
2399 (defun anything-c-kill-regexp-as-sexp (candidate)
2400 "Kill regexp in a format usable in lisp code."
2401 (anything-c-regexp-kill-new
2402 (prin1-to-string (funcall (anything-attr 'regexp)))))
2404 (defun anything-c-kill-regexp (candidate)
2405 "Kill regexp as it is in `anything-pattern'."
2406 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2408 (defun anything-c-query-replace-args (regexp)
2409 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2410 (let ((region-only (anything-region-active-p)))
2411 (list
2412 regexp
2413 (query-replace-read-to regexp
2414 (format "Query replace %sregexp %s"
2415 (if anything-current-prefix-arg "word " "")
2416 (if region-only "in region " ""))
2418 anything-current-prefix-arg
2419 (when region-only (region-beginning))
2420 (when region-only (region-end)))))
2422 (defvar anything-c-source-regexp
2423 '((name . "Regexp Builder")
2424 (init . (lambda ()
2425 (anything-candidate-buffer anything-current-buffer)))
2426 (candidates-in-buffer)
2427 (get-line . anything-c-regexp-get-line)
2428 (persistent-action . anything-c-regexp-persistent-action)
2429 (persistent-help . "Show this line")
2430 (multiline)
2431 (delayed)
2432 (requires-pattern . 2)
2433 (mode-line . "Press TAB to select action.")
2434 (regexp . (lambda () anything-input))
2435 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2436 ("Query Replace Regexp (C-u Not inside word.)"
2437 . anything-c-query-replace-regexp)
2438 ("Kill Regexp" . anything-c-kill-regexp)))))
2440 (defun anything-c-regexp-get-line (s e)
2441 (propertize
2442 (apply 'concat
2443 ;; Line contents
2444 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2445 ;; subexps
2446 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2447 collect (format "\n %s'%s'"
2448 (if (zerop i) "Group 0: " (format "Group %d: " i))
2449 (match-string i))))
2450 ;; match beginning
2451 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2452 ;; It is implementation problem of candidates-in-buffer.
2453 'anything-realvalue
2454 (1- s)))
2456 (defun anything-c-regexp-persistent-action (pt)
2457 (goto-char pt)
2458 (anything-persistent-highlight-point))
2460 (defun anything-c-regexp-kill-new (input)
2461 (kill-new input)
2462 (message "Killed: %s" input))
2466 ;;; Toggle all marks.
2469 ;;;###autoload
2470 (defun anything-mark-all ()
2471 "Mark all visible unmarked candidates in current source."
2472 (interactive)
2473 (with-anything-window
2474 (save-excursion
2475 (goto-char (anything-get-previous-header-pos))
2476 (anything-next-line)
2477 (let* ((next-head (anything-get-next-header-pos))
2478 (end (and next-head
2479 (save-excursion
2480 (goto-char next-head)
2481 (forward-line -1)
2482 (point))))
2483 (maxpoint (or end (point-max))))
2484 (while (< (point) maxpoint)
2485 (anything-mark-current-line)
2486 (let ((prefix (get-text-property (point-at-bol) 'display))
2487 (bn (anything-c-basename (anything-get-selection)))
2488 (src (assoc-default 'name (anything-get-current-source))))
2489 (when (and (not (anything-this-visible-mark))
2490 (not (or (string= prefix "[?]")
2491 (string= prefix "[@]"))))
2492 ;; Don't mark possibles directories ending with . or ..
2493 ;; and also autosave files/links.
2494 (unless
2495 (and (or (anything-file-completion-source-p)
2496 (equal src "Files from Current Directory"))
2497 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2498 (anything-make-visible-mark))))
2499 (forward-line 1) (end-of-line))))
2500 (anything-mark-current-line)
2501 (message "%s candidates marked" (length anything-marked-candidates))))
2503 ;;;###autoload
2504 (defun anything-unmark-all ()
2505 "Unmark all candidates in all sources of current anything session."
2506 (interactive)
2507 (with-anything-window
2508 (let ((len (length anything-marked-candidates)))
2509 (save-excursion
2510 (anything-clear-visible-mark))
2511 (setq anything-marked-candidates nil)
2512 (anything-mark-current-line)
2513 (message "%s candidates unmarked" len))))
2515 ;;;###autoload
2516 (defun anything-toggle-all-marks ()
2517 "Toggle all marks.
2518 Mark all visible candidates of current source or unmark all candidates
2519 visible or invisible in all sources of current anything session"
2520 (interactive)
2521 (let ((marked (anything-marked-candidates)))
2522 (if (and (>= (length marked) 1)
2523 (with-anything-window anything-visible-mark-overlays))
2524 (anything-unmark-all)
2525 (anything-mark-all))))
2529 ;;; Buffers
2532 (defun anything-c-buffer-list ()
2533 "Return the list of names of buffers with boring buffers filtered out.
2534 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2535 The first buffer in the list will be the last recently used
2536 buffer that is not the current buffer."
2537 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2538 (append (cdr buffers) (list (car buffers)))))
2540 (defvar anything-c-source-buffers
2541 '((name . "Buffers")
2542 (candidates . anything-c-buffer-list)
2543 (type . buffer)))
2544 ;; (anything 'anything-c-source-buffers)
2546 (defvar anything-c-source-buffer-not-found
2547 '((name . "Create buffer")
2548 (dummy)
2549 (filtered-candidate-transformer (lambda (cands source)
2550 (list anything-pattern)))
2551 (action . (lambda (candidate)
2552 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2553 ;; (anything 'anything-c-source-buffer-not-found)
2555 ;;; Buffers-list (was buffers+)
2558 (eval-when-compile (require 'dired))
2560 (defun anything-c-highlight-buffers (buffers)
2561 (loop for i in buffers
2562 for buf = (get-buffer i)
2563 for bfname = (buffer-file-name buf)
2564 collect
2565 (cond (;; A dired buffer.
2566 (rassoc buf dired-buffers)
2567 (propertize i 'face 'anything-ff-directory
2568 'help-echo (car (rassoc buf dired-buffers))))
2569 ;; A buffer file modified somewhere outside of emacs.
2570 ((and bfname (not (file-remote-p bfname))
2571 (file-exists-p bfname)
2572 (not (verify-visited-file-modtime buf)))
2573 (propertize i 'face 'anything-buffer-saved-out
2574 'help-echo bfname))
2575 ;; A new buffer file not already saved on disk.
2576 ((and bfname (not (file-remote-p bfname))
2577 (not (verify-visited-file-modtime buf)))
2578 (propertize i 'face 'anything-buffer-not-saved
2579 'help-echo bfname))
2580 ;; A Remote buffer file modified and not saved on disk.
2581 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2582 (let ((prefix (propertize
2583 " " 'display
2584 (propertize "@ " 'face 'anything-ff-prefix))))
2585 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2586 'help-echo bfname)) i)))
2587 ;; A buffer file modified and not saved on disk.
2588 ((and bfname (buffer-modified-p buf))
2589 (propertize i 'face 'anything-ff-symlink
2590 'help-echo bfname))
2591 ;; A remote buffer file not modified and saved on disk.
2592 ((and bfname (file-remote-p bfname))
2593 (let ((prefix (propertize
2594 " " 'display
2595 (propertize "@ " 'face 'anything-ff-prefix))))
2596 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2597 'help-echo bfname)) i)))
2598 ;; A buffer file not modified and saved on disk.
2599 (bfname
2600 (propertize i 'face 'font-lock-type-face
2601 'help-echo bfname))
2602 ;; Any non--file buffer.
2603 (t (propertize i 'face 'italic)))))
2606 (defvar anything-c-source-buffers-list
2607 '((name . "Buffers")
2608 (candidates . anything-c-buffer-list)
2609 (type . buffer)
2610 (match anything-c-buffer-match-major-mode)
2611 (candidate-transformer
2612 anything-c-skip-current-buffer
2613 anything-c-skip-boring-buffers
2614 anything-c-highlight-buffers)
2615 (persistent-action . anything-c-buffers-list-persistent-action)
2616 (volatile)
2617 (mode-line . anything-buffer-mode-line-string)
2618 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2619 ;; (anything '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 "c:/" result))
3536 (empty "/")
3538 (concat "/" result)))))))
3540 ;; Internal
3541 (defvar anything-file-completion-sources
3542 '("Find Files" "Read File Name"
3543 "Read File Name History" "Copy Files"
3544 "Rename Files" "Symlink Files"
3545 "Hardlink Files" "Write File" "Insert File")
3546 "Sources that use the *find-files mechanism can be added here.
3547 You should not modify this yourself and know what you do if you do so.")
3549 (defun anything-file-completion-source-p ()
3550 "Test if current source is a dired or find-files source."
3551 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3552 (loop for i in anything-file-completion-sources
3553 thereis (string= cur-source i))))
3555 (defun anything-find-files-down-one-level (arg)
3556 "Go down one level like unix command `cd ..'.
3557 If prefix numeric arg is given go ARG level down."
3558 (interactive "p")
3559 (when (and (anything-file-completion-source-p)
3560 (not (anything-ff-invalid-tramp-name-p)))
3561 (with-anything-window
3562 (setq anything-follow-mode nil))
3563 ;; When going to precedent level we want to be at the line
3564 ;; corresponding to actual directory, so store this info
3565 ;; in `anything-ff-last-expanded'.
3566 (if (and (not (file-directory-p anything-pattern))
3567 (file-exists-p anything-pattern))
3568 (setq anything-ff-last-expanded anything-pattern)
3569 (setq anything-ff-last-expanded anything-ff-default-directory))
3570 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3571 :unix-close t :expand t)))
3572 (anything-set-pattern new-pattern))))
3574 (defun anything-ff-retrieve-last-expanded ()
3575 "Move overlay to last visited directory `anything-ff-last-expanded'.
3576 This happen after using `anything-find-files-down-one-level',
3577 or hitting C-z on \"..\"."
3578 (when (and anything-ff-last-expanded
3579 (anything-file-completion-source-p))
3580 (let ((dirname (if anything-ff-transformer-show-only-basename
3581 (anything-c-basename
3582 (directory-file-name anything-ff-last-expanded))
3583 (directory-file-name anything-ff-last-expanded))))
3584 (with-anything-window
3585 (when (or (re-search-forward (concat dirname "$") nil t)
3586 (re-search-forward
3587 (concat anything-ff-last-expanded "$") nil t))
3588 (forward-line 0)
3589 (anything-mark-current-line)))
3590 (setq anything-ff-last-expanded nil))))
3591 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3593 ;; Auto-update - anything-find-files auto expansion of directories.
3595 (defun anything-ff-update-when-only-one-matched ()
3596 "Expand to directory when sole completion.
3597 When only one candidate is remaining and it is a directory,
3598 expand to this directory."
3599 (when (and anything-ff-auto-update-flag
3600 (anything-file-completion-source-p)
3601 (not (anything-ff-invalid-tramp-name-p)))
3602 (let* ((history-p (string= (assoc-default
3603 'name (anything-get-current-source))
3604 "Read File Name History"))
3605 (pat (if (string-match tramp-file-name-regexp
3606 anything-pattern)
3607 (anything-create-tramp-name anything-pattern)
3608 anything-pattern))
3609 (completed-p (string= (file-name-as-directory pat)
3610 anything-ff-default-directory)))
3611 (when (and (or
3612 ;; Only one candidate remaining
3613 ;; and at least 2 char in basename.
3614 (and (<= (anything-approximate-candidate-number) 2)
3615 (>= (length (anything-c-basename anything-pattern)) 2))
3616 ;; Already completed.
3617 completed-p)
3618 (not history-p)) ; Don't try to auto complete in history.
3619 (with-anything-window
3620 (let ((cur-cand (prog2
3621 (unless completed-p
3622 ;; Only one non--existing candidate
3623 ;; and one directory candidate, move to it.
3624 (anything-next-line))
3625 (anything-get-selection))))
3626 (when (file-directory-p cur-cand)
3627 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3628 ;; Maybe we are here because completed-p is true
3629 ;; but check this again to be sure. (Windows fix)
3630 (<= (anything-approximate-candidate-number) 2)) ; [2]
3631 ;; If after going to next line the candidate
3632 ;; is not one of "." or ".." [1]
3633 ;; and only one candidate is remaining [2],
3634 ;; assume candidate is a new directory to expand, and do it.
3635 (anything-set-pattern (file-name-as-directory cur-cand))
3636 ;; The candidate is one of "." or ".."
3637 ;; that mean we have entered the last letter of the directory name
3638 ;; in prompt, so expansion is already done, just add the "/" at end
3639 ;; of name unless anything-pattern ends with "."
3640 ;; (i.e we are writing something starting with ".")
3641 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3642 (anything-set-pattern
3643 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3644 (expand-file-name (file-name-as-directory anything-pattern)))))
3645 (anything-check-minibuffer-input-1))))))))
3646 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3648 ;; Allow expanding to home directory or root
3649 ;; when entering respectively "~/" or "//" at end of pattern.
3650 ;; e.g /home/thierry/labo/anything-config-qp/~/
3651 ;; will expand to "~/"
3652 ;; and /home/thierry/labo/anything-config-qp//
3653 ;; will expand to "/"
3654 (defun anything-ff-auto-expand-to-home-or-root ()
3655 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3656 This happen only in function using sources that are
3657 `anything-file-completion-source-p' compliant."
3658 (when (and (anything-file-completion-source-p)
3659 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3660 anything-pattern))
3661 (let ((match (match-string 1 anything-pattern)))
3662 (cond ((string= match "//")
3663 (if (eq system-type 'windows-nt)
3664 (setq anything-pattern "c:/")
3665 (setq anything-pattern "/")))
3666 ((string= match "/~/")
3667 (if (eq system-type 'windows-nt)
3668 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3669 (setq anything-pattern "~/")))
3670 ((string= match "/./")
3671 (setq anything-pattern
3672 (with-anything-current-buffer
3673 (expand-file-name default-directory))))))
3674 (setq anything-ff-default-directory anything-pattern)
3675 ;; For some reasons, i must use here with-current-buffer => mini buffer
3676 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3677 (with-current-buffer (window-buffer (minibuffer-window))
3678 (delete-minibuffer-contents)
3679 (insert anything-pattern))))
3681 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3683 (defun anything-c-point-file-in-dired (file)
3684 "Put point on filename FILE in dired buffer."
3685 (dired (file-name-directory file))
3686 (dired-goto-file file))
3688 (defun anything-create-tramp-name (fname)
3689 "Build filename for `anything-pattern' like /su:: or /sudo::."
3690 (apply #'tramp-make-tramp-file-name
3691 (loop with v = (tramp-dissect-file-name fname)
3692 for i across v collect i)))
3694 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3695 "Get a list of hosts for tramp method found in `anything-pattern'.
3696 Argument PATTERN default to `anything-pattern', it is here only for debugging
3697 purpose."
3698 (when (string-match tramp-file-name-regexp pattern)
3699 (let ((method (match-string 1 pattern))
3700 (tn (match-string 0 pattern))
3701 (all-methods (mapcar 'car tramp-methods)))
3702 (remove-duplicates
3703 (loop for (f . h) in (tramp-get-completion-function method)
3704 append (loop for e in (funcall f (car h))
3705 for host = (and (consp e) (cadr e))
3706 when (and host (not (member host all-methods)))
3707 collect (concat tn host)))
3708 :test 'equal))))
3710 (defun anything-ff-before-action-hook-fn ()
3711 "Exit anything when user try to execute action on an invalid tramp fname."
3712 (let ((cand (anything-get-selection)))
3713 (when (and (anything-file-completion-source-p)
3714 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3715 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3716 (error "Error: Unknow file or directory `%s'" cand))))
3717 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3719 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3720 "Return non--nil when PATTERN is an invalid tramp filename."
3721 (string= (anything-ff-set-pattern pattern)
3722 "Invalid tramp file name"))
3724 (defun anything-ff-set-pattern (pattern)
3725 "Handle tramp filenames in `anything-pattern'."
3726 (let ((methods (mapcar 'car tramp-methods))
3727 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3728 cur-method tramp-name)
3729 (cond ((string= pattern "") "")
3730 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3731 (with-anything-current-buffer
3732 (expand-file-name default-directory)))
3733 ((string-match ".*\\(~//\\|//\\)$" pattern)
3734 (if (eq system-type 'windows-nt) "c:/" "/"))
3735 ((string-match "^~\\|.*/~/$" pattern)
3736 (let* ((home (expand-file-name (getenv "HOME"))))
3737 (replace-match home nil t pattern)))
3738 ;; Match "/method:maybe_hostname:"
3739 ((and (string-match reg pattern)
3740 (setq cur-method (match-string 1 pattern))
3741 (member cur-method methods))
3742 (setq tramp-name (anything-create-tramp-name
3743 (match-string 0 pattern)))
3744 (replace-match tramp-name nil t pattern))
3745 ;; Match "/hostname:"
3746 ((and (string-match tramp-file-name-regexp pattern)
3747 (setq cur-method (match-string 1 pattern))
3748 (and cur-method (not (member cur-method methods))))
3749 (setq tramp-name (anything-create-tramp-name
3750 (match-string 0 pattern)))
3751 (replace-match tramp-name nil t pattern))
3752 ;; Match "/method:" in this case don't try to connect.
3753 ((and (not (string-match reg pattern))
3754 (string-match tramp-file-name-regexp pattern)
3755 (member (match-string 1 pattern) methods))
3756 "Invalid tramp file name") ; Write in anything-buffer.
3757 ;; PATTERN is a directory, end it with "/".
3758 ;; This will make PATTERN not ending yet with "/"
3759 ;; candidate for `anything-ff-default-directory',
3760 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3761 ;; when descending level.
3762 ((file-directory-p pattern)
3763 (file-name-as-directory pattern))
3764 ;; Return PATTERN unchanged.
3765 (t pattern))))
3767 (defun anything-find-files-get-candidates ()
3768 "Create candidate list for `anything-c-source-find-files'."
3769 (let* ((path (anything-ff-set-pattern anything-pattern))
3770 (path-name-dir (if (file-directory-p path)
3771 (file-name-as-directory path)
3772 (file-name-directory path)))
3773 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3774 (set-text-properties 0 (length path) nil path)
3775 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3776 ;; like that the actual value (e.g /ssh:) is passed to
3777 ;; `anything-ff-tramp-hostnames'.
3778 (unless (string= path "Invalid tramp file name")
3779 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3780 (setq anything-ff-default-directory
3781 (if (string= anything-pattern "")
3782 (if (eq system-type 'windows-nt) "c:/" "/")
3783 (unless (string-match ffap-url-regexp path)
3784 ;; If path is an url *default-directory have to be nil.
3785 path-name-dir)))
3786 (cond ((string= path "Invalid tramp file name")
3787 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3788 (prog2
3789 ;; `anything-pattern' have not been modified yet.
3790 ;; Set it here to the value of `path' that should be now
3791 ;; "Invalid tramp file name" and set the candidates list
3792 ;; to ("Invalid tramp file name") to make `anything-pattern'
3793 ;; match single candidate "Invalid tramp file name".
3794 (setq anything-pattern path)
3795 ;; "Invalid tramp file name" is now printed
3796 ;; in `anything-buffer'.
3797 (list path))))
3798 ((or (file-regular-p path)
3799 (and (not (file-exists-p path)) (string-match "/$" path))
3800 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3801 (list path))
3802 ((string= path "") (directory-files "/" t))
3803 ((and (file-directory-p path) (not (file-readable-p path)))
3804 (list (format "Opening directory: access denied, `%s'" path)))
3805 ((file-directory-p path) (directory-files path t))
3807 (append (list path) (directory-files path-name-dir t))))))
3809 (defun anything-ff-transform-fname-for-completion (fname)
3810 "Return FNAME with it's basename modified as a regexp.
3811 e.g foo => f.*o.*o .
3812 If basename contain one or more space or FNAME is a valid directory name
3813 return FNAME unchanged."
3814 (let ((bn (anything-c-basename fname)))
3815 (if (or (not anything-ff-smart-completion)
3816 (string-match "\\s-" bn)
3817 (string-match "/$" fname) ; Allow mkdir.
3818 (file-directory-p fname))
3819 fname ; Fall back to match-plugin.
3820 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3821 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3822 (concat (file-name-directory fname) bn))))
3824 (defun anything-ff-save-history ()
3825 "Store the last value of `anything-ff-default-directory' \
3826 in `anything-ff-history'."
3827 (when (and anything-ff-default-directory
3828 (anything-file-completion-source-p))
3829 (push anything-ff-default-directory anything-ff-history)))
3830 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3832 (defun anything-ff-valid-symlink-p (file)
3833 (file-exists-p (file-truename file)))
3835 (defun anything-ff-properties (candidate)
3836 "Show file properties of CANDIDATE in a tooltip or message."
3837 (let ((type (anything-ff-attributes candidate :type t))
3838 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3839 (if (window-system)
3840 (tooltip-show
3841 (concat
3842 (anything-c-basename candidate) ": \n"
3843 "Type: " type "\n"
3844 (when (string= type "symlink")
3845 (format "True name: '%s'\n"
3846 (cond ((string-match "^\.#" (anything-c-basename candidate))
3847 "Autosave symlink")
3848 ((anything-ff-valid-symlink-p candidate)
3849 (file-truename candidate))
3850 (t "Invalid Symlink"))))
3851 dired-line))
3852 (message dired-line) (sit-for 5))))
3854 ;;;###autoload
3855 (defun anything-ff-properties-persistent ()
3856 "Show properties without quitting anything."
3857 (interactive)
3858 (anything-attrset 'properties-action 'anything-ff-properties)
3859 (anything-execute-persistent-action 'properties-action))
3861 ;;;###autoload
3862 (defun anything-ff-persistent-delete ()
3863 "Delete current candidate without quitting."
3864 (interactive)
3865 (anything-attrset 'quick-delete 'anything-ff-quick-delete)
3866 (anything-execute-persistent-action 'quick-delete))
3868 (defun anything-ff-quick-delete (candidate)
3869 "Delete file CANDIDATE without quitting."
3870 (let ((presel (prog1 (save-excursion
3871 (let (sel)
3872 (anything-next-line)
3873 (setq sel (anything-get-selection))
3874 (if (string= sel candidate)
3875 (progn (anything-previous-line)
3876 (anything-get-selection))
3877 sel)))
3878 (anything-mark-current-line))))
3879 (setq presel (if (and anything-ff-transformer-show-only-basename
3880 (not (string-match-p "[.]\\{1,2\\}$" presel)))
3881 (anything-c-basename presel) presel))
3882 (if anything-ff-quick-delete-dont-prompt-for-deletion
3883 (anything-c-delete-file candidate)
3884 (save-selected-window
3885 (when (y-or-n-p (format "Really Delete file `%s'? " candidate))
3886 (anything-c-delete-file candidate))))
3887 (anything-force-update presel)))
3889 (defun anything-ff-kill-buffer-fname (candidate)
3890 (let* ((buf (get-file-buffer candidate))
3891 (buf-name (buffer-name buf)))
3892 (if buf
3893 (progn
3894 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3895 (message "No buffer to kill"))))
3897 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3898 "Find file CANDIDATE or kill it's buffer if it is visible.
3899 Never kill `anything-current-buffer'.
3900 Never kill buffer modified.
3901 This is called normally on third hit of \
3902 \\<anything-map>\\[anything-execute-persistent-action]
3903 in `anything-find-files-persistent-action'."
3904 (let* ((buf (get-file-buffer candidate))
3905 (buf-name (buffer-name buf)))
3906 (if (and buf (get-buffer-window buf)
3907 (not (eq buf (get-buffer anything-current-buffer)))
3908 (not (buffer-modified-p buf)))
3909 (progn
3910 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3911 (find-file candidate))))
3913 ;;;###autoload
3914 (defun anything-ff-run-kill-buffer-persistent ()
3915 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3916 (interactive)
3917 (anything-attrset 'kill-buffer-fname 'anything-ff-kill-buffer-fname)
3918 (anything-execute-persistent-action 'kill-buffer-fname))
3920 (defun anything-ff-human-size (size)
3921 "Return a string showing SIZE of a file in human readable form.
3922 SIZE can be an integer or a float depending it's value.
3923 `file-attributes' will take care of that to avoid overflow error.
3924 KBSIZE if a floating point number, default value is 1024.0."
3925 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3926 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3927 (K (cons "K" (/ size anything-ff-default-kbsize)))
3928 (B (cons "B" size)))
3929 (loop with result = B
3930 for (a . b) in
3931 (loop for (x . y) in (list M G K B)
3932 unless (< y 1) collect (cons x y))
3933 when (< b (cdr result)) do (setq result (cons a b))
3934 finally return (if (string= (car result) "B")
3935 (format "%s" size)
3936 (format "%.1f%s" (cdr result) (car result))))))
3938 (defun* anything-ff-attributes
3939 (file &key type links uid gid access-time modif-time
3940 status size mode gid-change inode device-num dired human-size)
3941 "Easy interface for `file-attributes'."
3942 (let ((all (destructuring-bind
3943 (type links uid gid access-time modif-time
3944 status size mode gid-change inode device-num)
3945 (file-attributes file 'string)
3946 (list :type type
3947 :links links
3948 :uid uid
3949 :gid gid
3950 :access-time access-time
3951 :modif-time modif-time
3952 :status status
3953 :size size
3954 :mode mode
3955 :gid-change gid-change
3956 :inode inode
3957 :device-num device-num))))
3958 (cond (type
3959 (let ((result (getf all :type)))
3960 (cond ((stringp result)
3961 "symlink")
3962 (result "directory")
3963 (t "file"))))
3964 (links (getf all :links))
3965 (uid (getf all :uid))
3966 (gid (getf all :gid))
3967 (access-time
3968 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3969 (modif-time
3970 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3971 (status
3972 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3973 (size (if human-size (anything-ff-human-size (getf all :size))
3974 (getf all :size)))
3975 (mode (getf all :mode))
3976 (gid-change (getf all :gid-change))
3977 (inode (getf all :inode))
3978 (device-num (getf all :device-num))
3979 (dired
3980 (concat
3981 (getf all :mode) " "
3982 (number-to-string (getf all :links)) " "
3983 (getf all :uid) ":"
3984 (getf all :gid) " "
3985 (if human-size (anything-ff-human-size (getf all :size))
3986 (int-to-string (getf all :size))) " "
3987 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3988 (t all))))
3990 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3991 "Return filename FNAME maybe prefixed with [?] or [@].
3992 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3993 existing filename or valid symlink and there is no need to test it.
3994 NEW-FILE when non--nil mean FNAME is a non existing file and
3995 return FNAME prefixed with [?]."
3996 (let* ((prefix-new (propertize
3997 " " 'display
3998 (propertize "[?]" 'face 'anything-ff-prefix)))
3999 (prefix-url (propertize
4000 " " 'display
4001 (propertize "[@]" 'face 'anything-ff-prefix))))
4002 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
4003 ((string-match ffap-url-regexp fname)
4004 (concat prefix-url " " fname))
4005 ((or new-file (not (file-exists-p fname)))
4006 (concat prefix-new " " fname)))))
4008 (defun anything-c-find-files-transformer (files sources)
4009 "Transformer for `anything-c-source-find-files'.
4010 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4011 is non--nil."
4012 (if (and (string-match tramp-file-name-regexp anything-pattern)
4013 anything-ff-tramp-not-fancy)
4014 (if anything-ff-transformer-show-only-basename
4015 (loop for i in files collect
4016 (if (string-match "[.]\\{1,2\\}$" i)
4017 i (cons (anything-c-basename i) i)))
4018 files)
4019 (anything-ff-highlight-files files sources)))
4021 (defun anything-ff-highlight-files (files sources)
4022 "Candidate transformer for `anything-c-source-find-files' without icons."
4023 (loop for i in files
4024 for disp = (if (and anything-ff-transformer-show-only-basename
4025 (not (string-match "[.]\\{1,2\\}$" i))
4026 (not (string-match ffap-url-regexp i)))
4027 (anything-c-basename i) i)
4028 collect
4029 (cond ((and (stringp (car (file-attributes i)))
4030 (not (anything-ff-valid-symlink-p i))
4031 (not (string-match "^\.#" (anything-c-basename i))))
4032 (cons (anything-ff-prefix-filename
4033 (propertize disp 'face 'anything-ff-invalid-symlink) t)
4035 ((stringp (car (file-attributes i)))
4036 (cons (anything-ff-prefix-filename
4037 (propertize disp 'face 'anything-ff-symlink) t)
4039 ((eq t (car (file-attributes i)))
4040 (cons (anything-ff-prefix-filename
4041 (propertize disp 'face 'anything-ff-directory) t)
4043 ((file-executable-p i)
4044 (cons (anything-ff-prefix-filename
4045 (propertize disp 'face 'anything-ff-executable) t)
4047 ((file-exists-p i)
4048 (cons (anything-ff-prefix-filename
4049 (propertize disp 'face 'anything-ff-file) t)
4052 (cons (anything-ff-prefix-filename
4053 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4054 i)))))
4056 (defun anything-find-files-action-transformer (actions candidate)
4057 "Action transformer for `anything-c-source-find-files'."
4058 (cond ((with-anything-current-buffer
4059 (eq major-mode 'message-mode))
4060 (append (subseq actions 0 4)
4061 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4062 (subseq actions 4)))
4063 ((string-match (image-file-name-regexp) candidate)
4064 (append (subseq actions 0 4)
4065 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4066 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4067 (subseq actions 4)))
4068 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4069 (car it) candidate))
4070 (append (subseq actions 0 4)
4071 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4072 . anything-find-files-byte-compile)
4073 ("Load File(s) `M-L'" . anything-find-files-load-files))
4074 (subseq actions 4)))
4075 ((and (string-match "\.html?$" candidate)
4076 (file-exists-p candidate))
4077 (append (subseq actions 0 4)
4078 '(("Browse url file" . browse-url-of-file))
4079 (subseq actions 5)))
4080 ((or (string= (file-name-extension candidate) "pdf")
4081 (string= (file-name-extension candidate) "PDF"))
4082 (append (subseq actions 0 4)
4083 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4084 (subseq actions 5)))
4085 (t actions)))
4087 (defun anything-ff-gnus-attach-files (candidate)
4088 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4089 (let ((flist (anything-marked-candidates)))
4090 (gnus-dired-attach flist)))
4092 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4093 "Rotate current image at NUM-ARG degrees.
4094 This is a destructive operation on FILE made by external tool mogrify."
4095 (declare (special image-dired-display-image-buffer))
4096 (setq file (file-truename file)) ; For symlinked images.
4097 ;; When FILE is not an image-file, do nothing.
4098 (when (string-match (image-file-name-regexp) file)
4099 (if (executable-find "mogrify")
4100 (progn
4101 (shell-command (format "mogrify -rotate %s %s"
4102 (or num-arg 90)
4103 (shell-quote-argument file)))
4104 (when (buffer-live-p image-dired-display-image-buffer)
4105 (kill-buffer image-dired-display-image-buffer))
4106 (image-dired-display-image file)
4107 (message nil)
4108 (display-buffer (get-buffer image-dired-display-image-buffer)))
4109 (error "mogrify not found"))))
4111 (defun anything-ff-rotate-image-left (candidate)
4112 "Rotate image file CANDIDATE left.
4113 This affect directly file CANDIDATE."
4114 (anything-ff-rotate-current-image-1 candidate -90))
4116 (defun anything-ff-rotate-image-right (candidate)
4117 "Rotate image file CANDIDATE right.
4118 This affect directly file CANDIDATE."
4119 (anything-ff-rotate-current-image-1 candidate))
4121 (defun anything-ff-rotate-left-persistent ()
4122 "Rotate image left without quitting anything."
4123 (interactive)
4124 (anything-attrset 'image-action1 'anything-ff-rotate-image-left)
4125 (anything-execute-persistent-action 'image-action1))
4127 (defun anything-ff-rotate-right-persistent ()
4128 "Rotate image right without quitting anything."
4129 (interactive)
4130 (anything-attrset 'image-action2 'anything-ff-rotate-image-right)
4131 (anything-execute-persistent-action 'image-action2))
4133 (defun anything-ff-exif-data (candidate)
4134 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4135 (if (and anything-ff-exif-data-program
4136 (executable-find anything-ff-exif-data-program))
4137 (shell-command-to-string (format "%s %s %s"
4138 anything-ff-exif-data-program
4139 anything-ff-exif-data-program-args
4140 candidate))
4141 (format "No program %s found to extract exif"
4142 anything-ff-exif-data-program)))
4144 (defun anything-find-files-persistent-action (candidate)
4145 "Open subtree CANDIDATE without quitting anything.
4146 If CANDIDATE is not a directory expand CANDIDATE filename.
4147 If CANDIDATE is alone, open file CANDIDATE filename.
4148 That's mean:
4149 First hit on C-z expand CANDIDATE second hit open file.
4150 If a prefix arg is given or `anything-follow-mode' is on open file."
4151 (let ((follow (buffer-local-value
4152 'anything-follow-mode
4153 (get-buffer-create anything-buffer)))
4154 (new-pattern (anything-get-selection))
4155 (num-lines-buf (with-current-buffer anything-buffer
4156 (count-lines (point-min) (point-max)))))
4157 (flet ((insert-in-minibuffer (fname)
4158 (with-selected-window (minibuffer-window)
4159 (unless follow
4160 (delete-minibuffer-contents)
4161 (set-text-properties 0 (length fname) nil fname)
4162 (insert fname)))))
4163 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4164 "Invalid tramp file name")
4165 (string-match tramp-file-name-regexp candidate))
4166 ;; First hit insert hostname and
4167 ;; second hit insert ":" and expand.
4168 (if (string= candidate anything-pattern)
4169 (insert-in-minibuffer (concat candidate ":"))
4170 (insert-in-minibuffer candidate)))
4171 (;; A symlink directory, expand it's truename.
4172 (and (file-directory-p candidate) (file-symlink-p candidate))
4173 (insert-in-minibuffer (file-name-as-directory
4174 (file-truename
4175 (expand-file-name candidate)))))
4176 ;; A directory, open it.
4177 ((file-directory-p candidate)
4178 (when (string= (anything-c-basename candidate) "..")
4179 (setq anything-ff-last-expanded anything-ff-default-directory))
4180 (insert-in-minibuffer (file-name-as-directory
4181 (expand-file-name candidate))))
4182 ;; A symlink file, expand to it's true name. (first hit)
4183 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4184 (insert-in-minibuffer (file-truename candidate)))
4185 ;; A regular file, expand it, (first hit)
4186 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4187 (insert-in-minibuffer new-pattern))
4188 ;; An image file and it is the second hit on C-z,
4189 ;; show the file in `image-dired'.
4190 ((string-match (image-file-name-regexp) candidate)
4191 (when (buffer-live-p image-dired-display-image-buffer)
4192 (kill-buffer image-dired-display-image-buffer))
4193 (image-dired-display-image candidate)
4194 (message nil)
4195 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4196 (with-current-buffer image-dired-display-image-buffer
4197 (let ((exif-data (anything-ff-exif-data candidate)))
4198 (image-dired-update-property 'help-echo exif-data))))
4199 ;; Allow browsing archive on avfs fs.
4200 ;; Assume volume is already mounted with mountavfs.
4201 ((and anything-ff-avfs-directory
4202 (string-match
4203 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4204 (file-name-directory candidate))
4205 (anything-ff-file-compressed-p candidate))
4206 (insert-in-minibuffer (concat candidate "#")))
4207 ;; On second hit we open file.
4208 ;; On Third hit we kill it's buffer maybe.
4210 (anything-ff-kill-or-find-buffer-fname candidate))))))
4212 (defun anything-ff-file-compressed-p (candidate)
4213 "Whether CANDIDATE is a compressed file or not."
4214 (member (file-name-extension candidate)
4215 anything-ff-file-compressed-list))
4217 (defun anything-c-insert-file-name-completion-at-point (candidate)
4218 "Insert file name completion at point."
4219 (with-anything-current-buffer
4220 (if buffer-read-only
4221 (error "Error: Buffer `%s' is read-only" (buffer-name))
4222 (let* ((end (point))
4223 (guess (substring-no-properties (thing-at-point 'filename)))
4224 (beg (- (point) (length guess)))
4225 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4226 (string-match-p "^[^\~]" guess))))
4227 (set-text-properties 0 (length candidate) nil candidate)
4228 (if (and guess (not (string= guess ""))
4229 (string-match-p "^~\\|/.*" guess))
4230 (progn
4231 (delete-region beg end)
4232 (insert (if full-path-p
4233 (expand-file-name candidate)
4234 (abbreviate-file-name candidate))))
4235 (error "Aborting completion: No valid file name at point"))))))
4237 (defun* anything-find-files-history (&key (comp-read t))
4238 "The `anything-find-files' history.
4239 Show the first `anything-ff-history-max-length' elements of
4240 `anything-ff-history' in an `anything-comp-read'."
4241 (let ((history (when anything-ff-history
4242 (anything-fast-remove-dups anything-ff-history
4243 :test 'equal))))
4244 (when history
4245 (setq anything-ff-history
4246 (if (>= (length history) anything-ff-history-max-length)
4247 (subseq history 0 anything-ff-history-max-length)
4248 history))
4249 (if comp-read
4250 (anything-comp-read
4251 "Switch to Directory: "
4252 anything-ff-history
4253 :name "Anything Find Files History"
4254 :must-match t)
4255 anything-ff-history))))
4257 (defun anything-find-files-1 (fname &optional preselect)
4258 "Find FNAME with `anything' completion.
4259 Like `find-file' but with `anything' support.
4260 Use it for non--interactive calls of `anything-find-files'."
4261 (when (get-buffer anything-action-buffer)
4262 (kill-buffer anything-action-buffer))
4263 (let ((anything-mp-highlight-delay nil)
4264 ;; Be sure we don't erase the precedent minibuffer if some.
4265 (anything-ff-auto-update-initial-value
4266 (not (minibuffer-window-active-p (minibuffer-window))))
4267 anything-samewindow)
4268 (anything :sources 'anything-c-source-find-files
4269 :input fname
4270 :preselect preselect
4271 :keymap anything-find-files-map
4272 :prompt "Find Files or Url: "
4273 :buffer "*Anything Find Files*")))
4276 (defun anything-find-files-initial-input (&optional input)
4277 "Return INPUT if present, otherwise try to guess it."
4278 (or (and input (expand-file-name input))
4279 (anything-find-files-input
4280 (ffap-guesser)
4281 (thing-at-point 'filename))))
4283 (defun anything-find-files-input (fap tap)
4284 "Default input of `anything-find-files'."
4285 (let* ((def-dir (anything-c-current-directory))
4286 (lib (anything-find-library-at-point))
4287 (url (anything-ff-find-url-at-point))
4288 (file-p (and fap (not (string= fap ""))
4289 (file-exists-p fap)
4290 tap (not (string= tap ""))
4291 (file-exists-p
4292 (file-name-directory (expand-file-name tap def-dir))))))
4293 (cond (lib) ; e.g we are inside a require sexp.
4294 (url) ; String at point is an hyperlink.
4295 (file-p (expand-file-name tap def-dir))
4296 (t (and (not (string= fap "")) fap)))))
4298 (defun anything-c-current-directory ()
4299 "Return current-directory name at point.
4300 Useful in dired buffers when there is inserted subdirs."
4301 (if (eq major-mode 'dired-mode)
4302 (dired-current-directory)
4303 default-directory))
4305 (defun anything-ff-find-url-at-point ()
4306 "Try to find link to an url in text-property at point."
4307 (let* ((he (get-text-property (point) 'help-echo))
4308 (ov (overlays-at (point)))
4309 (ov-he (and ov (overlay-get
4310 (car (overlays-at (point))) 'help-echo)))
4311 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4312 (nt-prop (get-text-property (point) 'nt-link)))
4313 ;; Org link.
4314 (when (and (stringp he) (string-match "^LINK: " he))
4315 (setq he (replace-match "" t t he)))
4316 (loop for i in (list he ov-he w3m-l nt-prop)
4317 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4319 (defun anything-find-library-at-point ()
4320 "Try to find library path at point.
4321 Find inside `require' and `declare-function' sexp."
4322 (require 'find-func)
4323 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4324 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4325 (sexp (and beg-sexp end-sexp
4326 (buffer-substring-no-properties
4327 (1+ beg-sexp) (1- end-sexp)))))
4328 (ignore-errors
4329 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4330 (find-library-name
4331 (replace-regexp-in-string
4332 "'\\|\)\\|\(" ""
4333 ;; If require use third arg, ignore it,
4334 ;; always use library path found in `load-path'.
4335 (second (split-string (match-string 0 sexp))))))
4336 ((and sexp (string-match-p "^declare-function" sexp))
4337 (find-library-name
4338 (replace-regexp-in-string
4339 "\"\\|ext:" ""
4340 (third (split-string sexp)))))
4341 (t nil)))))
4343 ;;; Anything completion for `write-file'.==> C-x C-w
4344 (defvar anything-c-source-write-file
4345 `((name . "Write File")
4346 (header-name . (lambda (name)
4347 (concat name anything-c-find-files-doc-header)))
4348 ;; It is needed for filenames with capital letters
4349 (disable-shortcuts)
4350 (candidates . anything-find-files-get-candidates)
4351 (filtered-candidate-transformer anything-c-find-files-transformer)
4352 (persistent-action . anything-find-files-persistent-action)
4353 (persistent-help . "Expand Candidate")
4354 (volatile)
4355 (action .
4356 (("Write File" . (lambda (candidate)
4357 (write-file candidate 'confirm)))))))
4359 ;;; Anything completion for `insert-file'.==> C-x i
4360 (defvar anything-c-source-insert-file
4361 `((name . "Insert File")
4362 (header-name . (lambda (name)
4363 (concat name anything-c-find-files-doc-header)))
4364 ;; It is needed for filenames with capital letters
4365 (disable-shortcuts)
4366 (candidates . anything-find-files-get-candidates)
4367 (filtered-candidate-transformer anything-c-find-files-transformer)
4368 (persistent-action . anything-find-files-persistent-action)
4369 (persistent-help . "Expand Candidate")
4370 (volatile)
4371 (action .
4372 (("Insert File" . (lambda (candidate)
4373 (when (y-or-n-p (format "Really insert %s in %s "
4374 candidate anything-current-buffer))
4375 (insert-file-contents candidate))))))))
4377 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4378 (defvar anything-c-source-copy-files
4379 `((name . "Copy Files")
4380 (header-name . (lambda (name)
4381 (concat name anything-c-find-files-doc-header)))
4382 ;; It is needed for filenames with capital letters
4383 (disable-shortcuts)
4384 (candidates . anything-find-files-get-candidates)
4385 (filtered-candidate-transformer anything-c-find-files-transformer)
4386 (persistent-action . anything-find-files-persistent-action)
4387 (persistent-help . "Expand Candidate")
4388 (volatile)
4389 (action .
4390 (("Copy File"
4391 . (lambda (candidate)
4392 (anything-dired-action candidate :action 'copy)))
4393 ("Copy and Follow"
4394 . (lambda (candidate)
4395 (anything-dired-action candidate :action 'copy :follow t)))))))
4398 (defvar anything-c-source-rename-files
4399 `((name . "Rename Files")
4400 (header-name . (lambda (name)
4401 (concat name anything-c-find-files-doc-header)))
4402 ;; It is needed for filenames with capital letters
4403 (disable-shortcuts)
4404 (candidates . anything-find-files-get-candidates)
4405 (filtered-candidate-transformer anything-c-find-files-transformer)
4406 (persistent-action . anything-find-files-persistent-action)
4407 (persistent-help . "Expand Candidate")
4408 (volatile)
4409 (action .
4410 (("Rename File"
4411 . (lambda (candidate)
4412 (anything-dired-action candidate :action 'rename)))
4413 ("Rename and Follow"
4414 . (lambda (candidate)
4415 (anything-dired-action candidate :action 'rename :follow t)))))))
4417 (defvar anything-c-source-symlink-files
4418 `((name . "Symlink Files")
4419 (header-name . (lambda (name)
4420 (concat name anything-c-find-files-doc-header)))
4421 ;; It is needed for filenames with capital letters
4422 (disable-shortcuts)
4423 (candidates . anything-find-files-get-candidates)
4424 (filtered-candidate-transformer anything-c-find-files-transformer)
4425 (persistent-action . anything-find-files-persistent-action)
4426 (persistent-help . "Expand Candidate")
4427 (volatile)
4428 (action
4429 . (("Symlink File"
4430 . (lambda (candidate)
4431 (anything-dired-action candidate :action 'symlink)))
4432 ("RelSymlink File"
4433 . (lambda (candidate)
4434 (anything-dired-action candidate :action 'relsymlink)))))))
4437 (defvar anything-c-source-hardlink-files
4438 `((name . "Hardlink Files")
4439 (header-name . (lambda (name)
4440 (concat name anything-c-find-files-doc-header)))
4441 ;; It is needed for filenames with capital letters
4442 (disable-shortcuts)
4443 (candidates . anything-find-files-get-candidates)
4444 (filtered-candidate-transformer anything-c-find-files-transformer)
4445 (persistent-action . anything-find-files-persistent-action)
4446 (persistent-help . "Expand Candidate")
4447 (volatile)
4448 (action
4449 . (("Hardlink File"
4450 . (lambda (candidate)
4451 (anything-dired-action candidate :action 'hardlink)))))))
4453 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4454 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4455 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4456 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4457 (let ((fn (case action
4458 ('copy 'dired-copy-file)
4459 ('rename 'dired-rename-file)
4460 ('symlink 'make-symbolic-link)
4461 ('relsymlink 'dired-make-relative-symlink)
4462 ('hardlink 'dired-hardlink)))
4463 (marker (case action
4464 ((copy rename) dired-keep-marker-copy)
4465 ('symlink dired-keep-marker-symlink)
4466 ('relsymlink dired-keep-marker-relsymlink)
4467 ('hardlink dired-keep-marker-hardlink)))
4468 (dirflag (and (= (length files) 1)
4469 (file-directory-p (car files))
4470 (not (file-directory-p candidate)))))
4471 (dired-create-files
4472 fn (symbol-name action) files
4473 ;; CANDIDATE is the destination.
4474 (if (file-directory-p candidate)
4475 ;; When CANDIDATE is a directory, build file-name in this directory.
4476 ;; Else we use CANDIDATE.
4477 #'(lambda (from)
4478 (expand-file-name (file-name-nondirectory from) candidate))
4479 #'(lambda (from) candidate))
4480 marker)
4481 (push (file-name-as-directory
4482 (if (file-directory-p candidate)
4483 candidate (file-name-directory candidate)))
4484 anything-ff-history)
4485 (when (and follow (not (get-buffer dired-log-buffer)))
4486 (let ((target (directory-file-name candidate)))
4487 (unwind-protect
4488 (progn
4489 (setq anything-ff-cand-to-mark
4490 (anything-get-dest-fnames-from-list files candidate dirflag))
4491 (if (and dirflag (eq action 'rename))
4492 (anything-find-files-1 (file-name-directory target)
4493 (if anything-ff-transformer-show-only-basename
4494 (anything-c-basename target) target))
4495 (anything-find-files-1 (expand-file-name candidate))))
4496 (setq anything-ff-cand-to-mark nil))))))
4499 (defun anything-c-basename (fname)
4500 "Resolve basename of file or directory named FNAME."
4501 (file-name-nondirectory (directory-file-name fname)))
4503 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4504 "Transform filenames of FLIST to abs of DEST-CAND.
4505 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4506 members of FLIST."
4507 ;; At this point files have been renamed/copied at destination.
4508 ;; That's mean DEST-CAND exists.
4509 (loop
4510 with dest = (expand-file-name dest-cand)
4511 for src in flist
4512 for basename-src = (anything-c-basename src)
4513 for fname = (cond (rename-dir-flag (directory-file-name dest))
4514 ((file-directory-p dest)
4515 (concat (file-name-as-directory dest) basename-src))
4516 (t dest))
4517 when (file-exists-p fname)
4518 collect fname into tmp-list
4519 finally return (sort tmp-list 'string<)))
4521 (defun anything-ff-maybe-mark-candidates ()
4522 "Mark all candidates of list `anything-ff-cand-to-mark'."
4523 (when (and (string= (assoc-default 'name (anything-get-current-source))
4524 (assoc-default 'name anything-c-source-find-files))
4525 anything-ff-cand-to-mark)
4526 (with-anything-window
4527 (while anything-ff-cand-to-mark
4528 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4529 (progn
4530 (anything-make-visible-mark)
4531 (anything-next-line)
4532 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4533 (anything-next-line)))
4534 (unless (anything-this-visible-mark)
4535 (anything-prev-visible-mark)))))
4537 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4539 (defun* anything-dired-do-action-on-file (&key action)
4540 (let* ((files (dired-get-marked-files))
4541 (len (length files))
4542 (fname (if (> len 1)
4543 (format "* %d Files" len)
4544 (car files)))
4545 (source (case action
4546 ('copy 'anything-c-source-copy-files)
4547 ('rename 'anything-c-source-rename-files)
4548 ('symlink 'anything-c-source-symlink-files)
4549 ('hardlink 'anything-c-source-hardlink-files)))
4550 (prompt-fm (case action
4551 ('copy "Copy %s to: ")
4552 ('rename "Rename %s to: ")
4553 ('symlink "Symlink %s to: ")
4554 ('hardlink "Hardlink %s to: ")))
4555 (buffer (case action
4556 ('copy "*Anything Copy Files*")
4557 ('rename "*Anything Rename Files*")
4558 ('symlink "*Anything Symlink Files*")
4559 ('hardlink "*Anything Hardlink Files*")))
4560 (anything-mp-highlight-delay nil))
4561 (anything :sources source
4562 :input (or (dired-dwim-target-directory)
4563 (expand-file-name (anything-c-current-directory)))
4564 :preselect (dired-get-filename)
4565 :prompt (format prompt-fm fname)
4566 :keymap anything-c-read-file-map
4567 :buffer buffer)))
4569 ;;;###autoload
4570 (define-minor-mode anything-dired-mode ()
4571 "Enable anything completion in Dired functions.
4572 Bindings affected are C, R, S, H.
4573 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4574 :group 'anything-config
4575 :global t
4576 (if anything-dired-mode
4577 (progn
4578 (substitute-key-definition
4579 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4580 (substitute-key-definition
4581 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4582 (substitute-key-definition
4583 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4584 (substitute-key-definition
4585 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4586 (substitute-key-definition
4587 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4588 (substitute-key-definition
4589 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4590 (substitute-key-definition
4591 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4592 (substitute-key-definition
4593 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4595 (defalias 'anything-dired-bindings 'anything-dired-mode)
4597 (defun* anything-c-read-file-name (prompt
4598 &key
4599 (name "Read File Name")
4600 (initial-input (expand-file-name default-directory))
4601 (buffer "*Anything Completions*")
4602 test
4603 (preselect nil)
4604 (history nil)
4605 (marked-candidates nil)
4606 (alistp t)
4607 (persistent-action 'anything-find-files-persistent-action)
4608 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4609 "Anything `read-file-name' emulation.
4610 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4611 (when (get-buffer anything-action-buffer)
4612 (kill-buffer anything-action-buffer))
4613 (let ((anything-mp-highlight-delay nil)
4614 ;; Be sure we don't erase the underlying minibuffer if some.
4615 (anything-ff-auto-update-initial-value
4616 (not (minibuffer-window-active-p (minibuffer-window))))
4617 anything-same-window
4618 (hist (and history (anything-comp-read-get-candidates
4619 history nil nil alistp))))
4620 (flet ((action-fn (candidate)
4621 (if marked-candidates
4622 (anything-marked-candidates)
4623 (identity candidate))))
4624 (or (anything
4625 :sources
4626 `(((name . ,(format "%s History" name))
4627 (header-name . (lambda (name)
4628 (concat name anything-c-find-files-doc-header)))
4629 (disable-shortcuts)
4630 (mode-line . anything-read-file-name-mode-line-string)
4631 (candidates . hist)
4632 (persistent-action . ,persistent-action)
4633 (persistent-help . ,persistent-help)
4634 (action . ,'action-fn))
4635 ((name . ,name)
4636 (header-name . (lambda (name)
4637 (concat name anything-c-find-files-doc-header)))
4638 (init . (lambda ()
4639 (setq anything-ff-auto-update-flag
4640 anything-ff-auto-update-initial-value)))
4641 ;; It is needed for filenames with capital letters
4642 (disable-shortcuts)
4643 (mode-line . anything-read-file-name-mode-line-string)
4644 (candidates . (lambda ()
4645 (let ((seq (anything-find-files-get-candidates)))
4646 (if test
4647 (loop for fname in seq
4648 when (funcall test fname) collect fname)
4649 seq))))
4650 (filtered-candidate-transformer anything-c-find-files-transformer)
4651 (persistent-action . ,persistent-action)
4652 (candidate-number-limit . 9999)
4653 (toggle-auto-update . anything-ff-toggle-auto-update)
4654 (persistent-help . ,persistent-help)
4655 (volatile)
4656 (action . ,'action-fn)))
4657 :input initial-input
4658 :prompt prompt
4659 :keymap anything-c-read-file-map
4660 :resume 'noresume
4661 :buffer buffer
4662 :preselect preselect)
4663 (keyboard-quit)))))
4666 ;;; File Cache
4667 (defvar anything-c-file-cache-initialized-p nil)
4669 (defvar anything-c-file-cache-files nil)
4671 (defvar anything-c-source-file-cache
4672 '((name . "File Cache")
4673 (init
4674 . (lambda ()
4675 (require 'filecache nil t)
4676 (unless anything-c-file-cache-initialized-p
4677 (setq anything-c-file-cache-files
4678 (loop for item in file-cache-alist append
4679 (destructuring-bind (base &rest dirs) item
4680 (loop for dir in dirs collect
4681 (concat dir base)))))
4682 (defadvice file-cache-add-file (after file-cache-list activate)
4683 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4684 (setq anything-c-file-cache-initialized-p t))))
4685 (candidates . anything-c-file-cache-files)
4686 (match anything-c-match-on-basename)
4687 (type . file)))
4688 ;; (anything 'anything-c-source-file-cache)
4691 ;;; Locate
4694 ;; NOTE for WINDOZE users:
4695 ;; You have to install Everything with his command line interface here:
4696 ;; http://www.voidtools.com/download.php
4698 (defun anything-locate-1 (&optional localdb init)
4699 "Generic function to run Locate.
4700 if LOCALDB is non--nil search and use a local locate db file.
4701 INIT is a string to use as initial input in prompt.
4702 See `anything-locate-with-db' and `anything-locate'."
4703 (anything-locate-with-db
4704 (and localdb
4705 (anything-c-read-file-name
4706 "LocateDBFiles: "
4707 :marked-candidates t
4708 :preselect anything-locate-db-file-regexp
4709 :test #'(lambda (x)
4710 (if anything-locate-db-file-regexp
4711 ;; Select only locate db files and directories
4712 ;; to allow navigation.
4713 (or (string-match
4714 anything-locate-db-file-regexp x)
4715 (file-directory-p x))
4716 x))))
4717 init))
4718 ;; (anything-locate-1 t)
4720 (defun anything-locate-with-db (&optional db initial-input)
4721 "Run locate -d DB.
4722 If DB is not given or nil use locate without -d option.
4723 Argument DB can be given as a string or list of db files.
4724 Argument INITIAL-INPUT is a string to use as initial-input.
4725 See also `anything-locate'."
4726 (when (and db (stringp db)) (setq db (list db)))
4727 (let ((anything-c-locate-command
4728 (if db
4729 (replace-regexp-in-string
4730 "locate"
4731 (format "locate -d %s"
4732 (mapconcat 'identity
4733 ;; Remove eventually
4734 ;; marked directories by error.
4735 (loop for i in db
4736 unless (file-directory-p i)
4737 collect i) ":"))
4738 anything-c-locate-command)
4739 anything-c-locate-command)))
4740 (anything :sources 'anything-c-source-locate
4741 :buffer "*anything locate*"
4742 :input initial-input
4743 :keymap anything-generic-files-map)))
4744 ;; (anything-locate-with-db "~/locate.db")
4746 (defun anything-c-locate-init ()
4747 "Initialize async locate process for `anything-c-source-locate'."
4748 (setq mode-line-format
4749 '(" " mode-line-buffer-identification " "
4750 (line-number-mode "%l") " "
4751 (:eval (propertize "(Locate Process Running) "
4752 'face '((:foreground "red"))))))
4753 (prog1
4754 (start-process-shell-command "locate-process" nil
4755 (format anything-c-locate-command
4756 anything-pattern))
4757 (set-process-sentinel (get-process "locate-process")
4758 #'(lambda (process event)
4759 (when (string= event "finished\n")
4760 (with-anything-window
4761 (force-mode-line-update nil)
4762 (anything-update-move-first-line)))))))
4764 (defvar anything-c-source-locate
4765 '((name . "Locate")
4766 (candidates . anything-c-locate-init)
4767 (type . file)
4768 (requires-pattern . 3)
4769 (candidate-number-limit . 9999)
4770 (mode-line . anything-generic-file-mode-line-string)
4771 (delayed))
4772 "Find files matching the current input pattern with locate.")
4773 ;; (anything 'anything-c-source-locate)
4775 (defun anything-c-locate-read-file-name (prompt &optional init)
4776 "Search a file with locate and return it's filename.
4777 Use argument PROMPT and INIT for `anything' arguments
4778 prompt and input."
4779 (anything :sources
4780 '((name . "Locate")
4781 (candidates . anything-c-locate-init)
4782 (action . identity)
4783 (requires-pattern . 3)
4784 (candidate-number-limit . 9999)
4785 (mode-line . anything-generic-file-mode-line-string)
4786 (delayed))
4787 :prompt prompt
4788 :input init
4789 :buffer "*anything locate rfn*"))
4793 ;;; Anything Incremental Grep.
4796 ;; Allow to grep incrementally with anything interface.
4797 ;; It allow also to Grep files recursively without using 'find' shell command.
4798 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4799 (defvar anything-c-grep-default-command
4800 "grep -d skip %e -niH -e %p %f"
4801 "Default grep format command for `anything-do-grep-1'.
4802 Where:
4803 '%e' format spec is for --exclude or --include grep options.
4804 '%p' format spec is for pattern.
4805 '%f' format spec is for filenames.")
4807 (defvar anything-c-grep-default-recurse-command
4808 "grep -d recurse %e -niH -e %p %f"
4809 "Default recursive grep format command for `anything-do-grep-1'.
4810 See `anything-c-grep-default-command' for format specs.")
4812 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4814 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4816 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4818 (defvar anything-c-grep-debug-command-line nil
4819 "Turn on anything grep command-line debugging when non--nil.")
4821 (defvar anything-c-zgrep-recurse-flag nil)
4823 (defvar anything-c-grep-history nil)
4825 (defvar anything-c-grep-max-length-history 100
4826 "*Max number of elements to save in `anything-c-grep-history'.")
4828 (defun anything-c-grep-prepare-candidates (candidates)
4829 "Prepare filenames and directories CANDIDATES for grep command line."
4830 ;; If one or more candidate is a directory, search in all files
4831 ;; of this candidate (e.g /home/user/directory/*).
4832 ;; If r option is enabled search also in subdidrectories.
4833 ;; We need here to expand wildcards to support crap windows filenames
4834 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4835 (if anything-c-zgrep-recurse-flag
4836 (mapconcat 'shell-quote-argument candidates " ")
4837 (loop for i in candidates append
4838 (cond ( ;; Candidate is a directory and we use recursion.
4839 (and (file-directory-p i)
4840 (anything-c-grep-recurse-p))
4841 (list (expand-file-name i)))
4842 ;; Candidate is a directory, search in all files.
4843 ((file-directory-p i)
4844 (file-expand-wildcards
4845 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4846 ;; Candidate is a file or wildcard and we use recursion, use the
4847 ;; current directory instead of candidate.
4848 ((and (or (file-exists-p i) (string-match "\*" i))
4849 (anything-c-grep-recurse-p))
4850 (list (expand-file-name
4851 (directory-file-name ; Needed for windoze.
4852 (file-name-directory (directory-file-name i))))))
4853 ;; Candidate use wildcard.
4854 ((string-match "^\*" (anything-c-basename i))
4855 (file-expand-wildcards i t))
4856 ;; Else should be one or more file.
4857 (t (list i))) into all-files
4858 finally return
4859 (mapconcat 'shell-quote-argument all-files " "))))
4861 (defun anything-c-grep-recurse-p ()
4862 "Check if `anything-do-grep-1' have switched to recursive."
4863 (let ((args (replace-regexp-in-string
4864 "grep" "" anything-c-grep-default-command)))
4865 (string-match-p "r\\|recurse" args)))
4867 (defun anything-c-grep-init (only-files &optional include zgrep)
4868 "Start an asynchronous grep process in ONLY-FILES list."
4869 (let* ((fnargs (anything-c-grep-prepare-candidates
4870 (if (file-remote-p anything-ff-default-directory)
4871 (mapcar #'(lambda (x)
4872 (file-remote-p x 'localname))
4873 only-files)
4874 only-files)))
4875 (ignored-files (mapconcat
4876 #'(lambda (x)
4877 (concat "--exclude=" (shell-quote-argument x)))
4878 grep-find-ignored-files " "))
4879 (ignored-dirs (mapconcat
4880 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4881 #'(lambda (x)
4882 (concat "--exclude-dir=" (shell-quote-argument x)))
4883 grep-find-ignored-directories " "))
4884 (exclude (if (anything-c-grep-recurse-p)
4885 (concat (or include ignored-files) " " ignored-dirs)
4886 ignored-files))
4887 (cmd-line (format-spec
4888 anything-c-grep-default-command
4889 (delq nil
4890 (list (unless zgrep (cons ?e exclude))
4891 (cons ?p (shell-quote-argument anything-pattern))
4892 (cons ?f fnargs))))))
4893 (when anything-c-grep-debug-command-line
4894 (with-current-buffer (get-buffer-create "*any grep debug*")
4895 (goto-char (point-max))
4896 (insert (concat ">>> " cmd-line "\n\n"))))
4897 (setq mode-line-format
4898 '(" " mode-line-buffer-identification " "
4899 (line-number-mode "%l") " "
4900 (:eval (when (get-process "grep-process")
4901 (propertize "[Grep Process Running] "
4902 'face 'anything-grep-running)))))
4903 (force-mode-line-update nil)
4904 (prog1
4905 (let ((default-directory anything-ff-default-directory))
4906 (start-file-process-shell-command "grep-process" nil cmd-line))
4907 (message nil)
4908 (set-process-sentinel
4909 (get-process "grep-process")
4910 #'(lambda (process event)
4911 (when (string= event "finished\n")
4912 (with-anything-window
4913 (anything-update-move-first-line)
4914 (setq mode-line-format
4915 '(" " mode-line-buffer-identification " "
4916 (line-number-mode "%l") " "
4917 (:eval (propertize
4918 (format "[Grep Process Finished - (%s results)] "
4919 (let ((nlines (1- (count-lines
4920 (point-min)
4921 (point-max)))))
4922 (if (> nlines 0) nlines 0)))
4923 'face 'anything-grep-finish))))
4924 (force-mode-line-update nil))))))))
4926 (defun anything-c-grep-action (candidate &optional where mark)
4927 "Define a default action for `anything-do-grep' on CANDIDATE.
4928 WHERE can be one of other-window, elscreen, other-frame."
4929 (let* ((split (anything-c-grep-split-line candidate))
4930 (lineno (string-to-number (nth 1 split)))
4931 (loc-fname (car split))
4932 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4933 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4934 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4935 (fname (if tramp-host
4936 (concat tramp-prefix loc-fname) loc-fname)))
4937 (case where
4938 (other-window (find-file-other-window fname))
4939 (elscreen (anything-elscreen-find-file fname))
4940 (other-frame (find-file-other-frame fname))
4941 (t (find-file fname)))
4942 (anything-goto-line lineno)
4943 (when mark
4944 (set-marker (mark-marker) (point))
4945 (push-mark (point) 'nomsg))
4946 ;; Save history
4947 (unless (or anything-in-persistent-action
4948 (string= anything-pattern ""))
4949 (setq anything-c-grep-history
4950 (cons anything-pattern
4951 (delete anything-pattern anything-c-grep-history)))
4952 (when (> (length anything-c-grep-history)
4953 anything-c-grep-max-length-history)
4954 (setq anything-c-grep-history
4955 (delete (car (last anything-c-grep-history))
4956 anything-c-grep-history))))))
4958 (defun anything-c-grep-other-window (candidate)
4959 "Jump to result in other window from anything grep."
4960 (anything-c-grep-action candidate 'other-window))
4962 (defun anything-c-grep-other-frame (candidate)
4963 "Jump to result in other frame from anything grep."
4964 (anything-c-grep-action candidate 'other-frame))
4966 (defun anything-c-grep-jump-elscreen (candidate)
4967 "Jump to result in elscreen from anything grep."
4968 (anything-c-grep-action candidate 'elscreen))
4970 (defun anything-c-grep-save-results (candidate)
4971 "Save anything grep result in a `grep-mode' buffer."
4972 (let ((buf "*grep*")
4973 new-buf)
4974 (when (get-buffer buf)
4975 (setq new-buf (read-string "GrepBufferName: " buf))
4976 (loop for b in (anything-c-buffer-list)
4977 when (and (string= new-buf b)
4978 (not (y-or-n-p
4979 (format "Buffer `%s' already exists overwrite? "
4980 new-buf))))
4981 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4982 (setq buf new-buf))
4983 (with-current-buffer (get-buffer-create buf)
4984 (let ((inhibit-read-only t))
4985 (erase-buffer)
4986 (insert "-*- mode: grep -*-\n\n"
4987 (format "Grep Results for `%s':\n\n" anything-pattern))
4988 (save-excursion
4989 (insert (with-current-buffer anything-buffer
4990 (forward-line 1)
4991 (buffer-substring (point) (point-max))))
4992 (grep-mode))))
4993 (message "Anything Grep Results saved in `%s' buffer" buf)))
4995 (defun anything-c-grep-persistent-action (candidate)
4996 "Persistent action for `anything-do-grep'.
4997 With a prefix arg record CANDIDATE in `mark-ring'."
4998 (if current-prefix-arg
4999 (anything-c-grep-action candidate nil 'mark)
5000 (anything-c-grep-action candidate))
5001 (anything-match-line-color-current-line))
5003 (defun anything-c-grep-guess-extensions (files)
5004 "Try to guess file extensions in FILES list when using grep recurse.
5005 These extensions will be added to command line with --include arg of grep."
5006 (loop
5007 with glob-list = nil
5008 with lst = (if (file-directory-p (car files))
5009 (directory-files
5010 (car files) nil
5011 directory-files-no-dot-files-regexp)
5012 files)
5013 for i in lst
5014 for ext = (file-name-extension i t)
5015 for glob = (and ext (not (string= ext ""))
5016 (concat "*" ext))
5017 unless (or (not glob)
5018 (member glob glob-list)
5019 (member glob grep-find-ignored-files))
5020 collect glob into glob-list
5021 finally return glob-list))
5023 (defun anything-do-grep-1 (only &optional recurse zgrep)
5024 "Launch grep with a list of ONLY files.
5025 When RECURSE is given use -r option of grep and prompt user
5026 to set the --include args of grep.
5027 You can give more than one arg separated by space.
5028 e.g *.el *.py *.tex.
5029 If it's empty --exclude `grep-find-ignored-files' is used instead."
5030 (let* ((anything-compile-source-functions
5031 ;; rule out anything-match-plugin because the input is one regexp.
5032 (delq 'anything-compile-source--match-plugin
5033 (copy-sequence anything-compile-source-functions)))
5034 (exts (anything-c-grep-guess-extensions only))
5035 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5036 (include-files (and recurse (not zgrep)
5037 (read-string "OnlyExt(*.[ext]): "
5038 globs)))
5039 ;; Set `minibuffer-history' AFTER includes-files
5040 ;; to avoid storing wild-cards here.
5041 (minibuffer-history anything-c-grep-history)
5042 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5043 (recurse anything-c-grep-default-recurse-command)
5044 (zgrep anything-c-default-zgrep-command)
5045 (t anything-c-grep-default-command)))
5046 ;; Disable match-plugin and use here own highlighting.
5047 (anything-mp-highlight-delay nil))
5048 (when include-files
5049 (setq include-files
5050 (and (not (string= include-files ""))
5051 (mapconcat #'(lambda (x)
5052 (concat "--include=" (shell-quote-argument x)))
5053 (split-string include-files) " "))))
5054 ;; When called as action from an other source e.g *-find-files
5055 ;; we have to kill action buffer.
5056 (when (get-buffer anything-action-buffer)
5057 (kill-buffer anything-action-buffer))
5058 ;; `anything-find-files' haven't already started,
5059 ;; give a default value to `anything-ff-default-directory'.
5060 (setq anything-ff-default-directory (or anything-ff-default-directory
5061 default-directory))
5062 (anything
5063 :sources
5064 `(((name . "Grep (C-c ? Help)")
5065 (candidates
5066 . (lambda ()
5067 (funcall anything-c-grep-default-function only include-files zgrep)))
5068 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5069 (candidate-number-limit . 9999)
5070 (mode-line . anything-grep-mode-line-string)
5071 (action . ,(delq
5073 `(("Find File" . anything-c-grep-action)
5074 ("Find file other frame" . anything-c-grep-other-frame)
5075 ,(and (locate-library "elscreen")
5076 '("Find file in Elscreen"
5077 . anything-c-grep-jump-elscreen))
5078 ("Save results in grep buffer" . anything-c-grep-save-results)
5079 ("Find file other window" . anything-c-grep-other-window))))
5080 (persistent-action . anything-c-grep-persistent-action)
5081 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5082 (requires-pattern . 3)
5083 (delayed)))
5084 :keymap anything-c-grep-map
5085 :buffer "*anything grep*")))
5087 (defun anything-ff-zgrep-1 (flist recursive)
5088 (unwind-protect
5089 (let* ((def-dir (or anything-ff-default-directory
5090 default-directory))
5091 (only (if recursive
5092 (or (gethash def-dir anything-c-rzgrep-cache)
5093 (puthash
5094 def-dir
5095 (anything-c-walk-directory
5096 def-dir
5097 :directories nil
5098 :path 'full
5099 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5100 anything-c-rzgrep-cache))
5101 flist)))
5102 (when recursive (setq anything-c-zgrep-recurse-flag t))
5103 (anything-do-grep-1 only recursive 'zgrep))
5104 (setq anything-c-zgrep-recurse-flag nil)))
5106 (defun anything-c-grep-split-line (line)
5107 "Split a grep output line."
5108 (let (beg fname lineno str)
5109 ;; Don't print until grep line is valid.
5110 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5111 (with-temp-buffer
5112 (insert line)
5113 (goto-char (point-min))
5114 (setq beg (point))
5115 (forward-char 2)
5116 (re-search-forward ":" nil t)
5117 (setq fname (buffer-substring-no-properties beg (1- (point))))
5118 (setq beg (point))
5119 (re-search-forward ":" nil t)
5120 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5121 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5122 (list fname lineno str))))
5124 (defun anything-c-grep-cand-transformer (candidates sources)
5125 "Filtered candidate transformer function for `anything-do-grep'."
5126 (loop for i in candidates
5127 for split = (and i (anything-c-grep-split-line i))
5128 for fname = (car split)
5129 for lineno = (nth 1 split)
5130 for str = (nth 2 split)
5131 when (and fname lineno str)
5132 collect
5133 (cons (concat (propertize (file-name-nondirectory fname)
5134 'face 'anything-grep-file
5135 'help-echo fname) ":"
5136 (propertize lineno 'face 'anything-grep-lineno) ":"
5137 (anything-c-grep-highlight-match str))
5138 i)))
5140 (defun anything-c-grep-highlight-match (str)
5141 "Highlight in string STR all occurences matching `anything-pattern'."
5142 (condition-case nil
5143 (with-temp-buffer
5144 (insert str)
5145 (goto-char (point-min))
5146 (while (and (re-search-forward anything-pattern nil t)
5147 (> (- (match-end 0) (match-beginning 0)) 0))
5148 (add-text-properties
5149 (match-beginning 0) (match-end 0)
5150 '(face anything-grep-match)))
5151 (buffer-string))
5152 (error nil)))
5154 ;; Go to next or precedent file (common to etags and grep).
5155 (defun anything-c-goto-next-or-prec-file (n)
5156 "Go to next or precedent candidate file in anything grep/etags buffers.
5157 If N is positive go forward otherwise go backward."
5158 (with-anything-window
5159 (let* ((current-line-list (split-string
5160 (buffer-substring
5161 (point-at-bol)
5162 (point-at-eol)) ":"))
5163 (current-fname (nth 0 current-line-list))
5164 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5165 (catch 'break
5166 (while (not (funcall fn-b-o-f))
5167 (forward-line n) ; Go forward or backward depending of n value.
5168 (unless (search-forward current-fname (point-at-eol) t)
5169 (anything-mark-current-line)
5170 (throw 'break nil))))
5171 (cond ((and (eq n 1) (eobp))
5172 (re-search-backward ".")
5173 (forward-line 0)
5174 (anything-mark-current-line))
5175 ((and (< n 1) (bobp))
5176 (forward-line 1)
5177 (anything-mark-current-line))))))
5179 ;;;###autoload
5180 (defun anything-c-goto-precedent-file ()
5181 "Go to precedent file in anything grep/etags buffers."
5182 (interactive)
5183 (anything-c-goto-next-or-prec-file -1))
5185 ;;;###autoload
5186 (defun anything-c-goto-next-file ()
5187 "Go to precedent file in anything grep/etags buffers."
5188 (interactive)
5189 (anything-c-goto-next-or-prec-file 1))
5191 ;;;###autoload
5192 (defun anything-c-grep-run-persistent-action ()
5193 "Run grep persistent action from `anything-do-grep-1'."
5194 (interactive)
5195 (anything-attrset 'jump-persistent 'anything-c-grep-persistent-action)
5196 (anything-execute-persistent-action 'jump-persistent))
5198 ;;;###autoload
5199 (defun anything-c-grep-run-default-action ()
5200 "Run grep default action from `anything-do-grep-1'."
5201 (interactive)
5202 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5204 ;;;###autoload
5205 (defun anything-c-grep-run-other-window-action ()
5206 "Run grep goto other window action from `anything-do-grep-1'."
5207 (interactive)
5208 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5210 ;;;###autoload
5211 (defun anything-c-grep-run-save-buffer ()
5212 "Run grep save results action from `anything-do-grep-1'."
5213 (interactive)
5214 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5216 ;; Grep buffers
5217 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5218 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5219 If one of selected buffers is not a file--buffer,
5220 it is ignored and grep will run on all others file--buffers.
5221 If only one candidate is selected and it is not a file--buffer,
5222 switch to this buffer and run `anything-occur'.
5223 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5224 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5225 (cands (if prefarg
5226 (buffer-list)
5227 (anything-marked-candidates)))
5228 (win-conf (current-window-configuration))
5229 ;; Non--fname buffers are ignored.
5230 (bufs (loop for buf in cands
5231 for fname = (buffer-file-name (get-buffer buf))
5232 when fname
5233 collect (expand-file-name fname))))
5234 (if bufs
5235 (if zgrep
5236 (anything-do-grep-1 bufs nil 'zgrep)
5237 (anything-do-grep-1 bufs))
5238 ;; bufs is empty, thats mean we have only CANDIDATE
5239 ;; and it is not a buffer-filename, fallback to occur.
5240 (anything-c-switch-to-buffer candidate)
5241 (when (get-buffer anything-action-buffer)
5242 (kill-buffer anything-action-buffer))
5243 (anything-occur)
5244 (when (eq anything-exit-status 1)
5245 (set-window-configuration win-conf)))))
5247 (defun anything-c-grep-buffers (candidate)
5248 "Action to grep buffers."
5249 (anything-c-grep-buffers-1 candidate))
5251 (defun anything-c-zgrep-buffers (candidate)
5252 "Action to zgrep buffers."
5253 (anything-c-grep-buffers-1 candidate 'zgrep))
5256 ;;; Anything interface for pdfgrep
5257 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5258 ;; and a pdf-reader (e.g xpdf) are needed.
5260 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5261 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5262 (defvar anything-c-pdfgrep-debug-command-line nil)
5264 (defun anything-c-pdfgrep-init (only-files)
5265 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5266 (let* ((fnargs (anything-c-grep-prepare-candidates
5267 (if (file-remote-p anything-ff-default-directory)
5268 (mapcar #'(lambda (x)
5269 (file-remote-p x 'localname))
5270 only-files)
5271 only-files)))
5272 (cmd-line (format anything-c-pdfgrep-default-command
5273 anything-pattern
5274 fnargs)))
5275 (when anything-c-pdfgrep-debug-command-line
5276 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5277 (goto-char (point-max))
5278 (insert (concat ">>> " cmd-line "\n\n"))))
5279 (setq mode-line-format
5280 '(" " mode-line-buffer-identification " "
5281 (line-number-mode "%l") " "
5282 (:eval (propertize "(Pdfgrep Process Running) "
5283 'face '((:foreground "red"))))))
5284 (prog1
5285 (let ((default-directory anything-ff-default-directory))
5286 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5287 (message nil)
5288 (set-process-sentinel
5289 (get-process "pdfgrep-process")
5290 #'(lambda (process event)
5291 (when (string= event "finished\n")
5292 (with-anything-window
5293 (anything-update-move-first-line))
5294 (force-mode-line-update nil)))))))
5297 (defun anything-do-pdfgrep-1 (only)
5298 "Launch pdfgrep with a list of ONLY files."
5299 (unless (executable-find "pdfgrep")
5300 (error "Error: No such program `pdfgrep'."))
5301 (let* ((anything-compile-source-functions
5302 ;; rule out anything-match-plugin because the input is one regexp.
5303 (delq 'anything-compile-source--match-plugin
5304 (copy-sequence anything-compile-source-functions)))
5305 ;; Disable match-plugin and use here own highlighting.
5306 (anything-mp-highlight-delay nil))
5307 ;; When called as action from an other source e.g *-find-files
5308 ;; we have to kill action buffer.
5309 (when (get-buffer anything-action-buffer)
5310 (kill-buffer anything-action-buffer))
5311 ;; If `anything-find-files' haven't already started,
5312 ;; give a default value to `anything-ff-default-directory'.
5313 (setq anything-ff-default-directory (or anything-ff-default-directory
5314 default-directory))
5315 (anything
5316 :sources
5317 `(((name . "PdfGrep")
5318 (candidates
5319 . (lambda ()
5320 (funcall anything-c-pdfgrep-default-function only)))
5321 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5322 (candidate-number-limit . 9999)
5323 (mode-line . anything-pdfgrep-mode-line-string)
5324 (action . anything-c-pdfgrep-action)
5325 (persistent-help . "Jump to PDF Page")
5326 (requires-pattern . 3)
5327 (delayed)))
5328 :keymap anything-c-pdfgrep-map
5329 :buffer "*anything grep*")))
5332 (defun anything-c-pdfgrep-action (candidate)
5333 (let* ((split (anything-c-grep-split-line candidate))
5334 (pageno (nth 1 split))
5335 (fname (car split)))
5336 (start-file-process-shell-command
5337 "pdf-reader" nil
5338 (format-spec anything-c-pdfgrep-default-read-command
5339 (list (cons ?f fname) (cons ?p pageno))))))
5341 (defun anything-do-pdfgrep ()
5342 (interactive)
5343 (let ((only (anything-c-read-file-name
5344 "Search in file(s): "
5345 :marked-candidates t
5346 :test #'(lambda (file)
5347 (or (string= (file-name-extension file) "pdf")
5348 (string= (file-name-extension file) "PDF")
5349 (file-directory-p file)))
5350 :preselect (or (dired-get-filename nil t)
5351 (buffer-file-name (current-buffer)))))
5352 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5353 (anything-do-pdfgrep-1 only)))
5356 ;; Yank text at point.
5359 ;; Internal
5360 (defvar anything-yank-point nil)
5362 ;;;###autoload
5363 (defun anything-yank-text-at-point ()
5364 "Yank text at point in minibuffer."
5365 (interactive)
5366 (let (input)
5367 (flet ((insert-in-minibuffer (word)
5368 (with-selected-window (minibuffer-window)
5369 (let ((str anything-pattern))
5370 (delete-minibuffer-contents)
5371 (set-text-properties 0 (length word) nil word)
5372 (insert (concat str word))))))
5373 (with-anything-current-buffer
5374 ;; Start to initial point if C-w have never been hit.
5375 (unless anything-yank-point (setq anything-yank-point (point)))
5376 (and anything-yank-point (goto-char anything-yank-point))
5377 (forward-word 1)
5378 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5379 (setq anything-yank-point (point))) ; End of last forward-word
5380 (insert-in-minibuffer input))))
5382 (defun anything-reset-yank-point ()
5383 (setq anything-yank-point nil))
5385 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5386 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5389 ;;; Recentf files
5392 (defvar anything-c-source-recentf
5393 '((name . "Recentf")
5394 (init . (lambda ()
5395 (require 'recentf)
5396 (or recentf-mode (recentf-mode 1))))
5397 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5398 (candidates . recentf-list)
5399 (match anything-c-match-on-basename)
5400 (type . file))
5401 "See (info \"(emacs)File Conveniences\").
5402 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5403 ;; (anything 'anything-c-source-recentf)
5405 ;;; ffap
5406 (eval-when-compile (require 'ffap))
5407 (defvar anything-c-source-ffap-guesser
5408 '((name . "File at point")
5409 (init . (lambda () (require 'ffap)))
5410 (candidates . (lambda ()
5411 (anything-aif
5412 (with-anything-current-buffer
5413 (ffap-guesser))
5414 (list it))))
5415 (type . file)))
5416 ;; (anything 'anything-c-source-ffap-guesser)
5418 ;;; ffap with line number
5419 (defun anything-c-ffap-file-line-at-point ()
5420 "Get (FILENAME . LINENO) at point."
5421 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5422 (save-excursion
5423 (beginning-of-line)
5424 (when (and (search-forward it nil t)
5425 (looking-at ":\\([0-9]+\\)"))
5426 (cons it (string-to-number (match-string 1)))))))
5428 (defvar anything-c-ffap-line-location nil
5429 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5430 It is cleared after jumping line.")
5432 (defun anything-c-ffap-line-candidates ()
5433 (with-anything-current-buffer
5434 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5435 (when anything-c-ffap-line-location
5436 (destructuring-bind (file . line) anything-c-ffap-line-location
5437 (list (cons (format "%s (line %d)" file line) file)))))
5439 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5440 (defun anything-c-ffap-line-goto-line ()
5441 (when (car anything-c-ffap-line-location)
5442 (unwind-protect
5443 (ignore-errors
5444 (with-selected-window
5445 (get-buffer-window
5446 (get-file-buffer (car anything-c-ffap-line-location)))
5447 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5448 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5449 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5451 (defvar anything-c-source-ffap-line
5452 '((name . "File/Lineno at point")
5453 (init . (lambda () (require 'ffap)))
5454 (candidates . anything-c-ffap-line-candidates)
5455 (type . file)))
5456 ;; (anything 'anything-c-source-ffap-line)
5458 ;;; list of files gleaned from every dired buffer
5459 (defun anything-c-files-in-all-dired-candidates ()
5460 (save-excursion
5461 (mapcan
5462 (lambda (dir)
5463 (cond ((listp dir) ;filelist
5464 dir)
5465 ((equal "" (file-name-nondirectory dir)) ;dir
5466 (directory-files dir t))
5467 (t ;wildcard
5468 (file-expand-wildcards dir t))))
5469 (delq nil
5470 (mapcar (lambda (buf)
5471 (set-buffer buf)
5472 (when (eq major-mode 'dired-mode)
5473 (if (consp dired-directory)
5474 (cdr dired-directory) ;filelist
5475 dired-directory))) ;dir or wildcard
5476 (buffer-list))))))
5477 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5479 (defvar anything-c-source-files-in-all-dired
5480 '((name . "Files in all dired buffer.")
5481 (candidates . anything-c-files-in-all-dired-candidates)
5482 (type . file)))
5483 ;; (anything 'anything-c-source-files-in-all-dired)
5485 (defvar anything-c-source-filelist
5486 '((name . "FileList")
5487 (grep-candidates . anything-c-filelist-file-name)
5488 (candidate-number-limit . 200)
5489 (requires-pattern . 4)
5490 (type . file))
5491 "Source to find files instantly.
5492 See `anything-c-filelist-file-name' docstring for usage.")
5495 ;;;; <info>
5496 ;;; Info pages
5497 (defvar anything-c-info-pages nil
5498 "All info pages on system.
5499 Will be calculated the first time you invoke anything with this
5500 source.")
5502 (defun anything-c-info-pages-init ()
5503 "Collect candidates for initial Info node Top."
5504 (if anything-c-info-pages
5505 anything-c-info-pages
5506 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5507 topics)
5508 (require 'info)
5509 (with-temp-buffer
5510 (Info-find-node "dir" "top")
5511 (goto-char (point-min))
5512 (while (re-search-forward info-topic-regexp nil t)
5513 (push (match-string-no-properties 1) topics))
5514 (kill-buffer))
5515 (setq anything-c-info-pages topics))))
5517 (defvar anything-c-source-info-pages
5518 `((name . "Info Pages")
5519 (init . anything-c-info-pages-init)
5520 (candidates . anything-c-info-pages)
5521 (action . (("Show with Info" .(lambda (node-str)
5522 (info (replace-regexp-in-string
5523 "^[^:]+: " "" node-str))))))
5524 (requires-pattern . 2)))
5525 ;; (anything 'anything-c-source-info-pages)
5528 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5529 (defun anything-c-describe-attributes (anything-attribute)
5530 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5531 Same as `anything-describe-anything-attribute' but with anything completion."
5532 (interactive (list (intern
5533 (anything-comp-read
5534 "Describe anything attribute: "
5535 (mapcar 'symbol-name anything-additional-attributes)
5536 :must-match t
5537 :persistent-action
5538 #'(lambda (candidate)
5539 (with-output-to-temp-buffer "*Help*"
5540 (princ (get (intern candidate) 'anything-attrdoc))))))))
5541 (with-output-to-temp-buffer "*Help*"
5542 (princ (get anything-attribute 'anything-attrdoc))))
5545 ;;; Use info-index plug-in.
5548 ;; Note that `name' attribute is not needed since
5549 ;; `anything-c-insert-summary' have been removed.
5550 ;; Info Elisp
5551 (defvar anything-c-source-info-elisp
5552 '((name . "Info index: elisp")
5553 (info-index . "elisp")))
5554 ;; (anything 'anything-c-source-info-elisp)
5556 ;; Info-Common-Lisp
5557 (defvar anything-c-source-info-cl
5558 '((name . "Info index: cl")
5559 (info-index . "cl")))
5560 ;; (anything 'anything-c-source-info-cl)
5562 ;; Info Index org
5563 (defvar anything-c-source-info-org
5564 '((name . "Info index: org")
5565 (info-index . "org")))
5566 ;; (anything 'anything-c-source-info-org)
5568 ;; Info Index gnus
5569 (defvar anything-c-source-info-gnus
5570 '((name . "Info index: Gnus")
5571 (info-index . "gnus")))
5573 ;; Info Index ratpoison
5574 (defvar anything-c-source-info-ratpoison
5575 '((name . "Info index: ratpoison")
5576 (info-index . "ratpoison")))
5577 ;; (anything 'anything-c-source-info-ratpoison)
5579 ;; Info Index zsh
5580 (defvar anything-c-source-info-zsh
5581 '((name . "Info index: zsh")
5582 (info-index . "zsh")))
5583 ;; (anything 'anything-c-source-info-zsh)
5585 ;; Info Index bash
5586 (defvar anything-c-source-info-bash
5587 '((name . "Info index: bash")
5588 (info-index . "bash")))
5589 ;; (anything 'anything-c-source-info-bash)
5591 ;; Info Index coreutils
5592 (defvar anything-c-source-info-coreutils
5593 '((name . "Info index: coreutils")
5594 (info-index . "coreutils")))
5595 ;; (anything 'anything-c-source-info-coreutils)
5597 ;; Info Index fileutils
5598 (defvar anything-c-source-info-fileutils
5599 '((name . "Info index: fileutils")
5600 (info-index . "fileutils")))
5601 ;; (anything 'anything-c-source-info-fileutils)
5603 ;; Info Index find
5604 (defvar anything-c-source-info-find
5605 '((name . "Info index: find")
5606 (info-index . "find")))
5607 ;; (anything 'anything-c-source-info-find)
5609 ;; Info Index sh-utils
5610 (defvar anything-c-source-info-sh-utils
5611 '((name . "Info index: sh-utils")
5612 (info-index . "sh-utils")))
5613 ;; (anything 'anything-c-source-info-sh-utils)
5615 ;; Info Index textutils
5616 (defvar anything-c-source-info-textutils
5617 '((name . "Info index: textutils")
5618 (info-index . "textutils")))
5619 ;; (anything 'anything-c-source-info-textutils)
5621 ;; Info Index libc
5622 (defvar anything-c-source-info-libc
5623 '((name . "Info index: libc")
5624 (info-index . "libc")))
5625 ;; (anything 'anything-c-source-info-libc)
5627 ;; Info Index make
5628 (defvar anything-c-source-info-make
5629 '((name . "Info index: make")
5630 (info-index . "make")))
5631 ;; (anything 'anything-c-source-info-make)
5633 ;; Info Index automake
5634 (defvar anything-c-source-info-automake
5635 '((name . "Info index: automake")
5636 (info-index . "automake")))
5637 ;; (anything 'anything-c-source-info-automake)
5639 ;; Info Index autoconf
5640 (defvar anything-c-source-info-autoconf
5641 '((name . "Info index: autoconf")
5642 (info-index . "autoconf")))
5643 ;; (anything 'anything-c-source-info-autoconf)
5645 ;; Info Index emacs-lisp-intro
5646 (defvar anything-c-source-info-emacs-lisp-intro
5647 '((name . "Info index: emacs-lisp-intro")
5648 (info-index . "emacs-lisp-intro")))
5649 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5651 ;; Info Index emacs
5652 (defvar anything-c-source-info-emacs
5653 '((name . "Info index: emacs")
5654 (info-index . "emacs")))
5655 ;; (anything 'anything-c-source-info-emacs)
5657 ;; Info Index elib
5658 (defvar anything-c-source-info-elib
5659 '((name . "Info index: elib")
5660 (info-index . "elib")))
5661 ;; (anything 'anything-c-source-info-elib)
5663 ;; Info Index eieio
5664 (defvar anything-c-source-info-eieio
5665 '((name . "Info index: eieio")
5666 (info-index . "eieio")))
5667 ;; (anything 'anything-c-source-info-eieio)
5669 ;; Info Index gauche-refe
5670 (defvar anything-c-source-info-gauche-refe
5671 '((name . "Info index: gauche")
5672 (info-index . "gauche-refe")))
5673 ;; (anything 'anything-c-source-info-gauche-refe)
5675 ;; Info Index guile
5676 (defvar anything-c-source-info-guile
5677 '((name . "Info index: guile")
5678 (info-index . "guile")))
5679 ;; (anything 'anything-c-source-info-guile)
5681 ;; Info Index guile-tut
5682 (defvar anything-c-source-info-guile-tut
5683 '((name . "Info index: guile-tut")
5684 (info-index . "guile-tut")))
5685 ;; (anything 'anything-c-source-info-guile-tut)
5687 ;; Info Index goops
5688 (defvar anything-c-source-info-goops
5689 '((name . "Info index: goops")
5690 (info-index . "goops")))
5691 ;; (anything 'anything-c-source-info-goops)
5693 ;; Info Index screen
5694 (defvar anything-c-source-info-screen
5695 '((name . "Info index: screen")
5696 (info-index . "screen")
5697 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5698 ;; (anything 'anything-c-source-info-screen)
5700 ;; Info Index latex
5701 (defvar anything-c-source-info-latex
5702 '((name . "Info index: latex")
5703 (info-index . "latex")))
5704 ;; (anything 'anything-c-source-info-latex)
5706 ;; Info Index gawk
5707 (defvar anything-c-source-info-gawk
5708 '((name . "Info index: gawk")
5709 (info-index . "gawk")))
5710 ;; (anything 'anything-c-source-info-gawk)
5712 ;; Info Index sed
5713 (defvar anything-c-source-info-sed
5714 '((name . "Info index: sed")
5715 (info-index . "sed")))
5716 ;; (anything 'anything-c-source-info-sed)
5718 ;; Info Index m4
5719 (defvar anything-c-source-info-m4
5720 '((name . "Info index: m4")
5721 (info-index . "m4")))
5722 ;; (anything 'anything-c-source-info-m4)
5724 ;; Info Index wget
5725 (defvar anything-c-source-info-wget
5726 '((name . "Info index: wget")
5727 (info-index . "wget")))
5728 ;; (anything 'anything-c-source-info-wget)
5730 ;; Info Index binutils
5731 (defvar anything-c-source-info-binutils
5732 '((name . "Info index: binutils")
5733 (info-index . "binutils")))
5734 ;; (anything 'anything-c-source-info-binutils)
5736 ;; Info Index as
5737 (defvar anything-c-source-info-as
5738 '((name . "Info index: as")
5739 (info-index . "as")))
5740 ;; (anything 'anything-c-source-info-as)
5742 ;; Info Index bfd
5743 (defvar anything-c-source-info-bfd
5744 '((name . "Info index: bfd")
5745 (info-index . "bfd")))
5746 ;; (anything 'anything-c-source-info-bfd)
5748 ;; Info Index gprof
5749 (defvar anything-c-source-info-gprof
5750 '((name . "Info index: gprof")
5751 (info-index . "gprof")))
5752 ;; (anything 'anything-c-source-info-gprof)
5754 ;; Info Index ld
5755 (defvar anything-c-source-info-ld
5756 '((name . "Info index: ld")
5757 (info-index . "ld")))
5758 ;; (anything 'anything-c-source-info-ld)
5760 ;; Info Index diff
5761 (defvar anything-c-source-info-diff
5762 '((name . "Info index: diff")
5763 (info-index . "diff")))
5764 ;; (anything 'anything-c-source-info-diff)
5766 ;; Info Index flex
5767 (defvar anything-c-source-info-flex
5768 '((name . "Info index: flex")
5769 (info-index . "flex")))
5770 ;; (anything 'anything-c-source-info-flex)
5772 ;; Info Index grep
5773 (defvar anything-c-source-info-grep
5774 '((name . "Info index: grep")
5775 (info-index . "grep")))
5776 ;; (anything 'anything-c-source-info-grep)
5778 ;; Info Index gzip
5779 (defvar anything-c-source-info-gzip
5780 '((name . "Info index: gzip")
5781 (info-index . "gzip")))
5782 ;; (anything 'anything-c-source-info-gzip)
5784 ;; Info Index libtool
5785 (defvar anything-c-source-info-libtool
5786 '((name . "Info index: libtool")
5787 (info-index . "libtool")))
5788 ;; (anything 'anything-c-source-info-libtool)
5790 ;; Info Index texinfo
5791 (defvar anything-c-source-info-texinfo
5792 '((name . "Info index: texinfo")
5793 (info-index . "texinfo")))
5794 ;; (anything 'anything-c-source-info-texinfo)
5796 ;; Info Index info
5797 (defvar anything-c-source-info-info
5798 '((name . "Info index: info")
5799 (info-index . "info")))
5800 ;; (anything 'anything-c-source-info-info)
5802 ;; Info Index gdb
5803 (defvar anything-c-source-info-gdb
5804 '((name . "Info index: gdb")
5805 (info-index . "gdb")))
5806 ;; (anything 'anything-c-source-info-gdb)
5808 ;; Info Index stabs
5809 (defvar anything-c-source-info-stabs
5810 '((name . "Info index: stabs")
5811 (info-index . "stabs")))
5812 ;; (anything 'anything-c-source-info-stabs)
5814 ;; Info Index cvsbook
5815 (defvar anything-c-source-info-cvsbook
5816 '((name . "Info index: cvsbook")
5817 (info-index . "cvsbook")))
5818 ;; (anything 'anything-c-source-info-cvsbook)
5820 ;; Info Index cvs
5821 (defvar anything-c-source-info-cvs
5822 '((name . "Info index: cvs")
5823 (info-index . "cvs")))
5824 ;; (anything 'anything-c-source-info-cvs)
5826 ;; Info Index bison
5827 (defvar anything-c-source-info-bison
5828 '((name . "Info index: bison")
5829 (info-index . "bison")))
5830 ;; (anything 'anything-c-source-info-bison)
5832 ;; Info Index id-utils
5833 (defvar anything-c-source-info-id-utils
5834 '((name . "Info index: id-utils")
5835 (info-index . "id-utils")))
5836 ;; (anything 'anything-c-source-info-id-utils)
5838 ;; Info Index global
5839 (defvar anything-c-source-info-global
5840 '((name . "Info index: global")
5841 (info-index . "global")))
5842 ;; (anything 'anything-c-source-info-global)
5845 ;;; Man and woman UI
5848 (defvar anything-c-man-pages nil
5849 "All man pages on system.
5850 Will be calculated the first time you invoke anything with this
5851 source.")
5853 (defun anything-c-man-default-action (candidate)
5854 "Default action for jumping to a woman or man page from anything."
5855 (let ((wfiles (woman-file-name-all-completions candidate)))
5856 (condition-case err
5857 (if (> (length wfiles) 1)
5858 (woman-find-file
5859 (anything-comp-read
5860 "ManFile: " wfiles :must-match t))
5861 (woman candidate))
5862 ;; If woman is unable to format correctly
5863 ;; use man instead.
5864 (error (kill-buffer) ; Kill woman buffer.
5865 (let ((Man-notify-method 'meek))
5866 (Man-getpage-in-background candidate))))))
5868 (defvar anything-c-source-man-pages
5869 `((name . "Manual Pages")
5870 (candidates . (lambda ()
5871 (if anything-c-man-pages
5872 anything-c-man-pages
5873 ;; XEmacs doesn't have a woman :)
5874 (setq anything-c-man-pages
5875 (ignore-errors
5876 (require 'woman)
5877 (woman-file-name "")
5878 (sort (mapcar 'car woman-topic-all-completions)
5879 'string-lessp))))))
5880 (action ("Show with Woman" . anything-c-man-default-action))
5881 ;; Woman does not work OS X
5882 ;; http://xahlee.org/emacs/modernization_man_page.html
5883 (action-transformer . (lambda (actions candidate)
5884 (if (eq system-type 'darwin)
5885 '(("Show with Man" . man))
5886 actions)))
5887 (requires-pattern . 2)))
5888 ;; (anything 'anything-c-source-man-pages)
5891 ;;;; <Command>
5892 ;;; Anything M-x - Enhanced M-x UI
5895 ;; Another replacement of `M-x' that act exactly like the
5896 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5897 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5898 ;; anything invocation.
5899 ;; Documentation of commands available without quitting,
5900 ;; Show keybindings of commands.
5901 ;; Show history.
5902 (defvar anything-M-x-input-history nil)
5904 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5905 "Return alist of MODE-MAP."
5906 (loop for key being the key-seqs of mode-map using (key-bindings com)
5907 for str-key = (key-description key)
5908 for ismenu = (string-match "<menu-bar>" str-key)
5909 unless ismenu collect (cons str-key com)))
5911 (defun anything-get-mode-map-from-mode (mode)
5912 "Guess the mode-map name according to MODE.
5913 Some modes don't use conventional mode-map name
5914 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5915 Return nil if no mode-map found."
5916 (loop
5917 ;; Start with a conventional mode-map name.
5918 with mode-map = (intern-soft (format "%s-map" mode))
5919 with mode-string = (symbol-name mode)
5920 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5921 while (not mode-map)
5922 for count downfrom (length mode-name)
5923 ;; Return when no result after parsing entire string.
5924 when (eq count 0) return nil
5925 for sub-name = (substring mode-name 0 count)
5926 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5927 finally return mode-map))
5929 (defun anything-M-x-current-mode-map-alist ()
5930 "Return mode-map alist of current `major-mode'."
5931 (let ((map (anything-get-mode-map-from-mode major-mode)))
5932 (when (and map (boundp map))
5933 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5936 (defun anything-M-x-transformer (candidates sources)
5937 "filtered-candidate-transformer to show bindings in emacs commands.
5938 Show global bindings and local bindings according to current `major-mode'."
5939 (with-anything-current-buffer
5940 (loop
5941 with local-map = (anything-M-x-current-mode-map-alist)
5942 for cand in candidates
5943 for local-key = (car (rassq cand local-map))
5944 for key = (substitute-command-keys (format "\\[%s]" cand))
5945 collect
5946 (cons (cond ((and (string-match "^M-x" key) local-key)
5947 (format "%s (%s)"
5948 cand (propertize
5949 local-key
5950 'face 'anything-M-x-key-face)))
5951 ((string-match "^M-x" key) cand)
5952 (t (format "%s (%s)"
5953 cand (propertize
5955 'face 'anything-M-x-key-face))))
5956 cand) into ls
5957 finally return
5958 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5961 ;;; Complex command history
5964 (defvar anything-c-source-complex-command-history
5965 '((name . "Complex Command History")
5966 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5967 (type . sexp)))
5968 ;; (anything 'anything-c-source-complex-command-history)
5970 ;;; M-x history (not related to `anything-M-x')
5973 (defvar anything-c-source-extended-command-history
5974 '((name . "Emacs Commands History")
5975 (candidates
5976 . (lambda ()
5977 (anything-fast-remove-dups extended-command-history :test 'equal)))
5978 (type . command)))
5979 ;; (anything 'anything-c-source-extended-command-history)
5981 ;;; Emacs commands (Basic source for emacs commands)
5984 (defvar anything-c-source-emacs-commands
5985 '((name . "Emacs Commands")
5986 (candidates . (lambda ()
5987 (let (commands)
5988 (mapatoms (lambda (a)
5989 (if (commandp a)
5990 (push (symbol-name a)
5991 commands))))
5992 (sort commands 'string-lessp))))
5993 (type . command)
5994 (requires-pattern . 2))
5995 "Source for completing and invoking Emacs commands.
5996 A command is a function with interactive spec that can
5997 be invoked with `M-x'.
5999 To get non-interactive functions listed, use
6000 `anything-c-source-emacs-functions'.")
6001 ;; (anything 'anything-c-source-emacs-commands)
6004 ;;;; <Function>
6005 ;;; Emacs functions
6008 (defvar anything-c-source-emacs-functions
6009 '((name . "Emacs Functions")
6010 (candidates . (lambda ()
6011 (let (commands)
6012 (mapatoms (lambda (a)
6013 (if (functionp a)
6014 (push (symbol-name a) commands))))
6015 (sort commands 'string-lessp))))
6016 (type . function)
6017 (requires-pattern . 2))
6018 "Source for completing Emacs functions.")
6019 ;; (anything 'anything-c-source-emacs-functions)
6021 ;;; With abbrev expansion
6022 ;;; Similar to my exec-abbrev-cmd.el
6023 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6024 (defvar anything-c-function-abbrev-regexp nil
6025 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6026 Regexp built from the current `anything-pattern' interpreting it
6027 as abbreviation.
6028 Only for internal use.")
6030 (defun anything-c-match-function-by-abbrev (candidate)
6031 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6033 Abbreviations are made by taking the first character from each
6034 word in the function's name, e.g. \"bb\" is an abbrev for
6035 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6036 (string-match anything-c-function-abbrev-regexp candidate))
6038 (defvar anything-c-source-emacs-functions-with-abbrevs
6039 (append anything-c-source-emacs-functions
6040 '((match anything-c-match-function-by-abbrev
6041 anything-c-string-match))
6042 '((init
6043 . (lambda ()
6044 (defadvice anything-update
6045 (before anything-c-update-function-abbrev-regexp activate)
6046 (let ((char-list (append anything-pattern nil))
6047 (str "^"))
6048 (dolist (c char-list)
6049 (setq str (concat str (list c) "[^-]*-")))
6050 (setq str (concat (substring str 0 (1- (length str))) "$"))
6051 (setq anything-c-function-abbrev-regexp str))))))))
6052 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6054 (defvar anything-c-source-advice
6055 '((name . "Function Advice")
6056 (candidates . anything-c-advice-candidates)
6057 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6058 (persistent-action . anything-c-advice-persistent-action)
6059 (multiline)
6060 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6061 ;; (anything 'anything-c-source-advice)
6062 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6063 ;; (testadvice)
6065 (defun anything-c-advice-candidates ()
6066 (require 'advice)
6067 (loop for (fname) in ad-advised-functions
6068 for function = (intern fname)
6069 append
6070 (loop for class in ad-advice-classes append
6071 (loop for advice in (ad-get-advice-info-field function class)
6072 for enabled = (ad-advice-enabled advice)
6073 collect
6074 (cons (format
6075 "%s %s %s"
6076 (if enabled "Enabled " "Disabled")
6077 (propertize fname 'face 'font-lock-function-name-face)
6078 (ad-make-single-advice-docstring advice class nil))
6079 (list function class advice))))))
6081 (defun anything-c-advice-persistent-action (func-class-advice)
6082 (if current-prefix-arg
6083 (anything-c-advice-toggle func-class-advice)
6084 (describe-function (car func-class-advice))))
6086 (defun anything-c-advice-toggle (func-class-advice)
6087 (destructuring-bind (function class advice) func-class-advice
6088 (cond ((ad-advice-enabled advice)
6089 (ad-advice-set-enabled advice nil)
6090 (message "Disabled"))
6091 (t ;disabled
6092 (ad-advice-set-enabled advice t)
6093 (message "Enabled")))
6094 (ad-activate function)
6095 (and anything-in-persistent-action
6096 (anything-c-advice-update-current-display-string))))
6098 (defun anything-c-advice-update-current-display-string ()
6099 (anything-edit-current-selection
6100 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6101 ((looking-at "Enabled") "Disabled")))
6102 realvalue)
6103 (when newword
6104 (delete-region (point) (progn (forward-word 1) (point)))
6105 (insert newword)))))
6108 ;;;; <Variable>
6109 ;;; Emacs variables
6112 (defvar anything-c-source-emacs-variables
6113 '((name . "Emacs Variables")
6114 (candidates . (lambda ()
6115 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6116 (type . variable)
6117 (requires-pattern . 2))
6118 "Source for completing Emacs variables.")
6119 ;; (anything 'anything-c-source-emacs-variables)
6122 ;;; LaCarte
6123 (defvar anything-c-source-lacarte
6124 '((name . "Lacarte")
6125 (init . (lambda () (require 'lacarte )))
6126 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6127 (candidate-number-limit . 9999)
6128 (action . anything-c-call-interactively))
6129 "Needs lacarte.el.
6131 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6132 ;; (anything 'anything-c-source-lacarte)
6135 ;;; Bookmarks
6138 ;; Bind some faces for bookmarks.
6139 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6140 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6141 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6143 (eval-when-compile (require 'bookmark))
6144 (defvar anything-c-source-bookmarks
6145 '((name . "Bookmarks")
6146 (init . (lambda ()
6147 (require 'bookmark)))
6148 (candidates . bookmark-all-names)
6149 (type . bookmark))
6150 "See (info \"(emacs)Bookmarks\").")
6151 ;; (anything 'anything-c-source-bookmarks)
6153 ;;; bookmark-set
6154 (defvar anything-c-source-bookmark-set
6155 '((name . "Set Bookmark")
6156 (dummy)
6157 (action . bookmark-set))
6158 "See (info \"(emacs)Bookmarks\").")
6159 ;; (anything 'anything-c-source-bookmark-set)
6161 ;;; Visible Bookmarks
6162 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6165 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6166 (defvar anything-c-source-bm
6167 '((name . "Visible Bookmarks")
6168 (init . anything-c-bm-init)
6169 (candidates-in-buffer)
6170 (type . line))
6171 "Needs bm.el.
6173 http://www.nongnu.org/bm/")
6175 (defun anything-c-bm-init ()
6176 "Init function for `anything-c-source-bm'."
6177 (when (require 'bm nil t)
6178 (with-no-warnings
6179 (let ((bookmarks (bm-lists))
6180 (buf (anything-candidate-buffer 'global)))
6181 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6182 '< :key 'overlay-start))
6183 (let ((start (overlay-start bm))
6184 (end (overlay-end bm))
6185 (annotation (or (overlay-get bm 'annotation) "")))
6186 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6187 (let ((str (format "%5d: [%s]: %s\n"
6188 (line-number-at-pos start)
6189 annotation
6190 (buffer-substring start (1- end)))))
6191 (with-current-buffer buf (insert str))))))))))
6193 ;;; Special bookmarks
6194 (defvar anything-c-source-bookmarks-ssh
6195 '((name . "Bookmarks-ssh")
6196 (init . (lambda ()
6197 (require 'bookmark)))
6198 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6199 (type . bookmark))
6200 "See (info \"(emacs)Bookmarks\").")
6201 ;; (anything 'anything-c-source-bookmarks-ssh)
6203 (defvar anything-c-source-bookmarks-su
6204 '((name . "Bookmarks-root")
6205 (init . (lambda ()
6206 (require 'bookmark)))
6207 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6208 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6210 (type . bookmark))
6211 "See (info \"(emacs)Bookmarks\").")
6212 ;; (anything 'anything-c-source-bookmarks-su)
6214 (defvar anything-c-source-bookmarks-local
6215 '((name . "Bookmarks-Local")
6216 (init . (lambda ()
6217 (require 'bookmark)))
6218 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6219 (filtered-candidate-transformer
6220 anything-c-adaptive-sort
6221 anything-c-highlight-bookmark)
6222 (type . bookmark))
6223 "See (info \"(emacs)Bookmarks\").")
6224 ;; (anything 'anything-c-source-bookmarks-local)
6226 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6227 (let* ((lis-all (bookmark-all-names))
6228 (lis-loc (cond (local (loop for i in lis-all
6229 unless (string-match "^(ssh)\\|^(su)" i)
6230 collect i))
6231 (su (loop for i in lis-all
6232 when (string-match "^(su)" i)
6233 collect i))
6234 (sudo (loop for i in lis-all
6235 when (string-match "^(sudo)" i)
6236 collect i))
6237 (ssh (loop for i in lis-all
6238 when (string-match "^(ssh)" i)
6239 collect i)))))
6240 (sort lis-loc 'string-lessp)))
6242 (defun anything-c-bookmark-root-logged-p ()
6243 (catch 'break
6244 (dolist (i (mapcar #'buffer-name (buffer-list)))
6245 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6246 (throw 'break t)))))
6248 (defun anything-c-highlight-bookmark-su (files source)
6249 (if (anything-c-bookmark-root-logged-p)
6250 (anything-c-highlight-bookmark files source)
6251 (anything-c-highlight-not-logged files source)))
6253 (defun anything-c-highlight-not-logged (files source)
6254 (loop for i in files
6255 collect (propertize i 'face anything-c-bookmarks-face3)))
6257 (defun anything-c-highlight-bookmark (bookmarks source)
6258 "Used as `candidate-transformer' to colorize bookmarks.
6259 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6260 (loop for i in bookmarks
6261 for isfile = (bookmark-get-filename i)
6262 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6263 (bmkext-get-buffer-name i))
6264 for handlerp = (and (fboundp 'bookmark-get-handler)
6265 (bookmark-get-handler i))
6266 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6267 (bmkext-w3m-bookmark-p i))
6268 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6269 (bmkext-gnus-bookmark-p i))
6270 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6271 (bmkext-man-bookmark-p i))
6272 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6273 (bmkext-woman-bookmark-p i))
6274 for handlerp = (bookmark-get-handler i)
6275 for isannotation = (bookmark-get-annotation i)
6276 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6277 for isinfo = (eq handlerp 'Info-bookmark-jump)
6278 ;; Add a * if bookmark have annotation
6279 if (and isannotation (not (string-equal isannotation "")))
6280 do (setq i (concat "*" i))
6281 collect (cond (;; info buffers
6282 isinfo
6283 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6284 (;; w3m buffers
6285 isw3m
6286 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6287 (;; gnus buffers
6288 isgnus
6289 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6290 (;; Man Woman
6291 (or iswoman isman)
6292 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6293 (;; Addressbook
6294 isabook
6295 (propertize i 'face '((:foreground "Tomato"))))
6296 (;; directories
6297 (and isfile (file-directory-p isfile))
6298 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6299 (;; regular files
6301 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6305 ;;; Sources to filter bookmark-extensions bookmarks.
6308 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6309 ;; If you want to enable google-maps in addressbook you will need
6310 ;; Julien Danjou google-maps-el package available here:
6311 ;; http://julien.danjou.info/google-maps-el.html
6313 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6314 "Return a filtered `bookmark-alist' sorted alphabetically."
6315 (loop
6316 with alist = (if args
6317 (apply #'(lambda (x) (funcall fn x)) args)
6318 (funcall fn))
6319 for i in alist
6320 for b = (car i)
6321 collect b into sa
6322 finally return (sort sa 'string-lessp)))
6324 ;;; Addressbook.
6327 (defvar anything-c-source-bmkext-addressbook
6328 '((name . "Bookmark Addressbook")
6329 (init . (lambda ()
6330 (require 'bookmark-extensions)
6331 (bookmark-maybe-load-default-file)))
6332 (candidates . anything-c-bmkext-addressbook-setup-alist)
6333 (persistent-action
6334 . (lambda (candidate)
6335 (let ((bmk (anything-bookmark-get-bookmark-from-name
6336 candidate)))
6337 (bookmark--jump-via bmk 'pop-to-buffer))))
6338 (persistent-help . "Show contact - Prefix with C-u to append")
6339 (filtered-candidate-transformer
6340 anything-c-adaptive-sort
6341 anything-c-highlight-bookmark)
6342 (action . (("Show Contact(s)"
6343 . (lambda (candidate)
6344 (let* ((contacts (anything-marked-candidates))
6345 (current-prefix-arg (or anything-current-prefix-arg
6346 (> (length contacts) 1))))
6347 (bookmark-jump
6348 (anything-bookmark-get-bookmark-from-name (car contacts)))
6349 (anything-aif (cdr contacts)
6350 (loop for bmk in it do
6351 (bookmark-jump
6352 (anything-bookmark-get-bookmark-from-name bmk)))))))
6353 ("Send Mail"
6354 . (lambda (candidate)
6355 (let* ((contacts (anything-marked-candidates))
6356 (bmk (anything-bookmark-get-bookmark-from-name
6357 (car contacts)))
6358 (append (message-buffers)))
6359 (if append
6360 (addressbook-set-mail-buffer1 bmk 'append)
6361 (addressbook-set-mail-buffer1 bmk))
6362 (setq contacts (cdr contacts))
6363 (when contacts
6364 (loop for bmk in contacts do
6365 (addressbook-set-mail-buffer1 bmk 'append))))))
6366 ("Edit Bookmark"
6367 . (lambda (candidate)
6368 (let ((bmk (anything-bookmark-get-bookmark-from-name
6369 candidate)))
6370 (addressbook-bookmark-edit
6371 (assoc bmk bookmark-alist)))))
6372 ("Insert Email at point"
6373 . (lambda (candidate)
6374 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6375 candidate))
6376 (mlist (split-string
6377 (assoc-default
6378 'email (assoc bmk bookmark-alist))
6379 ", ")))
6380 (insert
6381 (if (> (length mlist) 1)
6382 (anything-comp-read
6383 "Insert Mail Address: " mlist :must-match t)
6384 (car mlist))))))
6385 ("Show annotation"
6386 . (lambda (candidate)
6387 (let ((bmk (anything-bookmark-get-bookmark-from-name
6388 candidate)))
6389 (bookmark-show-annotation bmk))))
6390 ("Edit annotation"
6391 . (lambda (candidate)
6392 (let ((bmk (anything-bookmark-get-bookmark-from-name
6393 candidate)))
6394 (bookmark-edit-annotation bmk))))
6395 ("Show Google map"
6396 . (lambda (candidate)
6397 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6398 candidate))
6399 (full-bmk (assoc bmk bookmark-alist)))
6400 (addressbook-google-map full-bmk))))))))
6403 (defun anything-c-bmkext-addressbook-setup-alist ()
6404 "Specialized filter function for bookmarks w3m."
6405 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6407 ;; W3m bookmarks from bookmark-extensions.
6408 (defvar anything-c-source-bookmark-w3m
6409 '((name . "Bookmark W3m")
6410 (init . (lambda ()
6411 (require 'bookmark-extensions)
6412 (bookmark-maybe-load-default-file)))
6413 (candidates . anything-c-bookmark-w3m-setup-alist)
6414 (filtered-candidate-transformer
6415 anything-c-adaptive-sort
6416 anything-c-highlight-bookmark)
6417 (type . bookmark)))
6418 ;; (anything 'anything-c-source-bookmark-w3m)
6420 (defun anything-c-bookmark-w3m-setup-alist ()
6421 "Specialized filter function for bookmarks w3m."
6422 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6424 ;; Images
6425 (defvar anything-c-source-bookmark-images
6426 '((name . "Bookmark Images")
6427 (init . (lambda ()
6428 (require 'bookmark-extensions)
6429 (bookmark-maybe-load-default-file)))
6430 (candidates . anything-c-bookmark-images-setup-alist)
6431 (filtered-candidate-transformer
6432 anything-c-adaptive-sort
6433 anything-c-highlight-bookmark)
6434 (type . bookmark)))
6435 ;; (anything 'anything-c-source-bookmark-images)
6437 (defun anything-c-bookmark-images-setup-alist ()
6438 "Specialized filter function for images bookmarks."
6439 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6441 ;; Woman Man
6442 (defvar anything-c-source-bookmark-man
6443 '((name . "Bookmark Woman&Man")
6444 (init . (lambda ()
6445 (require 'bookmark-extensions)
6446 (bookmark-maybe-load-default-file)))
6447 (candidates . anything-c-bookmark-man-setup-alist)
6448 (filtered-candidate-transformer
6449 anything-c-adaptive-sort
6450 anything-c-highlight-bookmark)
6451 (type . bookmark)))
6452 ;; (anything 'anything-c-source-bookmark-man)
6454 (defun anything-c-bookmark-man-setup-alist ()
6455 "Specialized filter function for bookmarks w3m."
6456 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6457 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6459 ;; Gnus
6460 (defvar anything-c-source-bookmark-gnus
6461 '((name . "Bookmark Gnus")
6462 (init . (lambda ()
6463 (require 'bookmark-extensions)
6464 (bookmark-maybe-load-default-file)))
6465 (candidates . anything-c-bookmark-gnus-setup-alist)
6466 (filtered-candidate-transformer
6467 anything-c-adaptive-sort
6468 anything-c-highlight-bookmark)
6469 (type . bookmark)))
6470 ;; (anything 'anything-c-source-bookmark-gnus)
6472 (defun anything-c-bookmark-gnus-setup-alist ()
6473 "Specialized filter function for bookmarks gnus."
6474 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6476 ;; Info
6477 (defvar anything-c-source-bookmark-info
6478 '((name . "Bookmark Info")
6479 (init . (lambda ()
6480 (require 'bookmark-extensions)
6481 (bookmark-maybe-load-default-file)))
6482 (candidates . anything-c-bookmark-info-setup-alist)
6483 (filtered-candidate-transformer
6484 anything-c-adaptive-sort
6485 anything-c-highlight-bookmark)
6486 (type . bookmark)))
6487 ;; (anything 'anything-c-source-bookmark-info)
6489 (defun anything-c-bookmark-info-setup-alist ()
6490 "Specialized filter function for bookmarks info."
6491 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6493 ;; Local Files&directories
6494 (defvar anything-c-source-bookmark-files&dirs
6495 '((name . "Bookmark Files&Directories")
6496 (init . (lambda ()
6497 (require 'bookmark-extensions)
6498 (bookmark-maybe-load-default-file)))
6499 (candidates . anything-c-bookmark-local-files-setup-alist)
6500 (filtered-candidate-transformer
6501 anything-c-adaptive-sort
6502 anything-c-highlight-bookmark)
6503 (type . bookmark)))
6504 ;; (anything 'anything-c-source-bookmark-files&dirs)
6506 (defun anything-c-bookmark-local-files-setup-alist ()
6507 "Specialized filter function for bookmarks locals files."
6508 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6510 ;; Su Files&directories
6511 (defvar anything-c-source-bookmark-su-files&dirs
6512 '((name . "Bookmark Root-Files&Directories")
6513 (init . (lambda ()
6514 (require 'bookmark-extensions)
6515 (bookmark-maybe-load-default-file)))
6516 (candidates . anything-c-bookmark-su-files-setup-alist)
6517 (filtered-candidate-transformer
6518 anything-c-adaptive-sort
6519 anything-c-highlight-bookmark-su)
6520 (type . bookmark)))
6521 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6523 (defun anything-c-bookmark-su-files-setup-alist ()
6524 "Specialized filter function for bookmarks su/sudo files."
6525 (declare (special bmkext-su-or-sudo-regexp))
6526 (loop
6527 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6528 for i in l
6529 for isfile = (bookmark-get-filename i)
6530 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6531 (save-match-data
6532 (string-match tramp-file-name-regexp isfile)))
6533 for issu = (and istramp
6534 (string-match bmkext-su-or-sudo-regexp isfile))
6535 if issu
6536 collect i))
6538 ;; Ssh Files&directories
6539 (defvar anything-c-source-bookmark-ssh-files&dirs
6540 '((name . "Bookmark Ssh-Files&Directories")
6541 (init . (lambda ()
6542 (require 'bookmark-extensions)
6543 (bookmark-maybe-load-default-file)))
6544 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6545 (filtered-candidate-transformer . anything-c-adaptive-sort)
6546 (type . bookmark)))
6547 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6549 (defun anything-c-bookmark-ssh-files-setup-alist ()
6550 "Specialized filter function for bookmarks ssh files."
6551 (loop
6552 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6553 for i in l
6554 for isfile = (bookmark-get-filename i)
6555 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6556 (save-match-data
6557 (string-match tramp-file-name-regexp isfile)))
6558 for isssh = (and istramp
6559 (string-match "/ssh:" isfile))
6560 if isssh
6561 collect i))
6565 ;;; Firefox bookmarks
6568 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6569 ;; (only for firefox versions >=3)
6570 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6571 ;; to true:
6572 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6573 ;; You should have now:
6574 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6576 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6577 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6579 (defun anything-get-firefox-user-init-dir ()
6580 "Guess the default Firefox user directory name."
6581 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6582 (moz-user-dir
6583 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6584 (goto-char (point-min))
6585 (prog1
6586 (when (search-forward "Path=" nil t)
6587 (buffer-substring-no-properties (point) (point-at-eol)))
6588 (kill-buffer)))))
6589 (file-name-as-directory (concat moz-dir moz-user-dir))))
6591 (defun anything-guess-firefox-bookmark-file ()
6592 "Return the path of the Firefox bookmarks file."
6593 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6595 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6596 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6597 (let (bookmarks-alist url title)
6598 (with-temp-buffer
6599 (insert-file-contents file)
6600 (goto-char (point-min))
6601 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6602 (forward-line 0)
6603 (when (re-search-forward url-regexp nil t)
6604 (setq url (match-string 0)))
6605 (when (re-search-forward bmk-regexp nil t)
6606 (setq title (match-string 1)))
6607 (push (cons title url) bookmarks-alist)
6608 (forward-line)))
6609 (nreverse bookmarks-alist)))
6611 (defvar anything-c-firefox-bookmarks-alist nil)
6612 (defvar anything-c-source-firefox-bookmarks
6613 '((name . "Firefox Bookmarks")
6614 (init . (lambda ()
6615 (setq anything-c-firefox-bookmarks-alist
6616 (anything-html-bookmarks-to-alist
6617 (anything-guess-firefox-bookmark-file)
6618 anything-firefox-bookmark-url-regexp
6619 anything-firefox-bookmarks-regexp))))
6620 (candidates . (lambda ()
6621 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6622 (filtered-candidate-transformer
6623 anything-c-adaptive-sort
6624 anything-c-highlight-firefox-bookmarks)
6625 (action . (("Browse Url Firefox"
6626 . (lambda (candidate)
6627 (browse-url-firefox
6628 (anything-c-firefox-bookmarks-get-value candidate))))
6629 ("Browse Url w3m"
6630 . (lambda (candidate)
6631 (w3m-browse-url
6632 (anything-c-firefox-bookmarks-get-value candidate))))
6633 ("Copy Url"
6634 . (lambda (elm)
6635 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6637 ;; (anything 'anything-c-source-firefox-bookmarks)
6639 (defun anything-c-firefox-bookmarks-get-value (elm)
6640 (assoc-default elm anything-c-firefox-bookmarks-alist))
6642 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6643 (loop for i in bookmarks
6644 collect (propertize
6645 i 'face '((:foreground "YellowGreen"))
6646 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6650 ;;; W3m bookmark - anything interface.
6653 ;; Some users have the emacs-w3m library in load-path
6654 ;; without having the w3m executable :-;
6655 ;; So check if w3m program is present before trying to load
6656 ;; emacs-w3m.
6657 (eval-when-compile
6658 (when (executable-find "w3m")
6659 (require 'w3m-bookmark nil t)))
6661 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6662 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6663 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6664 (defvar anything-c-w3m-bookmarks-alist nil)
6665 (defvar anything-c-source-w3m-bookmarks
6666 '((name . "W3m Bookmarks")
6667 (init . (lambda ()
6668 (setq anything-c-w3m-bookmarks-alist
6669 (anything-html-bookmarks-to-alist
6670 w3m-bookmark-file
6671 anything-w3m-bookmark-url-regexp
6672 anything-w3m-bookmarks-regexp))))
6673 (candidates . (lambda ()
6674 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6675 (filtered-candidate-transformer
6676 anything-c-adaptive-sort
6677 anything-c-highlight-w3m-bookmarks)
6678 (action . (("Browse Url"
6679 . (lambda (candidate)
6680 (anything-c-w3m-browse-bookmark candidate)))
6681 ("Copy Url"
6682 . (lambda (elm)
6683 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6684 ("Browse Url Firefox"
6685 . (lambda (candidate)
6686 (anything-c-w3m-browse-bookmark candidate t)))
6687 ("Delete Bookmark"
6688 . (lambda (candidate)
6689 (anything-c-w3m-delete-bookmark candidate)))
6690 ("Rename Bookmark"
6691 . (lambda (candidate)
6692 (anything-c-w3m-rename-bookmark candidate)))))
6693 (persistent-action . (lambda (candidate)
6694 (if current-prefix-arg
6695 (anything-c-w3m-browse-bookmark candidate t)
6696 (anything-c-w3m-browse-bookmark candidate nil t))))
6697 (persistent-help . "Open URL with emacs-w3m in new tab / \
6698 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6699 "Needs w3m and emacs-w3m.
6701 http://w3m.sourceforge.net/
6702 http://emacs-w3m.namazu.org/")
6704 ;; (anything 'anything-c-source-w3m-bookmarks)
6706 (defun anything-c-w3m-bookmarks-get-value (elm)
6707 (replace-regexp-in-string
6708 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6710 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6711 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6712 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6713 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6715 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6716 (loop for i in bookmarks
6717 collect (propertize
6718 i 'face 'anything-w3m-bookmarks-face
6719 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6722 (defun anything-c-w3m-delete-bookmark (elm)
6723 "Delete w3m bookmark from `w3m-bookmark-file'."
6724 (with-current-buffer
6725 (find-file-literally w3m-bookmark-file)
6726 (goto-char (point-min))
6727 (when (re-search-forward elm nil t)
6728 (beginning-of-line)
6729 (delete-region (point)
6730 (line-end-position))
6731 (delete-blank-lines))
6732 (save-buffer)
6733 (kill-buffer)))
6735 (defun anything-c-w3m-rename-bookmark (elm)
6736 "Rename w3m bookmark in `w3m-bookmark-file'."
6737 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6738 (new-title (read-string "NewTitle: " old-title)))
6739 (with-current-buffer
6740 (find-file-literally w3m-bookmark-file)
6741 (goto-char (point-min))
6742 (when (re-search-forward (concat elm "<") nil t)
6743 (goto-char (1- (point)))
6744 (delete-char (- (length old-title)))
6745 (insert new-title))
6746 (save-buffer)
6747 (kill-buffer))))
6750 ;;;; <Library>
6751 ;;; Elisp library scan
6754 (defvar anything-c-source-elisp-library-scan
6755 '((name . "Elisp libraries (Scan)")
6756 (init . (anything-c-elisp-library-scan-init))
6757 (candidates-in-buffer)
6758 (action ("Find library"
6759 . (lambda (candidate) (find-file (find-library-name candidate))))
6760 ("Find library other window"
6761 . (lambda (candidate)
6762 (find-file-other-window (find-library-name candidate))))
6763 ("Load library"
6764 . (lambda (candidate) (load-library candidate))))))
6765 ;; (anything 'anything-c-source-elisp-library-scan)
6767 (defun anything-c-elisp-library-scan-init ()
6768 "Init anything buffer status."
6769 (let ((anything-buffer (anything-candidate-buffer 'global))
6770 (library-list (anything-c-elisp-library-scan-list)))
6771 (with-current-buffer anything-buffer
6772 (dolist (library library-list)
6773 (insert (format "%s\n" library))))))
6775 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6776 "Do completion for file names passed to `locate-file'.
6777 DIRS is directory to search path.
6778 STRING is string to match."
6779 ;; Use `load-path' as path when ignore `dirs'.
6780 (or dirs (setq dirs load-path))
6781 ;; Init with blank when ignore `string'.
6782 (or string (setq string ""))
6783 ;; Get library list.
6784 (let ((string-dir (file-name-directory string))
6785 ;; File regexp that suffix match `load-file-rep-suffixes'.
6786 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6787 name
6788 names)
6789 (dolist (dir dirs)
6790 (unless dir
6791 (setq dir default-directory))
6792 (if string-dir
6793 (setq dir (expand-file-name string-dir dir)))
6794 (when (file-directory-p dir)
6795 (dolist (file (file-name-all-completions
6796 (file-name-nondirectory string) dir))
6797 ;; Suffixes match `load-file-rep-suffixes'.
6798 (setq name (if string-dir (concat string-dir file) file))
6799 (if (string-match match-regexp name)
6800 (add-to-list 'names name)))))
6801 names))
6804 ;;;; <Programming>
6808 ;;; Imenu
6811 (defvar anything-c-imenu-delimiter " / ")
6813 (defvar anything-c-imenu-index-filter nil)
6814 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6816 (defvar anything-c-cached-imenu-alist nil)
6817 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6819 (defvar anything-c-cached-imenu-candidates nil)
6820 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6822 (defvar anything-c-cached-imenu-tick nil)
6823 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6825 (eval-when-compile (require 'imenu))
6826 (setq imenu-auto-rescan t)
6828 (defun anything-imenu-create-candidates (entry)
6829 "Create candidates with ENTRY."
6830 (if (listp (cdr entry))
6831 (mapcan
6832 (lambda (sub)
6833 (if (consp (cdr sub))
6834 (mapcar
6835 (lambda (subentry)
6836 (concat (car entry) anything-c-imenu-delimiter subentry))
6837 (anything-imenu-create-candidates sub))
6838 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6839 (cdr entry))
6840 (list entry)))
6842 (defvar anything-c-source-imenu
6843 '((name . "Imenu")
6844 (init . (lambda () (require 'imenu)))
6845 (candidates . anything-c-imenu-candidates)
6846 (persistent-action . (lambda (elm)
6847 (anything-c-imenu-default-action elm)
6848 (unless (fboundp 'semantic-imenu-tag-overlay)
6849 (anything-match-line-color-current-line))))
6850 (persistent-help . "Show this entry")
6851 (action . anything-c-imenu-default-action))
6852 "See (info \"(emacs)Imenu\")")
6854 ;; (anything 'anything-c-source-imenu)
6856 (defun anything-c-imenu-candidates ()
6857 (with-anything-current-buffer
6858 (let ((tick (buffer-modified-tick)))
6859 (if (eq anything-c-cached-imenu-tick tick)
6860 anything-c-cached-imenu-candidates
6861 (setq imenu--index-alist nil)
6862 (setq anything-c-cached-imenu-tick tick
6863 anything-c-cached-imenu-candidates
6864 (ignore-errors
6865 (mapcan
6866 'anything-imenu-create-candidates
6867 (setq anything-c-cached-imenu-alist
6868 (let ((index (imenu--make-index-alist)))
6869 (if anything-c-imenu-index-filter
6870 (funcall anything-c-imenu-index-filter index)
6871 index))))))
6872 (setq anything-c-cached-imenu-candidates
6873 (mapcar #'(lambda (x)
6874 (if (stringp x)
6876 (car x)))
6877 anything-c-cached-imenu-candidates))))))
6879 (setq imenu-default-goto-function 'imenu-default-goto-function)
6880 (defun anything-c-imenu-default-action (elm)
6881 "The default action for `anything-c-source-imenu'."
6882 (let ((path (split-string elm anything-c-imenu-delimiter))
6883 (alist anything-c-cached-imenu-alist))
6884 (dolist (elm path)
6885 (setq alist (assoc elm alist)))
6886 (imenu alist)))
6890 ;;; Ctags
6893 (defvar anything-c-ctags-modes
6894 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6895 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6896 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6898 (defun anything-c-source-ctags-init ()
6899 (when (and buffer-file-name
6900 (memq major-mode anything-c-ctags-modes)
6901 (anything-current-buffer-is-modified))
6902 (with-current-buffer (anything-candidate-buffer 'local)
6903 (call-process-shell-command
6904 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6905 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6906 anything-buffer-file-name)
6907 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6908 nil (current-buffer))
6909 (goto-char (point-min))
6910 (forward-line 2)
6911 (delete-region (point-min) (point))
6912 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6913 for lineno-start = (point)
6914 for lineno = (buffer-substring
6915 lineno-start
6916 (1- (search-forward "," (point-at-eol) t)))
6918 (beginning-of-line)
6919 (insert (format "%5s:" lineno))
6920 (search-forward "\177" (point-at-eol) t)
6921 (delete-region (1- (point)) (point-at-eol))
6922 (forward-line 1)))))
6924 (defvar anything-c-source-ctags
6925 '((name . "Exuberant ctags")
6926 (init . anything-c-source-ctags-init)
6927 (candidates-in-buffer)
6928 (adjust)
6929 (type . line))
6930 "Needs Exuberant Ctags.
6932 http://ctags.sourceforge.net/")
6933 ;; (anything 'anything-c-source-ctags)
6936 ;;; Etags
6939 ;; anything-etags.el is deprecated, if this file is found,
6940 ;; warn user at compile time.
6941 (eval-when-compile
6942 (when (locate-library "anything-etags.el")
6943 (display-warning
6944 '(anything-config)
6945 "You are using obsolete library `anything-etags.el' and should remove it."
6946 :warning)))
6948 (defvar anything-c-etags-tag-file-dir nil
6949 "Etags file directory.")
6950 (defvar anything-c-etags-mtime-alist nil
6951 "Store the last modification time of etags files here.")
6952 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6953 "Cache content of etags files used here for faster access.")
6955 (defun anything-c-etags-get-tag-file (&optional directory)
6956 "Return the path of etags file if found."
6957 ;; Get tag file from `default-directory' or upper directory.
6958 (let ((current-dir (anything-c-etags-find-tag-file-directory
6959 (or directory default-directory))))
6960 ;; Return nil if not find tag file.
6961 (when current-dir
6962 ;; Set tag file directory.
6963 (setq anything-c-etags-tag-file-dir current-dir)
6964 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6966 (defun anything-c-etags-find-tag-file-directory (current-dir)
6967 "Try to find the directory containing tag file.
6968 If not found in CURRENT-DIR search in upper directory."
6969 (flet ((file-exists? (dir)
6970 (let ((tag-path (expand-file-name
6971 anything-c-etags-tag-file-name dir)))
6972 (and (stringp tag-path)
6973 (file-exists-p tag-path)
6974 (file-readable-p tag-path)))))
6975 (loop with count = 0
6976 until (file-exists? current-dir)
6977 ;; Return nil if outside the value of
6978 ;; `anything-c-etags-tag-file-search-limit'.
6979 if (= count anything-c-etags-tag-file-search-limit)
6980 do (return nil)
6981 ;; Or search upper directories.
6982 else
6983 do (incf count)
6984 (setq current-dir (expand-file-name (concat current-dir "../")))
6985 finally return current-dir)))
6987 (defun anything-c-source-etags-header-name (x)
6988 "Create header name for this anything etags session."
6989 (concat "Etags in "
6990 (with-anything-current-buffer
6991 (anything-c-etags-get-tag-file))))
6993 (defmacro anything-c-etags-create-buffer (file)
6994 "Create the `anything-buffer' based on contents of etags tag FILE."
6995 `(let* ((tag-fname ,file)
6997 (split (with-current-buffer (find-file-noselect tag-fname)
6998 (prog1
6999 (split-string (buffer-string) "\n" 'omit-nulls)
7000 (setq max (line-number-at-pos (point-max)))
7001 (kill-buffer))))
7002 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7003 (loop
7004 with fname
7005 with cand
7006 for i in split for count from 0
7007 for elm = (unless (string-match "^\x0c" i)
7008 (anything-aif (string-match "\177" i)
7009 (substring i 0 it)
7011 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7012 (setq fname (match-string 1 elm)))
7013 (elm (setq cand (concat fname ": " elm)))
7014 (t (setq cand nil)))
7015 when cand do (progn
7016 (insert (concat cand "\n"))
7017 (progress-reporter-update progress-reporter count)))))
7019 (defun anything-c-etags-init ()
7020 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7021 If no entry in cache, create one."
7022 (let ((tagfile (anything-c-etags-get-tag-file)))
7023 (when tagfile
7024 (with-current-buffer (anything-candidate-buffer 'global)
7025 (anything-aif (gethash tagfile anything-c-etags-cache)
7026 ;; An entry is present in cache, insert it.
7027 (insert it)
7028 ;; No entry, create a new buffer using content of tag file (slower).
7029 (anything-c-etags-create-buffer tagfile)
7030 ;; Store content of buffer in cache.
7031 (puthash tagfile (buffer-string) anything-c-etags-cache)
7032 ;; Store or set the last modification of tag file.
7033 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7034 ;; If an entry exists modify it.
7035 (setcdr it (anything-c-etags-mtime tagfile))
7036 ;; No entry create a new one.
7037 (add-to-list 'anything-c-etags-mtime-alist
7038 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7040 (defvar anything-c-source-etags-select
7041 '((name . "Etags")
7042 (header-name . anything-c-source-etags-header-name)
7043 (init . anything-c-etags-init)
7044 (candidates-in-buffer)
7045 (search . (anything-c-etags-search-fn))
7046 (mode-line . anything-etags-mode-line-string)
7047 (action . anything-c-etags-default-action)
7048 (persistent-action . (lambda (candidate)
7049 (anything-c-etags-default-action candidate)
7050 (anything-match-line-color-current-line))))
7051 "Anything source for Etags.")
7053 (defun anything-c-etags-search-fn (pattern)
7054 "Search function for `anything-c-source-etags-select'."
7055 (re-search-forward
7056 (if anything-c-etags-use-regexp-search
7057 (format anything-c-etags-search-regexp pattern)
7058 pattern)
7059 nil t))
7061 (defun anything-c-etags-default-action (candidate)
7062 "Anything default action to jump to an etags entry."
7063 (let* ((split (split-string candidate ": "))
7064 (fname (expand-file-name
7065 (car split) anything-c-etags-tag-file-dir))
7066 (elm (cadr split)))
7067 (find-file fname)
7068 (goto-char (point-min))
7069 (search-forward elm nil t)
7070 (goto-char (match-beginning 0))))
7072 (defun anything-c-etags-mtime (file)
7073 "Last modification time of etags tag FILE."
7074 (cadr (nth 5 (file-attributes file))))
7076 (defun anything-c-etags-file-modified-p (file)
7077 "Check if tag FILE have been modified in this session.
7078 If FILE is nil return nil."
7079 (let ((last-modif (and file
7080 (assoc-default file anything-c-etags-mtime-alist))))
7081 (and last-modif
7082 (/= last-modif (anything-c-etags-mtime file)))))
7086 ;;; Semantic
7089 (defvar anything-semantic-candidates nil)
7091 (defun anything-semantic-construct-candidates (tags depth)
7092 (when (require 'semantic nil t)
7093 (apply
7094 'append
7095 (mapcar
7096 (lambda (tag)
7097 (if (listp tag)
7098 (let ((type (semantic-tag-type tag))
7099 (class (semantic-tag-class tag)))
7100 (if (or (and (stringp type)
7101 (or (string= type "class")
7102 (string= type "namespace")))
7103 (eq class 'function)
7104 (eq class 'variable))
7105 (cons (cons (concat (make-string (* depth 2) ?\s)
7106 (semantic-format-tag-summarize tag nil t))
7107 tag)
7108 (anything-semantic-construct-candidates
7109 (semantic-tag-components tag) (1+ depth)))))))
7110 tags))))
7112 (defun anything-semantic-default-action (candidate)
7113 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7114 (semantic-go-to-tag tag)))
7116 (defvar anything-c-source-semantic
7117 '((name . "Semantic Tags")
7118 (init . (lambda ()
7119 (setq anything-semantic-candidates
7120 (ignore-errors (anything-semantic-construct-candidates
7121 (semantic-fetch-tags) 0)))))
7122 (candidates . (lambda ()
7123 (if anything-semantic-candidates
7124 (mapcar 'car anything-semantic-candidates))))
7125 (persistent-action . (lambda (elm)
7126 (anything-semantic-default-action elm)
7127 (anything-match-line-color-current-line)))
7128 (persistent-help . "Show this entry")
7129 (action . anything-semantic-default-action)
7130 "Needs semantic in CEDET.
7132 http://cedet.sourceforge.net/semantic.shtml
7133 http://cedet.sourceforge.net/"))
7135 ;; (anything 'anything-c-source-semantic)
7138 ;;; Anything interface of `simple-call-tree.el'.
7140 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7142 ;; Function is called by
7143 (defvar anything-c-source-simple-call-tree-functions-callers
7144 '((name . "Function is called by")
7145 (init . anything-c-simple-call-tree-functions-callers-init)
7146 (multiline)
7147 (candidates . anything-c-simple-call-tree-candidates)
7148 (persistent-action . anything-c-simple-call-tree-persistent-action)
7149 (persistent-help . "Show function definitions by rotation")
7150 (action ("Find definition selected by persistent-action" .
7151 anything-c-simple-call-tree-find-definition)))
7152 "Needs simple-call-tree.el.
7153 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7155 (defvar anything-c-simple-call-tree-tick nil)
7156 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7157 (defun anything-c-simple-call-tree-analyze-maybe ()
7158 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7159 (simple-call-tree-analyze)
7160 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7162 (defun anything-c-simple-call-tree-init-base (function message)
7163 (require 'simple-call-tree)
7164 (with-no-warnings
7165 (when (anything-current-buffer-is-modified)
7166 (anything-c-simple-call-tree-analyze-maybe)
7167 (let ((list (funcall function simple-call-tree-alist)))
7168 (with-current-buffer (anything-candidate-buffer 'local)
7169 (dolist (entry list)
7170 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7171 (insert (car entry) message
7172 (if (string= funcs " ")
7173 " no functions."
7174 funcs)
7175 "\n\n"))))))))
7177 (defun anything-c-simple-call-tree-functions-callers-init ()
7178 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7179 " is called by\n"))
7181 (defun anything-c-simple-call-tree-candidates ()
7182 (with-current-buffer (anything-candidate-buffer)
7183 (split-string (buffer-string) "\n\n")))
7185 (defvar anything-c-simple-call-tree-related-functions nil)
7186 (defvar anything-c-simple-call-tree-function-index 0)
7187 (defun anything-c-simple-call-tree-persistent-action (candidate)
7188 (unless (eq last-command 'anything-execute-persistent-action)
7189 (setq anything-c-simple-call-tree-related-functions
7190 (delete "no functions."
7191 (split-string
7192 (replace-regexp-in-string " \\| is called by\\| calls "
7193 "" candidate)
7194 "\n")))
7195 (setq anything-c-simple-call-tree-function-index -1))
7196 (incf anything-c-simple-call-tree-function-index)
7197 (anything-c-simple-call-tree-find-definition candidate))
7199 (defun anything-c-simple-call-tree-find-definition (candidate)
7200 (find-function
7201 (intern
7202 (nth (mod anything-c-simple-call-tree-function-index
7203 (length anything-c-simple-call-tree-related-functions))
7204 anything-c-simple-call-tree-related-functions))))
7206 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7208 ;;; Function calls
7209 (defvar anything-c-source-simple-call-tree-callers-functions
7210 '((name . "Function calls")
7211 (init . anything-c-simple-call-tree-callers-functions-init)
7212 (multiline)
7213 (candidates . anything-c-simple-call-tree-candidates)
7214 (persistent-action . anything-c-simple-call-tree-persistent-action)
7215 (persistent-help . "Show function definitions by rotation")
7216 (action ("Find definition selected by persistent-action" .
7217 anything-c-simple-call-tree-find-definition)))
7218 "Needs simple-call-tree.el.
7219 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7221 (defun anything-c-simple-call-tree-callers-functions-init ()
7222 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7224 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7228 ;;; Anything UI of auto-document.el
7230 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7232 ;; Commands/Options with doc
7233 (defvar anything-c-auto-document-data nil)
7234 (make-variable-buffer-local 'anything-c-auto-document-data)
7235 (defvar anything-c-source-commands-and-options-in-file
7236 '((name . "Commands/Options in file")
7237 (header-name
7238 . (lambda (x) (format "Commands/Options in %s"
7239 (buffer-local-value 'buffer-file-name
7240 anything-current-buffer))))
7241 (candidates . anything-command-and-options-candidates)
7242 (multiline)
7243 (action . imenu))
7244 "List Commands and Options with doc. It needs auto-document.el .
7246 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7248 (eval-when-compile (require 'auto-document nil t))
7249 (defun anything-command-and-options-candidates ()
7250 (with-anything-current-buffer
7251 (when (and (require 'auto-document nil t)
7252 (eq major-mode 'emacs-lisp-mode)
7253 (or (anything-current-buffer-is-modified)
7254 (not anything-c-auto-document-data)))
7255 (or imenu--index-alist (imenu--make-index-alist t))
7256 (setq anything-c-auto-document-data
7257 (destructuring-bind (commands options)
7258 (adoc-construct anything-current-buffer)
7259 (append
7260 (loop for (command . doc) in commands
7261 for cmdname = (symbol-name command)
7262 collect
7263 (cons
7264 (format "Command: %s\n %s"
7265 (propertize cmdname 'face font-lock-function-name-face)
7266 (adoc-first-line doc))
7267 (assoc cmdname imenu--index-alist)))
7268 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7269 for (option doc default) in options
7270 for optname = (symbol-name option)
7271 collect
7272 (cons
7273 (format "Option: %s\n %s\n default = %s"
7274 (propertize optname 'face font-lock-variable-name-face)
7275 (adoc-first-line doc)
7276 (adoc-prin1-to-string default))
7277 (assoc optname
7278 var-alist)))))))
7279 anything-c-auto-document-data))
7281 ;; (anything 'anything-c-source-commands-and-options-in-file)
7284 ;;;; <Color and Face>
7287 ;;; Customize Face
7290 (defvar anything-c-source-customize-face
7291 '((name . "Customize Face")
7292 (init . (lambda ()
7293 (unless (anything-candidate-buffer)
7294 (save-selected-window
7295 (list-faces-display))
7296 (anything-candidate-buffer (get-buffer "*Faces*")))))
7297 (candidates-in-buffer)
7298 (get-line . buffer-substring)
7299 (action . (lambda (line)
7300 (customize-face (intern (car (split-string line))))))
7301 (requires-pattern . 3))
7302 "See (info \"(emacs)Faces\")")
7303 ;; (anything 'anything-c-source-customize-face)
7305 ;;; Colors browser
7308 (defvar anything-c-source-colors
7309 '((name . "Colors")
7310 (init . (lambda () (unless (anything-candidate-buffer)
7311 (save-selected-window
7312 (list-colors-display))
7313 (anything-candidate-buffer (get-buffer "*Colors*")))))
7314 (candidates-in-buffer)
7315 (get-line . buffer-substring)
7316 (action
7317 ("Copy Name" . (lambda (candidate)
7318 (kill-new (anything-c-colors-get-name candidate))))
7319 ("Copy RGB" . (lambda (candidate)
7320 (kill-new (anything-c-colors-get-rgb candidate))))
7321 ("Insert Name" . (lambda (candidate)
7322 (with-anything-current-buffer
7323 (insert (anything-c-colors-get-name candidate)))))
7324 ("Insert RGB" . (lambda (candidate)
7325 (with-anything-current-buffer
7326 (insert (anything-c-colors-get-rgb candidate))))))))
7327 ;; (anything 'anything-c-source-colors)
7329 (defun anything-c-colors-get-name (candidate)
7330 "Get color name."
7331 (replace-regexp-in-string
7332 " " ""
7333 (with-temp-buffer
7334 (insert (capitalize candidate))
7335 (goto-char (point-min))
7336 (search-forward-regexp "\\s-\\{2,\\}")
7337 (delete-region (point) (point-max))
7338 (buffer-string))))
7340 (defun anything-c-colors-get-rgb (candidate)
7341 "Get color RGB."
7342 (replace-regexp-in-string
7343 " " ""
7344 (with-temp-buffer
7345 (insert (capitalize candidate))
7346 (goto-char (point-max))
7347 (search-backward-regexp "\\s-\\{2,\\}")
7348 (delete-region (point) (point-min))
7349 (buffer-string))))
7352 ;;;; <Search Engine>
7353 ;;; Tracker desktop search
7354 (defvar anything-c-source-tracker-search
7355 '((name . "Tracker Search")
7356 (candidates . (lambda ()
7357 (start-process "tracker-search-process" nil
7358 "tracker-search"
7359 anything-pattern)))
7360 (type . file)
7361 (requires-pattern . 3)
7362 (delayed))
7363 "Source for retrieving files matching the current input pattern
7364 with the tracker desktop search.")
7365 ;; (anything 'anything-c-source-tracker-search)
7367 ;;; Spotlight (MacOS X desktop search)
7368 (defvar anything-c-source-mac-spotlight
7369 '((name . "mdfind")
7370 (candidates
7371 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7372 (type . file)
7373 (requires-pattern . 3)
7374 (delayed))
7375 "Source for retrieving files via Spotlight's command line
7376 utility mdfind.")
7377 ;; (anything 'anything-c-source-mac-spotlight)
7379 ;;; Picklist
7380 (defvar anything-c-source-picklist
7381 '((name . "Picklist")
7382 (candidates . (lambda () (mapcar 'car picklist-list)))
7383 (type . file)))
7384 ;; (anything 'anything-c-source-picklist)
7388 ;;; Kill ring
7391 (defvar anything-c-source-kill-ring
7392 '((name . "Kill Ring")
7393 (init . (lambda () (anything-attrset 'last-command last-command)))
7394 (candidates . anything-c-kill-ring-candidates)
7395 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7396 (action . anything-c-kill-ring-action)
7397 (last-command)
7398 (migemo)
7399 (multiline))
7400 "Source for browse and insert contents of kill-ring.")
7402 (defun anything-c-kill-ring-candidates ()
7403 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7404 unless (or (< (length kill) anything-kill-ring-threshold)
7405 (string-match "^[\\s\\t]+$" kill))
7406 collect kill))
7408 (defun anything-c-kill-ring-transformer (candidates source)
7409 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7410 (loop for i in candidates
7411 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7412 if (and anything-c-kill-ring-max-lines-number
7413 (> nlines anything-c-kill-ring-max-lines-number))
7414 collect (cons
7415 (with-temp-buffer
7416 (insert i)
7417 (goto-char (point-min))
7418 (concat
7419 (buffer-substring
7420 (point-min)
7421 (save-excursion
7422 (forward-line anything-c-kill-ring-max-lines-number)
7423 (point)))
7424 "[...]")) i)
7425 else collect i))
7427 (defun anything-c-kill-ring-action (str)
7428 "Insert STR in `kill-ring' and set STR to the head.
7429 If this action is executed just after `yank',
7430 replace with STR as yanked string."
7431 (setq kill-ring (delete str kill-ring))
7432 (if (not (eq (anything-attr 'last-command) 'yank))
7433 (insert-for-yank str)
7434 ;; from `yank-pop'
7435 (let ((inhibit-read-only t)
7436 (before (< (point) (mark t))))
7437 (if before
7438 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7439 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7440 (setq yank-undo-function nil)
7441 (set-marker (mark-marker) (point) (current-buffer))
7442 (insert-for-yank str)
7443 ;; Set the window start back where it was in the yank command,
7444 ;; if possible.
7445 (set-window-start (selected-window) yank-window-start t)
7446 (if before
7447 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7448 ;; It is cleaner to avoid activation, even though the command
7449 ;; loop would deactivate the mark because we inserted text.
7450 (goto-char (prog1 (mark t)
7451 (set-marker (mark-marker) (point) (current-buffer)))))))
7452 (kill-new str))
7454 ;; (anything 'anything-c-source-kill-ring)
7457 ;;;; <Mark ring>
7458 ;; DO NOT include these sources in `anything-sources' use
7459 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7460 ;; `anything-all-mark-rings' instead.
7462 (defun anything-c-source-mark-ring-candidates ()
7463 (flet ((get-marks (pos)
7464 (save-excursion
7465 (goto-char pos)
7466 (beginning-of-line)
7467 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7468 (when (string= "" line)
7469 (setq line "<EMPTY LINE>"))
7470 (format "%7d: %s" (line-number-at-pos) line)))))
7471 (with-anything-current-buffer
7472 (loop
7473 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7474 with recip = nil
7475 for i in marks
7476 for m = (get-marks i)
7477 unless (member m recip)
7478 collect m into recip
7479 finally return recip))))
7481 (defvar anything-mark-ring-cache nil)
7482 (defvar anything-c-source-mark-ring
7483 '((name . "mark-ring")
7484 (init . (lambda ()
7485 (setq anything-mark-ring-cache
7486 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7487 (candidates . (lambda ()
7488 (anything-aif anything-mark-ring-cache
7489 it)))
7490 (action . (("Goto line"
7491 . (lambda (candidate)
7492 (anything-goto-line (string-to-number candidate))))))
7493 (persistent-action . (lambda (candidate)
7494 (anything-goto-line (string-to-number candidate))
7495 (anything-match-line-color-current-line)))
7496 (persistent-help . "Show this line")))
7498 ;; (anything 'anything-c-source-mark-ring)
7500 ;;; Global-mark-ring
7501 (defvar anything-c-source-global-mark-ring
7502 '((name . "global-mark-ring")
7503 (candidates . anything-c-source-global-mark-ring-candidates)
7504 (action . (("Goto line"
7505 . (lambda (candidate)
7506 (let ((items (split-string candidate ":")))
7507 (anything-c-switch-to-buffer (second items))
7508 (anything-goto-line (string-to-number (car items))))))))
7509 (persistent-action . (lambda (candidate)
7510 (let ((items (split-string candidate ":")))
7511 (anything-c-switch-to-buffer (second items))
7512 (anything-goto-line (string-to-number (car items)))
7513 (anything-match-line-color-current-line))))
7514 (persistent-help . "Show this line")))
7516 (defun anything-c-source-global-mark-ring-candidates ()
7517 (flet ((buf-fn (m)
7518 (with-current-buffer (marker-buffer m)
7519 (goto-char m)
7520 (beginning-of-line)
7521 (let (line)
7522 (if (string= "" line)
7523 (setq line "<EMPTY LINE>")
7524 (setq line (car (split-string (thing-at-point 'line)
7525 "[\n\r]"))))
7526 (format "%7d:%s: %s"
7527 (line-number-at-pos) (marker-buffer m) line)))))
7528 (loop
7529 with marks = global-mark-ring
7530 with recip = nil
7531 for i in marks
7532 for gm = (unless (or (string-match
7533 "^ " (format "%s" (marker-buffer i)))
7534 (null (marker-buffer i)))
7535 (buf-fn i))
7536 when (and gm (not (member gm recip)))
7537 collect gm into recip
7538 finally return recip)))
7540 ;; (anything 'anything-c-source-global-mark-ring)
7543 ;;;; <Register>
7544 ;;; Insert from register
7545 (defvar anything-c-source-register
7546 '((name . "Registers")
7547 (candidates . anything-c-register-candidates)
7548 (action-transformer . anything-c-register-action-transformer)
7549 (multiline)
7550 (action))
7551 "See (info \"(emacs)Registers\")")
7553 (defun anything-c-register-candidates ()
7554 "Collecting register contents and appropriate commands."
7555 (loop for (char . val) in register-alist
7556 for key = (single-key-description char)
7557 for string-actions =
7558 (cond
7559 ((numberp val)
7560 (list (int-to-string val)
7561 'insert-register
7562 'increment-register))
7563 ((markerp val)
7564 (let ((buf (marker-buffer val)))
7565 (if (null buf)
7566 (list "a marker in no buffer")
7567 (list (concat
7568 "a buffer position:"
7569 (buffer-name buf)
7570 ", position "
7571 (int-to-string (marker-position val)))
7572 'jump-to-register
7573 'insert-register))))
7574 ((and (consp val) (window-configuration-p (car val)))
7575 (list "window configuration."
7576 'jump-to-register))
7577 ((and (consp val) (frame-configuration-p (car val)))
7578 (list "frame configuration."
7579 'jump-to-register))
7580 ((and (consp val) (eq (car val) 'file))
7581 (list (concat "file:"
7582 (prin1-to-string (cdr val))
7583 ".")
7584 'jump-to-register))
7585 ((and (consp val) (eq (car val) 'file-query))
7586 (list (concat "file:a file-query reference: file "
7587 (car (cdr val))
7588 ", position "
7589 (int-to-string (car (cdr (cdr val))))
7590 ".")
7591 'jump-to-register))
7592 ((consp val)
7593 (let ((lines (format "%4d" (length val))))
7594 (list (format "%s: %s\n" lines
7595 (truncate-string-to-width
7596 (mapconcat 'identity (list (car val))
7597 ;; (mapconcat (lambda (y) y) val
7598 "^J") (- (window-width) 15)))
7599 'insert-register)))
7600 ((stringp val)
7601 (list ;; without properties
7602 (substring-no-properties val)
7603 'insert-register
7604 'append-to-register
7605 'prepend-to-register))
7607 "GARBAGE!"))
7608 collect (cons (format "register %3s: %s" key (car string-actions))
7609 (cons char (cdr string-actions)))))
7611 (defun anything-c-register-action-transformer (actions register-and-functions)
7612 "Decide actions by the contents of register."
7613 (loop with func-actions =
7614 '((insert-register
7615 "Insert Register" .
7616 (lambda (c) (insert-register (car c))))
7617 (jump-to-register
7618 "Jump to Register" .
7619 (lambda (c) (jump-to-register (car c))))
7620 (append-to-register
7621 "Append Region to Register" .
7622 (lambda (c) (append-to-register
7623 (car c) (region-beginning) (region-end))))
7624 (prepend-to-register
7625 "Prepend Region to Register" .
7626 (lambda (c) (prepend-to-register
7627 (car c) (region-beginning) (region-end))))
7628 (increment-register
7629 "Increment Prefix Arg to Register" .
7630 (lambda (c) (increment-register
7631 anything-current-prefix-arg (car c)))))
7632 for func in (cdr register-and-functions)
7633 for cell = (assq func func-actions)
7634 when cell
7635 collect (cdr cell)))
7637 ;; (anything 'anything-c-source-register)
7640 ;;; Latex completion
7641 (defun anything-c-latex-math-candidates ()
7642 "Collect candidates for latex math completion."
7643 (declare (special LaTeX-math-menu))
7644 (loop for i in (cddr LaTeX-math-menu)
7645 for elm = (loop for s in i when (vectorp s)
7646 collect (cons (aref s 0) (aref s 1)))
7647 append elm))
7649 (defvar anything-c-source-latex-math
7650 '((name . "Latex Math Menu")
7651 (init . (lambda ()
7652 (with-anything-current-buffer
7653 (LaTeX-math-mode 1))))
7654 (candidate-number-limit . 9999)
7655 (candidates . anything-c-latex-math-candidates)
7656 (action . (lambda (candidate)
7657 (call-interactively candidate)))))
7660 ;;;; <Headline Extraction>
7661 (defvar anything-c-source-fixme
7662 '((name . "TODO/FIXME/DRY comments")
7663 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7664 (adjust)
7665 (recenter))
7666 "Show TODO/FIXME/DRY comments in current file.")
7667 ;; (anything 'anything-c-source-fixme)
7669 (defvar anything-c-source-rd-headline
7670 '((name . "RD HeadLine")
7671 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7672 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7673 (migemo)
7674 (subexp . 1))
7675 "Show RD headlines.
7677 RD is Ruby's POD.
7678 http://en.wikipedia.org/wiki/Ruby_Document_format")
7679 ;; (anything 'anything-c-source-rd-headline)
7681 (defvar anything-c-source-oddmuse-headline
7682 '((name . "Oddmuse HeadLine")
7683 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7684 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7685 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7686 (migemo)
7687 (subexp . 1))
7688 "Show Oddmuse headlines, such as EmacsWiki.")
7689 ;; (anything 'anything-c-source-oddmuse-headline)
7691 (defvar anything-c-source-emacs-source-defun
7692 '((name . "Emacs Source DEFUN")
7693 (headline . "DEFUN\\|DEFVAR")
7694 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7695 (or buffer-file-name ""))))
7696 "Show DEFUN/DEFVAR in Emacs C source file.")
7697 ;; (anything 'anything-c-source-emacs-source-defun)
7699 (defvar anything-c-source-emacs-lisp-expectations
7700 '((name . "Emacs Lisp Expectations")
7701 (headline . "(desc[ ]\\|(expectations")
7702 (condition . (eq major-mode 'emacs-lisp-mode)))
7703 "Show descriptions (desc) in Emacs Lisp Expectations.
7705 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7706 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7708 (defvar anything-c-source-emacs-lisp-toplevels
7709 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7710 (headline . "^(\\|(@\\*\\|^;;;;")
7711 (get-line . buffer-substring)
7712 (condition . (eq major-mode 'emacs-lisp-mode))
7713 (adjust))
7714 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7715 linkd.el is optional because linkd stars are extracted by regexp.
7716 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7717 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7720 ;;; Anything yaoddmuse
7722 ;; Be sure to have yaoddmuse.el installed
7723 ;; install-elisp may be required if you want to install elisp file from here.
7724 (defvar anything-yaoddmuse-use-cache-file nil)
7725 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7726 (defvar anything-c-yaoddmuse-ew-cache nil)
7728 (defun anything-yaoddmuse-get-candidates ()
7729 (declare (special yaoddmuse-pages-hash))
7730 (if anything-yaoddmuse-use-cache-file
7731 (ignore-errors
7732 (unless anything-c-yaoddmuse-ew-cache
7733 (load anything-c-yaoddmuse-cache-file)
7734 (setq anything-c-yaoddmuse-ew-cache
7735 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7736 anything-c-yaoddmuse-ew-cache)
7737 (yaoddmuse-update-pagename t)
7738 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7740 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7741 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7742 (candidates . anything-yaoddmuse-get-candidates)
7743 (action . (("Edit page" . (lambda (candidate)
7744 (yaoddmuse-edit "EmacsWiki" candidate)))
7745 ("Browse page"
7746 . (lambda (candidate)
7747 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7748 ("Browse page other window"
7749 . (lambda (candidate)
7750 (if (one-window-p)
7751 (split-window-vertically))
7752 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7753 ("Browse diff"
7754 . (lambda (candidate)
7755 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7756 ("Copy URL"
7757 . (lambda (candidate)
7758 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7759 (message "Have copy page %s's URL to yank." candidate)))
7760 ("Create page"
7761 . (lambda (candidate)
7762 (yaoddmuse-edit "EmacsWiki" anything-input)))
7763 ("Update cache"
7764 . (lambda (candidate)
7765 (if anything-yaoddmuse-use-cache-file
7766 (progn
7767 (anything-yaoddmuse-cache-pages t)
7768 (setq anything-c-yaoddmuse-ew-cache
7769 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7770 (yaoddmuse-update-pagename))))))
7771 (action-transformer anything-c-yaoddmuse-action-transformer))
7772 "Needs yaoddmuse.el.
7774 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7776 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7778 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7779 '((name . "Yaoddmuse Post library (EmacsWiki)")
7780 (init . (anything-yaoddmuse-init))
7781 (candidates-in-buffer)
7782 (action . (("Post library and Browse"
7783 . (lambda (candidate)
7784 (yaoddmuse-post-file
7785 (find-library-name candidate)
7786 "EmacsWiki"
7787 (file-name-nondirectory (find-library-name candidate))
7788 nil t)))
7789 ("Post library"
7790 . (lambda (candidate)
7791 (yaoddmuse-post-file
7792 (find-library-name candidate)
7793 "EmacsWiki"
7794 (file-name-nondirectory
7795 (find-library-name candidate))))))))
7796 "Needs yaoddmuse.el.
7798 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7800 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7802 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7803 "Allow the use of `install-elisp' only on elisp files."
7804 (if (string-match "\.el$" candidate)
7805 (append actions '(("Install Elisp"
7806 . (lambda (elm)
7807 (install-elisp-from-emacswiki elm)))))
7808 actions))
7810 ;;;###autoload
7811 (defun anything-yaoddmuse-cache-pages (&optional load)
7812 "Fetch the list of files on emacswiki and create cache file.
7813 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7814 (interactive)
7815 (declare (special yaoddmuse-pages-hash))
7816 (yaoddmuse-update-pagename)
7817 (save-excursion
7818 (find-file anything-c-yaoddmuse-cache-file)
7819 (erase-buffer)
7820 (insert "(puthash \"EmacsWiki\" '(")
7821 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7823 (insert (concat "(\"" (car i) "\") ")))
7824 (insert ") yaoddmuse-pages-hash)\n")
7825 (save-buffer)
7826 (kill-buffer (current-buffer))
7827 (when (or current-prefix-arg
7828 load)
7829 (load anything-c-yaoddmuse-cache-file))))
7831 (defun anything-yaoddmuse-init ()
7832 "Init anything buffer status."
7833 (let ((anything-buffer (anything-candidate-buffer 'global))
7834 (library-list (yaoddmuse-get-library-list)))
7835 (with-current-buffer anything-buffer
7836 ;; Insert library name.
7837 (dolist (library library-list)
7838 (insert (format "%s\n" library)))
7839 ;; Sort lines.
7840 (sort-lines nil (point-min) (point-max)))))
7843 ;;; Eev anchors
7844 (defvar anything-c-source-eev-anchor
7845 '((name . "Anchors")
7846 (candidates
7847 . (lambda ()
7848 (ignore-errors
7849 (with-anything-current-buffer
7850 (loop initially (goto-char (point-min))
7851 while (re-search-forward
7852 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7853 for anchor = (match-string-no-properties 1)
7854 collect (cons (format "%5d:%s"
7855 (line-number-at-pos (match-beginning 0))
7856 (format ee-anchor-format anchor))
7857 anchor))))))
7858 (persistent-action . (lambda (item)
7859 (ee-to item)
7860 (anything-match-line-color-current-line)))
7861 (persistent-help . "Show this entry")
7862 (action . (("Goto link" . ee-to)))))
7863 ;; (anything 'anything-c-source-eev-anchor)
7866 ;;; Org headlines
7869 (defvar anything-c-source-org-headline
7870 `((name . "Org HeadLine")
7871 (headline
7872 ,@(mapcar
7873 (lambda (num)
7874 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7875 num))
7876 (number-sequence 1 8)))
7877 (condition . (eq major-mode 'org-mode))
7878 (migemo)
7879 (subexp . 1)
7880 (persistent-action . (lambda (elm)
7881 (anything-c-action-line-goto elm)
7882 (org-cycle)))
7883 (action-transformer
7884 . (lambda (actions candidate)
7885 '(("Go to Line" . anything-c-action-line-goto)
7886 ("Refile to this Headline" . anything-c-org-headline-refile)
7887 ("Insert Link to This Headline"
7888 . anything-c-org-headline-insert-link-to-headline)))))
7889 "Show Org headlines.
7890 org-mode is very very much extended text-mode/outline-mode.
7892 See (find-library \"org.el\")
7893 See http://orgmode.org for the latest version.")
7894 ;; (anything 'anything-c-source-org-headline)
7896 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7897 (insert
7898 (save-excursion
7899 (anything-goto-line (car lineno-and-content))
7900 (and (looking-at org-complex-heading-regexp)
7901 (org-make-link-string (concat "*" (match-string 4)))))))
7903 (defun anything-c-org-headline-refile (lineno-and-content)
7904 "Refile current org entry to LINENO-AND-CONTENT."
7905 (with-anything-current-buffer
7906 (org-cut-subtree)
7907 (anything-goto-line (car lineno-and-content))
7908 (org-end-of-subtree t t)
7909 (let ((org-yank-adjusted-subtrees t))
7910 (org-yank))))
7913 ;;; Org keywords
7916 (defvar anything-c-source-org-keywords
7917 '((name . "Org Keywords")
7918 (init . anything-c-org-keywords-init)
7919 (candidates . anything-c-org-keywords-candidates)
7920 (action . anything-c-org-keywords-insert)
7921 (persistent-action . anything-c-org-keywords-show-help)
7922 (persistent-help . "Show an example and info page to describe this keyword.")
7923 (keywords-examples)
7924 (keywords)))
7925 ;; (anything 'anything-c-source-org-keywords)
7927 (defvar anything-c-org-keywords-info-location
7928 '(("#+TITLE:" . "(org)Export options")
7929 ("#+AUTHOR:" . "(org)Export options")
7930 ("#+DATE:" . "(org)Export options")
7931 ("#+EMAIL:" . "(org)Export options")
7932 ("#+DESCRIPTION:" . "(org)Export options")
7933 ("#+KEYWORDS:" . "(org)Export options")
7934 ("#+LANGUAGE:" . "(org)Export options")
7935 ("#+TEXT:" . "(org)Export options")
7936 ("#+TEXT:" . "(org)Export options")
7937 ("#+OPTIONS:" . "(org)Export options")
7938 ("#+BIND:" . "(org)Export options")
7939 ("#+LINK_UP:" . "(org)Export options")
7940 ("#+LINK_HOME:" . "(org)Export options")
7941 ("#+LATEX_HEADER:" . "(org)Export options")
7942 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7943 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7944 ("#+INFOJS_OPT" . "(org)Javascript support")
7945 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7946 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7947 ("#+ORGTBL" . "(org)Radio tables")
7948 ("#+HTML:" . "(org)Quoting HTML tags")
7949 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7950 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7951 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7952 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7953 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7954 ("#+BEGIN_SRC" . "(org)Literal examples")
7955 ("#+CAPTION" . "(org)Tables in HTML export")
7956 ("#+LABEL" . "(org)Tables in LaTeX export")
7957 ("#+ATTR_HTML" . "(org)Links")
7958 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7960 (defun anything-c-org-keywords-init ()
7961 (unless (anything-attr 'keywords-examples)
7962 (require 'org)
7963 (anything-attrset 'keywords-examples
7964 (append
7965 (mapcar
7966 (lambda (x)
7967 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7968 (cons (match-string 2 x) (match-string 1 x)))
7969 (org-split-string (org-get-current-options) "\n"))
7970 (mapcar 'list org-additional-option-like-keywords)))
7971 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7973 (defun anything-c-org-keywords-candidates ()
7974 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7975 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7976 (anything-attr 'keywords)))
7978 (defun anything-c-org-keywords-insert (keyword)
7979 (cond ((and (string-match "BEGIN" keyword)
7980 (anything-region-active-p))
7981 (let ((beg (region-beginning))
7982 (end (region-end)))
7983 (goto-char end)
7984 (insert "\n#+" (replace-regexp-in-string
7985 "BEGIN" "END" keyword) "\n")
7986 (goto-char beg)
7987 (insert "#+" keyword " ")
7988 (save-excursion (insert "\n"))))
7989 ((string-match "BEGIN" keyword)
7990 (insert "#+" keyword " ")
7991 (save-excursion
7992 (insert "\n#+" (replace-regexp-in-string
7993 "BEGIN" "END" keyword) "\n")))
7994 (t (insert "#+" keyword " "))))
7996 (defun anything-c-org-keywords-show-help (keyword)
7997 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7998 "(org)In-buffer settings"))
7999 (search-forward (concat "#+" keyword) nil t)
8000 (anything-persistent-highlight-point)
8001 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8005 ;;; bbdb
8008 (defvar bbdb-records)
8009 (defvar bbdb-buffer-name)
8011 (defun anything-c-bbdb-candidates ()
8012 "Return a list of all names in the bbdb database. The format
8013 is \"Firstname Lastname\"."
8014 (mapcar (lambda (bbdb-record)
8015 (replace-regexp-in-string
8016 "\\s-+$" ""
8017 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8018 (bbdb-records)))
8020 (defun anything-c-bbdb-create-contact (actions candidate)
8021 "Action transformer that returns only an entry to add the
8022 current `anything-pattern' as new contact. All other actions are
8023 removed."
8024 (if (string= candidate "*Add to contacts*")
8025 '(("Add to contacts" . (lambda (actions)
8026 (bbdb-create-internal
8027 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8028 (read-from-minibuffer "Company: ")
8029 (read-from-minibuffer "Email: ")
8032 (read-from-minibuffer "Note: ")))))
8033 actions))
8035 (defun anything-c-bbdb-get-record (candidate)
8036 "Return record that match CANDIDATE."
8037 (bbdb candidate nil)
8038 (set-buffer "*BBDB*")
8039 (bbdb-current-record))
8041 (defvar anything-c-bbdb-name nil
8042 "Only for internal use.")
8044 (defvar anything-c-source-bbdb
8045 '((name . "BBDB")
8046 (candidates . anything-c-bbdb-candidates)
8047 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8048 ("View person's data" . anything-c-bbdb-view-person-action))
8049 (filtered-candidate-transformer . (lambda (candidates source)
8050 (setq anything-c-bbdb-name anything-pattern)
8051 (if (not candidates)
8052 (list "*Add to contacts*")
8053 candidates)))
8054 (action-transformer . (lambda (actions candidate)
8055 (anything-c-bbdb-create-contact actions candidate))))
8056 "Needs BBDB.
8058 http://bbdb.sourceforge.net/")
8059 ;; (anything 'anything-c-source-bbdb)
8061 (defun anything-c-bbdb-view-person-action (candidate)
8062 "View BBDB data of single CANDIDATE or marked candidates."
8063 (anything-aif (anything-marked-candidates)
8064 (let ((bbdb-append-records (length it)))
8065 (dolist (i it)
8066 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8067 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8069 (defun anything-c-bbdb-collect-mail-addresses ()
8070 "Return a list of all mail addresses of records in bbdb buffer."
8071 (with-current-buffer bbdb-buffer-name
8072 (loop for i in bbdb-records
8073 if (bbdb-record-net (car i))
8074 collect (bbdb-dwim-net-address (car i)))))
8076 (defun anything-c-bbdb-compose-mail (candidate)
8077 "Compose a mail with all records of bbdb buffer."
8078 (anything-c-bbdb-view-person-action candidate)
8079 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8080 (address-str (mapconcat 'identity address-list ",\n ")))
8081 (compose-mail address-str)))
8084 ;;; Evaluation Result
8087 ;; Internal
8088 (defvar anything-eldoc-active-minibuffers-list nil)
8089 (defvar anything-eval-expression-input-history nil)
8091 (defvar anything-c-source-evaluation-result
8092 '((name . "Evaluation Result")
8093 (disable-shortcuts)
8094 (dummy)
8095 (multiline)
8096 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8097 (filtered-candidate-transformer . (lambda (candidates source)
8098 (list
8099 (condition-case nil
8100 (with-anything-current-buffer
8101 (pp-to-string
8102 (eval (read anything-pattern))))
8103 (error "Error")))))
8104 (action . (("Copy result to kill-ring" . (lambda (candidate)
8105 (with-current-buffer anything-buffer
8106 (let ((end (save-excursion
8107 (goto-char (point-max))
8108 (search-backward "\n")
8109 (point))))
8110 (kill-region (point) end)))))
8111 ("copy sexp to kill-ring" . (lambda (candidate)
8112 (kill-new anything-input)))))))
8113 ;; (anything 'anything-c-source-evaluation-result)
8115 (defun anything-eval-new-line-and-indent ()
8116 (interactive)
8117 (newline) (lisp-indent-line))
8119 (defun anything-eldoc-store-minibuffer ()
8120 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8121 (with-selected-window (minibuffer-window)
8122 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8124 (defun anything-eldoc-show-in-eval ()
8125 "Return eldoc in mode-line for current minibuffer input."
8126 (let ((buf (with-selected-window (minibuffer-window)
8127 (buffer-name))))
8128 (when (member buf anything-eldoc-active-minibuffers-list)
8129 (let* ((str-all (with-current-buffer buf
8130 (minibuffer-completion-contents)))
8131 (sym (when str-all
8132 (with-temp-buffer
8133 (insert str-all)
8134 (goto-char (point-max))
8135 (unless (looking-back ")\\|\"") (forward-char -1))
8136 (eldoc-current-symbol))))
8137 (info-fn (eldoc-fnsym-in-current-sexp))
8138 (doc (or (eldoc-get-var-docstring sym)
8139 (eldoc-get-fnsym-args-string
8140 (car info-fn) (cadr info-fn)))))
8141 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8143 (defun anything-c-show-info-in-mode-line (str)
8144 "Display string STR in mode-line."
8145 (save-selected-window
8146 (with-current-buffer anything-buffer
8147 (let ((mode-line-format (concat " " str)))
8148 (force-mode-line-update)
8149 (sit-for anything-c-show-info-in-mode-line-delay))
8150 (force-mode-line-update))))
8152 ;;; Calculation Result
8155 (defvar anything-c-source-calculation-result
8156 '((name . "Calculation Result")
8157 (dummy)
8158 (filtered-candidate-transformer . (lambda (candidates source)
8159 (list
8160 (condition-case nil
8161 (calc-eval anything-pattern)
8162 (error "error")))))
8163 (action ("Copy result to kill-ring" . kill-new))))
8164 ;; (anything 'anything-c-source-calculation-result)
8167 ;;; Google Suggestions
8170 ;; Internal
8171 (defvar anything-ggs-max-length-real-flag 0)
8172 (defvar anything-ggs-max-length-num-flag 0)
8174 (defun anything-c-google-suggest-fetch (input)
8175 "Fetch suggestions for INPUT from XML buffer.
8176 Return an alist with elements like (data . number_results)."
8177 (setq anything-ggs-max-length-real-flag 0
8178 anything-ggs-max-length-num-flag 0)
8179 (let ((request (concat anything-c-google-suggest-url
8180 (url-hexify-string input))))
8181 (flet ((fetch ()
8182 (loop
8183 with result-alist = (xml-get-children
8184 (car (xml-parse-region
8185 (point-min) (point-max)))
8186 'CompleteSuggestion)
8187 for i in result-alist
8188 for data = (cdr (caadr (assoc 'suggestion i)))
8189 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8190 for lqueries = (length (anything-c-ggs-set-number-result
8191 nqueries))
8192 for ldata = (length data)
8194 (progn
8195 (when (> ldata anything-ggs-max-length-real-flag)
8196 (setq anything-ggs-max-length-real-flag ldata))
8197 (when (> lqueries anything-ggs-max-length-num-flag)
8198 (setq anything-ggs-max-length-num-flag lqueries)))
8199 collect (cons data nqueries) into cont
8200 finally return cont)))
8201 (if anything-google-suggest-use-curl-p
8202 (with-temp-buffer
8203 (call-process "curl" nil t nil request)
8204 (fetch))
8205 (with-current-buffer
8206 (url-retrieve-synchronously request)
8207 (fetch))))))
8209 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8210 "Set candidates with result and number of google results found."
8211 (let ((suggestions
8212 (loop with suggested-results = (anything-c-google-suggest-fetch
8213 (or (and request-prefix
8214 (concat request-prefix " " anything-pattern))
8215 anything-pattern))
8216 for (real . numresult) in suggested-results
8217 ;; Prepare number of results with ","
8218 for fnumresult = (anything-c-ggs-set-number-result numresult)
8219 ;; Calculate number of spaces to add before fnumresult
8220 ;; if it is smaller than longest result
8221 ;; `anything-ggs-max-length-num-flag'.
8222 ;; e.g 1,234,567
8223 ;; 345,678
8224 ;; To be sure it is aligned properly.
8225 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8226 (- anything-ggs-max-length-num-flag (length fnumresult))
8228 ;; Add now the spaces before fnumresult.
8229 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8230 for interval = (- anything-ggs-max-length-real-flag (length real))
8231 for spaces = (make-string (+ 2 interval) ? )
8232 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8233 collect (cons display real))))
8234 (if (loop for (disp . dat) in suggestions
8235 thereis (equal dat anything-pattern))
8236 suggestions
8237 ;; if there is no suggestion exactly matching the input then
8238 ;; prepend a Search on Google item to the list
8239 (append
8240 suggestions
8241 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8242 anything-input))))))
8244 (defun anything-c-ggs-set-number-result (num)
8245 (if num
8246 (progn
8247 (and (numberp num) (setq num (number-to-string num)))
8248 (loop for i in (reverse (split-string num "" t))
8249 for count from 1
8250 append (list i) into C
8251 when (= count 3)
8252 append (list ",") into C
8253 and do (setq count 0)
8254 finally return
8255 (replace-regexp-in-string
8256 "^," "" (mapconcat 'identity (reverse C) ""))))
8257 "?"))
8259 (defvar anything-c-google-suggest-default-browser-function nil
8260 "*The browse url function you prefer to use with google suggest.
8261 When nil, use the first browser function available
8262 See `anything-browse-url-default-browser-alist'.")
8264 (defun anything-c-google-suggest-action (candidate)
8265 "Default action to jump to a google suggested candidate."
8266 (let ((arg (concat anything-c-google-suggest-search-url
8267 (url-hexify-string candidate))))
8268 (anything-aif anything-c-google-suggest-default-browser-function
8269 (funcall it arg)
8270 (anything-c-browse-url arg))))
8272 (defvar anything-c-google-suggest-default-function
8273 'anything-c-google-suggest-set-candidates
8274 "Default function to use in anything google suggest.")
8276 (defvar anything-c-source-google-suggest
8277 '((name . "Google Suggest")
8278 (candidates . (lambda ()
8279 (funcall anything-c-google-suggest-default-function)))
8280 (action . (("Google Search" . anything-c-google-suggest-action)))
8281 (volatile)
8282 (requires-pattern . 3)
8283 (delayed)))
8285 (defun anything-c-google-suggest-emacs-lisp ()
8286 "Try to emacs lisp complete with google suggestions."
8287 (anything-c-google-suggest-set-candidates "emacs lisp"))
8289 ;; (anything 'anything-c-source-google-suggest)
8291 ;;; Yahoo suggestions
8294 (defun anything-c-yahoo-suggest-fetch (input)
8295 "Fetch Yahoo suggestions for INPUT from XML buffer.
8296 Return an alist with elements like (data . number_results)."
8297 (let ((request (concat anything-c-yahoo-suggest-url
8298 (url-hexify-string input))))
8299 (flet ((fetch ()
8300 (loop
8301 with result-alist = (xml-get-children
8302 (car (xml-parse-region (point-min) (point-max)))
8303 'Result)
8304 for i in result-alist
8305 collect (caddr i))))
8306 (with-current-buffer
8307 (url-retrieve-synchronously request)
8308 (fetch)))))
8310 (defun anything-c-yahoo-suggest-set-candidates ()
8311 "Set candidates with Yahoo results found."
8312 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8313 (or suggestions
8314 (append
8315 suggestions
8316 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8317 anything-input))))))
8319 (defun anything-c-yahoo-suggest-action (candidate)
8320 "Default action to jump to a Yahoo suggested candidate."
8321 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8322 (url-hexify-string candidate))))
8324 (defvar anything-c-source-yahoo-suggest
8325 '((name . "Yahoo Suggest")
8326 (candidates . anything-c-yahoo-suggest-set-candidates)
8327 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8328 (volatile)
8329 (requires-pattern . 3)
8330 (delayed)))
8332 ;; (anything 'anything-c-source-yahoo-suggest)
8335 ;;; Web browser functions.
8338 (require 'browse-url)
8339 ;; If default setting of `w3m-command' is not
8340 ;; what you want you and you modify it, you will have to reeval
8341 ;; also `anything-browse-url-default-browser-alist'.
8342 (defvar w3m-command "/usr/bin/w3m")
8343 (defvar anything-c-home-url "http://www.google.fr"
8344 "*Default url to use as home url.")
8346 (defvar ac-browse-url-chromium-program "chromium-browser")
8347 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8348 (defvar anything-browse-url-default-browser-alist
8349 `((,w3m-command . w3m-browse-url)
8350 (,browse-url-firefox-program . browse-url-firefox)
8351 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8352 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8353 (,browse-url-kde-program . browse-url-kde)
8354 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8355 (,browse-url-mozilla-program . browse-url-mozilla)
8356 (,browse-url-galeon-program . browse-url-galeon)
8357 (,browse-url-netscape-program . browse-url-netscape)
8358 (,browse-url-mosaic-program . browse-url-mosaic)
8359 (,browse-url-xterm-program . browse-url-text-xterm))
8360 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8362 (defun* anything-c-generic-browser (url name &rest args)
8363 "Browse URL with NAME browser."
8364 (let ((proc (concat name " " url)))
8365 (message "Starting %s..." name)
8366 (apply 'start-process proc nil name
8367 (append args (list url)))
8368 (set-process-sentinel
8369 (get-process proc)
8370 #'(lambda (process event)
8371 (when (string= event "finished\n")
8372 (message "%s process %s" process event))))))
8374 (defun ac-browse-url-chromium (url)
8375 "Browse URL with google chrome browser."
8376 (interactive "sURL: ")
8377 (anything-c-generic-browser
8378 url ac-browse-url-chromium-program))
8380 (defun ac-browse-url-uzbl (url &optional ignore)
8381 "Browse URL with uzbl browser."
8382 (interactive "sURL: ")
8383 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8385 (defun anything-browse-url-default-browser (url &rest args)
8386 "Find the first available browser and ask it to load URL."
8387 (let ((default-browser-fn
8388 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8389 thereis (and exe (executable-find exe) fn))))
8390 (if default-browser-fn
8391 (apply default-browser-fn url args)
8392 (error "No usable browser found"))))
8394 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8395 "Default command to browse URL."
8396 (if browse-url-browser-function
8397 (browse-url url)
8398 (anything-browse-url-default-browser url)))
8401 ;;; Surfraw
8403 ;; Need external program surfraw.
8404 ;; <http://surfraw.alioth.debian.org/>
8406 (defvar anything-surfraw-default-browser-function nil
8407 "*The browse url function you prefer to use with surfraw.
8408 When nil, fallback to `browse-url-browser-function'.")
8410 ;; Internal
8411 (defvar anything-surfraw-engines-history nil)
8412 (defvar anything-surfraw-input-history nil)
8414 (defun anything-c-build-elvi-list ()
8415 "Return list of all engines and descriptions handled by surfraw."
8416 (cdr
8417 (with-temp-buffer
8418 (call-process "surfraw" nil t nil
8419 "-elvi")
8420 (split-string (buffer-string) "\n"))))
8423 ;;; Emms
8426 (defun anything-emms-stream-edit-bookmark (elm)
8427 "Change the information of current emms-stream bookmark from anything."
8428 (declare (special emms-stream-list))
8429 (let* ((cur-buf anything-current-buffer)
8430 (bookmark (assoc elm emms-stream-list))
8431 (name (read-from-minibuffer "Description: "
8432 (nth 0 bookmark)))
8433 (url (read-from-minibuffer "URL: "
8434 (nth 1 bookmark)))
8435 (fd (read-from-minibuffer "Feed Descriptor: "
8436 (int-to-string (nth 2 bookmark))))
8437 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8438 (format "%s" (car (last bookmark))))))
8439 (save-excursion
8440 (emms-streams)
8441 (when (re-search-forward (concat "^" name) nil t)
8442 (beginning-of-line)
8443 (emms-stream-delete-bookmark)
8444 (emms-stream-add-bookmark name url (string-to-number fd) type)
8445 (emms-stream-save-bookmarks-file)
8446 (emms-stream-quit)
8447 (anything-c-switch-to-buffer cur-buf)))))
8449 (defun anything-emms-stream-delete-bookmark (elm)
8450 "Delete an emms-stream bookmark from anything."
8451 (let* ((cur-buf anything-current-buffer)
8452 (bookmark (assoc elm emms-stream-list))
8453 (name (nth 0 bookmark)))
8454 (save-excursion
8455 (emms-streams)
8456 (when (re-search-forward (concat "^" name) nil t)
8457 (beginning-of-line)
8458 (emms-stream-delete-bookmark)
8459 (emms-stream-save-bookmarks-file)
8460 (emms-stream-quit)
8461 (anything-c-switch-to-buffer cur-buf)))))
8463 (defvar anything-c-source-emms-streams
8464 '((name . "Emms Streams")
8465 (init . (lambda ()
8466 (emms-stream-init)))
8467 (candidates . (lambda ()
8468 (declare (special emms-stream-list))
8469 (mapcar 'car emms-stream-list)))
8470 (action . (("Play" . (lambda (elm)
8471 (declare (special emms-stream-list))
8472 (let* ((stream (assoc elm emms-stream-list))
8473 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8474 (url (second stream)))
8475 (funcall fn url))))
8476 ("Delete" . anything-emms-stream-delete-bookmark)
8477 ("Edit" . anything-emms-stream-edit-bookmark)))
8478 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8479 ;; (anything 'anything-c-source-emms-streams)
8481 ;; Don't forget to set `emms-source-file-default-directory'
8482 (defvar anything-c-source-emms-dired
8483 '((name . "Music Directory")
8484 (candidates . (lambda ()
8485 (cddr (directory-files emms-source-file-default-directory))))
8486 (action .
8487 (("Play Directory" . (lambda (item)
8488 (emms-play-directory
8489 (expand-file-name
8490 item
8491 emms-source-file-default-directory))))
8492 ("Open dired in file's directory" . (lambda (item)
8493 (anything-c-open-dired
8494 (expand-file-name
8495 item
8496 emms-source-file-default-directory))))))
8497 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8498 ;; (anything 'anything-c-source-emms-dired)
8501 (defun anything-c-emms-files-modifier (candidates source)
8502 (let ((current-playlist (with-current-emms-playlist
8503 (loop
8504 with cur-list = (emms-playlist-tracks-in-region
8505 (point-min) (point-max))
8506 for i in cur-list
8507 collect (assoc-default 'name i)))))
8508 (loop for i in candidates
8509 if (member (cdr i) current-playlist)
8510 collect (cons (propertize (car i)
8511 'face 'anything-emms-playlist)
8512 (cdr i)) into lis
8513 else collect i into lis
8514 finally return lis)))
8516 (defun anything-c-emms-play-current-playlist ()
8517 "Play current playlist."
8518 (with-current-emms-playlist
8519 (emms-playlist-first)
8520 (emms-playlist-mode-play-smart)))
8522 (defvar anything-c-source-emms-files
8523 '((name . "Emms files")
8524 (candidates . (lambda ()
8525 (loop for v being the hash-values in emms-cache-db
8526 for name = (assoc-default 'name v)
8527 for artist = (or (assoc-default 'info-artist v) "unknown")
8528 for genre = (or (assoc-default 'info-genre v) "unknown")
8529 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8530 for song = (or (assoc-default 'info-title v) "unknown")
8531 for info = (concat artist " - " genre " - " tracknum ": " song)
8532 unless (string-match "^http:" name) collect (cons info name))))
8533 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8534 (action . (("Play file" . emms-play-file)
8535 ("Add to Playlist and play (C-u clear current)"
8536 . (lambda (candidate)
8537 (when anything-current-prefix-arg
8538 (emms-playlist-current-clear))
8539 (emms-playlist-new)
8540 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8541 (unless emms-player-playing-p
8542 (anything-c-emms-play-current-playlist))))))))
8544 ;; (anything 'anything-c-source-emms-files)
8547 ;;; Jabber Contacts (jabber.el)
8548 (defun anything-c-jabber-online-contacts ()
8549 "List online Jabber contacts."
8550 (with-no-warnings
8551 (let (jids)
8552 (dolist (item (jabber-concat-rosters) jids)
8553 (when (get item 'connected)
8554 (push (if (get item 'name)
8555 (cons (get item 'name) item)
8556 (cons (symbol-name item) item)) jids))))))
8558 (defvar anything-c-source-jabber-contacts
8559 '((name . "Jabber Contacts")
8560 (init . (lambda () (require 'jabber)))
8561 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8562 (action . (lambda (x)
8563 (jabber-chat-with
8564 (jabber-read-account)
8565 (symbol-name
8566 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8567 ;; (anything 'anything-c-source-jabber-contacts)
8571 ;;; Call source.
8572 (defvar anything-source-select-buffer "*anything source select*")
8573 (defvar anything-c-source-call-source
8574 `((name . "Call anything source")
8575 (candidate-number-limit)
8576 (candidates
8577 . (lambda ()
8578 (loop for vname in (all-completions "anything-c-source-" obarray)
8579 for var = (intern vname)
8580 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8581 if name collect
8582 (cons (format "%s `%s'"
8583 name (propertize vname 'face 'font-lock-variable-name-face))
8584 var))))
8585 (action
8586 . (("Invoke anything with selected source"
8588 (lambda (candidate)
8589 (setq anything-candidate-number-limit 9999)
8590 (anything candidate nil nil nil nil
8591 anything-source-select-buffer)))
8592 ("Describe variable" . describe-variable)
8593 ("Find variable" . find-variable)))
8594 (persistent-action . describe-variable)
8595 (persistent-help . "Show description of this source")))
8596 ;; (anything 'anything-c-source-call-source)
8598 (defun anything-call-source-from-anything ()
8599 "Call anything source within `anything' session."
8600 (interactive)
8601 (setq anything-input-idle-delay 0)
8602 (anything-set-sources '(anything-c-source-call-source)))
8604 ;;; Execute Preconfigured anything.
8605 (defvar anything-c-source-anything-commands
8606 '((name . "Preconfigured Anything")
8607 (candidates . anything-c-anything-commands-candidates)
8608 (type . command)
8609 (candidate-number-limit)))
8610 ;; (anything 'anything-c-source-anything-commands)
8612 (defun anything-c-anything-commands-candidates ()
8613 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8614 collect (cons (if (where-is-internal cmd nil t)
8615 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8616 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8617 cmd)))
8620 ;;; Occur
8623 (defun anything-c-occur-init ()
8624 "Create the initial anything occur buffer.
8625 If region is active use region as buffer contents
8626 instead of whole buffer."
8627 (with-current-buffer (anything-candidate-buffer 'global)
8628 (erase-buffer)
8629 (let ((buf-contents
8630 (with-anything-current-buffer
8631 (if (anything-region-active-p)
8632 (buffer-substring (region-beginning) (region-end))
8633 (buffer-substring (point-min) (point-max))))))
8634 (insert buf-contents))))
8636 (defun anything-c-occur-get-line (s e)
8637 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8639 (defun anything-c-occur-query-replace-regexp (candidate)
8640 "Query replace regexp starting from CANDIDATE.
8641 If region is active ignore CANDIDATE and replace only in region.
8642 With a prefix arg replace only matches surrounded by word boundaries,
8643 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8644 (let ((regexp anything-input))
8645 (unless (anything-region-active-p)
8646 (anything-c-action-line-goto candidate))
8647 (apply 'query-replace-regexp
8648 (anything-c-query-replace-args regexp))))
8650 (defvar anything-c-source-occur
8651 '((name . "Occur")
8652 (init . anything-c-occur-init)
8653 (candidates-in-buffer)
8654 (migemo)
8655 (get-line . anything-c-occur-get-line)
8656 (display-to-real . anything-c-display-to-real-line)
8657 (action . (("Go to Line" . anything-c-action-line-goto)
8658 ("Query replace regexp (C-u Not inside word.)"
8659 . anything-c-occur-query-replace-regexp)))
8660 (recenter)
8661 (requires-pattern . 1)
8662 (delayed)
8663 (volatile)))
8664 ;; (anything 'anything-c-source-occur)
8667 ;;; Anything browse code.
8668 (defun anything-c-browse-code-get-line (beg end)
8669 "Select line if it match the regexp corresponding to current `major-mode'.
8670 Line is parsed for BEG position to END position."
8671 (let ((str-line (buffer-substring beg end))
8672 (regexp (assoc-default major-mode
8673 anything-c-browse-code-regexp-alist))
8674 (num-line (if (string= anything-pattern "") beg (1- beg))))
8675 (when (and regexp (string-match regexp str-line))
8676 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8679 (defvar anything-c-source-browse-code
8680 '((name . "Browse code")
8681 (init . (lambda ()
8682 (anything-candidate-buffer anything-current-buffer)
8683 (with-anything-current-buffer
8684 (jit-lock-fontify-now))))
8685 (candidate-number-limit . 9999)
8686 (candidates-in-buffer)
8687 (get-line . anything-c-browse-code-get-line)
8688 (type . line)
8689 (recenter)))
8692 ;; Do many actions for input
8693 (defvar anything-c-source-create
8694 '((name . "Create")
8695 (dummy)
8696 (action)
8697 (action-transformer . anything-create--actions))
8698 "Do many create actions from `anything-pattern'.
8699 See also `anything-create--actions'.")
8700 ;; (anything 'anything-c-source-create)
8702 (defun anything-create-from-anything ()
8703 "Run `anything-create' from `anything' as a fallback."
8704 (interactive)
8705 (anything-run-after-quit 'anything-create nil anything-pattern))
8707 (defun anything-create--actions (&rest ignored)
8708 "Default actions for `anything-create' / `anything-c-source-create'."
8709 (remove-if-not
8710 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8711 (append anything-create--actions-private
8712 '(("find-file" . find-file)
8713 ("find-file other window" . find-file-other-window)
8714 ("New buffer" . anything-c-switch-to-buffer)
8715 ("New buffer other window" . switch-to-buffer-other-window)
8716 ("Bookmark Set" . bookmark-set)
8717 ("Set Register" .
8718 (lambda (x) (set-register (read-char "Register: ") x)))
8719 ("Insert Linkd star" . linkd-insert-star)
8720 ("Insert Linkd Tag" . linkd-insert-tag)
8721 ("Insert Linkd Link" . linkd-insert-link)
8722 ("Insert Linkd Lisp" . linkd-insert-lisp)
8723 ("Insert Linkd Wiki" . linkd-insert-wiki)
8724 ("Google Search" . google)))))
8727 ;; Minibuffer History
8730 (defvar anything-c-source-minibuffer-history
8731 '((name . "Minibuffer History")
8732 (header-name . (lambda (name)
8733 (format "%s (%s)" name minibuffer-history-variable)))
8734 (candidates
8735 . (lambda ()
8736 (let ((history (loop
8737 for i in (symbol-value minibuffer-history-variable)
8738 unless (string= "" i) collect i)))
8739 (if (consp (car history))
8740 (mapcar 'prin1-to-string history)
8741 history))))
8742 (migemo)
8743 (action . insert)))
8744 ;; (anything 'anything-c-source-minibuffer-history)
8747 ;;; Elscreen
8750 (defvar anything-c-source-elscreen
8751 '((name . "Elscreen")
8752 (candidates . (lambda ()
8753 (if (cdr (elscreen-get-screen-to-name-alist))
8754 (sort
8755 (loop for sname in (elscreen-get-screen-to-name-alist)
8756 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8757 finally (return lst))
8758 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8759 (action . (("Change Screen".
8760 (lambda (candidate)
8761 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8762 ("Kill Screen(s)".
8763 (lambda (candidate)
8764 (dolist (i (anything-marked-candidates))
8765 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8766 (elscreen-kill))))
8767 ("Only Screen".
8768 (lambda (candidate)
8769 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8770 (elscreen-kill-others)))))))
8771 ;; (anything 'anything-c-source-elscreen)
8774 ;;;; <System>
8776 ;;; Top (process)
8777 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8778 "Top command (batch mode). %s is replaced with `frame-width'.")
8779 (defvar anything-c-source-top
8780 '((name . "Top (Press C-c C-u to refresh)")
8781 (init . anything-c-top-init)
8782 (candidates-in-buffer)
8783 (display-to-real . anything-c-top-display-to-real)
8784 (update . anything-c-top-update)
8785 (persistent-action . anything-c-top-sh-persistent-action)
8786 (persistent-help . "SIGTERM")
8787 (action
8788 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8789 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8790 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8791 ;; (anything 'anything-c-source-top)
8793 (defun anything-c-top-sh (cmd)
8794 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8796 (defun anything-c-top-sh-persistent-action (pid)
8797 (delete-other-windows)
8798 (anything-c-top-sh (format "kill -TERM %s" pid))
8799 (anything-force-update))
8801 (defun anything-c-top-init ()
8802 (with-current-buffer (anything-candidate-buffer 'global)
8803 (call-process-shell-command
8804 (format anything-c-top-command
8805 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8806 nil (current-buffer))))
8808 (defun anything-c-top-display-to-real (line)
8809 (car (split-string line)))
8811 (defun anything-c-top-update ()
8812 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8813 (anything-c-top-init)))
8815 ;;; Timers
8816 (defvar anything-c-source-absolute-time-timers
8817 '((name . "Absolute Time Timers")
8818 (candidates . timer-list)
8819 (type . timer)))
8820 ;; (anything 'anything-c-source-absolute-time-timers)
8822 (defvar anything-c-source-idle-time-timers
8823 '((name . "Idle Time Timers")
8824 (candidates . timer-idle-list)
8825 (type . timer)))
8826 ;; (anything 'anything-c-source-idle-time-timers)
8828 (defun anything-c-timer-real-to-display (timer)
8829 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8830 (append timer nil) ;use `append' to convert vector->list
8831 (format "%s repeat=%5S %s(%s)"
8832 (let ((time (list t1 t2 t3)))
8833 (if idle-delay
8834 (format-time-string "idle-for=%5s" time)
8835 (format-time-string "%m/%d %T" time)))
8836 repeat-delay
8837 func
8838 (mapconcat 'prin1-to-string args " "))))
8840 ;;; X RandR resolution change
8841 ;;; FIXME I do not care multi-display.
8842 (defvar anything-c-xrandr-output "VGA")
8843 (defvar anything-c-xrandr-screen "0")
8844 (defvar anything-c-source-xrandr-change-resolution
8845 '((name . "Change Resolution")
8846 (candidates
8847 . (lambda ()
8848 (with-temp-buffer
8849 (call-process "xrandr" nil (current-buffer) nil
8850 "--screen" anything-c-xrandr-screen "-q")
8851 (goto-char 1)
8852 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8853 collect (match-string 1)))))
8854 (action
8855 ("Change Resolution" . (lambda (mode)
8856 (call-process "xrandr" nil nil nil
8857 "--screen" anything-c-xrandr-screen
8858 "--output" anything-c-xrandr-output
8859 "--mode" mode))))))
8860 ;; (anything 'anything-c-source-xrandr-change-resolution)
8862 ;;; Xfont selection
8865 (defun anything-c-persistent-xfont-action (elm)
8866 "Show current font temporarily"
8867 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8868 (default-font elm))
8869 (unwind-protect
8870 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8871 (set-frame-font current-font))))
8873 (defvar anything-c-xfonts-cache nil)
8874 (defvar anything-c-source-xfonts
8875 '((name . "X Fonts")
8876 (init . (lambda ()
8877 (unless anything-c-xfonts-cache
8878 (setq anything-c-xfonts-cache
8879 (x-list-fonts "*")))))
8880 (candidates . anything-c-xfonts-cache)
8881 (action . (("Copy to kill ring" . (lambda (elm)
8882 (kill-new elm)))
8883 ("Set Font" . (lambda (elm)
8884 (kill-new elm)
8885 (set-frame-font elm 'keep-size)
8886 (message "New font have been copied to kill ring")))))
8887 (persistent-action . anything-c-persistent-xfont-action)
8888 (persistent-help . "Switch to this font temporarily")))
8889 ;; (anything 'anything-c-source-xfonts)
8891 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8894 (defvar anything-c-ucs-max-len 0)
8895 (defun anything-c-calculate-ucs-max-len ()
8896 "Calculate the length of longest `ucs-names' candidate."
8897 (loop with count = 0
8898 for (n . v) in (ucs-names)
8899 for len = (length n)
8900 if (> len count)
8901 do (setq count len)
8902 finally return count))
8904 (defun anything-c-ucs-init ()
8905 "Initialize an anything buffer with ucs symbols.
8906 Only math* symbols are collected."
8907 (unless (> anything-c-ucs-max-len 0)
8908 (setq anything-c-ucs-max-len
8909 (anything-c-calculate-ucs-max-len)))
8910 (with-current-buffer (anything-candidate-buffer
8911 (get-buffer-create "*anything ucs*"))
8912 ;; `ucs-names' fn will not run again, data is cached in
8913 ;; var `ucs-names'.
8914 (loop for (n . v) in (ucs-names)
8915 for len = (length n)
8916 for diff = (+ (- anything-c-ucs-max-len len) 2)
8917 unless (string= "" n)
8918 do (progn (insert (concat
8919 n ":"
8920 (make-string
8921 diff ? )))
8922 (ucs-insert v)
8923 (insert "\n")))))
8925 (defun anything-c-ucs-forward-char (candidate)
8926 (with-anything-current-buffer
8927 (forward-char 1)))
8929 (defun anything-c-ucs-backward-char (candidate)
8930 (with-anything-current-buffer
8931 (forward-char -1)))
8933 (defun anything-c-ucs-delete-backward (candidate)
8934 (with-anything-current-buffer
8935 (delete-char -1)))
8937 (defun anything-c-ucs-insert-char (candidate)
8938 (with-anything-current-buffer
8939 (insert
8940 (replace-regexp-in-string
8941 " " ""
8942 (cadr (split-string candidate ":"))))))
8944 (defun anything-c-ucs-persistent-insert ()
8945 (interactive)
8946 (anything-attrset 'action-insert 'anything-c-ucs-insert-char)
8947 (anything-execute-persistent-action 'action-insert))
8949 (defun anything-c-ucs-persistent-forward ()
8950 (interactive)
8951 (anything-attrset 'action-forward 'anything-c-ucs-forward-char)
8952 (anything-execute-persistent-action 'action-forward))
8954 (defun anything-c-ucs-persistent-backward ()
8955 (interactive)
8956 (anything-attrset 'action-back 'anything-c-ucs-backward-char)
8957 (anything-execute-persistent-action 'action-back))
8959 (defun anything-c-ucs-persistent-delete ()
8960 (interactive)
8961 (anything-attrset 'action-delete 'anything-c-ucs-delete-backward)
8962 (anything-execute-persistent-action 'action-delete))
8964 (defvar anything-c-source-ucs
8965 '((name . "Ucs names")
8966 (init . anything-c-ucs-init)
8967 (candidate-number-limit . 9999)
8968 (candidates-in-buffer)
8969 (mode-line . anything-c-ucs-mode-line-string)
8970 (action . (("Insert" . anything-c-ucs-insert-char)
8971 ("Forward char" . anything-c-ucs-forward-char)
8972 ("Backward char" . anything-c-ucs-backward-char)
8973 ("Delete char backward" . anything-c-ucs-delete-backward))))
8974 "Source for collecting `ucs-names' math symbols.")
8977 ;;; Emacs process
8980 (defvar anything-c-source-emacs-process
8981 '((name . "Emacs Process")
8982 (candidates . (lambda () (mapcar #'process-name (process-list))))
8983 (persistent-action . (lambda (elm)
8984 (delete-process (get-process elm))
8985 (anything-delete-current-selection)))
8986 (persistent-help . "Kill Process")
8987 (action ("Kill Process" . (lambda (elm)
8988 (delete-process (get-process elm)))))))
8989 ;; (anything 'anything-c-source-emacs-process)
8991 ;;; World time
8994 (defvar anything-c-source-time-world
8995 '((name . "Time World List")
8996 (init . (lambda ()
8997 (let ((anything-buffer (anything-candidate-buffer 'global)))
8998 (with-current-buffer anything-buffer
8999 (display-time-world-display display-time-world-list)))))
9000 (candidates-in-buffer)))
9004 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9007 (defvar anything-c-source-apt
9008 '((name . "APT")
9009 (init . anything-c-apt-init)
9010 (candidates-in-buffer)
9011 (candidate-transformer anything-c-apt-candidate-transformer)
9012 (display-to-real . anything-c-apt-display-to-real)
9013 (requires-pattern . 2)
9014 (update . anything-c-apt-refresh)
9015 (action
9016 ("Show package description" . anything-c-apt-cache-show)
9017 ("Install package" . anything-c-apt-install)
9018 ("Remove package" . anything-c-apt-uninstall)
9019 ("Purge package" . anything-c-apt-purge))
9020 (persistent-action . anything-c-apt-persistent-action)
9021 (persistent-help . "Show package description")))
9022 ;; (anything 'anything-c-source-apt)
9024 (defvar anything-c-apt-query "emacs")
9025 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9026 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9027 (defvar anything-c-apt-installed-packages nil)
9028 (defvar anything-c-apt-all-packages nil)
9029 (defvar anything-c-apt-input-history nil)
9031 (defun anything-c-apt-refresh ()
9032 "Refresh installed candidates list."
9033 (setq anything-c-apt-installed-packages nil)
9034 (setq anything-c-apt-all-packages nil))
9036 (defun anything-c-apt-persistent-action (candidate)
9037 "Persistent action for APT source."
9038 (anything-c-apt-cache-show candidate))
9040 (defun anything-c-apt-candidate-transformer (candidates)
9041 "Show installed candidates in a different color."
9042 (loop
9043 with all
9044 for cand in candidates
9045 for name = (anything-c-apt-display-to-real cand)
9046 if (member name anything-c-apt-installed-packages)
9047 collect (propertize cand 'face 'anything-apt-installed) into all
9048 else collect cand into all finally return all))
9050 (defun anything-c-apt-init ()
9051 "Initialize list of debian packages."
9052 (let ((query ""))
9053 (unless (and anything-c-apt-installed-packages
9054 anything-c-apt-all-packages)
9055 (message "Loading package list...")
9056 (setq anything-c-apt-installed-packages
9057 (with-temp-buffer
9058 (call-process-shell-command "dpkg --get-selections"
9059 nil (current-buffer))
9060 (loop for i in (split-string (buffer-string) "\n" t)
9061 collect (car (split-string i)))))
9062 (setq anything-c-apt-all-packages
9063 (with-current-buffer
9064 (anything-candidate-buffer
9065 (get-buffer-create (format "*anything-apt*")))
9066 (erase-buffer)
9067 (call-process-shell-command
9068 (format anything-c-apt-search-command query)
9069 nil (current-buffer))))
9070 (message "Loading package list done")
9071 (sit-for 0.5))))
9073 (defun anything-c-apt-display-to-real (line)
9074 "Return only name of a debian package.
9075 LINE is displayed like:
9076 package name - description."
9077 (car (split-string line " - ")))
9079 (defun anything-c-shell-command-if-needed (command)
9080 "Run shell command COMMAND to describe package.
9081 If a buffer named COMMAND already exists, just switch to it."
9082 (let ((buf (get-buffer command)))
9083 (anything-c-switch-to-buffer (get-buffer-create command))
9084 (unless buf (insert (shell-command-to-string command)))))
9086 (defun anything-c-apt-cache-show (package)
9087 "Show information on apt package PACKAGE."
9088 (anything-c-shell-command-if-needed
9089 (format anything-c-apt-show-command package)))
9091 (defun anything-c-apt-install (package)
9092 "Run 'apt-get install' shell command on PACKAGE."
9093 (anything-c-apt-generic-action :action 'install))
9095 (defun anything-c-apt-uninstall (package)
9096 "Run 'apt-get remove' shell command on PACKAGE."
9097 (anything-c-apt-generic-action :action 'uninstall))
9099 (defun anything-c-apt-purge (package)
9100 "Run 'apt-get purge' shell command on PACKAGE."
9101 (anything-c-apt-generic-action :action 'purge))
9103 (defun* anything-c-apt-generic-action (&key action)
9104 "Run 'apt-get ACTION'.
9105 Support install, remove and purge actions."
9106 (ansi-term (getenv "SHELL") "anything apt")
9107 (term-line-mode)
9108 (let ((command (case action
9109 ('install "sudo apt-get install ")
9110 ('uninstall "sudo apt-get remove ")
9111 ('purge "sudo apt-get purge ")
9112 (t (error "Unknow action"))))
9113 (beg (point))
9115 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9116 (anything-marked-candidates) " ")))
9117 (goto-char (point-max))
9118 (insert (concat command cand-list))
9119 (setq end (point))
9120 (if (y-or-n-p (format "%s package" (symbol-name action)))
9121 (progn
9122 (setq anything-c-external-commands-list nil)
9123 (setq anything-c-apt-installed-packages nil)
9124 (term-char-mode) (term-send-input))
9125 (delete-region beg end) (term-send-eof) (kill-buffer))))
9127 ;; (anything-c-apt-install "jed")
9130 ;;; Anything UI for gentoo portage.
9133 (defvar anything-c-gentoo-use-flags nil)
9134 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9135 (defvar anything-c-cache-gentoo nil)
9136 (defvar anything-c-cache-world nil)
9137 (defvar anything-c-source-gentoo
9138 '((name . "Portage sources")
9139 (init . (lambda ()
9140 (get-buffer-create anything-c-gentoo-buffer)
9141 (unless anything-c-cache-gentoo
9142 (anything-c-gentoo-setup-cache))
9143 (unless anything-c-cache-world
9144 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9145 (anything-c-gentoo-init-list)))
9146 (candidates-in-buffer)
9147 (match . identity)
9148 (candidate-transformer anything-c-highlight-world)
9149 (action . (("Show package" . (lambda (elm)
9150 (anything-c-gentoo-eshell-action elm "eix")))
9151 ("Show history" . (lambda (elm)
9152 (if (member elm anything-c-cache-world)
9153 (anything-c-gentoo-eshell-action elm "genlop -qe")
9154 (message "No infos on packages not yet installed"))))
9155 ("Copy in kill-ring" . kill-new)
9156 ("insert at point" . insert)
9157 ("Browse HomePage" . (lambda (elm)
9158 (let ((urls (anything-c-gentoo-get-url elm)))
9159 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9160 ("Show extra infos" . (lambda (elm)
9161 (if (member elm anything-c-cache-world)
9162 (anything-c-gentoo-eshell-action elm "genlop -qi")
9163 (message "No infos on packages not yet installed"))))
9164 ("Show use flags" . (lambda (elm)
9165 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9166 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9167 (font-lock-mode 1)))
9168 ("Run emerge pretend" . (lambda (elm)
9169 (anything-c-gentoo-eshell-action elm "emerge -p")))
9170 ("Emerge" . (lambda (elm)
9171 (anything-gentoo-install elm :action 'install)))
9172 ("Unmerge" . (lambda (elm)
9173 (anything-gentoo-install elm :action 'uninstall)))
9174 ("Show dependencies" . (lambda (elm)
9175 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9176 ("Show related files" . (lambda (elm)
9177 (anything-c-gentoo-default-action elm "equery" "files")))
9178 ("Refresh" . (lambda (elm)
9179 (anything-c-gentoo-setup-cache)
9180 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9182 ;; (anything 'anything-c-source-gentoo)
9184 (defun* anything-gentoo-install (candidate &key action)
9185 (setq anything-c-external-commands-list nil)
9186 (ansi-term (getenv "SHELL") "Gentoo emerge")
9187 (term-line-mode)
9188 (let ((command (case action
9189 ('install "sudo emerge -av ")
9190 ('uninstall "sudo emerge -avC ")
9191 (t (error "Unknow action"))))
9192 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9193 (beg (point)) end)
9194 (goto-char (point-max))
9195 (insert (concat command elms))
9196 (setq end (point))
9197 (term-char-mode) (term-send-input)))
9199 (defun anything-c-gentoo-default-action (elm command &rest args)
9200 "Gentoo default action that use `anything-c-gentoo-buffer'."
9201 (if (member elm anything-c-cache-world)
9202 (progn
9203 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9204 (erase-buffer)
9205 (let ((com-list (append args (list elm))))
9206 (apply #'call-process command nil t nil
9207 com-list)))
9208 (message "No infos on packages not yet installed")))
9210 (defvar anything-c-source-use-flags
9211 '((name . "Use Flags")
9212 (init . (lambda ()
9213 (unless anything-c-gentoo-use-flags
9214 (anything-c-gentoo-setup-use-flags-cache))
9215 (anything-c-gentoo-get-use)))
9216 (candidates-in-buffer)
9217 (match . identity)
9218 (candidate-transformer anything-c-highlight-local-use)
9219 (action . (("Description"
9220 . (lambda (elm)
9221 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9222 (erase-buffer)
9223 (apply #'call-process "euse" nil t nil
9224 `("-i"
9225 ,elm))
9226 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9227 (font-lock-mode 1)))
9228 ("Enable"
9229 . (lambda (elm)
9230 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9231 ("Disable"
9232 . (lambda (elm)
9233 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9234 ("Remove"
9235 . (lambda (elm)
9236 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9237 ("Show which dep use this flag"
9238 . (lambda (elm)
9239 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9240 (erase-buffer)
9241 (apply #'call-process "equery" nil t nil
9242 `("-C"
9244 ,elm))))))))
9247 ;; (anything 'anything-c-source-use-flags)
9249 (defun anything-c-gentoo-init-list ()
9250 "Initialize buffer with all packages in Portage."
9251 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9252 (buf (anything-candidate-buffer 'portage-buf)))
9253 (with-current-buffer buf
9254 (dolist (i anything-c-cache-gentoo)
9255 (insert (concat i "\n"))))))
9257 (defun anything-c-gentoo-setup-cache ()
9258 "Set up `anything-c-cache-gentoo'"
9259 (setq anything-c-cache-gentoo
9260 (split-string (with-temp-buffer
9261 (call-process "eix" nil t nil
9262 "--only-names")
9263 (buffer-string)))))
9265 (defun anything-c-gentoo-eshell-action (elm command)
9266 (when (get-buffer "*EShell Command Output*")
9267 (kill-buffer "*EShell Command Output*"))
9268 (message "Wait searching...")
9269 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9270 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9271 (progn
9272 (save-window-excursion
9273 (pop-to-buffer "*scratch*")
9274 (eshell-command (format "%s %s" command elm)))
9275 (pop-to-buffer "*EShell Command Output*"))
9276 (eshell-command (format "%s %s" command elm)))))
9278 (defun anything-c-gentoo-get-use ()
9279 "Initialize buffer with all use flags."
9280 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9281 (buf (anything-candidate-buffer 'use-buf)))
9282 (with-current-buffer buf
9283 (dolist (i anything-c-gentoo-use-flags)
9284 (insert (concat i "\n"))))))
9287 (defun anything-c-gentoo-setup-use-flags-cache ()
9288 "Setup `anything-c-gentoo-use-flags'"
9289 (setq anything-c-gentoo-use-flags
9290 (split-string (with-temp-buffer
9291 (call-process "eix" nil t nil
9292 "--print-all-useflags")
9293 (buffer-string)))))
9295 (defun anything-c-gentoo-get-url (elm)
9296 "Return a list of urls from eix output."
9297 (loop
9298 with url-list = (split-string
9299 (with-temp-buffer
9300 (call-process "eix" nil t nil
9301 elm "--format" "<homepage>\n")
9302 (buffer-string)))
9303 with all
9304 for i in url-list
9305 when (and (string-match "^http://.*" i)
9306 (not (member i all)))
9307 collect i into all
9308 finally return all))
9310 (defun anything-c-gentoo-get-world ()
9311 "Return list of all installed package on your system."
9312 (split-string (with-temp-buffer
9313 (call-process "qlist" nil t nil
9314 "-I")
9315 (buffer-string))))
9317 (defun anything-c-gentoo-get-local-use ()
9318 (split-string (with-temp-buffer
9319 (call-process "portageq" nil t nil
9320 "envvar"
9321 "USE")
9322 (buffer-string))))
9325 (defun anything-c-highlight-world (eix)
9326 "Highlight all installed package."
9327 (loop for i in eix
9328 if (member i anything-c-cache-world)
9329 collect (propertize i 'face 'anything-gentoo-match-face)
9330 else
9331 collect i))
9333 (defun anything-c-highlight-local-use (use-flags)
9334 (let ((local-uses (anything-c-gentoo-get-local-use)))
9335 (loop for i in use-flags
9336 if (member i local-uses)
9337 collect (propertize i 'face 'anything-gentoo-match-face)
9338 else
9339 collect i)))
9343 ;;; Anything ratpoison UI
9346 (defvar anything-c-source-ratpoison-commands
9347 '((name . "Ratpoison Commands")
9348 (init . anything-c-ratpoison-commands-init)
9349 (candidates-in-buffer)
9350 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9351 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9352 (candidate-number-limit)))
9353 ;; (anything 'anything-c-source-ratpoison-commands)
9355 (defun anything-c-ratpoison-commands-init ()
9356 (unless (anything-candidate-buffer)
9357 (with-current-buffer (anything-candidate-buffer 'global)
9358 ;; with ratpoison prefix key
9359 (save-excursion
9360 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9361 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9362 (replace-match "<ratpoison> \\1: \\2"))
9363 (goto-char (point-max))
9364 ;; direct binding
9365 (save-excursion
9366 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9367 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9368 (replace-match "\\1: \\2")))))
9370 (defun anything-c-ratpoison-commands-display-to-real (display)
9371 (and (string-match ": " display)
9372 (substring display (match-end 0))))
9374 (defun anything-c-ratpoison-commands-execute (candidate)
9375 (call-process "ratpoison" nil nil nil "-ic" candidate))
9379 ;;; Anything `completing-read' replacement
9382 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9383 "Convert COLLECTION to list removing elements that don't match TEST.
9384 See `anything-comp-read' about supported COLLECTION arguments.
9386 SORT-FN is a predicate to sort COLLECTION.
9388 ALISTP when non--nil will not use `all-completions' to collect
9389 candidates because it doesn't handle alists correctly for anything.
9390 i.e In `all-completions' the keys \(cars of elements\)
9391 are the possible completions. In anything we want to use the cdr instead
9392 like \(display . real\).
9396 \(setq A '((a . 1) (b . 2) (c . 3)))
9397 ==>((a . 1) (b . 2) (c . 3))
9398 \(anything-comp-read \"test: \" A :alistp nil
9399 :exec-when-only-one t
9400 :initial-input \"a\")
9401 ==>\"a\"
9402 \(anything-comp-read \"test: \" A :alistp t
9403 :exec-when-only-one t
9404 :initial-input \"1\")
9405 ==>\"1\"
9407 See docstring of `all-completions' for more info.
9409 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9410 (let ((cands
9411 (cond ((and (eq collection obarray) test)
9412 (all-completions "" collection test))
9413 ((and (vectorp collection) test)
9414 (loop for i across collection when (funcall test i) collect i))
9415 ((vectorp collection)
9416 (loop for i across collection collect i))
9417 ((and alistp test)
9418 (loop for i in collection when (funcall test i) collect i))
9419 ((and (symbolp collection) (boundp collection))
9420 (symbol-value collection))
9421 (alistp collection)
9422 ((and collection test)
9423 (all-completions "" collection test))
9424 (t (all-completions "" collection)))))
9425 (if sort-fn (sort cands sort-fn) cands)))
9427 (defun anything-cr-default-transformer (candidates source)
9428 "Default filter candidate function for `anything-comp-read'.
9429 Do nothing, just return candidate list unmodified."
9430 candidates)
9432 (defun* anything-comp-read (prompt collection
9433 &key
9434 test
9435 initial-input
9436 default
9437 preselect
9438 (buffer "*Anything Completions*")
9439 must-match
9440 (requires-pattern 0)
9441 (history nil)
9442 input-history
9443 (persistent-action nil)
9444 (persistent-help "DoNothing")
9445 (name "Anything Completions")
9446 candidates-in-buffer
9447 exec-when-only-one
9448 (volatile t)
9449 sort
9450 (fc-transformer 'anything-cr-default-transformer)
9451 (marked-candidates nil)
9452 (alistp t))
9453 "Read a string in the minibuffer, with anything completion.
9455 It is anything `completing-read' equivalent.
9457 - PROMPT is the prompt name to use.
9459 - COLLECTION can be a list, vector, obarray or hash-table.
9460 It can be also a function that receives three arguments:
9461 the values string, predicate and t. See `all-completions' for more details.
9463 Keys description:
9465 - TEST: A predicate called with one arg i.e candidate.
9467 - INITIAL-INPUT: Same as input arg in `anything'.
9469 - PRESELECT: See preselect arg of `anything'.
9471 - DEFAULT: This option is used only for compatibility with regular
9472 Emacs `completing-read'.
9474 - BUFFER: Name of anything-buffer.
9476 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9478 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9480 - HISTORY: A list containing specific history, default is nil.
9481 When it is non--nil, all elements of HISTORY are displayed in
9482 a special source before COLLECTION.
9484 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9485 stored there, if nil or not provided, `minibuffer-history'
9486 will be used instead.
9488 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9490 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9492 - NAME: The name related to this local source.
9494 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9495 to non--nil. (possibles values are t or nil).
9497 - VOLATILE: Use volatile attribute \(enabled by default\).
9499 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9501 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9503 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9505 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9507 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9508 `anything-candidates-in-buffer' which is much faster.
9509 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9511 Any prefix args passed during `anything-comp-read' invocation will be recorded
9512 in `anything-current-prefix-arg', otherwise if prefix args were given before
9513 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9514 That's mean you can pass prefix args before or after calling a command
9515 that use `anything-comp-read' See `anything-M-x' for example."
9516 (when (get-buffer anything-action-buffer)
9517 (kill-buffer anything-action-buffer))
9518 (flet ((action-fn (candidate)
9519 (if marked-candidates
9520 (anything-marked-candidates)
9521 (identity candidate))))
9522 (let* ((src-hist `((name . ,(format "%s History" name))
9523 (candidates
9524 . (lambda ()
9525 (let ((all (anything-comp-read-get-candidates
9526 history nil nil ,alistp)))
9527 (anything-fast-remove-dups
9528 (if (and default (not (string= default "")))
9529 (delq nil (cons default (delete default all)))
9530 all)
9531 :test 'equal))))
9532 (filtered-candidate-transformer
9533 . (lambda (candidates sources)
9534 (loop for i in candidates
9535 do (set-text-properties 0 (length i) nil i)
9536 collect i)))
9537 (persistent-action . ,persistent-action)
9538 (persistent-help . ,persistent-help)
9539 (action . ,'action-fn)))
9540 (src `((name . ,name)
9541 (candidates
9542 . (lambda ()
9543 (let ((cands (anything-comp-read-get-candidates
9544 collection test sort alistp)))
9545 (unless (or must-match (string= anything-pattern ""))
9546 (setq cands (append (list anything-pattern) cands)))
9547 (if (and default (not (string= default "")))
9548 (delq nil (cons default (delete default cands)))
9549 cands))))
9550 (filtered-candidate-transformer ,fc-transformer)
9551 (requires-pattern . ,requires-pattern)
9552 (persistent-action . ,persistent-action)
9553 (persistent-help . ,persistent-help)
9554 (action . ,'action-fn)))
9555 (src-1 `((name . ,name)
9556 (init
9557 . (lambda ()
9558 (let ((cands (anything-comp-read-get-candidates
9559 collection test sort alistp)))
9560 (unless (or must-match (string= anything-pattern ""))
9561 (setq cands (append (list anything-pattern) cands)))
9562 (with-current-buffer (anything-candidate-buffer 'global)
9563 (loop for i in
9564 (if (and default (not (string= default "")))
9565 (delq nil (cons default (delete default cands)))
9566 cands)
9567 do (insert (concat i "\n")))))))
9568 (candidates-in-buffer)
9569 (filtered-candidate-transformer ,fc-transformer)
9570 (requires-pattern . ,requires-pattern)
9571 (persistent-action . ,persistent-action)
9572 (persistent-help . ,persistent-help)
9573 (action . ,'action-fn)))
9574 (src-list (list src-hist
9575 (if candidates-in-buffer
9576 src-1
9577 (if volatile
9578 (append src '((volatile)))
9579 src))))
9580 (anything-execute-action-at-once-if-one exec-when-only-one))
9582 (anything
9583 :sources src-list
9584 :input initial-input
9585 :default default
9586 :preselect preselect
9587 :prompt prompt
9588 :resume 'noresume
9589 :history input-history
9590 :buffer buffer)
9591 (unless (or (eq anything-exit-status 1) must-match)
9592 default)
9593 (keyboard-quit)))))
9595 ;; Generic completing-read
9597 ;; Support also function as collection.
9598 ;; e.g M-x man is supported.
9599 ;; Support hash-table and vectors as collection.
9600 ;; NOTE:
9601 ;; Some crap emacs functions may not be supported
9602 ;; like ffap-alternate-file (bad use of completing-read)
9603 ;; and maybe others.
9604 ;; Provide a mode `anything-completion-mode' which turn on
9605 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9607 (defvar anything-completion-mode-string " AC")
9609 (defvar anything-completion-mode-quit-message
9610 "Anything completion disabled")
9612 (defvar anything-completion-mode-start-message
9613 "Anything completion enabled")
9615 ;;; Specialized handlers
9618 (defun anything-completing-read-symbols
9619 (prompt collection test require-match init
9620 hist default inherit-input-method name buffer)
9621 "Specialized function for fast symbols completion in `ac-mode'."
9623 (anything
9624 :sources `((name . ,name)
9625 (init . (lambda ()
9626 (with-current-buffer (anything-candidate-buffer 'global)
9627 (goto-char (point-min))
9628 (when (and default (stringp default)
9629 ;; Some defaults args result as
9630 ;; (symbol-name nil) == "nil".
9631 ;; e.g debug-on-entry.
9632 (not (string= default "nil"))
9633 (not (string= default "")))
9634 (insert (concat default "\n")))
9635 (loop with all = (all-completions "" collection test)
9636 for sym in all
9637 unless (and default (eq sym default))
9638 do (insert (concat sym "\n"))))))
9639 (persistent-action . anything-lisp-completion-persistent-action)
9640 (persistent-help . "Show brief doc in mode-line")
9641 (candidates-in-buffer)
9642 (action . identity))
9643 :prompt prompt
9644 :buffer buffer
9645 :input init
9646 :history hist
9647 :resume 'noresume
9648 :default (or default ""))
9649 (keyboard-quit)))
9652 ;;; Generic completing read
9655 (defun anything-completing-read-default-1
9656 (prompt collection test require-match
9657 init hist default inherit-input-method
9658 name buffer &optional cands-in-buffer exec-when-only-one)
9659 "Call `anything-comp-read' with same args as `completing-read'.
9660 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9661 method which is faster.
9662 It should be used when candidate list don't need to rebuild dynamically."
9663 (let ((history (or (car-safe hist) hist)))
9664 (anything-comp-read
9665 prompt collection
9666 :test test
9667 :history history
9668 :input-history history
9669 :must-match require-match
9670 :alistp nil ; Be sure `all-completions' is used.
9671 :name name
9672 :candidates-in-buffer cands-in-buffer
9673 :exec-when-only-one exec-when-only-one
9674 :buffer buffer
9675 ;; If DEF is not provided, fallback to empty string
9676 ;; to avoid `thing-at-point' to be appended on top of list
9677 :default (or default "")
9678 :initial-input init)))
9680 (defun anything-completing-read-with-cands-in-buffer
9681 (prompt collection test require-match
9682 init hist default inherit-input-method
9683 name buffer)
9684 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9685 ;; Some commands like find-tag may use `read-file-name' from inside
9686 ;; the calculation of collection. in this case it clash with
9687 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9688 ;; So (re)calculate collection outside of main anything-session.
9689 (let ((cands (all-completions "" collection)))
9690 (anything-completing-read-default-1 prompt cands test require-match
9691 init hist default inherit-input-method
9692 name buffer t)))
9694 (defun* anything-completing-read-default
9695 (prompt collection &optional
9696 predicate require-match
9697 initial-input hist def
9698 inherit-input-method)
9699 "An anything replacement of `completing-read'.
9700 This function should be used only as a `completing-read-function'.
9702 Don't use it directly, use instead `anything-comp-read' in your programs.
9704 See documentation of `completing-read' and `all-completions' for details."
9705 (declare (special anything-completion-mode))
9706 (let* ((current-command this-command)
9707 (str-command (symbol-name current-command))
9708 (buf-name (format "*ac-mode-%s*" str-command))
9709 (entry (assq current-command
9710 anything-completing-read-handlers-alist))
9711 (def-com (cdr-safe entry))
9712 (str-defcom (and def-com (symbol-name def-com)))
9713 (def-args (list prompt collection predicate require-match
9714 initial-input hist def inherit-input-method))
9715 ;; Append the two extra args needed to set the buffer and source name
9716 ;; in anything specialized functions.
9717 (any-args (append def-args (list str-command buf-name)))
9718 anything-completion-mode-start-message ; Be quiet
9719 anything-completion-mode-quit-message
9720 (minibuffer-completion-table collection)
9721 (minibuffer-completion-predicate predicate))
9722 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9723 (unless (or (not entry) def-com)
9724 ;; An entry in *read-handlers-alist exists but have
9725 ;; a nil value, so we exit from here, disable `ac-mode'
9726 ;; and run the command again with it original behavior.
9727 ;; `ac-mode' will be restored on exit.
9728 (return-from anything-completing-read-default
9729 (unwind-protect
9730 (progn
9731 (ac-mode -1)
9732 (apply completing-read-function def-args))
9733 (ac-mode 1))))
9734 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9735 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9736 (when (or (eq def-com 'completing-read)
9737 ;; All specialized functions are prefixed by "anything"
9738 (and (stringp str-defcom)
9739 (not (string-match "^anything" str-defcom))))
9740 (ac-mode -1))
9741 (unwind-protect
9742 (cond (;; An anything specialized function exists, run it.
9743 (and def-com anything-completion-mode)
9744 (apply def-com any-args))
9745 (;; Try to handle `ido-completing-read' everywhere.
9746 (and def-com (eq def-com 'ido-completing-read))
9747 (setcar (memq collection def-args)
9748 (all-completions "" collection predicate))
9749 (apply def-com def-args))
9750 (;; User set explicitely `completing-read' or something similar
9751 ;; in *read-handlers-alist, use this with exactly the same
9752 ;; args as in `completing-read'.
9753 ;; If we are here `anything-completion-mode' is now disabled.
9754 def-com
9755 (apply def-com def-args))
9756 (t ; Fall back to classic `anything-comp-read'.
9757 (anything-completing-read-default-1
9758 prompt collection predicate require-match
9759 initial-input hist def inherit-input-method
9760 str-command buf-name)))
9761 (ac-mode 1)
9762 ;; When exiting minibuffer, `this-command' is set to
9763 ;; `anything-exit-minibuffer', which is unwanted when starting
9764 ;; on another `completing-read', so restore `this-command' to
9765 ;; initial value when exiting.
9766 (setq this-command current-command))))
9768 (defun* anything-generic-read-file-name
9769 (prompt &optional dir default-filename mustmatch initial predicate)
9770 "An anything replacement of `read-file-name'."
9771 (declare (special anything-completion-mode))
9772 (let* ((default (and default-filename
9773 (if (listp default-filename)
9774 (car default-filename)
9775 default-filename)))
9776 (init (or default initial dir default-directory))
9777 (ini-input (and init (expand-file-name init)))
9778 (current-command this-command)
9779 (str-command (symbol-name current-command))
9780 (anything-file-completion-sources
9781 (cons str-command
9782 (remove str-command anything-file-completion-sources)))
9783 (buf-name (format "*ac-mode-%s*" str-command))
9784 (entry (assq current-command
9785 anything-completing-read-handlers-alist))
9786 (def-com (cdr-safe entry))
9787 (str-defcom (symbol-name def-com))
9788 (def-args (list prompt dir default-filename mustmatch initial predicate))
9789 ;; Append the two extra args needed to set the buffer and source name
9790 ;; in anything specialized functions.
9791 (any-args (append def-args (list str-command buf-name)))
9792 (ido-state ido-mode)
9793 anything-completion-mode-start-message ; Be quiet
9794 anything-completion-mode-quit-message ; Same here
9795 fname)
9796 ;; Some functions that normally call `completing-read' can switch
9797 ;; brutally to `read-file-name' (e.g find-tag), in this case
9798 ;; the anything specialized function will fail because it is build
9799 ;; for `completing-read', so set it to 'incompatible to be sure
9800 ;; we switch to `anything-c-read-file-name' and don't try to call it
9801 ;; with wrong number of args.
9802 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9803 (setq def-com 'incompatible))
9804 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9805 (unless (or (not entry) def-com)
9806 (return-from anything-generic-read-file-name
9807 (unwind-protect
9808 (progn
9809 (ac-mode -1)
9810 (apply read-file-name-function def-args))
9811 (ac-mode 1))))
9812 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9813 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9814 (when (or (eq def-com 'read-file-name)
9815 (eq def-com 'ido-read-file-name)
9816 (and (stringp str-defcom)
9817 (not (string-match "^anything" str-defcom))))
9818 (ac-mode -1))
9819 (unwind-protect
9820 (setq fname
9821 (cond (;; A specialized function exists, run it
9822 ;; with the two extra args specific to anything..
9823 (and def-com anything-completion-mode
9824 (not (eq def-com 'ido-read-file-name))
9825 (not (eq def-com 'incompatible)))
9826 (apply def-com any-args))
9827 (;; Def-com value is `ido-read-file-name'
9828 ;; run it with default args.
9829 (and def-com (eq def-com 'ido-read-file-name))
9830 (ido-mode 1)
9831 (apply def-com def-args))
9832 (;; Def-com value is `read-file-name'
9833 ;; run it with default args.
9834 (eq def-com 'read-file-name)
9835 (apply def-com def-args))
9836 (t ; Fall back to classic `anything-c-read-file-name'.
9837 (anything-c-read-file-name
9838 prompt
9839 :name str-command
9840 :buffer buf-name
9841 :initial-input (expand-file-name init dir)
9842 :alistp nil
9843 :test predicate))))
9844 (ac-mode 1)
9845 (ido-mode (if ido-state 1 -1))
9846 ;; Same comment as in `anything-completing-read-default'.
9847 (setq this-command current-command))
9848 (if (and mustmatch (not (file-exists-p fname)))
9849 (if (y-or-n-p "File does not exists, create buffer?")
9850 fname (error "Abort file does not exists"))
9851 fname)))
9853 ;;;###autoload
9854 (define-minor-mode anything-completion-mode
9855 "Toggle generic anything completion.
9857 All functions in Emacs that use `completing-read'
9858 or `read-file-name' and friends will use anything interface
9859 when this mode is turned on.
9860 However you can modify this behavior for functions of your choice
9861 with `anything-completing-read-handlers-alist'.
9863 Called with a positive arg, turn on unconditionally, with a
9864 negative arg turn off.
9865 You can turn it on with `ac-mode'.
9867 Some crap emacs functions may not be supported,
9868 e.g `ffap-alternate-file' and maybe others
9869 You can add such functions to `anything-completing-read-handlers-alist'
9870 with a nil value.
9872 Note: This mode will work only partially on Emacs23."
9873 :group 'anything
9874 :global t
9875 :lighter anything-completion-mode-string
9876 (declare (special completing-read-function))
9877 (if anything-completion-mode
9878 (progn
9879 (setq completing-read-function 'anything-completing-read-default
9880 read-file-name-function 'anything-generic-read-file-name)
9881 (message anything-completion-mode-start-message))
9882 (setq completing-read-function (and (fboundp 'completing-read-default)
9883 'completing-read-default)
9884 read-file-name-function (and (fboundp 'read-file-name-default)
9885 'read-file-name-default))
9886 (message anything-completion-mode-quit-message)))
9888 (defalias 'ac-mode 'anything-completion-mode)
9892 ;;; Eshell completion.
9894 ;; Enable like this in .emacs:
9896 ;; (add-hook 'eshell-mode-hook
9897 ;; #'(lambda ()
9898 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9900 (defvar anything-c-source-esh
9901 '((name . "Eshell completions")
9902 (init . (lambda ()
9903 (setq pcomplete-current-completions nil
9904 pcomplete-last-completion-raw nil)
9905 ;; Eshell-command add this hook in all minibuffers
9906 ;; Remove it for the anything one. (Fixed in Emacs24)
9907 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9908 (candidates . anything-esh-get-candidates)
9909 (action . anything-ec-insert))
9910 "Anything source for Eshell completion.")
9912 ;; Internal.
9913 (defvar anything-ec-target "")
9914 (defun anything-ec-insert (candidate)
9915 "Insert CANDIDATE at point.
9916 This is the same as `ac-insert', just inlined here for compatibility."
9917 (let ((pt (point)))
9918 (when (and anything-ec-target
9919 (search-backward anything-ec-target nil t)
9920 (string= (buffer-substring (point) pt) anything-ec-target))
9921 (delete-region (point) pt)))
9922 (insert candidate))
9924 (defun anything-esh-get-candidates ()
9925 "Get candidates for eshell completion using `pcomplete'."
9926 (catch 'pcompleted
9927 (let* ((pcomplete-stub)
9928 pcomplete-seen pcomplete-norm-func
9929 pcomplete-args pcomplete-last pcomplete-index
9930 (pcomplete-autolist pcomplete-autolist)
9931 (pcomplete-suffix-list pcomplete-suffix-list))
9932 (with-anything-current-buffer
9933 (loop
9934 with table = (pcomplete-completions)
9935 with entry = (condition-case nil
9936 ;; For Emacs24
9937 (try-completion anything-pattern (pcomplete-entries))
9938 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9939 (error
9941 (let ((fc (car (last (pcomplete-parse-arguments)))))
9942 ;; Check if last arg require fname completion.
9943 (and (file-name-directory fc) fc))))
9944 for i in (if (listp table) table ; Emacs23 or commands.
9945 (all-completions pcomplete-stub table)) ; Emacs24
9946 for file-cand = (and entry
9947 (if (file-remote-p i) i
9948 (expand-file-name i (file-name-directory entry))))
9949 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9950 collect file-cand into ls
9951 else collect i into ls
9952 finally return
9953 (if (and entry (not (string= entry "")) (file-exists-p entry))
9954 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9956 ;;; Eshell history.
9959 (defvar anything-c-source-eshell-history
9960 '((name . "Eshell history")
9961 (init . (lambda ()
9962 (let (eshell-hist-ignoredups)
9963 ;; Write the content's of ring to file.
9964 (eshell-write-history eshell-history-file-name t)
9965 (with-current-buffer (anything-candidate-buffer 'global)
9966 (insert-file-contents eshell-history-file-name)))
9967 ;; Same comment as in `anything-c-source-esh'
9968 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9969 (candidates-in-buffer)
9970 (filtered-candidate-transformer . (lambda (candidates sources)
9971 (reverse candidates)))
9972 (candidate-number-limit . 9999)
9973 (action . (lambda (candidate)
9974 (eshell-kill-input)
9975 (insert candidate))))
9976 "Anything source for Eshell history.")
9979 ;;; Show completion - an alternative of anything-show-completion.el.
9981 ;; Provide show completion with macro `with-anything-show-completion'.
9984 ;; Called each time cursor move in anything-buffer.
9985 (defun anything-c-show-completion ()
9986 (with-anything-current-buffer
9987 (overlay-put anything-c-show-completion-overlay
9988 'display (anything-get-selection))))
9990 (defun anything-c-show-completion-init-overlay (beg end)
9991 (and anything-c-turn-on-show-completion
9992 (setq anything-c-show-completion-overlay (make-overlay beg end))
9993 (overlay-put anything-c-show-completion-overlay
9994 'face 'anything-lisp-show-completion)))
9996 (defmacro with-anything-show-completion (beg end &rest body)
9997 "Show anything candidate in an overlay at point.
9998 BEG and END are the beginning and end position of the current completion
9999 in `anything-current-buffer'.
10000 BODY is an anything call where we want to enable show completion.
10001 If `anything-c-turn-on-show-completion' is nil just do nothing."
10002 (declare (indent 2) (debug t))
10003 `(let ((anything-move-selection-after-hook
10004 (and anything-c-turn-on-show-completion
10005 (append (list 'anything-c-show-completion)
10006 anything-move-selection-after-hook))))
10007 (unwind-protect
10008 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10009 ,@body)
10010 (and anything-c-turn-on-show-completion
10011 (delete-overlay anything-c-show-completion-overlay)))))
10014 ;;; Lisp symbol completion.
10017 ;;;###autoload
10018 (defun anything-lisp-completion-at-point ()
10019 "Anything lisp symbol completion at point."
10020 (interactive)
10021 (let* ((data (lisp-completion-at-point))
10022 (beg (car data))
10023 (end (point)) ; 'cadr data' is wrong when no space after point.
10024 (plist (nthcdr 3 data))
10025 (pred (plist-get plist :predicate))
10026 (lgst-len 0)
10027 (target (and beg end (buffer-substring-no-properties beg end)))
10028 (candidates (all-completions target (nth 2 data) pred))
10029 (anything-quit-if-no-candidate t)
10030 (anything-execute-action-at-once-if-one t)
10031 (anything-match-plugin-enabled
10032 (member 'anything-compile-source--match-plugin
10033 anything-compile-source-functions)))
10034 (if candidates
10035 (with-anything-show-completion beg end
10036 ;; Overlay is initialized now in anything-current-buffer.
10037 (anything
10038 :sources
10039 '((name . "Lisp completion")
10040 (init . (lambda ()
10041 (with-current-buffer (anything-candidate-buffer 'global)
10042 (loop for sym in candidates
10043 for len = (length sym)
10044 when (> len lgst-len) do (setq lgst-len len)
10045 do (insert (concat sym "\n"))))))
10046 (candidates-in-buffer)
10047 (persistent-action . anything-lisp-completion-persistent-action)
10048 (persistent-help . "Show brief doc in mode-line")
10049 (filtered-candidate-transformer anything-lisp-completion-transformer)
10050 (action . (lambda (candidate)
10051 (delete-region beg end)
10052 (insert candidate))))
10053 :input (if anything-match-plugin-enabled (concat target " ") target)))
10054 (message "[No Match]"))))
10056 (defun anything-lisp-completion-persistent-action (candidate)
10057 (let ((cursor-in-echo-area t)
10058 mode-line-in-non-selected-windows)
10059 (anything-c-show-info-in-mode-line
10060 (propertize
10061 (anything-c-get-first-line-documentation
10062 (intern candidate))
10063 'face 'anything-lisp-completion-info))))
10065 (defun anything-lisp-completion-transformer (candidates source)
10066 "Anything candidates transformer for lisp completion."
10067 (declare (special lgst-len))
10068 (loop for c in candidates
10069 for sym = (intern c)
10070 for annot = (cond ((commandp sym) " (Com)")
10071 ((fboundp sym) " (Fun)")
10072 ((boundp sym) " (Var)")
10073 ((facep sym) " (Face)"))
10074 for spaces = (make-string (- lgst-len (length c)) ? )
10075 collect (cons (concat c spaces annot) c)))
10077 (defun anything-c-get-first-line-documentation (sym)
10078 "Return first line documentation of symbol SYM.
10079 If SYM is not documented, return \"Not documented\"."
10080 (let ((doc (cond ((fboundp sym)
10081 (documentation sym t))
10082 ((boundp sym)
10083 (documentation-property sym 'variable-documentation t))
10084 ((facep sym)
10085 (face-documentation sym))
10086 (t nil))))
10087 (if (and doc (not (string= doc ""))
10088 ;; `documentation' return "\n\n(args...)"
10089 ;; for CL-style functions.
10090 (not (string-match-p "^\n\n" doc)))
10091 (car (split-string doc "\n"))
10092 "Not documented")))
10094 ;;; File completion.
10096 ;; Complete file name at point.
10097 (defun anything-c-thing-before-point ()
10098 "Get symbol name before point.
10099 Borrowed from anything-complete.el, inlined here for compatibility."
10100 (save-excursion
10101 (let ((beg (point)))
10102 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10103 (when (re-search-backward
10104 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10105 (buffer-substring-no-properties beg (match-end 0))))))
10107 ;;;###autoload
10108 (defun anything-c-complete-file-name-at-point ()
10109 "Complete file name at point."
10110 (interactive)
10111 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10112 (end (point))
10113 (beg (- (point) (length init)))
10114 (anything-quit-if-no-candidate t)
10115 (anything-execute-action-at-once-if-one t)
10116 completion)
10117 (with-anything-show-completion beg end
10118 (setq completion (anything-c-read-file-name "FileName: "
10119 :initial-input init)))
10120 (anything-c-insert-file-name-completion-at-point completion)))
10122 ;; Internal
10123 (defvar anything-lisp-completion-counter 0)
10124 ;;;###autoload
10125 (defun anything-lisp-completion-at-point-or-indent (arg)
10126 "First call indent and second call complete lisp symbol.
10127 The second call should happen before `anything-lisp-completion-or-indent-delay',
10128 after this delay, next call will indent again.
10129 After completion, next call is always indent.
10130 See that like click and double mouse click.
10131 One hit indent, two quick hits maybe indent and complete."
10132 (interactive "P")
10133 ;; Be sure `indent-for-tab-command' will not try
10134 ;; to use `completion-at-point'.
10135 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10136 t tab-always-indent)))
10137 (incf anything-lisp-completion-counter)
10138 (unwind-protect
10139 (if (> anything-lisp-completion-counter 1)
10140 (anything-lisp-completion-or-file-name-at-point)
10141 (indent-for-tab-command arg))
10142 ;; After `anything-lisp-completion-or-indent-delay' seconds
10143 ;; reset to 0.
10144 (run-with-timer anything-lisp-completion-or-indent-delay nil
10145 #'(lambda ()
10146 (setq anything-lisp-completion-counter 0)))
10147 ;; Always reset to 0 at second hit.
10148 (when (eq anything-lisp-completion-counter 2)
10149 (setq anything-lisp-completion-counter 0)))))
10151 ;;;###autoload
10152 (defun anything-lisp-completion-or-file-name-at-point ()
10153 "Complete lisp symbol or filename at point.
10154 Filename completion happen if filename is started in
10155 or between double quotes."
10156 (interactive)
10157 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10158 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10159 (save-excursion (search-backward "\"" (point-at-bol) t)))
10160 (anything-c-complete-file-name-at-point)
10161 (anything-lisp-completion-at-point))))
10163 (defun anything-c-apropos-init (test default)
10164 "Init candidates buffer for `anything-c-apropos' sources."
10165 (with-current-buffer (anything-candidate-buffer 'global)
10166 (goto-char (point-min))
10167 (when (and default (stringp default)
10168 ;; Some defaults args result as
10169 ;; (symbol-name nil) == "nil".
10170 ;; e.g debug-on-entry.
10171 (not (string= default "nil"))
10172 (funcall test (intern default)))
10173 (insert (concat default "\n")))
10174 (loop with all = (all-completions "" obarray test)
10175 for sym in all
10176 unless (and default (eq sym default))
10177 do (insert (concat sym "\n")))))
10180 ;;; Run Externals commands within Emacs with anything completion
10183 (defvar anything-external-command-history nil)
10185 (defun anything-c-external-commands-list-1 (&optional sort)
10186 "Returns a list of all external commands the user can execute.
10187 If `anything-c-external-commands-list' is non-nil it will
10188 return its contents. Else it calculates all external commands
10189 and sets `anything-c-external-commands-list'."
10190 (if anything-c-external-commands-list
10191 anything-c-external-commands-list
10192 (setq anything-c-external-commands-list
10193 (loop
10194 with paths = (split-string (getenv "PATH") path-separator)
10195 with completions = ()
10196 for dir in paths
10197 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10198 for lsdir = (loop for i in (directory-files dir t)
10199 for bn = (file-name-nondirectory i)
10200 when (and (not (member bn completions))
10201 (not (file-directory-p i))
10202 (file-executable-p i))
10203 collect bn)
10204 append lsdir into completions
10205 finally return (if sort (sort completions 'string-lessp) completions)))))
10207 (defun anything-run-or-raise (exe &optional file)
10208 "Generic command that run asynchronously EXE.
10209 If EXE is already running just jump to his window if `anything-raise-command'
10210 is non--nil.
10211 When FILE argument is provided run EXE with FILE.
10212 In this case EXE must be provided as \"EXE %s\"."
10213 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10214 "%s" "" exe))))
10215 (proc (if file (concat real-com " " file) real-com)))
10216 (if (get-process proc)
10217 (if anything-raise-command
10218 (shell-command (format anything-raise-command real-com))
10219 (error "Error: %s is already running" real-com))
10220 (when (loop for i in anything-c-external-commands-list thereis real-com)
10221 (message "Starting %s..." real-com)
10222 (if file
10223 (start-process-shell-command
10224 proc nil (format exe (shell-quote-argument file)))
10225 (start-process-shell-command proc nil real-com))
10226 (set-process-sentinel
10227 (get-process proc)
10228 #'(lambda (process event)
10229 (when (and (string= event "finished\n")
10230 anything-raise-command
10231 (not (anything-c-get-pid-from-process-name real-com)))
10232 (shell-command (format anything-raise-command "emacs")))
10233 (message "%s process...Finished." process))))
10234 (setq anything-c-external-commands-list
10235 (cons real-com
10236 (delete real-com anything-c-external-commands-list))))))
10240 ;;; Generic action functions
10243 (defun anything-c-file-buffers (filename)
10244 "Returns a list of buffer names corresponding to FILENAME."
10245 (let ((name (expand-file-name filename))
10246 (buf-list ()))
10247 (dolist (buf (buffer-list) buf-list)
10248 (let ((bfn (buffer-file-name buf)))
10249 (when (and bfn (string= name bfn))
10250 (push (buffer-name buf) buf-list))))))
10252 (defun anything-revert-buffer (candidate)
10253 (with-current-buffer candidate
10254 (when (or (buffer-modified-p)
10255 (not (verify-visited-file-modtime
10256 (get-buffer candidate))))
10257 (revert-buffer t t))))
10259 (defun anything-revert-marked-buffers (ignore)
10260 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10262 (defun anything-kill-marked-buffers (ignore)
10263 (mapc 'kill-buffer (anything-marked-candidates)))
10265 (defun anything-c-delete-file (file)
10266 "Delete the given file after querying the user.
10267 Ask to kill buffers associated with that file, too."
10268 (let ((buffers (anything-c-file-buffers file)))
10269 (if (< emacs-major-version 24)
10270 ;; `dired-delete-file' in Emacs versions < 24
10271 ;; doesn't support delete-by-moving-to-trash
10272 ;; so use `delete-directory' and `delete-file'
10273 ;; that handle it.
10274 (cond ((and (not (file-symlink-p file))
10275 (file-directory-p file)
10276 (directory-files file t dired-re-no-dot))
10277 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10278 (delete-directory file 'recursive)))
10279 ((and (not (file-symlink-p file))
10280 (file-directory-p file))
10281 (delete-directory file))
10282 (t (delete-file file)))
10283 (dired-delete-file
10284 file 'dired-recursive-deletes delete-by-moving-to-trash))
10285 (when buffers
10286 (dolist (buf buffers)
10287 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10288 (kill-buffer buf))))))
10290 (defun anything-get-mailcap-for-file (filename)
10291 "Get the command to use for FILENAME from mailcap files.
10292 The command is like <command %s> and is meant to use with `format'."
10293 (mailcap-parse-mailcaps)
10294 (let* ((ext (file-name-extension filename))
10295 (mime (when ext (mailcap-extension-to-mime ext)))
10296 (result (when mime (mailcap-mime-info mime))))
10297 ;; If elisp file have no associations in .mailcap
10298 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10299 (when (stringp result) result)))
10301 (defun anything-get-default-program-for-file (filename)
10302 "Try to find a default program to open FILENAME.
10303 Try first in `anything-c-external-programs-associations' and then in mailcap file
10304 if nothing found return nil."
10305 (let* ((ext (file-name-extension filename))
10306 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10307 (cond ((and def-prog (not (string= def-prog "")))
10308 (concat def-prog " %s"))
10309 ((and anything-c-default-external-file-browser
10310 (file-directory-p filename))
10311 (concat anything-c-default-external-file-browser " %s"))
10312 (t (anything-get-mailcap-for-file filename)))))
10314 (defun anything-c-open-file-externally (file)
10315 "Open FILE with an external program.
10316 Try to guess which program to use with `anything-get-default-program-for-file'.
10317 If not found or a prefix arg is given query the user which tool to use."
10318 (let* ((fname (expand-file-name file))
10319 (collection (anything-c-external-commands-list-1 'sort))
10320 (def-prog (anything-get-default-program-for-file fname))
10321 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10322 ;; Prefix arg or no default program.
10323 (prog1
10324 (anything-comp-read
10325 "Program: " collection
10326 :must-match t
10327 :name "Open file Externally"
10328 :history anything-external-command-history)
10329 ;; Always prompt to set this program as default.
10330 (setq def-prog nil))
10331 ;; No prefix arg or default program exists.
10332 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10333 (program (concat real-prog-name " %s")))
10334 (unless (or def-prog ; Association exists, no need to record it.
10335 ;; Don't try to record non--filenames associations (e.g urls).
10336 (not (file-exists-p fname)))
10337 (when
10338 (y-or-n-p
10339 (format
10340 "Do you want to make `%s' the default program for this kind of files? "
10341 real-prog-name))
10342 (anything-aif (assoc (file-name-extension fname)
10343 anything-c-external-programs-associations)
10344 (setq anything-c-external-programs-associations
10345 (delete it anything-c-external-programs-associations)))
10346 (push (cons (file-name-extension fname)
10347 (read-string
10348 "Program (Add args maybe and confirm): " real-prog-name))
10349 anything-c-external-programs-associations)
10350 (customize-save-variable 'anything-c-external-programs-associations
10351 anything-c-external-programs-associations)))
10352 (anything-run-or-raise program file)
10353 (setq anything-external-command-history
10354 (cons real-prog-name
10355 (delete real-prog-name
10356 (loop for i in anything-external-command-history
10357 when (executable-find i) collect i))))))
10359 (defun anything-c-find-file-or-marked (candidate)
10360 "Open file CANDIDATE or open anything marked files in background."
10361 (let ((marked (anything-marked-candidates))
10362 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10363 (find-file-wildcards nil))
10364 (if (> (length marked) 1)
10365 ;; Open all marked files in background and display
10366 ;; the first one.
10367 (progn (mapc 'find-file-noselect (cdr marked))
10368 (find-file (car marked)))
10369 (if (and (not (file-exists-p candidate))
10370 (and ffap-url-regexp
10371 (not (string-match ffap-url-regexp candidate)))
10372 (string-match "/$" candidate))
10373 ;; A a non--existing filename ending with /
10374 ;; Create a directory and jump to it.
10375 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10376 (let ((dirfname (directory-file-name candidate)))
10377 (if (file-exists-p dirfname)
10378 (error "Mkdir: Unable to create directory `%s': file exists."
10379 (anything-c-basename dirfname))
10380 (make-directory candidate 'parent)))
10381 (anything-find-files-1 candidate))
10382 ;; A non--existing filename NOT ending with / or
10383 ;; an existing filename, create or jump to it.
10384 (find-file-at-point (car marked))))))
10386 (defun anything-delete-marked-files (ignore)
10387 (let* ((files (anything-marked-candidates))
10388 (len (length files)))
10389 (if (not (y-or-n-p
10390 (format "Delete *%s File(s):\n%s"
10392 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10393 (message "(No deletions performed)")
10394 (dolist (i files)
10395 (set-text-properties 0 (length i) nil i)
10396 (anything-c-delete-file i))
10397 (message "%s File(s) deleted" len))))
10399 (defun anything-ediff-marked-buffers (candidate &optional merge)
10400 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10401 With optional arg MERGE call `ediff-merge-buffers'."
10402 (let ((lg-lst (length (anything-marked-candidates)))
10403 buf1 buf2)
10404 (case lg-lst
10406 (error "Error:You have to mark at least 1 buffer"))
10408 (setq buf1 anything-current-buffer
10409 buf2 (first (anything-marked-candidates))))
10411 (setq buf1 (first (anything-marked-candidates))
10412 buf2 (second (anything-marked-candidates))))
10414 (error "Error:To much buffers marked!")))
10415 (if merge
10416 (ediff-merge-buffers buf1 buf2)
10417 (ediff-buffers buf1 buf2))))
10419 (defun anything-ediff-marked-buffers-merge (candidate)
10420 "Ediff merge `anything-current-buffer' with CANDIDATE.
10421 See `anything-ediff-marked-buffers'."
10422 (anything-ediff-marked-buffers candidate t))
10424 (defun anything-bookmark-get-bookmark-from-name (bmk)
10425 "Return bookmark name even if it is a bookmark with annotation.
10426 e.g prepended with *.
10427 Return nil if bmk is not a valid bookmark."
10428 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10429 (if (assoc bookmark bookmark-alist)
10430 bookmark
10431 (when (assoc bmk bookmark-alist)
10432 bmk))))
10434 (defun anything-delete-marked-bookmarks (ignore)
10435 "Delete this bookmark or all marked bookmarks."
10436 (dolist (i (anything-marked-candidates))
10437 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10438 'batch)))
10440 (defun anything-require-or-error (feature function)
10441 (or (require feature nil t)
10442 (error "Need %s to use `%s'." feature function)))
10444 (defun anything-find-buffer-on-elscreen (candidate)
10445 "Open buffer in new screen, if marked buffers open all in elscreens."
10446 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10447 (anything-aif (anything-marked-candidates)
10448 (dolist (i it)
10449 (let ((target-screen (elscreen-find-screen-by-buffer
10450 (get-buffer i) 'create)))
10451 (elscreen-goto target-screen)))
10452 (let ((target-screen (elscreen-find-screen-by-buffer
10453 (get-buffer candidate) 'create)))
10454 (elscreen-goto target-screen))))
10456 (defun anything-elscreen-find-file (file)
10457 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10458 (elscreen-find-file file))
10460 ;;;###autoload
10461 (defun w32-shell-execute-open-file (file)
10462 (interactive "fOpen file:")
10463 (with-no-warnings
10464 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10465 "/" "\\"
10466 (replace-regexp-in-string ; strip cygdrive paths
10467 "/cygdrive/\\(.\\)" "\\1:"
10468 file nil nil) nil t))))
10470 (defun anything-c-open-file-with-default-tool (file)
10471 "Open FILE with the default tool on this platform."
10472 (if (eq system-type 'windows-nt)
10473 (w32-shell-execute-open-file file)
10474 (start-process "anything-c-open-file-with-default-tool"
10476 (cond ((eq system-type 'gnu/linux)
10477 "xdg-open")
10478 ((or (eq system-type 'darwin) ;; Mac OS X
10479 (eq system-type 'macos)) ;; Mac OS 9
10480 "open"))
10481 file)))
10483 (defun anything-c-open-dired (file)
10484 "Opens a dired buffer in FILE's directory. If FILE is a
10485 directory, open this directory."
10486 (if (file-directory-p file)
10487 (dired file)
10488 (dired (file-name-directory file))
10489 (dired-goto-file file)))
10491 (defun anything-c-display-to-real-line (candidate)
10492 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10493 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10494 (error "Line number not found")))
10496 (defun anything-c-action-line-goto (lineno-and-content)
10497 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10498 (append lineno-and-content
10499 (list (if (and (anything-attr-defined 'target-file)
10500 (not anything-in-persistent-action))
10501 'find-file-other-window
10502 'find-file)))))
10504 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10505 (apply #'anything-goto-file-line
10506 (if (stringp file-line-content)
10507 ;; Case: filtered-candidate-transformer is skipped
10508 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10509 file-line-content)))
10511 (require 'compile)
10512 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10513 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10515 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10516 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10517 (let ((filename (match-string 1 candidate))
10518 (lineno (match-string 2 candidate))
10519 (content (match-string 3 candidate)))
10520 (cons (format "%s:%s\n %s"
10521 (propertize filename 'face compilation-info-face)
10522 (propertize lineno 'face compilation-line-face)
10523 content)
10524 (list (expand-file-name
10525 filename
10526 (or (anything-interpret-value (anything-attr 'default-directory))
10527 (and (anything-candidate-buffer)
10528 (buffer-local-value
10529 'default-directory (anything-candidate-buffer)))))
10530 (string-to-number lineno) content)))))
10532 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10533 (anything-aif (anything-attr 'before-jump-hook)
10534 (funcall it))
10535 (when file (funcall find-file-function file))
10536 (if (anything-attr-defined 'adjust)
10537 (anything-c-goto-line-with-adjustment lineno content)
10538 (anything-goto-line lineno))
10539 (unless (anything-attr-defined 'recenter)
10540 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10541 (anything-aif (anything-attr 'after-jump-hook)
10542 (funcall it))
10543 (when anything-in-persistent-action
10544 (anything-match-line-color-current-line)))
10546 (defun anything-find-file-as-root (candidate)
10547 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10549 (defun anything-find-many-files (ignore)
10550 (mapc 'find-file (anything-marked-candidates)))
10552 ;; borrowed from etags.el
10553 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10554 (defun anything-c-goto-line-with-adjustment (line line-content)
10555 (let ((startpos)
10556 offset found pat)
10557 ;; This constant is 1/2 the initial search window.
10558 ;; There is no sense in making it too small,
10559 ;; since just going around the loop once probably
10560 ;; costs about as much as searching 2000 chars.
10561 (setq offset 1000
10562 found nil
10563 pat (concat (if (eq selective-display t)
10564 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10565 (regexp-quote line-content)))
10566 ;; If no char pos was given, try the given line number.
10567 (setq startpos (progn (anything-goto-line line) (point)))
10568 (or startpos (setq startpos (point-min)))
10569 ;; First see if the tag is right at the specified location.
10570 (goto-char startpos)
10571 (setq found (looking-at pat))
10572 (while (and (not found)
10573 (progn
10574 (goto-char (- startpos offset))
10575 (not (bobp))))
10576 (setq found
10577 (re-search-forward pat (+ startpos offset) t)
10578 offset (* 3 offset))) ; expand search window
10579 (or found
10580 (re-search-forward pat nil t)
10581 (error "not found")))
10582 ;; Position point at the right place
10583 ;; if the search string matched an extra Ctrl-m at the beginning.
10584 (and (eq selective-display t)
10585 (looking-at "\^m")
10586 (forward-char 1))
10587 (beginning-of-line))
10589 (anything-document-attribute 'default-directory "type . file-line"
10590 "`default-directory' to interpret file.")
10591 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10592 "Function to call before jumping to the target location.")
10593 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10594 "Function to call after jumping to the target location.")
10595 (anything-document-attribute 'adjust "type . file-line"
10596 "Search around line matching line contents.")
10597 (anything-document-attribute 'recenter "type . file-line / line"
10598 "`recenter' after jumping.")
10599 (anything-document-attribute 'target-file "type . line"
10600 "Goto line of target-file.")
10602 ;;;###autoload
10603 (defun anything-c-call-interactively (cmd-or-name)
10604 "Execute CMD-OR-NAME as Emacs command.
10605 It is added to `extended-command-history'.
10606 `anything-current-prefix-arg' is used as the command's prefix argument."
10607 (setq extended-command-history
10608 (cons (anything-c-stringify cmd-or-name)
10609 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10610 (let ((current-prefix-arg anything-current-prefix-arg)
10611 (cmd (anything-c-symbolify cmd-or-name)))
10612 (if (stringp (symbol-function cmd))
10613 (execute-kbd-macro (symbol-function cmd))
10614 (setq this-command cmd)
10615 (call-interactively cmd))))
10617 ;;;###autoload
10618 (defun anything-c-set-variable (var)
10619 "Set value to VAR interactively."
10620 (interactive)
10621 (let ((sym (anything-c-symbolify var)))
10622 (set sym (eval-minibuffer (format "Set %s: " var)
10623 (prin1-to-string (symbol-value sym))))))
10624 ;; (setq hh 12)
10625 ;; (anything-c-set-variable 'hh)
10629 ;;; Persistent Action Helpers
10632 (defvar anything-match-line-overlay-face nil)
10633 (defvar anything-match-line-overlay nil)
10635 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10636 "Highlight and underline current position"
10637 (let ((args (list (or start (line-beginning-position))
10638 (or end (1+ (line-end-position)))
10639 buf)))
10640 (if (not anything-match-line-overlay)
10641 (setq anything-match-line-overlay (apply 'make-overlay args))
10642 (apply 'move-overlay anything-match-line-overlay args)))
10643 (overlay-put anything-match-line-overlay
10644 'face (or face anything-match-line-overlay-face))
10645 (when rec
10646 (goto-char start)
10647 (recenter)))
10649 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10652 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10654 (defun anything-match-line-cleanup ()
10655 (when anything-match-line-overlay
10656 (delete-overlay anything-match-line-overlay)
10657 (setq anything-match-line-overlay nil)))
10659 (defun anything-match-line-update ()
10660 (when anything-match-line-overlay
10661 (delete-overlay anything-match-line-overlay)
10662 (anything-match-line-color-current-line)))
10664 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10665 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10668 ;;; Actions Transformers
10671 ;;; Files
10672 (defun anything-c-transform-file-load-el (actions candidate)
10673 "Add action to load the file CANDIDATE if it is an emacs lisp
10674 file. Else return ACTIONS unmodified."
10675 (if (member (file-name-extension candidate) '("el" "elc"))
10676 (append actions '(("Load Emacs Lisp File" . load-file)))
10677 actions))
10679 (defun anything-c-transform-file-browse-url (actions candidate)
10680 "Add an action to browse the file CANDIDATE if it in a html
10681 file or URL. Else return ACTIONS unmodified."
10682 (let ((browse-action '("Browse with Browser" . browse-url)))
10683 (cond ((string-match "^http\\|^ftp" candidate)
10684 (cons browse-action actions))
10685 ((string-match "\\.html?$" candidate)
10686 (append actions (list browse-action)))
10687 (t actions))))
10689 ;;; Function
10690 (defun anything-c-transform-function-call-interactively (actions candidate)
10691 "Add an action to call the function CANDIDATE interactively if
10692 it is a command. Else return ACTIONS unmodified."
10693 (if (commandp (intern-soft candidate))
10694 (append actions '(("Call Interactively"
10696 anything-c-call-interactively)))
10697 actions))
10699 ;;;; S-Expressions
10700 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10701 "If CANDIDATE's `car' is a command, then add an action to
10702 evaluate it and put it onto the `command-history'."
10703 (if (commandp (car (read candidate)))
10704 ;; Make it first entry
10705 (cons '("Eval and put onto command-history" .
10706 (lambda (sexp)
10707 (let ((sym (read sexp)))
10708 (eval sym)
10709 (setq command-history
10710 (cons sym command-history)))))
10711 actions)
10712 actions))
10715 ;;; Candidate Transformers
10718 ;;; Buffers
10719 (defun anything-c-skip-boring-buffers (buffers)
10720 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10722 (defun anything-c-skip-current-buffer (buffers)
10723 (if anything-allow-skipping-current-buffer
10724 (remove (buffer-name anything-current-buffer) buffers)
10725 buffers))
10727 (defun anything-c-shadow-boring-buffers (buffers)
10728 "Buffers matching `anything-c-boring-buffer-regexp' will be
10729 displayed with the `file-name-shadow' face if available."
10730 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10732 (defvar anything-c-buffer-display-string-functions
10733 '(anything-c-buffer-display-string--compilation
10734 anything-c-buffer-display-string--shell
10735 anything-c-buffer-display-string--eshell)
10736 "Functions to setup display string for buffer.
10738 Function has one argument, buffer name.
10739 If it returns string, use it.
10740 If it returns nil, display buffer name.
10741 See `anything-c-buffer-display-string--compilation' for example.")
10743 (defun anything-c-transform-buffer-display-string (buffers)
10744 "Setup display string for buffer candidates
10745 using `anything-c-buffer-display-string-functions'."
10746 (loop for buf in buffers
10747 if (consp buf)
10748 collect buf
10749 else
10750 for disp = (progn (set-buffer buf)
10751 (run-hook-with-args-until-success
10752 'anything-c-buffer-display-string-functions buf))
10753 collect (if disp (cons disp buf) buf)))
10755 (defun anything-c-buffer-display-string--compilation (buf)
10756 (anything-aif (car compilation-arguments)
10757 (format "%s: %s [%s]" buf it default-directory)))
10759 (defun anything-c-buffer-display-string--eshell (buf)
10760 (declare (special eshell-history-ring))
10761 (when (eq major-mode 'eshell-mode)
10762 (format "%s: %s [%s]" buf
10763 (ignore-errors (ring-ref eshell-history-ring 0))
10764 default-directory)))
10766 (defun anything-c-buffer-display-string--shell (buf)
10767 (when (eq major-mode 'shell-mode)
10768 (format "%s: %s [%s]" buf
10769 (ignore-errors (ring-ref comint-input-ring 0))
10770 default-directory)))
10772 ;;; Files
10773 (defun anything-c-shadow-boring-files (files)
10774 "Files matching `anything-c-boring-file-regexp' will be
10775 displayed with the `file-name-shadow' face if available."
10776 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10778 (defun anything-c-skip-boring-files (files)
10779 "Files matching `anything-c-boring-file-regexp' will be skipped."
10780 (anything-c-skip-entries files anything-c-boring-file-regexp))
10781 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10783 (defun anything-c-skip-current-file (files)
10784 "Current file will be skipped."
10785 (remove (buffer-file-name anything-current-buffer) files))
10787 (defun anything-c-w32-pathname-transformer (args)
10788 "Change undesirable features of windows pathnames to ones more acceptable to
10789 other candidate transformers."
10790 (if (eq system-type 'windows-nt)
10791 (mapcar (lambda (x)
10792 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10793 (mapcar (lambda (y)
10794 (replace-regexp-in-string "\\\\" "/" y)) args))
10795 args))
10797 (defun anything-c-shorten-home-path (files)
10798 "Replaces /home/user with ~."
10799 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10800 (getenv "HOME"))))
10801 (mapcar (lambda (file)
10802 (if (and (stringp file) (string-match home file))
10803 (cons (replace-match "~" nil nil file) file)
10804 file))
10805 files)))
10807 ;;; Functions
10808 (defun anything-c-mark-interactive-functions (functions)
10809 "Mark interactive functions (commands) with (i) after the function name."
10810 (let (list)
10811 (loop for function in functions
10812 do (push (cons (concat function
10813 (when (commandp (intern-soft function)) " (i)"))
10814 function)
10815 list)
10816 finally (return (nreverse list)))))
10819 ;;; Adaptive Sorting of Candidates
10822 ;; Internal
10823 (defvar anything-c-adaptive-done nil
10824 "nil if history information is not yet stored for the current
10825 selection.")
10827 (defvar anything-c-adaptive-history nil
10828 "Contains the stored history information.
10829 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10831 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10832 "Reset `anything-c-adaptive-done' when anything is started."
10833 (when anything-c-use-adaptative-sorting
10834 (setq anything-c-adaptive-done nil)))
10836 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10837 "Store history information when action is executed on selected candidate."
10838 (when anything-c-use-adaptative-sorting
10839 (anything-c-adaptive-store-selection)))
10841 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10842 "Store history information when the user goes to the action buffer."
10843 (when anything-c-use-adaptative-sorting
10844 (anything-c-adaptive-store-selection)))
10846 (defun anything-c-source-use-adaptative-p (&optional source-name)
10847 "Return current source only if it use adaptative history, nil otherwise."
10848 (when anything-c-use-adaptative-sorting
10849 (let* ((source (or source-name (anything-get-current-source)))
10850 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10851 (assoc (assoc-default 'type source)
10852 anything-type-attributes))
10853 (assoc-default 'candidate-transformer
10854 (assoc (assoc-default 'type source)
10855 anything-type-attributes))
10856 (assoc-default 'filtered-candidate-transformer source)
10857 (assoc-default 'candidate-transformer source))))
10858 (if (listp adapt-source)
10859 (when (member 'anything-c-adaptive-sort adapt-source) source)
10860 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10862 (defun anything-c-adaptive-store-selection ()
10863 "Store history information for the selected candidate."
10864 (unless anything-c-adaptive-done
10865 (setq anything-c-adaptive-done t)
10866 (let ((source (anything-c-source-use-adaptative-p)))
10867 (when source
10868 (let* ((source-name (or (assoc-default 'type source)
10869 (assoc-default 'name source)))
10870 (source-info (or (assoc source-name anything-c-adaptive-history)
10871 (progn
10872 (push (list source-name) anything-c-adaptive-history)
10873 (car anything-c-adaptive-history))))
10874 (selection (anything-get-selection))
10875 (selection-info (progn
10876 (setcdr source-info
10877 (cons
10878 (let ((found (assoc selection (cdr source-info))))
10879 (if (not found)
10880 ;; new entry
10881 (list selection)
10883 ;; move entry to the beginning of the
10884 ;; list, so that it doesn't get
10885 ;; trimmed when the history is
10886 ;; truncated
10887 (setcdr source-info
10888 (delete found (cdr source-info)))
10889 found))
10890 (cdr source-info)))
10891 (cadr source-info)))
10892 (pattern-info (progn
10893 (setcdr selection-info
10894 (cons
10895 (let ((found (assoc anything-pattern (cdr selection-info))))
10896 (if (not found)
10897 ;; new entry
10898 (cons anything-pattern 0)
10900 ;; move entry to the beginning of the
10901 ;; list, so if two patterns used the
10902 ;; same number of times then the one
10903 ;; used last appears first in the list
10904 (setcdr selection-info
10905 (delete found (cdr selection-info)))
10906 found))
10907 (cdr selection-info)))
10908 (cadr selection-info))))
10910 ;; increase usage count
10911 (setcdr pattern-info (1+ (cdr pattern-info)))
10913 ;; truncate history if needed
10914 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10915 (setcdr selection-info
10916 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10918 (defun anything-c-adaptative-maybe-load-history ()
10919 (when (and anything-c-use-adaptative-sorting
10920 (file-readable-p anything-c-adaptive-history-file))
10921 (load-file anything-c-adaptive-history-file)))
10923 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10924 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10926 (defun anything-c-adaptive-save-history (&optional arg)
10927 "Save history information to file given by `anything-c-adaptive-history-file'."
10928 (interactive "p")
10929 (when anything-c-use-adaptative-sorting
10930 (with-temp-buffer
10931 (insert
10932 ";; -*- mode: emacs-lisp -*-\n"
10933 ";; History entries used for anything adaptive display.\n")
10934 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10935 (current-buffer))
10936 (insert ?\n)
10937 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10938 (unless arg 'quiet)))))
10940 (defun anything-c-adaptive-sort (candidates source)
10941 "Sort the CANDIDATES for SOURCE by usage frequency.
10942 This is a filtered candidate transformer you can use for the
10943 attribute `filtered-candidate-transformer' of a source in
10944 `anything-sources' or a type in `anything-type-attributes'."
10945 (let* ((source-name (or (assoc-default 'type source)
10946 (assoc-default 'name source)))
10947 (source-info (assoc source-name anything-c-adaptive-history)))
10948 (if source-info
10949 (let ((usage
10950 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10951 ;; pairs
10952 (mapcar (lambda (candidate-info)
10953 (let ((count 0))
10954 (dolist (pattern-info (cdr candidate-info))
10955 (if (not (equal (car pattern-info)
10956 anything-pattern))
10957 (incf count (cdr pattern-info))
10959 ;; if current pattern is equal to the previously
10960 ;; used one then this candidate has priority
10961 ;; (that's why its count is boosted by 10000) and
10962 ;; it only has to compete with other candidates
10963 ;; which were also selected with the same pattern
10964 (setq count (+ 10000 (cdr pattern-info)))
10965 (return)))
10966 (cons (car candidate-info) count)))
10967 (cdr source-info)))
10968 sorted)
10969 (if (and usage (consp usage))
10970 ;; sort the list in descending order, so candidates with highest
10971 ;; priorty come first
10972 (progn
10973 (setq usage (sort usage (lambda (first second)
10974 (> (cdr first) (cdr second)))))
10976 ;; put those candidates first which have the highest usage count
10977 (dolist (info usage)
10978 (when (member* (car info) candidates
10979 :test 'anything-c-adaptive-compare)
10980 (push (car info) sorted)
10981 (setq candidates (remove* (car info) candidates
10982 :test 'anything-c-adaptive-compare))))
10984 ;; and append the rest
10985 (append (reverse sorted) candidates nil))
10986 (message "Your `%s' is maybe corrupted or too old, \
10987 you should reinitialize it with `anything-c-reset-adaptative-history'"
10988 anything-c-adaptive-history-file)
10989 (sit-for 1)
10990 candidates))
10991 ;; if there is no information stored for this source then do nothing
10992 candidates)))
10994 ;;;###autoload
10995 (defun anything-c-reset-adaptative-history ()
10996 "Delete all `anything-c-adaptive-history' and his file.
10997 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10998 (interactive)
10999 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11000 (setq anything-c-adaptive-history nil)
11001 (delete-file anything-c-adaptive-history-file)))
11003 (defun anything-c-adaptive-compare (x y)
11004 "Compare candidates X and Y taking into account that the
11005 candidate can be in (DISPLAY . REAL) format."
11006 (equal (if (listp x)
11007 (cdr x)
11009 (if (listp y)
11010 (cdr y)
11011 y)))
11015 ;;; Outliner
11018 (defvar anything-outline-goto-near-line-flag t)
11019 (defvar anything-outline-using nil)
11020 (defun anything-after-update-hook--outline ()
11021 (if (and (eq anything-outline-using t)
11022 (eq anything-outline-goto-near-line-flag t))
11023 (anything-outline-goto-near-line)))
11024 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11026 (defun anything-outline-goto-near-line ()
11027 (with-anything-window
11028 ;; TODO need consideration whether to update position by every input.
11029 (when t ; (equal anything-pattern "")
11030 (anything-goto-line 2)
11031 (let ((lineno (with-anything-current-buffer
11032 (line-number-at-pos (car anything-current-position)))))
11033 (block exit
11034 (while (<= (progn (skip-chars-forward " ")
11035 (or (number-at-point) lineno))
11036 lineno)
11037 (forward-line 1)
11038 (when (eobp)
11039 (forward-line -1)
11040 (return-from exit))))
11041 (forward-line -1)
11042 (and (bobp) (forward-line 1))
11043 (and (anything-pos-header-line-p) (forward-line -2))
11044 (anything-mark-current-line)))))
11048 ;;; Plug-in
11051 ;; Plug-in: info-index
11052 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11053 (let (result)
11054 (unless (anything-candidate-buffer)
11055 (save-window-excursion
11056 (info file)
11057 (let (Info-history
11058 (tobuf (anything-candidate-buffer 'global))
11059 (infobuf (current-buffer))
11060 s e)
11061 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11062 (Info-goto-node node)
11063 (goto-char (point-min))
11064 (while (search-forward "\n* " nil t)
11065 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11066 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11067 (setq s (point-at-bol)
11068 e (point-at-eol))
11069 (with-current-buffer tobuf
11070 (insert-buffer-substring infobuf s e)
11071 (insert "\n"))))))))))
11073 (defun anything-c-info-goto (node-line)
11074 (Info-goto-node (car node-line))
11075 (anything-goto-line (cdr node-line)))
11077 (defun anything-c-info-display-to-real (line)
11078 (and (string-match
11079 ;; This regexp is stolen from Info-apropos-matches
11080 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11081 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11082 (string-to-number (or (match-string 3 line) "1")))))
11084 (defun anything-c-make-info-source (source file)
11085 `(,@source
11086 (name . ,(concat "Info Index: " file))
11087 (info-file . ,file)
11088 (init . anything-c-info-init)
11089 (display-to-real . anything-c-info-display-to-real)
11090 (get-line . buffer-substring)
11091 (candidates-in-buffer)
11092 (action ("Goto node" . anything-c-info-goto))))
11094 (defun anything-compile-source--info-index (source)
11095 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11096 (anything-c-make-info-source source it)
11097 source))
11098 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11100 (anything-document-attribute 'info-index "info-index plugin"
11101 "Create a source of info index very easily.
11103 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11105 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11106 "Index nodes of info file.
11108 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11109 Some info files are missing index specification.
11111 ex. See `anything-c-source-info-screen'.")
11113 ;; Plug-in: candidates-file
11114 (defun anything-compile-source--candidates-file (source)
11115 (if (assoc-default 'candidates-file source)
11116 `((init anything-p-candidats-file-init
11117 ,@(let ((orig-init (assoc-default 'init source)))
11118 (cond ((null orig-init) nil)
11119 ((functionp orig-init) (list orig-init))
11120 (t orig-init))))
11121 (candidates-in-buffer)
11122 ,@source)
11123 source))
11124 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11126 (defun anything-p-candidats-file-init ()
11127 (destructuring-bind (file &optional updating)
11128 (anything-mklist (anything-attr 'candidates-file))
11129 (setq file (anything-interpret-value file))
11130 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11131 (when updating
11132 (buffer-disable-undo)
11133 (font-lock-mode -1)
11134 (auto-revert-mode 1)))))
11136 (anything-document-attribute 'candidates-file "candidates-file plugin"
11137 "Use a file as the candidates buffer.
11139 1st argument is a filename, string or function name or variable name.
11140 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11142 ;; Plug-in: headline
11143 (defun anything-compile-source--anything-headline (source)
11144 (if (assoc-default 'headline source)
11145 (append '((init . anything-headline-init)
11146 (get-line . buffer-substring)
11147 (type . line))
11148 source
11149 '((candidates-in-buffer)
11150 (persistent-help . "Show this line")))
11151 source))
11152 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11154 (defun anything-headline-init ()
11155 (when (and (anything-current-buffer-is-modified)
11156 (with-anything-current-buffer
11157 (eval (or (anything-attr 'condition) t))))
11158 (anything-headline-make-candidate-buffer
11159 (anything-interpret-value (anything-attr 'headline))
11160 (anything-interpret-value (anything-attr 'subexp)))))
11162 (anything-document-attribute 'headline "Headline plug-in"
11163 "Regexp string for anything-headline to scan.")
11164 (anything-document-attribute 'condition "Headline plug-in"
11165 "A sexp representing the condition to use anything-headline.")
11166 (anything-document-attribute 'subexp "Headline plug-in"
11167 "Display (match-string-no-properties subexp).")
11169 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11170 ;; of regexps.
11172 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11173 ;; 2. Sort this list by start-of-match.
11174 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11176 ;; It's quite brilliantly written.
11180 (defun anything-headline-get-candidates (regexp subexp)
11181 (with-anything-current-buffer
11182 (save-excursion
11183 (goto-char (point-min))
11184 (if (functionp regexp) (setq regexp (funcall regexp)))
11185 (let (hierarchy curhead)
11186 (flet ((matched ()
11187 (if (numberp subexp)
11188 (cons (match-string-no-properties subexp) (match-beginning subexp))
11189 (cons (buffer-substring (point-at-bol) (point-at-eol))
11190 (point-at-bol))))
11191 (hierarchies (headlines)
11192 (1+ (loop for (_ . hierarchy) in headlines
11193 maximize hierarchy)))
11194 (vector-0-n (v n)
11195 (loop for i from 0 to hierarchy
11196 collecting (aref curhead i)))
11197 (arrange (headlines)
11198 (unless (null headlines) ; FIX headlines empty bug!
11199 (loop with curhead = (make-vector (hierarchies headlines) "")
11200 for ((str . pt) . hierarchy) in headlines
11201 do (aset curhead hierarchy str)
11202 collecting
11203 (cons
11204 (format "H%d:%s" (1+ hierarchy)
11205 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11206 pt)))))
11207 (if (listp regexp)
11208 (arrange
11209 (sort
11210 (loop for re in regexp
11211 for hierarchy from 0
11212 do (goto-char (point-min))
11213 appending
11214 (loop
11215 while (re-search-forward re nil t)
11216 collect (cons (matched) hierarchy)))
11217 (lambda (a b) (> (cdar b) (cdar a)))))
11218 (loop while (re-search-forward regexp nil t)
11219 collect (matched))))))))
11222 (defun anything-headline-make-candidate-buffer (regexp subexp)
11223 (with-current-buffer (anything-candidate-buffer 'local)
11224 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11225 do (insert
11226 (format "%5d:%s\n"
11227 (with-anything-current-buffer
11228 (line-number-at-pos pos))
11229 content)))))
11231 (defun anything-headline-goto-position (pos recenter)
11232 (goto-char pos)
11233 (unless recenter
11234 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11237 ;; Plug-in: persistent-help
11238 (defun anything-compile-source--persistent-help (source)
11239 (append source '((header-line . anything-persistent-help-string))))
11240 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11242 (defun anything-persistent-help-string ()
11243 (substitute-command-keys
11244 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11245 (or (anything-interpret-value (anything-attr 'persistent-help))
11246 (anything-aif (or (assoc-default 'persistent-action
11247 (anything-get-current-source))
11248 (assoc-default 'action
11249 (anything-get-current-source)))
11250 (cond ((symbolp it) (symbol-name it))
11251 ((listp it) (or (ignore-errors (caar it)) ""))))
11253 " (keeping session)")))
11255 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11256 "A string to explain persistent-action of this source.
11257 It also accepts a function or a variable name.")
11259 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11261 ;; Plug-in: Type customize
11262 (defun anything-c-uniq-list (lst)
11263 "Like `remove-duplicates' in CL.
11264 But cut deeper duplicates and test by `equal'. "
11265 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11266 (defvar anything-additional-type-attributes nil)
11267 (defun anything-c-arrange-type-attribute (type spec)
11268 "Override type attributes by `define-anything-type-attribute'.
11270 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11272 Example: Set `play-sound-file' as default action
11273 (anything-c-arrange-type-attribute 'file
11274 '((action (\"Play sound\" . play-sound-file)
11275 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11278 (add-to-list 'anything-additional-type-attributes
11279 (cons type
11280 (loop with typeattr = (assoc-default type anything-type-attributes)
11281 for (attr . value) in spec
11282 if (listp value)
11283 collect (cons attr
11284 (anything-c-uniq-list
11285 (loop for v in value
11286 if (eq v 'REST)
11287 append (assoc-default attr typeattr)
11288 else
11289 collect v)))
11290 else
11291 collect (cons attr value)))))
11292 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11294 (defun anything-compile-source--type-customize (source)
11295 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11296 (append it source)
11297 source))
11298 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11300 ;; Plug-in: default-action
11301 (defun anything-compile-source--default-action (source)
11302 (anything-aif (assoc-default 'default-action source)
11303 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11304 source)
11305 source))
11306 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11307 (anything-document-attribute 'default-action "default-action plug-in"
11308 "Default action.")
11311 ;;; Toggle anything-match-plugin
11314 (defvar anything-mp-initial-highlight-delay nil)
11316 ;;;###autoload
11317 (defun anything-c-toggle-match-plugin ()
11318 "Toggle anything-match-plugin."
11319 (interactive)
11320 (let ((anything-match-plugin-enabled
11321 (member 'anything-compile-source--match-plugin
11322 anything-compile-source-functions)))
11323 (flet ((disable-match-plugin ()
11324 (setq anything-compile-source-functions
11325 (delq 'anything-compile-source--match-plugin
11326 anything-compile-source-functions))
11327 (setq anything-mp-initial-highlight-delay
11328 anything-mp-highlight-delay)
11329 (setq anything-mp-highlight-delay nil))
11330 (enable-match-plugin ()
11331 (require 'anything-match-plugin)
11332 (unless anything-mp-initial-highlight-delay
11333 (setq anything-mp-initial-highlight-delay
11334 anything-mp-highlight-delay))
11335 (setq anything-compile-source-functions
11336 (cons 'anything-compile-source--match-plugin
11337 anything-compile-source-functions))
11338 (unless anything-mp-highlight-delay
11339 (setq anything-mp-highlight-delay
11340 anything-mp-initial-highlight-delay))))
11341 (if anything-match-plugin-enabled
11342 (when (y-or-n-p "Really disable match-plugin? ")
11343 (disable-match-plugin)
11344 (message "Anything-match-plugin disabled"))
11345 (when (y-or-n-p "Really enable match-plugin? ")
11346 (enable-match-plugin)
11347 (message "Anything-match-plugin enabled"))))))
11351 ;;; Type Attributes
11354 (define-anything-type-attribute 'buffer
11355 `((action
11356 ("Switch to buffer" . anything-c-switch-to-buffer)
11357 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11358 ("Switch to buffer other window" . switch-to-buffer-other-window)
11359 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11360 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11361 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11362 ("Query replace" . anything-c-buffer-query-replace)
11363 ("View buffer" . view-buffer)
11364 ("Display buffer" . display-buffer)
11365 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11366 ("Revert buffer(s)" . anything-revert-marked-buffers)
11367 ("Insert buffer" . insert-buffer)
11368 ("Kill buffer(s)" . anything-kill-marked-buffers)
11369 ("Diff with file" . diff-buffer-with-file)
11370 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11371 ("Ediff Merge marked buffers" . (lambda (candidate)
11372 (anything-ediff-marked-buffers candidate t))))
11373 (persistent-help . "Show this buffer")
11374 (candidate-transformer anything-c-skip-current-buffer
11375 anything-c-skip-boring-buffers
11376 anything-c-transform-buffer-display-string))
11377 "Buffer or buffer name.")
11379 (define-anything-type-attribute 'file
11380 `((action
11381 ("Find file" . anything-find-many-files)
11382 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11383 ("Find file as root" . anything-find-file-as-root)
11384 ("Find file other window" . find-file-other-window)
11385 ("Find file other frame" . find-file-other-frame)
11386 ("Open dired in file's directory" . anything-c-open-dired)
11387 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11388 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11389 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11390 ("Checksum File" . anything-ff-checksum)
11391 ("Ediff File" . anything-find-files-ediff-files)
11392 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11393 ("View file" . view-file)
11394 ("Insert file" . insert-file)
11395 ("Delete file(s)" . anything-delete-marked-files)
11396 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11397 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11398 ("Find file in hex dump" . hexl-find-file))
11399 (persistent-help . "Show this file")
11400 (action-transformer anything-c-transform-file-load-el
11401 anything-c-transform-file-browse-url)
11402 (candidate-transformer anything-c-w32-pathname-transformer
11403 anything-c-skip-current-file
11404 anything-c-skip-boring-files
11405 anything-c-shorten-home-path))
11406 "File name.")
11408 (let ((actions '(("Describe command" . describe-function)
11409 ("Add command to kill ring" . anything-c-kill-new)
11410 ("Go to command's definition" . find-function)
11411 ("Debug on entry" . debug-on-entry)
11412 ("Cancel debug on entry" . cancel-debug-on-entry)
11413 ("Trace function" . trace-function)
11414 ("Trace function (background)" . trace-function-background)
11415 ("Untrace function" . untrace-function))))
11416 (define-anything-type-attribute 'command
11417 `((action ("Call interactively" . anything-c-call-interactively)
11418 ,@actions)
11419 ;; Sort commands according to their usage count.
11420 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11421 (coerce . anything-c-symbolify)
11422 (persistent-action . describe-function))
11423 "Command. (string or symbol)")
11425 (define-anything-type-attribute 'function
11426 `((action . ,actions)
11427 (action-transformer anything-c-transform-function-call-interactively)
11428 (candidate-transformer anything-c-mark-interactive-functions)
11429 (coerce . anything-c-symbolify))
11430 "Function. (string or symbol)"))
11432 (define-anything-type-attribute 'variable
11433 '((action ("Describe variable" . describe-variable)
11434 ("Add variable to kill ring" . anything-c-kill-new)
11435 ("Go to variable's definition" . find-variable)
11436 ("Set variable" . anything-c-set-variable))
11437 (coerce . anything-c-symbolify))
11438 "Variable.")
11440 (define-anything-type-attribute 'sexp
11441 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11442 ("Add s-expression to kill ring" . kill-new))
11443 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11444 "String representing S-Expressions.")
11446 (define-anything-type-attribute 'bookmark
11447 `((coerce . anything-bookmark-get-bookmark-from-name)
11448 (action
11449 ("Jump to bookmark" . (lambda (bookmark)
11450 (let ((current-prefix-arg anything-current-prefix-arg))
11451 (bookmark-jump bookmark))
11452 (anything-update)))
11453 ("Jump to BM other window" . (lambda (bookmark)
11454 (bookmark-jump-other-window bookmark)
11455 (anything-update)))
11456 ("Bookmark edit annotation" . bookmark-edit-annotation)
11457 ("Bookmark show annotation" . bookmark-show-annotation)
11458 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11459 ,@(and (locate-library "bookmark-extensions")
11460 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11461 ("Rename bookmark" . bookmark-rename)
11462 ("Relocate bookmark" . bookmark-relocate)))
11463 "Bookmark name.")
11465 (define-anything-type-attribute 'line
11466 '((display-to-real . anything-c-display-to-real-line)
11467 (action ("Go to Line" . anything-c-action-line-goto)))
11468 "LINENO:CONTENT string, eg. \" 16:foo\".
11470 Optional `target-file' attribute is a name of target file.
11472 Optional `before-jump-hook' attribute is a function with no
11473 arguments which is called before jumping to position.
11475 Optional `after-jump-hook' attribute is a function with no
11476 arguments which is called after jumping to position.
11478 If `adjust' attribute is specified, searches the line whose
11479 content is CONTENT near the LINENO.
11481 If `recenter' attribute is specified, the line is displayed at
11482 the center of window, otherwise at the top of window.
11485 (define-anything-type-attribute 'file-line
11486 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11487 (multiline)
11488 (action ("Go to" . anything-c-action-file-line-goto)))
11489 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11491 Optional `default-directory' attribute is a default-directory
11492 FILENAME is interpreted.
11494 Optional `before-jump-hook' attribute is a function with no
11495 arguments which is called before jumping to position.
11497 Optional `after-jump-hook' attribute is a function with no
11498 arguments which is called after jumping to position.
11500 If `adjust' attribute is specified, searches the line whose
11501 content is CONTENT near the LINENO.
11503 If `recenter' attribute is specified, the line is displayed at
11504 the center of window, otherwise at the top of window.
11507 (define-anything-type-attribute 'timer
11508 '((real-to-display . anything-c-timer-real-to-display)
11509 (action ("Cancel Timer" . cancel-timer)
11510 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11511 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11512 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11513 (persistent-help . "Describe Function"))
11514 "Timer.")
11517 ;;; Default `anything-sources'
11518 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11519 ;; tend to invoke M-x anything directly. So I offer default setting.
11520 (setq anything-sources
11521 '(anything-c-source-buffers-list
11522 anything-c-source-recentf
11523 anything-c-source-files-in-current-dir+))
11526 ;;; Preconfigured Anything
11529 ;;;###autoload
11530 (defun anything-mini ()
11531 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11532 (interactive)
11533 (anything-other-buffer '(anything-c-source-buffers-list
11534 anything-c-source-recentf
11535 anything-c-source-buffer-not-found)
11536 "*anything mini*"))
11537 ;;;###autoload
11538 (defun anything-for-files ()
11539 "Preconfigured `anything' for opening files.
11540 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11541 (interactive)
11542 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11544 ;;;###autoload
11545 (defun anything-recentf ()
11546 "Preconfigured `anything' for `recentf'."
11547 (interactive)
11548 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11550 ;;;###autoload
11551 (defun anything-info-at-point (arg)
11552 "Preconfigured `anything' for searching info at point.
11553 With a prefix-arg insert symbol at point."
11554 (interactive "P")
11555 (let ((anything-c-google-suggest-default-function
11556 'anything-c-google-suggest-emacs-lisp))
11557 (anything :sources '(anything-c-source-info-elisp
11558 anything-c-source-info-cl
11559 anything-c-source-info-pages
11560 anything-c-source-google-suggest)
11561 :input (and arg (thing-at-point 'symbol))
11562 :buffer "*anything info*")))
11564 ;;;###autoload
11565 (defun anything-info-emacs ()
11566 "Preconfigured anything for Emacs manual index."
11567 (interactive)
11568 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11570 ;;;###autoload
11571 (defun anything-show-kill-ring ()
11572 "Preconfigured `anything' for `kill-ring'.
11573 It is drop-in replacement of `yank-pop'.
11574 You may bind this command to M-y.
11575 First call open the kill-ring browser, next calls move to next line."
11576 (interactive)
11577 (let ((buf "*anything kill-ring*"))
11578 (if (get-buffer-window buf)
11579 (with-anything-window
11580 (if (eq (overlay-end anything-selection-overlay) (point-max))
11581 (anything-beginning-of-buffer)
11582 (anything-next-line)))
11583 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11585 ;;;###autoload
11586 (defun anything-minibuffer-history ()
11587 "Preconfigured `anything' for `minibuffer-history'."
11588 (interactive)
11589 (let ((enable-recursive-minibuffers t))
11590 (anything-other-buffer 'anything-c-source-minibuffer-history
11591 "*anything minibuffer-history*")))
11593 ;;;###autoload
11594 (defun anything-gentoo ()
11595 "Preconfigured `anything' for gentoo linux."
11596 (interactive)
11597 (anything-other-buffer '(anything-c-source-gentoo
11598 anything-c-source-use-flags)
11599 "*anything gentoo*"))
11601 ;;;###autoload
11602 (defun anything-imenu ()
11603 "Preconfigured `anything' for `imenu'."
11604 (interactive)
11605 (anything :sources 'anything-c-source-imenu
11606 :buffer "*anything imenu*"))
11608 ;;;###autoload
11609 (defun anything-google-suggest ()
11610 "Preconfigured `anything' for google search with google suggest."
11611 (interactive)
11612 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11614 ;;;###autoload
11615 (defun anything-yahoo-suggest ()
11616 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11617 (interactive)
11618 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11620 ;;; Converted from anything-show-*-only
11621 ;;;###autoload
11622 (defun anything-for-buffers ()
11623 "Preconfigured `anything' for buffer."
11624 (interactive)
11625 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11627 ;;;###autoload
11628 (defun anything-buffers-list ()
11629 "Enhanced preconfigured `anything' for buffer."
11630 (interactive)
11631 (anything :sources '(anything-c-source-buffers-list
11632 anything-c-source-buffer-not-found)
11633 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11635 ;;;###autoload
11636 (defun anything-bbdb ()
11637 "Preconfigured `anything' for BBDB.
11639 Needs BBDB.
11641 http://bbdb.sourceforge.net/"
11642 (interactive)
11643 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11645 ;;;###autoload
11646 (defun anything-locate (arg)
11647 "Preconfigured `anything' for Locate.
11648 Note: you can add locate options after entering pattern.
11649 See 'man locate' for valid options.
11651 You can specify a specific database with prefix argument ARG \(C-u\).
11652 Many databases can be used: navigate and mark them.
11653 See also `anything-locate-with-db'.
11655 To create a user specific db, use
11656 \"updatedb -l 0 -o db_path -U directory\".
11657 Where db_path is a filename matched by
11658 `anything-locate-db-file-regexp'."
11659 (interactive "P")
11660 (anything-locate-1 arg))
11662 ;;;###autoload
11663 (defun anything-w3m-bookmarks ()
11664 "Preconfigured `anything' for w3m bookmark.
11666 Needs w3m and emacs-w3m.
11668 http://w3m.sourceforge.net/
11669 http://emacs-w3m.namazu.org/"
11670 (interactive)
11671 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11672 "*anything w3m bookmarks*"))
11674 ;;;###autoload
11675 (defun anything-firefox-bookmarks ()
11676 "Preconfigured `anything' for firefox bookmark.
11677 You will have to enable html bookmarks in firefox:
11678 open about:config in firefox and double click on this line to enable value \
11679 to true:
11681 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11683 You should have now:
11685 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11687 After closing firefox, you will be able to browse you bookmarks.
11689 (interactive)
11690 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11691 "*Anything Firefox*"))
11693 ;;;###autoload
11694 (defun anything-colors ()
11695 "Preconfigured `anything' for color."
11696 (interactive)
11697 (anything-other-buffer
11698 '(anything-c-source-colors anything-c-source-customize-face)
11699 "*anything colors*"))
11701 ;;;###autoload
11702 (defun anything-bookmarks ()
11703 "Preconfigured `anything' for bookmarks."
11704 (interactive)
11705 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11707 ;;;###autoload
11708 (defun anything-c-pp-bookmarks ()
11709 "Preconfigured `anything' for bookmarks (pretty-printed)."
11710 (interactive)
11711 (anything-other-buffer '(anything-c-source-bookmarks-local
11712 anything-c-source-bookmarks-su
11713 anything-c-source-bookmarks-ssh)
11714 "*anything pp bookmarks*"))
11716 ;;;###autoload
11717 (defun anything-c-insert-latex-math ()
11718 "Preconfigured anything for latex math symbols completion."
11719 (interactive)
11720 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11722 ;;;###autoload
11723 (defun anything-register ()
11724 "Preconfigured `anything' for Emacs registers."
11725 (interactive)
11726 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11728 ;;;###autoload
11729 (defun anything-man-woman ()
11730 "Preconfigured `anything' for Man and Woman pages."
11731 (interactive)
11732 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11734 ;;;###autoload
11735 (defun anything-org-keywords ()
11736 "Preconfigured `anything' for org keywords."
11737 (interactive)
11738 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11740 ;;;###autoload
11741 (defun anything-emms ()
11742 "Preconfigured `anything' for emms sources."
11743 (interactive)
11744 (anything :sources '(anything-c-source-emms-streams
11745 anything-c-source-emms-files
11746 anything-c-source-emms-dired)
11747 :buffer "*Anything Emms*"))
11749 ;;;###autoload
11750 (defun anything-eev-anchors ()
11751 "Preconfigured `anything' for eev anchors."
11752 (interactive)
11753 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11755 ;;;###autoload
11756 (defun anything-bm-list ()
11757 "Preconfigured `anything' for visible bookmarks.
11759 Needs bm.el
11761 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11762 (interactive)
11763 (let ((anything-outline-using t))
11764 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11766 ;;;###autoload
11767 (defun anything-timers ()
11768 "Preconfigured `anything' for timers."
11769 (interactive)
11770 (anything-other-buffer '(anything-c-source-absolute-time-timers
11771 anything-c-source-idle-time-timers)
11772 "*anything timers*"))
11774 ;;;###autoload
11775 (defun anything-list-emacs-process ()
11776 "Preconfigured `anything' for emacs process."
11777 (interactive)
11778 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11780 ;;;###autoload
11781 (defun anything-occur ()
11782 "Preconfigured Anything for Occur source.
11783 If region is active, search only in region,
11784 otherwise search in whole buffer."
11785 (interactive)
11786 (let ((anything-compile-source-functions
11787 ;; rule out anything-match-plugin because the input is one regexp.
11788 (delq 'anything-compile-source--match-plugin
11789 (copy-sequence anything-compile-source-functions))))
11790 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11792 ;;;###autoload
11793 (defun anything-browse-code ()
11794 "Preconfigured anything to browse code."
11795 (interactive)
11796 (anything :sources 'anything-c-source-browse-code
11797 :buffer "*anything browse code*"
11798 :default (thing-at-point 'symbol)))
11800 ;;;###autoload
11801 (defun anything-org-headlines ()
11802 "Preconfigured anything to show org headlines."
11803 (interactive)
11804 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11806 ;;;###autoload
11807 (defun anything-info-gnus ()
11808 "Preconfigured anything to browse Gnus Manual."
11809 (interactive)
11810 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11812 ;;;###autoload
11813 (defun anything-regexp ()
11814 "Preconfigured anything to build regexps.
11815 `query-replace-regexp' can be run from there against found regexp."
11816 (interactive)
11817 (save-restriction
11818 (let ((anything-compile-source-functions
11819 ;; rule out anything-match-plugin because the input is one regexp.
11820 (delq 'anything-compile-source--match-plugin
11821 (copy-sequence anything-compile-source-functions))))
11822 (when (and (anything-region-active-p)
11823 ;; Don't narrow to region if buffer is already narrowed.
11824 (not (anything-current-buffer-narrowed-p)))
11825 (narrow-to-region (region-beginning) (region-end)))
11826 (anything :sources anything-c-source-regexp
11827 :buffer "*anything regexp*"
11828 :prompt "Regexp: "
11829 :history 'anything-build-regexp-history))))
11831 ;;;###autoload
11832 (defun anything-c-copy-files-async ()
11833 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11834 (interactive)
11835 (let* ((flist (anything-c-read-file-name
11836 "Copy File async: "
11837 :marked-candidates t))
11838 (dest (anything-c-read-file-name
11839 "Copy File async To: "
11840 :preselect (car flist)
11841 :initial-input (car anything-ff-history)
11842 :history (anything-find-files-history :comp-read nil))))
11843 (anything-c-copy-async-with-log flist dest)))
11845 ;;;###autoload
11846 (defun anything-find-files (arg)
11847 "Preconfigured `anything' for anything implementation of `find-file'.
11848 Called with a prefix arg show history if some.
11849 Don't call it from programs, use `anything-find-files-1' instead.
11850 This is the starting point for nearly all actions you can do on files."
11851 (interactive "P")
11852 (let ((any-input (if (and arg anything-ff-history)
11853 (anything-find-files-history)
11854 (anything-find-files-initial-input)))
11855 (presel (buffer-file-name (current-buffer))))
11856 (when (and (eq major-mode 'org-agenda-mode)
11857 org-directory
11858 (not any-input))
11859 (setq any-input (expand-file-name org-directory)))
11860 (set-text-properties 0 (length any-input) nil any-input)
11861 (if any-input
11862 (anything-find-files-1 any-input)
11863 (setq any-input (expand-file-name (anything-c-current-directory)))
11864 (anything-find-files-1
11865 any-input (if anything-ff-transformer-show-only-basename
11866 (and presel (anything-c-basename presel))
11867 presel)))))
11869 ;;;###autoload
11870 (defun anything-write-file ()
11871 "Preconfigured `anything' providing completion for `write-file'."
11872 (interactive)
11873 (let ((anything-mp-highlight-delay nil))
11874 (anything :sources 'anything-c-source-write-file
11875 :input (expand-file-name default-directory)
11876 :prompt "Write buffer to file: "
11877 :buffer "*Anything write file*")))
11879 ;;;###autoload
11880 (defun anything-insert-file ()
11881 "Preconfigured `anything' providing completion for `insert-file'."
11882 (interactive)
11883 (let ((anything-mp-highlight-delay nil))
11884 (anything :sources 'anything-c-source-insert-file
11885 :input (expand-file-name default-directory)
11886 :prompt "Insert file: "
11887 :buffer "*Anything insert file*")))
11889 ;;;###autoload
11890 (defun anything-dired-rename-file ()
11891 "Preconfigured `anything' to rename files from dired."
11892 (interactive)
11893 (anything-dired-do-action-on-file :action 'rename))
11895 ;;;###autoload
11896 (defun anything-dired-copy-file ()
11897 "Preconfigured `anything' to copy files from dired."
11898 (interactive)
11899 (anything-dired-do-action-on-file :action 'copy))
11901 ;;;###autoload
11902 (defun anything-dired-symlink-file ()
11903 "Preconfigured `anything' to symlink files from dired."
11904 (interactive)
11905 (anything-dired-do-action-on-file :action 'symlink))
11907 ;;;###autoload
11908 (defun anything-dired-hardlink-file ()
11909 "Preconfigured `anything' to hardlink files from dired."
11910 (interactive)
11911 (anything-dired-do-action-on-file :action 'hardlink))
11913 ;;;###autoload
11914 (defun anything-do-grep ()
11915 "Preconfigured anything for grep.
11916 Contrarily to Emacs `grep' no default directory is given, but
11917 the full path of candidates in ONLY.
11918 That allow to grep different files not only in `default-directory' but anywhere
11919 by marking them (C-<SPACE>). If one or more directory is selected
11920 grep will search in all files of these directories.
11921 You can use also wildcard in the base name of candidate.
11922 If a prefix arg is given use the -r option of grep.
11923 The prefix arg can be passed before or after start.
11924 See also `anything-do-grep-1'."
11925 (interactive)
11926 (let ((only (anything-c-read-file-name
11927 "Search in file(s): "
11928 :marked-candidates t
11929 :preselect (or (dired-get-filename nil t)
11930 (buffer-file-name (current-buffer)))))
11931 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11932 (anything-do-grep-1 only prefarg)))
11934 ;;;###autoload
11935 (defun anything-do-zgrep (candidate)
11936 "Preconfigured anything for zgrep."
11937 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11938 (ls (anything-c-read-file-name
11939 "Search in file(s): "
11940 :marked-candidates t
11941 :preselect (or (dired-get-filename nil t)
11942 (buffer-file-name (current-buffer))))))
11943 (anything-ff-zgrep-1 ls prefarg)))
11945 (defun anything-c-etags-select (arg)
11946 "Preconfigured anything for etags.
11947 Called with one prefix arg use symbol at point as initial input.
11948 Called with two prefix arg reinitialize cache.
11949 If tag file have been modified reinitialize cache."
11950 (interactive "P")
11951 (let ((tag (anything-c-etags-get-tag-file))
11952 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11953 (anything-quit-if-no-candidate t)
11954 (anything-execute-action-at-once-if-one t)
11955 (anything-compile-source-functions
11956 (if anything-c-etags-use-regexp-search
11957 ;; rule out anything-match-plugin because the input is one regexp.
11958 (delq 'anything-compile-source--match-plugin
11959 (copy-sequence anything-compile-source-functions))
11960 anything-compile-source-functions)))
11961 (when (or (equal arg '(16))
11962 (and anything-c-etags-mtime-alist
11963 (anything-c-etags-file-modified-p tag)))
11964 (remhash tag anything-c-etags-cache))
11965 (if (and tag (file-exists-p tag))
11966 (anything :sources 'anything-c-source-etags-select
11967 :keymap anything-c-etags-map
11968 :input init
11969 :buffer "*anything etags*")
11970 (message "Error: No tag file found, please create one with etags shell command."))))
11972 ;;;###autoload
11973 (defun anything-filelist ()
11974 "Preconfigured `anything' to open files instantly.
11976 See `anything-c-filelist-file-name' docstring for usage."
11977 (interactive)
11978 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11980 ;;;###autoload
11981 (defun anything-filelist+ ()
11982 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11984 This is a replacement for `anything-for-files'.
11985 See `anything-c-filelist-file-name' docstring for usage."
11986 (interactive)
11987 (anything-other-buffer
11988 '(anything-c-source-ffap-line
11989 anything-c-source-ffap-guesser
11990 anything-c-source-buffers-list
11991 anything-c-source-recentf
11992 anything-c-source-bookmarks
11993 anything-c-source-file-cache
11994 anything-c-source-filelist)
11995 "*anything file list*"))
11997 ;;;###autoload
11998 (defun anything-M-x ()
11999 "Preconfigured `anything' for Emacs commands.
12000 It is `anything' replacement of regular `M-x' `execute-extended-command'."
12001 (interactive)
12002 (let* (in-help
12003 help-cand
12004 special-display-buffer-names
12005 special-display-regexps
12006 anything-persistent-action-use-special-display
12007 (history (loop with hist
12008 for i in extended-command-history
12009 for com = (intern i)
12010 when (fboundp com)
12011 collect i into hist finally return hist)))
12012 (flet ((pers-help (candidate)
12013 (let ((hbuf (get-buffer (help-buffer))))
12014 (if (and in-help (string= candidate help-cand))
12015 (progn
12016 ;; When M-x is started from a help buffer,
12017 ;; Don't kill it as it is anything-current-buffer.
12018 (unless (equal hbuf anything-current-buffer)
12019 (kill-buffer hbuf))
12020 (setq in-help nil))
12021 ;; Be sure anything-current-buffer
12022 ;; have not a dedicated window.
12023 (set-window-dedicated-p
12024 (get-buffer-window anything-current-buffer) nil)
12025 (describe-function (intern candidate))
12026 (message nil) ; Erase the new stupid message Type "q"[...]
12027 (setq in-help t))
12028 (setq help-cand candidate))))
12029 (let* ((command
12031 (anything
12032 :sources
12033 `(((name . "Emacs Commands history")
12034 (candidates . ,history)
12035 (filtered-candidate-transformer
12036 . (lambda (candidates sources)
12037 (loop for i in candidates
12038 do (set-text-properties 0 (length i) nil i)
12039 collect i)))
12040 (persistent-action . pers-help)
12041 (persistent-help . "Describe this command")
12042 (action . identity))
12043 ((name . "Emacs Commands")
12044 (init
12045 . (lambda ()
12046 (with-current-buffer (anything-candidate-buffer 'global)
12047 (goto-char (point-min))
12048 (loop for sym in
12049 (all-completions "" obarray 'commandp)
12050 do (insert (concat sym "\n"))))))
12051 (persistent-action . pers-help)
12052 (persistent-help . "Describe this command")
12053 (filtered-candidate-transformer . anything-M-x-transformer)
12054 (candidates-in-buffer)
12055 (action . identity)))
12056 :resume 'noresume
12057 :prompt "M-x "
12058 :history 'anything-M-x-input-history
12059 :buffer "*anything M-x*")
12060 (keyboard-quit)))
12061 (sym-com (intern command)))
12062 (unless current-prefix-arg
12063 (setq current-prefix-arg anything-current-prefix-arg))
12064 ;; Avoid having `this-command' set to *exit-minibuffer.
12065 (setq this-command sym-com)
12066 (call-interactively sym-com)
12067 (setq extended-command-history
12068 (cons command (delete command history)))))))
12070 ;;;###autoload
12071 (defun anything-manage-advice ()
12072 "Preconfigured `anything' to disable/enable function advices."
12073 (interactive)
12074 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12076 ;;;###autoload
12077 (defun anything-bookmark-ext ()
12078 "Preconfigured `anything' for bookmark-extensions sources.
12079 Needs bookmark-ext.el:
12080 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12081 Contain also `anything-c-source-google-suggest'."
12082 (interactive)
12083 (anything
12084 :sources
12085 '(anything-c-source-bookmark-files&dirs
12086 anything-c-source-bookmark-w3m
12087 anything-c-source-google-suggest
12088 anything-c-source-bmkext-addressbook
12089 anything-c-source-bookmark-gnus
12090 anything-c-source-bookmark-info
12091 anything-c-source-bookmark-man
12092 anything-c-source-bookmark-images
12093 anything-c-source-bookmark-su-files&dirs
12094 anything-c-source-bookmark-ssh-files&dirs)
12095 :prompt "SearchBookmark: "
12096 :buffer "*anything bmkext*"))
12098 ;;;###autoload
12099 (defun anything-simple-call-tree ()
12100 "Preconfigured `anything' for simple-call-tree. List function relationships.
12102 Needs simple-call-tree.el.
12103 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12104 (interactive)
12105 (anything-other-buffer
12106 '(anything-c-source-simple-call-tree-functions-callers
12107 anything-c-source-simple-call-tree-callers-functions)
12108 "*anything simple-call-tree*"))
12110 ;;;###autoload
12111 (defun anything-mark-ring ()
12112 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12113 (interactive)
12114 (anything :sources 'anything-c-source-mark-ring))
12116 ;;;###autoload
12117 (defun anything-global-mark-ring ()
12118 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12119 (interactive)
12120 (anything :sources 'anything-c-source-global-mark-ring))
12122 ;;;###autoload
12123 (defun anything-all-mark-rings ()
12124 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12125 `anything-c-source-mark-ring'."
12126 (interactive)
12127 (anything :sources '(anything-c-source-mark-ring
12128 anything-c-source-global-mark-ring)))
12130 ;;;###autoload
12131 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12132 "Preconfigured `anything' to edit or view EmacsWiki page.
12134 Needs yaoddmuse.el.
12136 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12137 (interactive)
12138 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12140 ;;;###autoload
12141 (defun anything-yaoddmuse-emacswiki-post-library ()
12142 "Preconfigured `anything' to post library to EmacsWiki.
12144 Needs yaoddmuse.el.
12146 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12147 (interactive)
12148 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12150 ;;;###autoload
12151 (defun anything-eval-expression (arg)
12152 "Preconfigured anything for `anything-c-source-evaluation-result'."
12153 (interactive "P")
12154 (anything :sources 'anything-c-source-evaluation-result
12155 :input (when arg (thing-at-point 'sexp))
12156 :buffer "*anything eval*"
12157 :history 'anything-eval-expression-input-history
12158 :keymap anything-eval-expression-map))
12160 ;;;###autoload
12161 (defun anything-eval-expression-with-eldoc ()
12162 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12163 (interactive)
12164 (declare (special eldoc-idle-delay))
12165 (let ((timer (run-with-idle-timer eldoc-idle-delay
12166 'repeat 'anything-eldoc-show-in-eval))
12167 (minibuffer-completing-symbol t) ; Enable lisp completion.
12168 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12169 (unwind-protect
12170 (minibuffer-with-setup-hook
12171 'anything-eldoc-store-minibuffer
12172 (call-interactively 'anything-eval-expression))
12173 (and timer (cancel-timer timer))
12174 (setq anything-eldoc-active-minibuffers-list
12175 (cdr anything-eldoc-active-minibuffers-list)))))
12177 ;;;###autoload
12178 (defun anything-calcul-expression ()
12179 "Preconfigured anything for `anything-c-source-calculation-result'."
12180 (interactive)
12181 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12183 ;;;###autoload
12184 (defun anything-surfraw (pattern engine)
12185 "Preconfigured `anything' to search PATTERN with search ENGINE."
12186 (interactive (list (read-string "SearchFor: "
12187 nil 'anything-surfraw-input-history)
12188 (anything-comp-read
12189 "Engine: "
12190 (anything-c-build-elvi-list)
12191 :must-match t
12192 :name "Surfraw Search Engines"
12193 :history anything-surfraw-engines-history)))
12194 (let* ((engine-nodesc (car (split-string engine)))
12195 (url (with-temp-buffer
12196 (apply 'call-process "surfraw" nil t nil
12197 ;;JAVE
12198 (append (list engine-nodesc "-p") (split-string pattern)))
12199 (replace-regexp-in-string
12200 "\n" "" (buffer-string))))
12201 (browse-url-browser-function (or anything-surfraw-default-browser-function
12202 browse-url-browser-function)))
12203 (if (string= engine-nodesc "W")
12204 (anything-c-browse-url)
12205 (anything-c-browse-url url)
12206 (setq anything-surfraw-engines-history
12207 (cons engine (delete engine anything-surfraw-engines-history))))))
12209 ;;;###autoload
12210 (defun anything-call-source ()
12211 "Preconfigured `anything' to call anything source."
12212 (interactive)
12213 (anything :sources 'anything-c-source-call-source
12214 :buffer anything-source-select-buffer))
12216 ;;;###autoload
12217 (defun anything-execute-anything-command ()
12218 "Preconfigured `anything' to execute preconfigured `anything'."
12219 (interactive)
12220 (anything-other-buffer 'anything-c-source-anything-commands
12221 "*anything commands*"))
12223 ;;;###autoload
12224 (defun anything-create (&optional string initial-input)
12225 "Preconfigured `anything' to do many create actions from STRING.
12226 See also `anything-create--actions'."
12227 (interactive)
12228 (setq string (or string (read-string "Create Anything: " initial-input)))
12229 (anything :sources '(((name . "Anything Create")
12230 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12231 (candidates . anything-create--actions)
12232 (candidate-number-limit)
12233 (action . (lambda (func) (funcall func string)))))))
12235 ;;;###autoload
12236 (defun anything-top ()
12237 "Preconfigured `anything' for top command."
12238 (interactive)
12239 (let ((anything-samewindow t)
12240 (anything-enable-shortcuts)
12241 (anything-display-function 'anything-default-display-buffer)
12242 (anything-candidate-number-limit 9999))
12243 (save-window-excursion
12244 (delete-other-windows)
12245 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12247 ;;;###autoload
12248 (defun anything-select-xfont ()
12249 "Preconfigured `anything' to select Xfont."
12250 (interactive)
12251 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12253 ;;;###autoload
12254 (defun anything-world-time ()
12255 "Preconfigured `anything' to show world time."
12256 (interactive)
12257 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12259 ;;;###autoload
12260 (defun anything-apt (arg)
12261 "Preconfigured `anything' : frontend of APT package manager.
12262 With a prefix arg reload cache."
12263 (interactive "P")
12264 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12265 (when arg (anything-c-apt-refresh))
12266 (anything :sources 'anything-c-source-apt
12267 :prompt "Search Package: "
12268 :input query
12269 :history 'anything-c-apt-input-history)))
12271 ;;;###autoload
12272 (defun anything-esh-pcomplete ()
12273 "Preconfigured anything to provide anything completion in eshell."
12274 (interactive)
12275 (let* ((anything-quit-if-no-candidate t)
12276 (anything-execute-action-at-once-if-one t)
12277 (target (thing-at-point 'symbol))
12278 (end (point))
12279 (beg (or (and target (- end (length target)))
12280 ;; Nothing at point.
12281 (progn (insert " ") (point)))))
12282 (setq anything-ec-target (or target " "))
12283 (with-anything-show-completion beg end
12284 (anything :sources 'anything-c-source-esh
12285 :input (anything-ff-set-pattern ; Handle tramp filenames.
12286 (car (last (ignore-errors ; Needed in lisp symbols completion.
12287 (pcomplete-parse-arguments)))))))))
12289 ;;;###autoload
12290 (defun anything-eshell-history ()
12291 "Preconfigured anything for eshell history."
12292 (interactive)
12293 (let* ((end (point))
12294 (beg (save-excursion (eshell-bol) (point)))
12295 flag-empty)
12296 (when (eq beg end)
12297 (insert " ")
12298 (setq flag-empty t)
12299 (setq end (point)))
12300 (unwind-protect
12301 (with-anything-show-completion beg end
12302 (anything :sources 'anything-c-source-eshell-history
12303 :buffer "*Eshell history*"))
12304 (when (and flag-empty
12305 (looking-back " "))
12306 (delete-char -1)))))
12308 ;;;###autoload
12309 (defun anything-c-run-external-command (program)
12310 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12311 If program is already running exit with error.
12312 You can set your own list of commands with
12313 `anything-c-external-commands-list'."
12314 (interactive (list
12315 (anything-comp-read
12316 "RunProgram: "
12317 (anything-c-external-commands-list-1 'sort)
12318 :must-match t
12319 :name "External Commands"
12320 :history anything-external-command-history)))
12321 (anything-run-or-raise program)
12322 (setq anything-external-command-history
12323 (cons program (delete program
12324 (loop for i in anything-external-command-history
12325 when (executable-find i) collect i)))))
12327 ;;;###autoload
12328 (defun anything-ratpoison-commands ()
12329 "Preconfigured `anything' to execute ratpoison commands."
12330 (interactive)
12331 (anything-other-buffer 'anything-c-source-ratpoison-commands
12332 "*anything ratpoison commands*"))
12334 ;;;###autoload
12335 (defun anything-ucs ()
12336 "Preconfigured anything for `ucs-names' math symbols."
12337 (interactive)
12338 (anything :sources 'anything-c-source-ucs
12339 :keymap anything-c-ucs-map))
12341 ;;;###autoload
12342 (defun anything-c-apropos ()
12343 "Preconfigured anything to describe commands, functions, variables and faces."
12344 (interactive)
12345 (let ((default (thing-at-point 'symbol)))
12346 (anything :sources
12347 `(((name . "Commands")
12348 (init . (lambda ()
12349 (anything-c-apropos-init 'commandp ,default)))
12350 (persistent-action . anything-lisp-completion-persistent-action)
12351 (persistent-help . "Show brief doc in mode-line")
12352 (candidates-in-buffer)
12353 (action . (lambda (candidate)
12354 (describe-function (intern candidate)))))
12355 ((name . "Functions")
12356 (init . (lambda ()
12357 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12358 (not (commandp x))))
12359 ,default)))
12360 (persistent-action . anything-lisp-completion-persistent-action)
12361 (persistent-help . "Show brief doc in mode-line")
12362 (candidates-in-buffer)
12363 (action . (lambda (candidate)
12364 (describe-function (intern candidate)))))
12365 ((name . "Variables")
12366 (init . (lambda ()
12367 (anything-c-apropos-init 'boundp ,default)))
12368 (persistent-action . anything-lisp-completion-persistent-action)
12369 (persistent-help . "Show brief doc in mode-line")
12370 (candidates-in-buffer)
12371 (action . (lambda (candidate)
12372 (describe-variable (intern candidate)))))
12373 ((name . "Faces")
12374 (init . (lambda ()
12375 (anything-c-apropos-init 'facep ,default)))
12376 (persistent-action . anything-lisp-completion-persistent-action)
12377 (persistent-help . "Show brief doc in mode-line")
12378 (candidates-in-buffer)
12379 (filtered-candidate-transformer . (lambda (candidates source)
12380 (loop for c in candidates
12381 collect (propertize c 'face (intern c)))))
12382 (action . (lambda (candidate)
12383 (describe-face (intern candidate)))))
12384 ((name . "Anything attributes")
12385 (candidates . (lambda ()
12386 (mapcar 'symbol-name anything-additional-attributes)))
12387 (action . (lambda (candidate)
12388 (with-output-to-temp-buffer "*Help*"
12389 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12392 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12395 (provide 'anything-config)
12397 ;;; Local Variables:
12398 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12399 ;;; End:
12401 ;; How to save (DO NOT REMOVE!!)
12402 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12403 ;;; anything-config.el ends here
12405 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12406 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12407 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12408 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12409 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12410 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12411 ;;; LocalWords: dotimes Thierry online vname
12412 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12413 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12414 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12415 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12416 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12417 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12418 ;;; LocalWords: startpos noselect dont desc