* anything-config.el (anything-build-regexp-history): new use it.
[anything-config.git] / anything-config.el
blob1c4340ad8e16b4daa4cf433d7e7cec7bdc43ac5e
1 ;;; anything-config.el --- Applications libary for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Applications libary for `anything.el'
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
17 ;; Created: 2009-02-16 21:38:23
19 ;; X-URL: http://repo.or.cz/w/anything-config.git
21 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
23 ;; Keywords: anything, anything-config
25 ;; Compatibility: GNU Emacs 22 ~ 24
27 ;; Dependencies: `anything.el'
29 ;;; This file is NOT part of GNU Emacs
31 ;;; License
33 ;; This program is free software; you can redistribute it and/or modify
34 ;; it under the terms of the GNU General Public License as published by
35 ;; the Free Software Foundation; either version 3, or (at your option)
36 ;; any later version.
38 ;; This program is distributed in the hope that it will be useful,
39 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 ;; GNU General Public License for more details.
43 ;; You should have received a copy of the GNU General Public License
44 ;; along with this program; see the file COPYING. If not, write to
45 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
46 ;; Floor, Boston, MA 02110-1301, USA.
48 ;;; !NOTICE!
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
53 ;;; Commentary:
55 ;; Predefined configurations for `anything.el'
57 ;; For quick start, try `anything-for-files' to open files.
59 ;; To configure anything you should define anything command
60 ;; with your favorite sources, like below:
62 ;; (defun my-anything ()
63 ;; (interactive)
64 ;; (anything-other-buffer
65 ;; '(anything-c-source-buffers
66 ;; anything-c-source-file-name-history
67 ;; anything-c-source-info-pages
68 ;; anything-c-source-info-elisp
69 ;; anything-c-source-man-pages
70 ;; anything-c-source-locate
71 ;; anything-c-source-emacs-commands)
72 ;; " *my-anything*"))
74 ;; Then type M-x my-anything to use sources.
76 ;; Defining own command is better than setup `anything-sources'
77 ;; directly, because you can define multiple anything commands with
78 ;; different sources. Each anything command should have own anything
79 ;; buffer, because M-x anything-resume revives anything command.
82 ;;; Autodoc documentation:
83 ;; ---------------------
85 ;; * Commands defined here are:
86 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
87 ;; `anything-configuration'
88 ;; Customize `anything'.
89 ;; `anything-c-buffer-help'
90 ;; Help command for anything buffers.
91 ;; `anything-ff-help'
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
94 ;; Not documented.
95 ;; `anything-generic-file-help'
96 ;; Not documented.
97 ;; `anything-grep-help'
98 ;; Not documented.
99 ;; `anything-pdfgrep-help'
100 ;; Not documented.
101 ;; `anything-etags-help'
102 ;; The help function for etags.
103 ;; `anything-c-ucs-help'
104 ;; Help command for `anything-ucs'.
105 ;; `anything-mini'
106 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
107 ;; `anything-for-files'
108 ;; Preconfigured `anything' for opening files.
109 ;; `anything-recentf'
110 ;; Preconfigured `anything' for `recentf'.
111 ;; `anything-info-at-point'
112 ;; Preconfigured `anything' for searching info at point.
113 ;; `anything-info-emacs'
114 ;; Preconfigured anything for Emacs manual index.
115 ;; `anything-show-kill-ring'
116 ;; Preconfigured `anything' for `kill-ring'.
117 ;; `anything-minibuffer-history'
118 ;; Preconfigured `anything' for `minibuffer-history'.
119 ;; `anything-gentoo'
120 ;; Preconfigured `anything' for gentoo linux.
121 ;; `anything-imenu'
122 ;; Preconfigured `anything' for `imenu'.
123 ;; `anything-google-suggest'
124 ;; Preconfigured `anything' for google search with google suggest.
125 ;; `anything-yahoo-suggest'
126 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
127 ;; `anything-for-buffers'
128 ;; Preconfigured `anything' for buffer.
129 ;; `anything-buffers-list'
130 ;; Enhanced preconfigured `anything' for buffer.
131 ;; `anything-bbdb'
132 ;; Preconfigured `anything' for BBDB.
133 ;; `anything-locate'
134 ;; Preconfigured `anything' for Locate.
135 ;; `anything-w3m-bookmarks'
136 ;; Preconfigured `anything' for w3m bookmark.
137 ;; `anything-firefox-bookmarks'
138 ;; Preconfigured `anything' for firefox bookmark.
139 ;; `anything-colors'
140 ;; Preconfigured `anything' for color.
141 ;; `anything-bookmarks'
142 ;; Preconfigured `anything' for bookmarks.
143 ;; `anything-c-pp-bookmarks'
144 ;; Preconfigured `anything' for bookmarks (pretty-printed).
145 ;; `anything-c-insert-latex-math'
146 ;; Preconfigured anything for latex math symbols completion.
147 ;; `anything-register'
148 ;; Preconfigured `anything' for Emacs registers.
149 ;; `anything-man-woman'
150 ;; Preconfigured `anything' for Man and Woman pages.
151 ;; `anything-org-keywords'
152 ;; Preconfigured `anything' for org keywords.
153 ;; `anything-emms'
154 ;; Preconfigured `anything' for emms sources.
155 ;; `anything-eev-anchors'
156 ;; Preconfigured `anything' for eev anchors.
157 ;; `anything-bm-list'
158 ;; Preconfigured `anything' for visible bookmarks.
159 ;; `anything-timers'
160 ;; Preconfigured `anything' for timers.
161 ;; `anything-list-emacs-process'
162 ;; Preconfigured `anything' for emacs process.
163 ;; `anything-occur'
164 ;; Preconfigured Anything for Occur source.
165 ;; `anything-browse-code'
166 ;; Preconfigured anything to browse code.
167 ;; `anything-org-headlines'
168 ;; Preconfigured anything to show org headlines.
169 ;; `anything-info-gnus'
170 ;; Preconfigured anything to browse Gnus Manual.
171 ;; `anything-regexp'
172 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
173 ;; `anything-c-copy-files-async'
174 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
175 ;; `anything-find-files'
176 ;; Preconfigured `anything' for anything implementation of `find-file'.
177 ;; `anything-write-file'
178 ;; Preconfigured `anything' providing completion for `write-file'.
179 ;; `anything-insert-file'
180 ;; Preconfigured `anything' providing completion for `insert-file'.
181 ;; `anything-dired-rename-file'
182 ;; Preconfigured `anything' to rename files from dired.
183 ;; `anything-dired-copy-file'
184 ;; Preconfigured `anything' to copy files from dired.
185 ;; `anything-dired-symlink-file'
186 ;; Preconfigured `anything' to symlink files from dired.
187 ;; `anything-dired-hardlink-file'
188 ;; Preconfigured `anything' to hardlink files from dired.
189 ;; `anything-do-grep'
190 ;; Preconfigured anything for grep.
191 ;; `anything-c-etags-select'
192 ;; Preconfigured anything for etags.
193 ;; `anything-filelist'
194 ;; Preconfigured `anything' to open files instantly.
195 ;; `anything-filelist+'
196 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
197 ;; `anything-M-x'
198 ;; Preconfigured `anything' for Emacs commands.
199 ;; `anything-manage-advice'
200 ;; Preconfigured `anything' to disable/enable function advices.
201 ;; `anything-bookmark-ext'
202 ;; Preconfigured `anything' for bookmark-extensions sources.
203 ;; `anything-simple-call-tree'
204 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
205 ;; `anything-mark-ring'
206 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
207 ;; `anything-global-mark-ring'
208 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
209 ;; `anything-all-mark-rings'
210 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
211 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
212 ;; Preconfigured `anything' to edit or view EmacsWiki page.
213 ;; `anything-yaoddmuse-emacswiki-post-library'
214 ;; Preconfigured `anything' to post library to EmacsWiki.
215 ;; `anything-eval-expression'
216 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
217 ;; `anything-eval-expression-with-eldoc'
218 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
219 ;; `anything-calcul-expression'
220 ;; Preconfigured anything for `anything-c-source-calculation-result'.
221 ;; `anything-surfraw'
222 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
223 ;; `anything-call-source'
224 ;; Preconfigured `anything' to call anything source.
225 ;; `anything-execute-anything-command'
226 ;; Preconfigured `anything' to execute preconfigured `anything'.
227 ;; `anything-create'
228 ;; Preconfigured `anything' to do many create actions from STRING.
229 ;; `anything-top'
230 ;; Preconfigured `anything' for top command.
231 ;; `anything-select-xfont'
232 ;; Preconfigured `anything' to select Xfont.
233 ;; `anything-world-time'
234 ;; Preconfigured `anything' to show world time.
235 ;; `anything-apt'
236 ;; Preconfigured `anything' : frontend of APT package manager.
237 ;; `anything-esh-pcomplete'
238 ;; Preconfigured anything to provide anything completion in eshell.
239 ;; `anything-eshell-history'
240 ;; Preconfigured anything for eshell history.
241 ;; `anything-c-run-external-command'
242 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
243 ;; `anything-ratpoison-commands'
244 ;; Preconfigured `anything' to execute ratpoison commands.
245 ;; `anything-ucs'
246 ;; Preconfigured anything for `ucs-names' math symbols.
247 ;; `anything-show-this-source-only'
248 ;; Show all candidates of this source.
249 ;; `anything-test-sources'
250 ;; List all anything sources for test.
251 ;; `anything-select-source'
252 ;; [OBSOLETE] Select source.
253 ;; `anything-mark-all'
254 ;; Mark all visible unmarked candidates in current source.
255 ;; `anything-unmark-all'
256 ;; Unmark all candidates in all sources of current anything session.
257 ;; `anything-toggle-all-marks'
258 ;; Toggle all marks.
259 ;; `anything-buffer-diff-persistent'
260 ;; Toggle diff buffer without quitting anything.
261 ;; `anything-buffer-revert-persistent'
262 ;; Revert buffer without quitting anything.
263 ;; `anything-buffer-save-persistent'
264 ;; Save buffer without quitting anything.
265 ;; `anything-buffer-run-kill-buffers'
266 ;; Run kill buffer action from `anything-c-source-buffers-list'.
267 ;; `anything-buffer-run-grep'
268 ;; Run Grep action from `anything-c-source-buffers-list'.
269 ;; `anything-buffer-run-zgrep'
270 ;; Run Grep action from `anything-c-source-buffers-list'.
271 ;; `anything-buffer-run-query-replace-regexp'
272 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
273 ;; `anything-buffer-run-query-replace'
274 ;; Run Query replace action from `anything-c-source-buffers-list'.
275 ;; `anything-buffer-switch-other-window'
276 ;; Run switch to other window action from `anything-c-source-buffers-list'.
277 ;; `anything-buffer-switch-other-frame'
278 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
279 ;; `anything-buffer-switch-to-elscreen'
280 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
281 ;; `anything-buffer-run-ediff'
282 ;; Run ediff action from `anything-c-source-buffers-list'.
283 ;; `anything-buffer-run-ediff-merge'
284 ;; Run ediff action from `anything-c-source-buffers-list'.
285 ;; `anything-ff-run-toggle-auto-update'
286 ;; Not documented.
287 ;; `anything-ff-run-switch-to-history'
288 ;; Run Switch to history action from `anything-c-source-find-files'.
289 ;; `anything-ff-run-grep'
290 ;; Run Grep action from `anything-c-source-find-files'.
291 ;; `anything-ff-run-pdfgrep'
292 ;; Run Pdfgrep action from `anything-c-source-find-files'.
293 ;; `anything-ff-run-zgrep'
294 ;; Run Grep action from `anything-c-source-find-files'.
295 ;; `anything-ff-run-copy-file'
296 ;; Run Copy file action from `anything-c-source-find-files'.
297 ;; `anything-ff-run-rename-file'
298 ;; Run Rename file action from `anything-c-source-find-files'.
299 ;; `anything-ff-run-byte-compile-file'
300 ;; Run Byte compile file action from `anything-c-source-find-files'.
301 ;; `anything-ff-run-load-file'
302 ;; Run Load file action from `anything-c-source-find-files'.
303 ;; `anything-ff-run-eshell-command-on-file'
304 ;; Run eshell command on file action from `anything-c-source-find-files'.
305 ;; `anything-ff-run-ediff-file'
306 ;; Run Ediff file action from `anything-c-source-find-files'.
307 ;; `anything-ff-run-ediff-merge-file'
308 ;; Run Ediff merge file action from `anything-c-source-find-files'.
309 ;; `anything-ff-run-symlink-file'
310 ;; Run Symlink file action from `anything-c-source-find-files'.
311 ;; `anything-ff-run-delete-file'
312 ;; Run Delete file action from `anything-c-source-find-files'.
313 ;; `anything-ff-run-complete-fn-at-point'
314 ;; Run complete file name action from `anything-c-source-find-files'.
315 ;; `anything-ff-run-switch-to-eshell'
316 ;; Run switch to eshell action from `anything-c-source-find-files'.
317 ;; `anything-ff-run-switch-other-window'
318 ;; Run switch to other window action from `anything-c-source-find-files'.
319 ;; `anything-ff-run-switch-other-frame'
320 ;; Run switch to other frame action from `anything-c-source-find-files'.
321 ;; `anything-ff-run-open-file-externally'
322 ;; Run open file externally command action from `anything-c-source-find-files'.
323 ;; `anything-ff-run-locate'
324 ;; Run locate action from `anything-c-source-find-files'.
325 ;; `anything-ff-run-gnus-attach-files'
326 ;; Run gnus attach files command action from `anything-c-source-find-files'.
327 ;; `anything-ff-run-etags'
328 ;; Run Etags command action from `anything-c-source-find-files'.
329 ;; `anything-ff-run-print-file'
330 ;; Run Print file action from `anything-c-source-find-files'.
331 ;; `anything-ff-run-toggle-basename'
332 ;; Not documented.
333 ;; `anything-find-files-down-one-level'
334 ;; Go down one level like unix command `cd ..'.
335 ;; `anything-ff-properties-persistent'
336 ;; Show properties without quitting anything.
337 ;; `anything-ff-run-kill-buffer-persistent'
338 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
339 ;; `anything-ff-rotate-left-persistent'
340 ;; Rotate image left without quitting anything.
341 ;; `anything-ff-rotate-right-persistent'
342 ;; Rotate image right without quitting anything.
343 ;; `anything-c-goto-precedent-file'
344 ;; Go to precedent file in anything grep/etags buffers.
345 ;; `anything-c-goto-next-file'
346 ;; Go to precedent file in anything grep/etags buffers.
347 ;; `anything-c-grep-run-persistent-action'
348 ;; Run grep persistent action from `anything-do-grep-1'.
349 ;; `anything-c-grep-run-default-action'
350 ;; Run grep default action from `anything-do-grep-1'.
351 ;; `anything-c-grep-run-other-window-action'
352 ;; Run grep goto other window action from `anything-do-grep-1'.
353 ;; `anything-c-grep-run-save-buffer'
354 ;; Run grep save results action from `anything-do-grep-1'.
355 ;; `anything-do-pdfgrep'
356 ;; Not documented.
357 ;; `anything-yank-text-at-point'
358 ;; Yank text at point in minibuffer.
359 ;; `anything-c-describe-attributes'
360 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
361 ;; `anything-yaoddmuse-cache-pages'
362 ;; Fetch the list of files on emacswiki and create cache file.
363 ;; `anything-eval-new-line-and-indent'
364 ;; Not documented.
365 ;; `anything-call-source-from-anything'
366 ;; Call anything source within `anything' session.
367 ;; `anything-create-from-anything'
368 ;; Run `anything-create' from `anything' as a fallback.
369 ;; `anything-c-ucs-persistent-insert'
370 ;; Not documented.
371 ;; `anything-c-ucs-persistent-forward'
372 ;; Not documented.
373 ;; `anything-c-ucs-persistent-backward'
374 ;; Not documented.
375 ;; `anything-c-ucs-persistent-delete'
376 ;; Not documented.
377 ;; `anything-lisp-completion-at-point'
378 ;; Anything lisp symbol completion at point.
379 ;; `anything-c-complete-file-name-at-point'
380 ;; Complete file name at point.
381 ;; `anything-lisp-completion-at-point-or-indent'
382 ;; First call indent and second call complete lisp symbol.
383 ;; `anything-lisp-completion-or-file-name-at-point'
384 ;; Complete lisp symbol or filename at point.
385 ;; `anything-c-set-variable'
386 ;; Set value to VAR interactively.
387 ;; `anything-c-adaptive-save-history'
388 ;; Save history information to file given by `anything-c-adaptive-history-file'.
389 ;; `anything-c-reset-adaptative-history'
390 ;; Delete all `anything-c-adaptive-history' and his file.
391 ;; `anything-c-toggle-match-plugin'
392 ;; Toggle anything-match-plugin.
394 ;; * User variables defined here:
395 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
396 ;; `anything-c-adaptive-history-file'
397 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
398 ;; `anything-c-adaptive-history-length'
399 ;; Default Value: 50
400 ;; `anything-c-google-suggest-url'
401 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
402 ;; `anything-c-google-suggest-search-url'
403 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
404 ;; `anything-google-suggest-use-curl-p'
405 ;; Default Value: nil
406 ;; `anything-c-yahoo-suggest-url'
407 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
408 ;; `anything-c-yahoo-suggest-search-url'
409 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
410 ;; `anything-c-boring-buffer-regexp'
411 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
412 ;; `anything-c-boring-file-regexp'
413 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
414 ;; `anything-kill-ring-threshold'
415 ;; Default Value: 10
416 ;; `anything-c-kill-ring-max-lines-number'
417 ;; Default Value: nil
418 ;; `anything-su-or-sudo'
419 ;; Default Value: "su"
420 ;; `anything-for-files-prefered-list'
421 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
422 ;; `anything-create--actions-private'
423 ;; Default Value: nil
424 ;; `anything-allow-skipping-current-buffer'
425 ;; Default Value: t
426 ;; `anything-c-enable-eval-defun-hack'
427 ;; Default Value: t
428 ;; `anything-tramp-verbose'
429 ;; Default Value: 0
430 ;; `anything-raise-command'
431 ;; Default Value: nil
432 ;; `anything-command-map-prefix-key'
433 ;; Default Value: "<f5> a"
434 ;; `anything-c-browse-code-regexp-lisp'
435 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
436 ;; `anything-c-browse-code-regexp-python'
437 ;; Default Value: "\\<def\\>\\|\\<class\\>"
438 ;; `anything-c-browse-code-regexp-alist'
439 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
440 ;; `anything-c-external-programs-associations'
441 ;; Default Value: nil
442 ;; `anything-ff-auto-update-initial-value'
443 ;; Default Value: t
444 ;; `anything-c-copy-async-prefered-emacs'
445 ;; Default Value: "emacs"
446 ;; `anything-ff-lynx-style-map'
447 ;; Default Value: t
448 ;; `anything-ff-history-max-length'
449 ;; Default Value: 100
450 ;; `anything-ff-smart-completion'
451 ;; Default Value: t
452 ;; `anything-ff-default-kbsize'
453 ;; Default Value: 1024.0
454 ;; `anything-ff-tramp-not-fancy'
455 ;; Default Value: t
456 ;; `anything-ff-exif-data-program'
457 ;; Default Value: "exiftran"
458 ;; `anything-ff-exif-data-program-args'
459 ;; Default Value: "-d"
460 ;; `anything-c-grep-use-ioccur-style-keys'
461 ;; Default Value: t
462 ;; `anything-c-pdfgrep-default-read-command'
463 ;; Default Value: "xpdf '%f' %p"
464 ;; `anything-c-etags-tag-file-name'
465 ;; Default Value: "TAGS"
466 ;; `anything-c-etags-tag-file-search-limit'
467 ;; Default Value: 10
468 ;; `anything-c-etags-use-regexp-search'
469 ;; Default Value: nil
470 ;; `anything-c-filelist-file-name'
471 ;; Default Value: nil
472 ;; `anything-c-eldoc-in-minibuffer-show-fn'
473 ;; Default Value: anything-c-eldoc-show-in-mode-line
474 ;; `anything-c-turn-on-show-completion'
475 ;; Default Value: t
476 ;; `anything-lisp-completion-or-indent-delay'
477 ;; Default Value: 0.6
478 ;; `anything-c-default-external-file-browser'
479 ;; Default Value: "nautilus"
480 ;; `anything-c-use-adaptative-sorting'
481 ;; Default Value: nil
482 ;; `anything-ff-newfile-prompt-p'
483 ;; Default Value: t
484 ;; `anything-ff-avfs-directory'
485 ;; Default Value: nil
486 ;; `anything-ff-file-compressed-list'
487 ;; Default Value: ("gz" "bz2" "zip" "7z")
488 ;; `anything-locate-db-file-regexp'
489 ;; Default Value: "m?locate.db$"
490 ;; `anything-c-eldoc-show-in-mode-line-delay'
491 ;; Default Value: 12
492 ;; `anything-c-copy-files-async-log-file'
493 ;; Default Value: "/tmp/dired.log"
494 ;; `anything-ff-printer-list'
495 ;; Default Value: nil
496 ;; `anything-ff-transformer-show-only-basename'
497 ;; Default Value: nil
499 ;; * Anything sources defined here:
500 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
501 ;; `anything-c-source-regexp' (Regexp Builder)
502 ;; `anything-c-source-buffers' (Buffers)
503 ;; `anything-c-source-buffer-not-found' (Create buffer)
504 ;; `anything-c-source-buffers-list' (Buffers)
505 ;; `anything-c-source-file-name-history' (File Name History)
506 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
507 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
508 ;; `anything-c-source-find-files' (Find Files)
509 ;; `anything-c-source-write-file' (Write File)
510 ;; `anything-c-source-insert-file' (Insert File)
511 ;; `anything-c-source-copy-files' (Copy Files)
512 ;; `anything-c-source-symlink-files' (Symlink Files)
513 ;; `anything-c-source-hardlink-files' (Hardlink Files)
514 ;; `anything-c-source-file-cache' (File Cache)
515 ;; `anything-c-source-locate' (Locate)
516 ;; `anything-c-source-recentf' (Recentf)
517 ;; `anything-c-source-ffap-guesser' (File at point)
518 ;; `anything-c-source-ffap-line' (File/Lineno at point)
519 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
520 ;; `anything-c-source-filelist' (FileList)
521 ;; `anything-c-source-info-pages' (Info Pages)
522 ;; `anything-c-source-info-elisp' (Info index: elisp)
523 ;; `anything-c-source-info-cl' (Info index: cl)
524 ;; `anything-c-source-info-org' (Info index: org)
525 ;; `anything-c-source-info-gnus' (Info index: Gnus)
526 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
527 ;; `anything-c-source-info-zsh' (Info index: zsh)
528 ;; `anything-c-source-info-bash' (Info index: bash)
529 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
530 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
531 ;; `anything-c-source-info-find' (Info index: find)
532 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
533 ;; `anything-c-source-info-textutils' (Info index: textutils)
534 ;; `anything-c-source-info-libc' (Info index: libc)
535 ;; `anything-c-source-info-make' (Info index: make)
536 ;; `anything-c-source-info-automake' (Info index: automake)
537 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
538 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
539 ;; `anything-c-source-info-emacs' (Info index: emacs)
540 ;; `anything-c-source-info-elib' (Info index: elib)
541 ;; `anything-c-source-info-eieio' (Info index: eieio)
542 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
543 ;; `anything-c-source-info-guile' (Info index: guile)
544 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
545 ;; `anything-c-source-info-goops' (Info index: goops)
546 ;; `anything-c-source-info-screen' (Info index: screen)
547 ;; `anything-c-source-info-latex' (Info index: latex)
548 ;; `anything-c-source-info-gawk' (Info index: gawk)
549 ;; `anything-c-source-info-sed' (Info index: sed)
550 ;; `anything-c-source-info-m4' (Info index: m4)
551 ;; `anything-c-source-info-wget' (Info index: wget)
552 ;; `anything-c-source-info-binutils' (Info index: binutils)
553 ;; `anything-c-source-info-as' (Info index: as)
554 ;; `anything-c-source-info-bfd' (Info index: bfd)
555 ;; `anything-c-source-info-gprof' (Info index: gprof)
556 ;; `anything-c-source-info-ld' (Info index: ld)
557 ;; `anything-c-source-info-diff' (Info index: diff)
558 ;; `anything-c-source-info-flex' (Info index: flex)
559 ;; `anything-c-source-info-grep' (Info index: grep)
560 ;; `anything-c-source-info-gzip' (Info index: gzip)
561 ;; `anything-c-source-info-libtool' (Info index: libtool)
562 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
563 ;; `anything-c-source-info-info' (Info index: info)
564 ;; `anything-c-source-info-gdb' (Info index: gdb)
565 ;; `anything-c-source-info-stabs' (Info index: stabs)
566 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
567 ;; `anything-c-source-info-cvs' (Info index: cvs)
568 ;; `anything-c-source-info-bison' (Info index: bison)
569 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
570 ;; `anything-c-source-info-global' (Info index: global)
571 ;; `anything-c-source-man-pages' (Manual Pages)
572 ;; `anything-c-source-complex-command-history' (Complex Command History)
573 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
574 ;; `anything-c-source-emacs-commands' (Emacs Commands)
575 ;; `anything-c-source-lacarte' (Lacarte)
576 ;; `anything-c-source-emacs-functions' (Emacs Functions)
577 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
578 ;; `anything-c-source-advice' (Function Advice)
579 ;; `anything-c-source-emacs-variables' (Emacs Variables)
580 ;; `anything-c-source-bookmarks' (Bookmarks)
581 ;; `anything-c-source-bookmark-set' (Set Bookmark)
582 ;; `anything-c-source-bm' (Visible Bookmarks)
583 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
584 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
585 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
586 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
587 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
588 ;; `anything-c-source-bookmark-images' (Bookmark Images)
589 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
590 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
591 ;; `anything-c-source-bookmark-info' (Bookmark Info)
592 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
593 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
594 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
595 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
596 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
597 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
598 ;; `anything-c-source-imenu' (Imenu)
599 ;; `anything-c-source-ctags' (Exuberant ctags)
600 ;; `anything-c-source-etags-select' (Etags)
601 ;; `anything-c-source-semantic' (Semantic Tags)
602 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
603 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
604 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
605 ;; `anything-c-source-customize-face' (Customize Face)
606 ;; `anything-c-source-colors' (Colors)
607 ;; `anything-c-source-tracker-search' (Tracker Search)
608 ;; `anything-c-source-mac-spotlight' (mdfind)
609 ;; `anything-c-source-picklist' (Picklist)
610 ;; `anything-c-source-kill-ring' (Kill Ring)
611 ;; `anything-c-source-mark-ring' (mark-ring)
612 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
613 ;; `anything-c-source-register' (Registers)
614 ;; `anything-c-source-latex-math' (Latex Math Menu)
615 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
616 ;; `anything-c-source-rd-headline' (RD HeadLine)
617 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
618 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
619 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
620 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
621 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
622 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
623 ;; `anything-c-source-eev-anchor' (Anchors)
624 ;; `anything-c-source-org-headline' (Org HeadLine)
625 ;; `anything-c-source-org-keywords' (Org Keywords)
626 ;; `anything-c-source-bbdb' (BBDB)
627 ;; `anything-c-source-evaluation-result' (Evaluation Result)
628 ;; `anything-c-source-calculation-result' (Calculation Result)
629 ;; `anything-c-source-google-suggest' (Google Suggest)
630 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
631 ;; `anything-c-source-emms-streams' (Emms Streams)
632 ;; `anything-c-source-emms-dired' (Music Directory)
633 ;; `anything-c-source-emms-files' (Emms files)
634 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
635 ;; `anything-c-source-call-source' (Call anything source)
636 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
637 ;; `anything-c-source-occur' (Occur)
638 ;; `anything-c-source-browse-code' (Browse code)
639 ;; `anything-c-source-create' (Create)
640 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
641 ;; `anything-c-source-elscreen' (Elscreen)
642 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
643 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
644 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
645 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
646 ;; `anything-c-source-xfonts' (X Fonts)
647 ;; `anything-c-source-ucs' (Ucs names)
648 ;; `anything-c-source-emacs-process' (Emacs Process)
649 ;; `anything-c-source-time-world' (Time World List)
650 ;; `anything-c-source-apt' (APT)
651 ;; `anything-c-source-gentoo' (Portage sources)
652 ;; `anything-c-source-use-flags' (Use Flags)
653 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
654 ;; `anything-c-source-esh' (Eshell completions)
655 ;; `anything-c-source-eshell-history' (Eshell history)
657 ;; *** END auto-documentation
659 ;;; For Maintainers:
661 ;; Install developer-tools/autodoc.el and
662 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
663 ;; This function generates anything-c-source-* / functions / options list.
665 ;; [EVAL IT] (autodoc-update-all)
667 ;; Please write details documentation about function, then others will
668 ;; read code more easier. -- Andy Stewart
672 ;;; Change log:
674 ;; Change log of this file is found at
675 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
677 ;; Change log of this project is found at
678 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
680 ;;; Contributors:
682 ;; Tamas Patrovics
683 ;; Tassilo Horn <tassilo@member.fsf.org>
684 ;; Vagn Johansen <gonz808@hotmail.com>
685 ;; Mathias Dahl <mathias.dahl@gmail.com>
686 ;; Bill Clementson <billclem@gmail.com>
687 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
688 ;; Drew Adams <drew.adams@oracle.com>
689 ;; Jason McBrayer <jmcbray@carcosa.net>
690 ;; Andy Stewart <lazycat.manatee@gmail.com>
691 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
692 ;; rubikitch <rubikitch@ruby-lang.org>
693 ;; Scott Vokes <vokes.s@gmail.com>
694 ;; Kenichirou Oyama <k1lowxb@gmail.com>
697 ;;; TODO
699 ;; - Fix documentation, now many functions haven't documentations.
703 ;;; Code:
705 ;;; Require
708 (require 'anything)
709 (require 'thingatpt)
710 (require 'ffap)
711 (require 'cl)
712 (require 'dired-aux)
713 (require 'dired-x)
714 (require 'tramp)
715 (require 'grep)
716 (require 'url)
717 (require 'xml)
718 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
719 (eval-when-compile (require 'semantic nil t))
720 (require 'anything-match-plugin)
724 ;;; Declare external functions
727 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
728 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
729 (declare-function image-dired-update-property "image-dired.el" (prop value))
730 (declare-function woman-file-name-all-completions "woman.el" (topic))
731 (declare-function Man-getpage-in-background "man.el" (topic))
732 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
733 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
734 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
735 (declare-function org-get-current-options "ext:org-exp.el")
736 (declare-function emms-streams "ext:emms-streams")
737 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
738 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
739 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
740 (declare-function emms-stream-quit "ext:emms-streams")
741 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
742 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
743 (declare-function emms-playlist-first "ext:emms")
744 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
745 (declare-function term-line-mode "term")
746 (declare-function term-char-mode "term")
747 (declare-function term-send-input "term")
748 (declare-function term-send-eof "term")
749 (declare-function Info-index-nodes "info" (&optional file))
750 (declare-function Info-goto-node "info" (&optional fork))
751 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
752 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
753 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
754 (declare-function elscreen-goto "ext:elscreen.el" (screen))
755 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
756 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
757 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
758 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
759 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
760 (declare-function bbdb "ext:bbdb-com")
761 (declare-function bbdb-current-record "ext:bbdb-com")
762 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
763 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
764 (declare-function bbdb-current-record "ext:bbdb-com")
765 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
766 (declare-function bbdb-records "ext:bbdb-com"
767 (&optional dont-check-disk already-in-db-buffer))
768 (declare-function eshell-read-aliases-list "em-alias")
769 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
770 (declare-function eshell-bol "esh-mode")
771 (declare-function eldoc-current-symbol "eldoc")
772 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
773 (declare-function eldoc-get-var-docstring "eldoc" (sym))
774 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
775 (declare-function find-library-name "find-func.el" (library))
776 (declare-function adoc-construct "ext:auto-document.el" (buf))
777 (declare-function adoc-first-line "ext:auto-document.el" (str))
778 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
779 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
783 ;;; compatibility
786 (unless (fboundp 'window-system)
787 (defun window-system (&optional arg)
788 window-system))
792 ;;; Customize
795 (defgroup anything-config nil
796 "Predefined configurations for `anything.el'."
797 :group 'anything)
799 (defcustom anything-c-adaptive-history-file
800 "~/.emacs.d/anything-c-adaptive-history"
801 "Path of file where history information is stored."
802 :type 'string
803 :group 'anything-config)
805 (defcustom anything-c-adaptive-history-length 50
806 "Maximum number of candidates stored for a source."
807 :type 'number
808 :group 'anything-config)
810 (defcustom anything-c-google-suggest-url
811 "http://google.com/complete/search?output=toolbar&q="
812 "URL used for looking up Google suggestions."
813 :type 'string
814 :group 'anything-config)
816 (defcustom anything-c-google-suggest-search-url
817 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
818 "URL used for Google searching."
819 :type 'string
820 :group 'anything-config)
822 (defcustom anything-google-suggest-use-curl-p nil
823 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
824 Otherwise `url-retrieve-synchronously' is used."
825 :type 'boolean
826 :group 'anything-config)
828 (defcustom anything-c-yahoo-suggest-url
829 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
830 "Url used for looking up Yahoo suggestions."
831 :type 'string
832 :group 'anything-config)
834 (defcustom anything-c-yahoo-suggest-search-url
835 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
836 "Url used for Yahoo searching."
837 :type 'string
838 :group 'anything-config)
840 (defcustom anything-c-boring-buffer-regexp
841 (rx (or
842 (group bos " ")
843 ;; anything-buffers
844 "*anything" "*ac-mode"
845 ;; echo area
846 " *Echo Area" " *Minibuf"))
847 "The regexp that match boring buffers.
848 Buffer candidates matching this regular expression will be
849 filtered from the list of candidates if the
850 `anything-c-skip-boring-buffers' candidate transformer is used, or
851 they will be displayed with face `file-name-shadow' if
852 `anything-c-shadow-boring-buffers' is used."
853 :type 'string
854 :group 'anything-config)
855 ;; (string-match anything-c-boring-buffer-regexp "buf")
856 ;; (string-match anything-c-boring-buffer-regexp " hidden")
857 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
859 (defcustom anything-c-boring-file-regexp
860 (rx (or
861 ;; Boring directories
862 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
863 ;; Boring files
864 (and line-start ".#")
865 (and (or ".class" ".la" ".o" "~") eol)))
866 "The regexp that match boring files.
867 File candidates matching this regular expression will be
868 filtered from the list of candidates if the
869 `anything-c-skip-boring-files' candidate transformer is used, or
870 they will be displayed with face `file-name-shadow' if
871 `anything-c-shadow-boring-files' is used."
872 :type 'string
873 :group 'anything-config)
875 (defcustom anything-kill-ring-threshold 10
876 "*Minimum length to be listed by `anything-c-source-kill-ring'."
877 :type 'integer
878 :group 'anything-config)
880 (defcustom anything-c-kill-ring-max-lines-number nil
881 "Max number of lines displayed per candidate in kill-ring browser.
882 If nil or zero, don't truncate candidate, show all."
883 :type 'integer
884 :group 'anything-config)
886 (defcustom anything-su-or-sudo "su"
887 "What command to use for root access."
888 :type 'string
889 :group 'anything-config)
891 (defcustom anything-for-files-prefered-list
892 '(anything-c-source-ffap-line
893 anything-c-source-ffap-guesser
894 anything-c-source-buffers-list
895 anything-c-source-recentf
896 anything-c-source-bookmarks
897 anything-c-source-file-cache
898 anything-c-source-files-in-current-dir+
899 anything-c-source-locate)
900 "Your prefered sources to find files."
901 :type 'list
902 :group 'anything-config)
904 (defcustom anything-create--actions-private nil
905 "User defined actions for `anything-create' / `anything-c-source-create'.
906 It is a list of (DISPLAY . FUNCTION) pairs like `action'
907 attribute of `anything-sources'.
909 It is prepended to predefined pairs."
910 :type 'list
911 :group 'anything-config)
913 (defcustom anything-allow-skipping-current-buffer t
914 "Show current buffer or not in anything buffer"
915 :type 'boolean
916 :group 'anything-config)
918 (defcustom anything-c-enable-eval-defun-hack t
919 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
920 This hack is invoked when pressing C-M-x in the form \
921 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
922 :type 'boolean
923 :group 'anything-config)
925 (defcustom anything-tramp-verbose 0
926 "*Just like `tramp-verbose' but specific to anything.
927 When set to 0 don't show tramp messages in anything.
928 If you want to have the default tramp messages set it to 3."
929 :type 'integer
930 :group 'anything-config)
932 (defcustom anything-raise-command nil
933 "*A shell command to jump to a window running specific program.
934 Need external program wmctrl.
935 This will be use with `format', so use something like \"wmctrl -xa %s\"."
936 :type 'string
937 :group 'anything-config)
939 (defun anything-set-anything-command-map-prefix-key (var key)
940 (declare (special anything-command-map-prefix-key))
941 (when (boundp 'anything-command-map-prefix-key)
942 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
943 (setq anything-command-map-prefix-key key)
944 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
945 'anything-command-map))
947 (defcustom anything-command-map-prefix-key "<f5> a"
948 "*The prefix key for all `anything-command-map' commands.
950 !!WARNING!!
951 This default value is very likely to be changed,
952 because it is under discussion."
953 :type 'string
954 :set 'anything-set-anything-command-map-prefix-key
955 :group 'anything-config)
957 (defcustom anything-c-browse-code-regexp-lisp
958 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
959 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
960 "*Regexp used to parse lisp buffer when browsing code."
961 :type 'string
962 :group 'anything-config)
964 (defcustom anything-c-browse-code-regexp-python
965 "\\<def\\>\\|\\<class\\>"
966 "*Regexp used to parse python buffer when browsing code."
967 :type 'string
968 :group 'anything-config)
970 (defcustom anything-c-browse-code-regexp-alist
971 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
972 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
973 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
974 (python-mode . ,anything-c-browse-code-regexp-python))
975 "*Alist to store regexps for browsing code corresponding \
976 to a specific `major-mode'."
977 :type 'list
978 :group 'anything-config)
980 (defcustom anything-c-external-programs-associations nil
981 "*Alist to store externals programs associated with file extension.
982 This variable overhide setting in .mailcap file.
983 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
984 :type 'list
985 :group 'anything-config)
987 (defcustom anything-ff-auto-update-initial-value t
988 "Auto update when only one candidate directory is matched.
989 This is the default value when starting `anything-find-files'."
990 :group 'anything-config
991 :type 'boolean)
993 (defcustom anything-c-copy-async-prefered-emacs "emacs"
994 "Path to the emacs you want to use for copying async.
995 Emacs versions < 24 fail to copy directory due to a bug not fixed
996 in `copy-directory'."
997 :group 'anything-config
998 :type 'string)
1000 (defcustom anything-ff-lynx-style-map t
1001 "Use arrow keys to navigate with `anything-find-files'.
1002 You will have to restart Emacs or reeval `anything-find-files-map'
1003 and `anything-c-read-file-map' for this take effect."
1004 :group 'anything-config
1005 :type 'boolean)
1007 (defcustom anything-ff-history-max-length 100
1008 "*Number of elements shown in `anything-find-files' history."
1009 :group 'anything-config
1010 :type 'integer)
1012 (defcustom anything-ff-smart-completion t
1013 "Try to complete filenames smarter when non--nil.
1014 See `anything-ff-transform-fname-for-completion' for more info."
1015 :group 'anything-config
1016 :type 'boolean)
1018 (defcustom anything-ff-default-kbsize 1024.0
1019 "Default Kbsize to use for showing files size.
1020 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1021 :group 'anything-config
1022 :type 'float)
1024 (defcustom anything-ff-tramp-not-fancy t
1025 "No colors when listing remote files when set to non--nil.
1026 This make listing much faster, specially on slow machines."
1027 :group 'anything-config
1028 :type 'boolean)
1030 (defcustom anything-ff-exif-data-program "exiftran"
1031 "*Program used to extract exif data of an image file."
1032 :group 'anything-config
1033 :type 'string)
1035 (defcustom anything-ff-exif-data-program-args "-d"
1036 "*Arguments used for `anything-ff-exif-data-program'."
1037 :group 'anything-config
1038 :type 'string)
1040 (defcustom anything-c-grep-use-ioccur-style-keys t
1041 "Use Arrow keys to jump to occurences."
1042 :group 'anything-config
1043 :type 'boolean)
1045 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1046 "Default command to read pdf files from pdfgrep.
1047 Where '%f' format spec is filename and '%p' is page number"
1048 :group 'anything-config
1049 :type 'string)
1051 (defcustom anything-c-etags-tag-file-name "TAGS"
1052 "Etags tag file name."
1053 :type 'string
1054 :group 'anything-config)
1056 (defcustom anything-c-etags-tag-file-search-limit 10
1057 "The limit level of directory to search tag file.
1058 Don't search tag file deeply if outside this value."
1059 :type 'number
1060 :group 'anything-config)
1062 (defcustom anything-c-etags-use-regexp-search nil
1063 "When non--nil search etags candidates by regexp.
1064 This disable anything-match-plugin when enabled.
1065 When nil search is performed directly on patter and *match-plugin is used
1066 if available. You can customize `anything-c-etags-search-regexp'."
1067 :group 'anything-config
1068 :type 'boolean)
1070 (defcustom anything-c-etags-search-regexp "^.+: .+ \\<%s"
1071 "Regexp that match tags in an anything etags buffer.
1072 The format spec is replaced by pattern.
1073 This regexp have no effect when `anything-c-etags-use-regexp-search'
1074 is nil."
1075 :group 'anything-config
1076 :type 'regexp)
1078 (defcustom anything-c-filelist-file-name nil
1079 "Filename of file list.
1080 Accept a list of string for multiple files.
1082 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1083 File list is created by make-filelist.rb script.
1085 Usage:
1086 ruby make-filelist.rb > /tmp/all.filelist
1088 Then
1089 ;; Assume that /tmp is ramdisk or tmpfs
1090 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1091 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1093 :type 'string
1094 :group 'anything-config)
1096 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1097 'anything-c-eldoc-show-in-mode-line
1098 "A function to display eldoc info.
1099 Should take one arg: the string to display."
1100 :group 'anything-config
1101 :type 'symbol)
1103 (defcustom anything-c-turn-on-show-completion t
1104 "Display candidate in buffer while moving selection when non--nil."
1105 :group 'anything-config
1106 :type 'boolean)
1108 (defcustom anything-lisp-completion-or-indent-delay 0.6
1109 "After this delay `anything-lisp-completion-counter' is reset to 0.
1110 This allow to indent again without completing lisp symbol after this delay.
1111 Default is 0.6 seconds."
1112 :group 'anything-config
1113 :type 'number)
1115 (defcustom anything-c-default-external-file-browser "nautilus"
1116 "Default external file browser for your system.
1117 Directories will be opened externally with it.
1118 Set to nil if you do not have external file browser
1119 or do not want to use it."
1120 :group 'anything-config
1121 :type 'string)
1123 (defcustom anything-c-use-adaptative-sorting nil
1124 "*Wheter to use or not adaptative sorting.
1125 Even if a source use it, it will have no effect when set to nil."
1126 :type 'boolean
1127 :group 'anything-config)
1129 (defcustom anything-ff-newfile-prompt-p t
1130 "Whether Prompt or not when creating new file.
1131 This set `ffap-newfile-prompt'."
1132 :type 'boolean
1133 :group 'anything-config)
1136 (defcustom anything-ff-avfs-directory nil
1137 "*The default avfs directory, usually '.avfs'.
1138 When this is set you will be able to expand archive filenames with `C-z'
1139 inside an avfs directory mounted with mountavfs.
1140 See <http://sourceforge.net/projects/avf/>."
1141 :type 'boolean
1142 :group 'anything-config)
1144 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1145 "*Minimal list of compressed files extension."
1146 :type 'list
1147 :group 'anything-config)
1149 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1150 "Default regexp to match locate database.
1151 If nil Search in all files."
1152 :type 'string
1153 :group 'anything-config)
1155 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1156 "Eldoc will show info in mode-line during this delay if user is idle."
1157 :type 'integer
1158 :group 'anything-config)
1160 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1161 "The file used to communicate with two emacs when copying files async."
1162 :type 'string
1163 :group 'anything-config)
1165 (defcustom anything-ff-printer-list nil
1166 "A list of available printers on your system.
1167 When non--nil let you choose a printer to print file.
1168 Otherwise when nil the variable `printer-name' will be used.
1169 On Unix based systems you can use `anything-ff-find-printers' to
1170 find a list of available printers."
1171 :type 'list
1172 :group 'anything-config)
1174 (defcustom anything-ff-transformer-show-only-basename nil
1175 "Show only basename of candidates in `anything-find-files'.
1176 This can be toggled at anytime from `anything-find-files' with \
1177 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1178 :type 'boolean
1179 :group 'anything-config)
1181 (defcustom anything-completing-read-handlers-alist
1182 '((describe-function . anything-completing-read-symbols)
1183 (describe-variable . anything-completing-read-symbols)
1184 (debug-on-entry . anything-completing-read-symbols)
1185 (find-function . anything-completing-read-symbols)
1186 (trace-function . anything-completing-read-symbols)
1187 (trace-function-background . anything-completing-read-symbols)
1188 (find-tag . anything-completing-read-with-cands-in-buffer)
1189 (ffap-alternate-file . nil))
1190 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1191 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1192 where key and value are symbols.
1194 Each key is an Emacs command that use originaly `completing-read'.
1196 Each value maybe an anything function that take same arguments as
1197 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1198 anything source and BUFFER the name of the buffer we will use.
1199 This function prefix name must start by \"anything\".
1201 See `anything-completing-read-symbols' for example.
1203 If the value of an entry is nil completion will fall back to
1204 emacs vanilla behavior.
1205 e.g If you want to disable anything completion for `describe-function':
1206 \(describe-function . nil\).
1208 Ido is also supported, you can use `ido-completing-read' and
1209 `ido-read-file-name' as value of an entry or just 'ido.
1210 e.g ido completion for `find-file':
1211 \(find-file . ido\)
1212 same as
1213 \(find-file . ido-read-file-name\)
1214 Note that you don't need to enable `ido-mode' for this to work."
1215 :group 'anything-config
1216 :type '(alist :key-type symbol :value-type symbol))
1220 ;;; General internal variables
1222 ;; Some internals variable that need to be loaded
1223 ;; here to avoid compiler warnings.
1224 (defvar anything-c-external-commands-list nil
1225 "A list of all external commands the user can execute. If this
1226 variable is not set by the user, it will be calculated
1227 automatically.")
1229 (defvar anything-c-show-completion-overlay nil)
1231 (defvar anything-c-locate-command
1232 (case system-type
1233 ('gnu/linux "locate -i -r %s")
1234 ('berkeley-unix "locate -i %s")
1235 ('windows-nt "es -i -r %s")
1236 (t "locate %s"))
1237 "A list of arguments for locate program.
1238 The \"-r\" option must be the last option.")
1241 ;;; Faces
1244 (defface anything-buffer-saved-out
1245 '((t (:foreground "red")))
1246 "*Face used for buffer files modified outside of emacs."
1247 :group 'anything-config)
1249 (defface anything-buffer-not-saved
1250 '((t (:foreground "Indianred2")))
1251 "*Face used for buffer files not already saved on disk."
1252 :group 'anything-config)
1254 (defface anything-ff-prefix
1255 '((t (:background "yellow" :foreground "black")))
1256 "*Face used to prefix new file or url paths in `anything-find-files'."
1257 :group 'anything-config)
1259 (defface anything-ff-executable
1260 '((t (:foreground "green")))
1261 "*Face used for executable files in `anything-find-files'."
1262 :group 'anything-config)
1264 (defface anything-ff-directory
1265 '((t (:foreground "DarkRed" :background "LightGray")))
1266 "*Face used for directories in `anything-find-files'."
1267 :group 'anything-config)
1269 (defface anything-ff-symlink
1270 '((t (:foreground "DarkOrange")))
1271 "*Face used for symlinks in `anything-find-files'."
1272 :group 'anything-config)
1274 (defface anything-ff-invalid-symlink
1275 '((t (:foreground "black" :background "red")))
1276 "*Face used for invalid symlinks in `anything-find-files'."
1277 :group 'anything-config)
1279 (defface anything-ff-file
1280 '((t (:foreground "CadetBlue" :underline t)))
1281 "*Face used for file names in `anything-find-files'."
1282 :group 'anything-config)
1284 (defface anything-grep-match
1285 '((t (:inherit match)))
1286 "Face used to highlight grep matches."
1287 :group 'anything-config)
1289 (defface anything-grep-file
1290 '((t (:foreground "BlueViolet" :underline t)))
1291 "Face used to highlight grep results filenames."
1292 :group 'anything-config)
1294 (defface anything-grep-lineno
1295 '((t (:foreground "Darkorange1")))
1296 "Face used to highlight grep number lines."
1297 :group 'anything-config)
1299 (defface anything-grep-running
1300 '((t (:foreground "Red")))
1301 "Face used in mode line when grep is running."
1302 :group 'anything-config)
1304 (defface anything-grep-finish
1305 '((t (:foreground "Green")))
1306 "Face used in mode line when grep is finish."
1307 :group 'anything-config)
1309 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1310 "*Face used in anything-M-x to show keybinding."
1311 :group 'anything)
1313 (defface anything-bmkext-info
1314 '((t (:foreground "green")))
1315 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1316 :group 'anything)
1318 (defface anything-bmkext-w3m
1319 '((t (:foreground "yellow")))
1320 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1321 :group 'anything)
1323 (defface anything-bmkext-gnus
1324 '((t (:foreground "magenta")))
1325 "*Face used for Gnus bookmarks."
1326 :group 'anything)
1328 (defface anything-bmkext-man
1329 '((t (:foreground "Orange4")))
1330 "*Face used for Woman/man bookmarks."
1331 :group 'anything)
1333 (defface anything-bmkext-no--file
1334 '((t (:foreground "grey")))
1335 "*Face used for non--file bookmarks."
1336 :group 'anything)
1338 (defface anything-bmkext-file
1339 '((t (:foreground "Deepskyblue2")))
1340 "*Face used for non--file bookmarks."
1341 :group 'anything)
1343 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1344 "Face for su/sudo bookmarks."
1345 :group 'anything)
1347 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1348 "Face for w3m bookmarks" :group 'anything)
1350 (defface anything-emms-playlist
1351 '((t (:foreground "Springgreen4" :underline t)))
1352 "*Face used for tracks in current emms playlist."
1353 :group 'anything)
1355 (defface anything-apt-installed
1356 '((t (:foreground "green")))
1357 "*Face used for apt installed candidates."
1358 :group 'anything)
1360 (defface anything-gentoo-match-face '((t (:foreground "red")))
1361 "Face for anything-gentoo installed packages."
1362 :group 'traverse-faces)
1364 (defface anything-lisp-show-completion
1365 '((t (:background "DarkSlateGray")))
1366 "*Face used for showing candidates in `anything-lisp-completion'."
1367 :group 'anything-config)
1369 (defface anything-lisp-completion-info
1370 '((t (:foreground "red")))
1371 "*Face used for showing info in `anything-lisp-completion'."
1372 :group 'anything-config)
1374 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1375 "Face for source header in the anything buffer." :group 'anything)
1377 ;;;###autoload
1378 (defun anything-configuration ()
1379 "Customize `anything'."
1380 (interactive)
1381 (customize-group "anything-config"))
1385 ;;; Anything-command-map
1388 ;;;###autoload
1389 (defvar anything-command-map)
1390 (define-prefix-command 'anything-command-map)
1393 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1394 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1395 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1396 (define-key anything-command-map (kbd "l") 'anything-locate)
1397 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1398 (define-key anything-command-map (kbd "r") 'anything-regexp)
1399 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1400 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1401 (define-key anything-command-map (kbd "#") 'anything-emms)
1402 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1403 (define-key anything-command-map (kbd "t") 'anything-top)
1404 (define-key anything-command-map (kbd "i") 'anything-imenu)
1405 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1406 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1407 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1408 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1409 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1410 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1411 (define-key anything-command-map (kbd "f") 'anything-for-files)
1412 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1413 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1414 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1415 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1416 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1417 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1418 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1419 (define-key anything-command-map (kbd "c") 'anything-colors)
1420 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1421 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1422 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1423 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1424 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1425 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1426 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1427 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1428 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1429 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1431 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1432 ;; minibuffer-local-filename-must-match-map.
1433 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1434 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1435 (dolist (map (list minibuffer-local-filename-completion-map
1436 minibuffer-local-completion-map
1437 minibuffer-local-must-match-filename-map
1438 minibuffer-local-filename-must-match-map
1439 minibuffer-local-map
1440 minibuffer-local-isearch-map
1441 minibuffer-local-must-match-map
1442 minibuffer-local-ns-map))
1443 (define-key map "\C-r" 'anything-minibuffer-history))
1447 ;;; Menu
1450 (easy-menu-define nil global-map
1451 "`anything' menu"
1452 '("Anything"
1453 ["All anything commands" anything-execute-anything-command t]
1454 ["Find any Files/Buffers" anything-for-files t]
1455 ["Anything Everywhere (Toggle)" ac-mode t]
1456 "----"
1457 ("Files:"
1458 ["Find files" anything-find-files t]
1459 ["Recent Files" anything-recentf t]
1460 ["Locate" anything-locate t]
1461 ["Bookmarks" anything-c-pp-bookmarks t])
1462 ("Buffers:"
1463 ["Find buffers" anything-buffers-list t])
1464 ("Commands:"
1465 ["Emacs Commands" anything-M-x t]
1466 ["Externals Commands" anything-c-run-external-command t])
1467 ("Help:"
1468 ["Anything Apropos" anything-c-apropos t])
1469 ("Info:"
1470 ["Info at point" anything-info-at-point t]
1471 ["Emacs Manual index" anything-info-emacs t]
1472 ["Gnus Manual index" anything-info-gnus t])
1473 ("Org:"
1474 ["Org keywords" anything-org-keywords t]
1475 ["Org headlines" anything-org-headlines t])
1476 ("Tools:"
1477 ["Occur" anything-occur t]
1478 ["Grep" anything-do-grep t]
1479 ["Etags" anything-c-etags-select t]
1480 ["Lisp complete at point" anything-lisp-completion-at-point t]
1481 ["Browse Kill ring" anything-show-kill-ring t]
1482 ["Browse register" anything-register t]
1483 ["Browse code" anything-browse-code t]
1484 ["Mark Ring" anything-all-mark-rings t]
1485 ["Regexp handler" anything-regexp t]
1486 ["Colors & Faces" anything-colors t]
1487 ["Show xfonts" anything-select-xfont t]
1488 ["Ucs Symbols" anything-ucs t]
1489 ["Imenu" anything-imenu t]
1490 ["Google Suggest" anything-google-suggest t]
1491 ["Eval expression" anything-eval-expression-with-eldoc t]
1492 ["Calcul expression" anything-calcul-expression t]
1493 ["Man pages" anything-man-woman t]
1494 ["Top externals process" anything-top t]
1495 ["Emacs internals process" anything-list-emacs-process t])
1496 "----"
1497 ["Prefered Options" anything-configuration t]))
1499 ;;; Anything map add ons
1502 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1503 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1504 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1507 ;;; Specialized keymaps
1510 (defvar anything-c-buffer-map
1511 (let ((map (copy-keymap anything-map)))
1512 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1513 ;; No need to have separate command for grep and zgrep
1514 ;; as we don't use recursivity for buffers.
1515 ;; So use zgrep for both as it is capable to handle non--compressed files.
1516 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1517 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1518 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1519 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1520 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1521 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1522 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1523 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1524 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1525 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1526 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1527 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1528 (define-key map (kbd "M-a") 'anything-mark-all)
1529 (when (locate-library "elscreen")
1530 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1531 (delq nil map))
1532 "Keymap for buffer sources in anything.")
1534 (defvar anything-find-files-map
1535 (let ((map (copy-keymap anything-map)))
1536 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1537 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1538 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1539 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1540 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1541 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1542 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1543 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1544 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1545 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1546 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1547 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1548 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1549 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1550 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1551 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1552 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1553 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1554 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1555 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1556 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1557 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1558 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1559 (define-key map (kbd "C-c ?") 'anything-ff-help)
1560 (define-key map (kbd "C-}") 'anything-narrow-window)
1561 (define-key map (kbd "C-{") 'anything-enlarge-window)
1562 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1563 (define-key map (kbd "M-a") 'anything-mark-all)
1564 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1565 (define-key map (kbd "M-u") 'anything-unmark-all)
1566 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1567 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1568 ;; Next 2 have no effect if candidate is not an image file.
1569 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1570 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1571 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1572 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1573 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1574 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1575 (when anything-ff-lynx-style-map
1576 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1577 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1578 (delq nil map))
1579 "Keymap for `anything-find-files'.")
1581 (defvar anything-c-read-file-map
1582 (let ((map (copy-keymap anything-map)))
1583 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1584 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1585 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1586 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1587 (when anything-ff-lynx-style-map
1588 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1589 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1590 (define-key map (kbd "<M-left>") 'anything-previous-source)
1591 (define-key map (kbd "<M-right>") 'anything-next-source))
1592 (delq nil map))
1593 "Keymap for `anything-c-read-file-name'.")
1595 (defvar anything-generic-files-map
1596 (let ((map (copy-keymap anything-map)))
1597 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1598 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1599 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1600 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1601 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1602 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1603 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1604 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1605 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1606 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1607 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1608 map)
1609 "Generic Keymap for files.")
1611 (defvar anything-c-grep-map
1612 (let ((map (copy-keymap anything-map)))
1613 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1614 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1615 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1616 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1617 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1618 (when anything-c-grep-use-ioccur-style-keys
1619 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1620 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1621 (define-key map (kbd "C-c ?") 'anything-grep-help)
1622 (delq nil map))
1623 "Keymap used in Grep sources.")
1625 (defvar anything-c-pdfgrep-map
1626 (let ((map (copy-keymap anything-map)))
1627 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1628 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1629 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1630 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1631 map)
1632 "Keymap used in pdfgrep.")
1634 (defvar anything-c-etags-map
1635 (let ((map (copy-keymap anything-map)))
1636 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1637 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1638 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1639 (define-key map (kbd "C-c ?") 'anything-etags-help)
1640 map)
1641 "Keymap used in Etags.")
1643 (defvar anything-eval-expression-map
1644 (let ((map (copy-keymap anything-map)))
1645 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1646 (define-key map (kbd "<tab>") 'lisp-indent-line)
1647 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1648 (define-key map (kbd "C-p") 'previous-line)
1649 (define-key map (kbd "C-n") 'next-line)
1650 (define-key map (kbd "<up>") 'previous-line)
1651 (define-key map (kbd "<down>") 'next-line)
1652 (define-key map (kbd "<right>") 'forward-char)
1653 (define-key map (kbd "<left>") 'backward-char)
1654 map))
1656 (defvar anything-c-ucs-map
1657 (let ((map (copy-keymap anything-map)))
1658 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1659 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1660 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1661 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1662 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1663 map)
1664 "Keymap for `anything-ucs'.")
1668 ;;; Embeded documentation.
1671 (defun anything-c-list-preconfigured-anything ()
1672 "Collect preconfigured anything functions in this file."
1673 (loop with doc
1674 with sym
1675 for entry in (cdr (assoc
1676 (file-truename (locate-library "anything-config"))
1677 load-history))
1678 if (and (consp entry)
1679 (eq (car entry) 'defun)
1680 (string-match "^Preconfigured.+$"
1681 (setq doc (or (documentation (setq sym (cdr entry)))
1682 ""))))
1683 collect (cons sym (match-string 0 doc))))
1685 (defun anything-c-format-preconfigured-anything ()
1686 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1687 (anything-c-list-preconfigured-anything)))
1689 ;;; Global help message - Used by `anything-help'
1692 (setq anything-help-message
1693 (lambda ()
1694 (concat
1695 "\\<anything-map>"
1696 "`anything' is QuickSilver-like candidate-selection framework.
1698 Narrow the list by typing some pattern,
1699 Multiple patterns are allowed by splitting by space.
1700 Select with natural Emacs operations, choose with RET.
1702 If you have any problems, press C-c C-x C-b!!
1703 Feel free to send bug reports. I'll fix them.
1704 The steps are described in the beginning of anything.el file.
1706 == Basic Operations ==
1707 C-p, Up: Previous Line
1708 C-n, Down : Next Line
1709 M-v, PageUp : Previous Page
1710 C-v, PageDown : Next Page
1711 Enter : Execute first (default) action / Select
1712 M-< : First Line
1713 M-> : Last Line
1714 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1715 M-PageDown, C-M-v : Next Page (other-window)
1717 Tab, C-i : Show action list
1718 Left : Previous Source
1719 Right, C-o : Next Source
1720 C-k : Delete pattern
1721 C-z : Persistent Action (Execute action with anything session kept)
1722 C-c C-x C-b: Send a bug report
1724 == Shortcuts For 2nd/3rd Action ==
1725 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1726 \\[anything-select-3rd-action] : Execute 3rd Action
1728 == Visible Marks ==
1729 Visible marks store candidate. Some actions uses marked candidates.
1731 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1732 \\[anything-prev-visible-mark] : Previous Mark
1733 \\[anything-next-visible-mark] : Next Mark
1735 == Miscellaneous Commands ==
1736 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1737 \\[anything-quit-and-find-file] : Drop into `find-file'
1738 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1739 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1740 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1741 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1742 \\[anything-force-update] : Recalculate And Redisplay Candidates
1744 == Global Commands ==
1745 \\<global-map>\\[anything-resume] revives last `anything' session.
1746 It is very useful, so you should bind any key.
1748 Single source is executed by \\[anything-call-source].
1750 == Preconfigured `anything' ==
1751 Preconfigured `anything' is commands that uses `anything' interface.
1752 You can use them without configuration.
1755 (apply 'concat (anything-c-format-preconfigured-anything))
1757 Enjoy!")))
1759 ;;; `anything-buffer-list' help
1762 ;;;###autoload
1763 (defun anything-c-buffer-help ()
1764 "Help command for anything buffers."
1765 (interactive)
1766 (let ((anything-help-message "== Anything Buffer ==
1767 \nTips:
1768 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1769 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1770 \nSpecific commands for `anything-buffers-list':
1771 \\<anything-c-buffer-map>
1772 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1773 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1774 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1775 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1776 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1777 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1778 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1779 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1780 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1781 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1782 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1783 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1784 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1785 \\[anything-mark-all]\t\t->Mark all.
1786 \\[anything-c-buffer-help]\t\t->Display this help.
1787 \n== Anything Map ==
1788 \\{anything-map}
1790 (anything-help)))
1793 ;;; Find files help (`anything-find-files')
1796 ;;;###autoload
1797 (defun anything-ff-help ()
1798 "Help command for `anything-find-files'."
1799 (interactive)
1800 (let ((anything-help-message "== Anything Find Files ==
1801 \nTips:
1802 \n- Enter `~/' at end of pattern to quickly reach home directory.
1803 - Enter `/' at end of pattern to quickly reach root of your file system.
1804 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1805 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1806 - Use `C-u C-z' to watch an image.
1807 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1808 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1810 \nSpecific commands for `anything-find-files':
1811 \\<anything-find-files-map>
1812 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1813 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1814 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1815 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1816 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1817 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1818 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1819 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1820 \\[anything-ff-run-load-file]\t\t->Load File.
1821 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1822 \\[anything-ff-run-delete-file]\t\t->Delete File.
1823 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1824 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1825 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1826 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1827 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1828 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1829 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1830 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1831 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1832 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1833 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1834 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1835 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1836 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1837 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1838 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1839 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1840 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1841 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1842 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1843 \\[anything-narrow-window]\t\t->Narrow anything window.
1844 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1845 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1846 \\[anything-ff-help]\t\t->Display this help info.
1847 \n== Anything Map ==
1848 \\{anything-map}
1850 (anything-help)))
1852 ;;; Help for `anything-c-read-file-name'
1855 ;;;###autoload
1856 (defun anything-read-file-name-help ()
1857 (interactive)
1858 (let ((anything-help-message "== Anything read file name Map ==\
1859 \nSpecific commands for anything-c-read-file-name:
1860 \\<anything-c-read-file-map>
1861 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1862 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1863 \\[anything-next-source]\t\t->Goto next source.
1864 \\[anything-previous-source]\t->Goto previous source.
1865 \\[anything-read-file-name-help]\t\t->Display this help info.
1866 \n== Anything Map ==
1867 \\{anything-map}
1869 (anything-help)))
1871 ;;; Generic file help - Used by locate.
1874 ;;;###autoload
1875 (defun anything-generic-file-help ()
1876 (interactive)
1877 (let ((anything-help-message "== Anything Generic files Map ==\
1878 \nSpecific commands for anything locate and others files sources:
1879 \\<anything-generic-files-map>
1880 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1881 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1882 \\[anything-ff-run-delete-file]\t\t->Delete file.
1883 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1884 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1885 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1886 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1887 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1888 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1889 \nLocate tips:
1890 You can add after writing search pattern any of the locate command line options.
1891 e.g -b, -e, -n <number>...etc.
1892 See Man locate for more infos.
1893 \n== Anything Map ==
1894 \\{anything-map}"))
1895 (anything-help)))
1898 ;;; Grep help
1901 ;;;###autoload
1902 (defun anything-grep-help ()
1903 (interactive)
1904 (let ((anything-help-message "== Anything Grep Map ==\
1905 \nSpecific commands for Grep and Etags:
1906 \\<anything-c-grep-map>
1907 \\[anything-c-goto-next-file]\t->Next File.
1908 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1909 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1910 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1911 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1912 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1913 \\[anything-grep-help]\t\t->Show this help.
1914 \n== Anything Map ==
1915 \\{anything-map}"))
1916 (anything-help)))
1918 ;;; Pdf grep help
1921 ;;;###autoload
1922 (defun anything-pdfgrep-help ()
1923 (interactive)
1924 (let ((anything-help-message "== Anything PdfGrep Map ==\
1925 \nSpecific commands for Pdf Grep:
1926 \\<anything-c-pdfgrep-map>
1927 \\[anything-c-goto-next-file]\t->Next File.
1928 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1929 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1930 \\[anything-pdfgrep-help]\t\t->Show this help.
1931 \n== Anything Map ==
1932 \\{anything-map}"))
1933 (anything-help)))
1935 ;;; Etags help
1938 ;;;###autoload
1939 (defun anything-etags-help ()
1940 "The help function for etags."
1941 (interactive)
1942 (let ((anything-help-message "== Anything Etags Map ==\
1943 \nSpecific commands for Etags:
1944 \\<anything-c-etags-map>
1945 \\[anything-c-goto-next-file]\t->Next File.
1946 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1947 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1948 \\[anything-etags-help]\t\t->Show this help.
1949 \n== Anything Map ==
1950 \\{anything-map}"))
1951 (anything-help)))
1953 ;;; Ucs help
1956 (defun anything-c-ucs-help ()
1957 "Help command for `anything-ucs'."
1958 (interactive)
1959 (let ((anything-help-message "== Anything Ucs ==
1960 \nSpecific commands for `anything-ucs':
1961 \\<anything-c-ucs-map>
1962 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1963 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1964 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1965 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1966 \\[anything-c-ucs-help]\t\t->Show this help.
1968 \n== Anything Map ==
1969 \\{anything-map}
1971 (anything-help)))
1975 ;;; Mode line strings
1978 (defvar anything-buffer-mode-line-string
1979 '("Buffer(s)"
1980 "\\<anything-c-buffer-map>\
1981 \\[anything-c-buffer-help]:Help, \
1982 \\<anything-map>\
1983 \\[anything-select-action]:Acts,\
1984 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1985 \\[anything-select-3rd-action]:NthAct,\
1986 \\[anything-send-bug-report-from-anything]:BugReport."
1987 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1989 (defvar anything-ff-mode-line-string
1990 "\\<anything-find-files-map>\
1991 \\[anything-ff-help]:Help, \
1992 \\[anything-send-bug-report-from-anything]:BugReport, \
1993 \\<anything-map>\
1994 \\[anything-select-action]:Acts, \
1995 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1996 \\[anything-select-3rd-action]:NthAct"
1997 "String displayed in mode-line in `anything-c-source-find-files'")
1999 (defvar anything-read-file-name-mode-line-string
2000 "\\<anything-c-read-file-map>\
2001 \\[anything-read-file-name-help]:Help, \
2002 \\<anything-map>\
2003 \\[anything-select-action]:Acts,\
2004 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2005 \\[anything-select-3rd-action]:NthAct"
2006 "String displayed in mode-line in `anything-c-source-find-files'")
2008 (defvar anything-generic-file-mode-line-string
2009 "\\<anything-generic-files-map>\
2010 \\[anything-generic-file-help]:Help, \
2011 \\<anything-map>\
2012 \\[anything-select-action]:Acts,\
2013 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2014 \\[anything-select-3rd-action]:NthAct,\
2015 \\[anything-send-bug-report-from-anything]:BugReport."
2016 "String displayed in mode-line in Locate.")
2018 (defvar anything-grep-mode-line-string
2019 "\\<anything-c-grep-map>\
2020 \\[anything-grep-help]:Help,\
2021 \\<anything-map>\
2022 \\[anything-select-action]:Acts,\
2023 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2024 \\[anything-select-3rd-action]:NthAct,\
2025 \\[anything-send-bug-report-from-anything]:BugReport."
2026 "String displayed in mode-line in `anything-do-grep'.")
2028 (defvar anything-pdfgrep-mode-line-string
2029 "\\<anything-c-pdfgrep-map>\
2030 \\[anything-pdfgrep-help]:Help,\
2031 \\<anything-map>\
2032 \\[anything-select-action]:Acts,\
2033 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2034 \\[anything-select-3rd-action]:NthAct,\
2035 \\[anything-send-bug-report-from-anything]:BugReport."
2036 "String displayed in mode-line in `anything-do-pdfgrep'.")
2038 (defvar anything-etags-mode-line-string
2039 "\\<anything-c-etags-map>\
2040 \\[anything-etags-help]:Help,\
2041 \\<anything-map>\
2042 \\[anything-select-action]:Acts,\
2043 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2044 \\[anything-select-3rd-action]:NthAct,\
2045 \\[anything-send-bug-report-from-anything]:BugReport."
2046 "String displayed in mode-line in `anything-c-etags-select'.")
2049 (defvar anything-c-ucs-mode-line-string
2050 "\\<anything-c-ucs-map>\
2051 \\[anything-c-ucs-help]:Help, \
2052 \\<anything-map>\
2053 \\[anything-select-action]:Acts,\
2054 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2055 \\[anything-select-3rd-action]:NthAct."
2056 "String displayed in mode-line in `anything-ucs'.")
2060 ;;; Utilities Functions
2063 (defun anything-ff-find-printers ()
2064 "Return a list of available printers on Unix systems."
2065 (let ((printer-list (with-temp-buffer
2066 (call-process "lpstat" nil t nil "-a")
2067 (split-string (buffer-string) "\n"))))
2068 (loop for p in printer-list
2069 for printer = (car (split-string p))
2070 when printer
2071 collect printer)))
2073 ;; Shut up byte compiler in emacs24*.
2074 (defun anything-c-switch-to-buffer (buffer-or-name)
2075 "Same as `switch-to-buffer' whithout warnings at compile time."
2076 (with-no-warnings
2077 (switch-to-buffer buffer-or-name)))
2079 (defsubst* anything-c-position (item seq &key (test 'eq))
2080 "A simple and faster replacement of CL `position'."
2081 (loop for i in seq for index from 0
2082 when (funcall test i item) return index))
2084 (defun anything-c-get-pid-from-process-name (process-name)
2085 "Get pid from running process PROCESS-NAME."
2086 (loop with process-list = (list-system-processes)
2087 for pid in process-list
2088 for process = (assoc-default 'comm (process-attributes pid))
2089 when (and process (string-match process-name process))
2090 return pid))
2092 (defun* anything-current-buffer-narrowed-p (&optional
2093 (buffer anything-current-buffer))
2094 "Check if BUFFER is narrowed.
2095 Default is `anything-current-buffer'."
2096 (with-current-buffer buffer
2097 (let ((beg (point-min))
2098 (end (point-max))
2099 (total (buffer-size)))
2100 (or (/= beg 1) (/= end (1+ total))))))
2102 (defun anything-region-active-p ()
2103 (and transient-mark-mode mark-active (/= (mark) (point))))
2105 (defun anything-goto-line (lineno)
2106 "Goto LINENO opening only outline headline if needed."
2107 (goto-char (point-min)) (forward-line (1- lineno))
2108 (when (or (eq major-mode 'org-mode)
2109 (and (boundp 'outline-minor-mode)
2110 outline-minor-mode))
2111 (require 'org) ; On some old Emacs versions org may not be loaded.
2112 (org-reveal))
2113 (anything-match-line-color-current-line) (sit-for 0.3)
2114 (anything-match-line-cleanup))
2116 (defun anything-show-this-source-only ()
2117 "Show all candidates of this source."
2118 (interactive)
2119 (setq anything-candidate-number-limit nil)
2120 (anything-set-source-filter
2121 (list (assoc-default 'name (anything-get-current-source)))))
2123 ;;;###autoload
2124 (defun anything-test-sources ()
2125 "List all anything sources for test.
2126 The output is sexps which are evaluated by \\[eval-last-sexp]."
2127 (interactive)
2128 (with-output-to-temp-buffer "*Anything Test Sources*"
2129 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2130 (apropos-internal "^anything-c-source" #'boundp))
2131 (pop-to-buffer standard-output)))
2133 (defun anything-nest (&rest same-as-anything)
2134 "Nested `anything'. If you use `anything' within `anything', use it."
2135 (with-selected-window (anything-window)
2136 (let (anything-current-position
2137 anything-current-buffer
2138 (orig-anything-buffer anything-buffer)
2139 anything-pattern
2140 anything-buffer
2141 anything-sources
2142 anything-compiled-sources
2143 anything-buffer-chars-modified-tick
2144 (anything-samewindow t)
2145 (enable-recursive-minibuffers t))
2146 (unwind-protect
2147 (apply #'anything same-as-anything)
2148 (anything-initialize-overlays orig-anything-buffer)
2149 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2151 (defun anything-displaying-source-names ()
2152 "Display sources name."
2153 (with-current-buffer anything-buffer
2154 (goto-char (point-min))
2155 (loop with pos
2156 while (setq pos (next-single-property-change (point) 'anything-header))
2157 do (goto-char pos)
2158 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2159 do (forward-line 1))))
2161 ;; [Obsolete]
2162 (defun anything-select-source ()
2163 "[OBSOLETE] Select source."
2164 (interactive)
2165 (let ((default (assoc-default 'name (anything-get-current-source)))
2166 (source-names (anything-displaying-source-names))
2167 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2168 (anything-get-sources))))
2169 (setq anything-candidate-number-limit 9999)
2170 (anything-aif
2171 (let (anything-source-filter)
2172 (anything-nest '(((name . "Anything Source")
2173 (candidates . source-names)
2174 (action . identity))
2175 ((name . "Anything Source (ALL)")
2176 (candidates . all-source-names)
2177 (action . identity)))
2178 nil "Source: " nil
2179 default "*anything select source*"))
2180 (anything-set-source-filter (list it))
2181 (anything-set-source-filter nil))))
2183 (defun anything-c-match-on-file-name (candidate)
2184 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2185 (string-match anything-pattern (file-name-nondirectory candidate)))
2187 (defun anything-c-match-on-directory-name (candidate)
2188 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2189 (anything-aif (file-name-directory candidate)
2190 (string-match anything-pattern it)))
2192 (defun anything-c-match-on-basename (candidate)
2193 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2194 (string-match anything-pattern (anything-c-basename candidate)))
2196 (defun anything-c-string-match (candidate)
2197 "Return non-nil if `anything-pattern' match CANDIDATE.
2198 The match is done with `string-match'."
2199 (string-match anything-pattern candidate))
2201 (defun anything-c-skip-entries (list regexp)
2202 "Remove entries which matches REGEXP from LIST."
2203 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2204 list))
2206 (defun anything-c-shadow-entries (list regexp)
2207 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2208 (mapcar (lambda (file)
2209 ;; Add shadow face property to boring files.
2210 (let ((face (if (facep 'file-name-shadow)
2211 'file-name-shadow
2212 ;; fall back to default on XEmacs
2213 'default)))
2214 (if (string-match regexp file)
2215 (setq file (propertize file 'face face))))
2216 file)
2217 list))
2219 (defsubst anything-c-stringify (str-or-sym)
2220 "Get string of STR-OR-SYM."
2221 (if (stringp str-or-sym)
2222 str-or-sym
2223 (symbol-name str-or-sym)))
2225 (defsubst anything-c-symbolify (str-or-sym)
2226 "Get symbol of STR-OR-SYM."
2227 (if (symbolp str-or-sym)
2228 str-or-sym
2229 (intern str-or-sym)))
2231 (defun anything-c-describe-function (func)
2232 "FUNC is symbol or string."
2233 (describe-function (anything-c-symbolify func)))
2235 (defun anything-c-describe-variable (var)
2236 "VAR is symbol or string."
2237 (describe-variable (anything-c-symbolify var)))
2239 (defun anything-c-find-function (func)
2240 "FUNC is symbol or string."
2241 (find-function (anything-c-symbolify func)))
2243 (defun anything-c-find-variable (var)
2244 "VAR is symbol or string."
2245 (find-variable (anything-c-symbolify var)))
2247 (defun anything-c-kill-new (candidate &optional replace)
2248 "CANDIDATE is symbol or string.
2249 See `kill-new' for argument REPLACE."
2250 (kill-new (anything-c-stringify candidate) replace))
2252 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2253 "Remove duplicates elements in list SEQ.
2254 This is same as `remove-duplicates' but with memoisation.
2255 It is much faster, especially in large lists.
2256 A test function can be provided with TEST argument key.
2257 Default is `eq'."
2258 (let ((cont (make-hash-table :test test)))
2259 (loop for elm in seq
2260 unless (gethash elm cont)
2261 do (puthash elm elm cont)
2262 finally return
2263 (loop for i being the hash-values in cont collect i))))
2265 (defadvice eval-defun (after anything-source-hack activate)
2266 "Allow immediate execution of anything source when evaling it.
2267 See `anything-c-enable-eval-defun-hack'."
2268 (when anything-c-enable-eval-defun-hack
2269 (let ((varsym (save-excursion
2270 (beginning-of-defun)
2271 (forward-char 1)
2272 (when (memq (read (current-buffer)) '(defvar setq))
2273 (read (current-buffer))))))
2274 (when (string-match "^anything-c-source-" (symbol-name varsym))
2275 (anything varsym)))))
2276 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2279 ;; Move this function from anything.el and redefine here
2280 ;; to avoid an unneeded defadvice.
2281 (defun anything-quit-and-find-file ()
2282 "Drop into `anything-find-files' from `anything'.
2283 If current selection is a buffer or a file, `anything-find-files'
2284 from its directory."
2285 (interactive)
2286 (anything-run-after-quit
2287 (lambda (f)
2288 (if (file-exists-p f)
2289 (anything-find-files-1 (file-name-directory f)
2290 (if anything-ff-transformer-show-only-basename
2291 (anything-c-basename f) f))
2292 (anything-find-files-1 f)))
2293 (anything-aif (get-buffer (anything-get-selection))
2294 (or (buffer-file-name it)
2295 (car (rassoc it dired-buffers))
2296 (and (with-current-buffer it
2297 (eq major-mode 'org-agenda-mode))
2298 org-directory
2299 (expand-file-name org-directory))
2300 default-directory)
2301 (let ((sel (anything-get-selection)))
2302 (if (file-exists-p sel)
2303 (expand-file-name sel)
2304 default-directory)))))
2307 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2308 "Walk through DIRECTORY tree.
2309 PATH can be one of basename, relative, or full.
2310 DIRECTORIES when non--nil (default) return also directories names, otherwise
2311 skip directories names.
2312 MATCH match only filenames matching regexp MATCH."
2313 `(let (result
2314 (fn (case ,path
2315 (basename 'file-name-nondirectory)
2316 (relative 'file-relative-name)
2317 (full 'identity)
2318 (t 'file-name-nondirectory))))
2319 (labels ((ls-R (dir)
2320 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2321 for f in ls
2322 if (file-directory-p f)
2323 do (progn (when ,directories
2324 (push (funcall fn f) result))
2325 ;; Don't recurse in directory symlink.
2326 (unless (file-symlink-p f)
2327 (ls-R f)))
2328 else do
2329 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2330 (push (funcall fn f) result)))))
2331 (ls-R ,directory)
2332 (nreverse result))))
2334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2336 ;;; Anything regexp.
2339 (defvar anything-build-regexp-history nil)
2340 (defun anything-c-query-replace-regexp (candidate)
2341 "Query replace regexp from `anything-regexp'.
2342 With a prefix arg replace only matches surrounded by word boundaries,
2343 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2344 (let ((regexp (funcall (anything-attr 'regexp))))
2345 (apply 'query-replace-regexp
2346 (anything-c-query-replace-args regexp))))
2348 (defun anything-c-kill-regexp-as-sexp (candidate)
2349 "Kill regexp in a format usable in lisp code."
2350 (anything-c-regexp-kill-new
2351 (prin1-to-string (funcall (anything-attr 'regexp)))))
2353 (defun anything-c-kill-regexp (candidate)
2354 "Kill regexp as it is in `anything-pattern'."
2355 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2357 (defun anything-c-query-replace-args (regexp)
2358 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2359 (let ((region-only (anything-region-active-p)))
2360 (list
2361 regexp
2362 (query-replace-read-to regexp
2363 (format "Query replace %sregexp %s"
2364 (if anything-current-prefix-arg "word " "")
2365 (if region-only "in region " ""))
2367 anything-current-prefix-arg
2368 (when region-only (region-beginning))
2369 (when region-only (region-end)))))
2371 (defvar anything-c-source-regexp
2372 '((name . "Regexp Builder")
2373 (init . (lambda ()
2374 (anything-candidate-buffer anything-current-buffer)))
2375 (candidates-in-buffer)
2376 (get-line . anything-c-regexp-get-line)
2377 (persistent-action . anything-c-regexp-persistent-action)
2378 (persistent-help . "Show this line")
2379 (multiline)
2380 (delayed)
2381 (requires-pattern . 2)
2382 (mode-line . "Press TAB to select action.")
2383 (regexp . (lambda () anything-input))
2384 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2385 ("Query Replace Regexp (C-u Not inside word.)"
2386 . anything-c-query-replace-regexp)
2387 ("Kill Regexp" . anything-c-kill-regexp)))))
2389 (defun anything-c-regexp-get-line (s e)
2390 (propertize
2391 (apply 'concat
2392 ;; Line contents
2393 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2394 ;; subexps
2395 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2396 collect (format "\n %s'%s'"
2397 (if (zerop i) "Group 0: " (format "Group %d: " i))
2398 (match-string i))))
2399 ;; match beginning
2400 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2401 ;; It is implementation problem of candidates-in-buffer.
2402 'anything-realvalue
2403 (1- s)))
2405 (defun anything-c-regexp-persistent-action (pt)
2406 (goto-char pt)
2407 (anything-persistent-highlight-point))
2409 (defun anything-c-regexp-kill-new (input)
2410 (kill-new input)
2411 (message "Killed: %s" input))
2415 ;;; Toggle all marks.
2418 ;;;###autoload
2419 (defun anything-mark-all ()
2420 "Mark all visible unmarked candidates in current source."
2421 (interactive)
2422 (with-anything-window
2423 (save-excursion
2424 (goto-char (anything-get-previous-header-pos))
2425 (anything-next-line)
2426 (let* ((next-head (anything-get-next-header-pos))
2427 (end (and next-head
2428 (save-excursion
2429 (goto-char next-head)
2430 (forward-line -1)
2431 (point))))
2432 (maxpoint (or end (point-max))))
2433 (while (< (point) maxpoint)
2434 (anything-mark-current-line)
2435 (let ((prefix (get-text-property (point-at-bol) 'display))
2436 (bn (anything-c-basename (anything-get-selection)))
2437 (src (assoc-default 'name (anything-get-current-source))))
2438 (when (and (not (anything-this-visible-mark))
2439 (not (or (string= prefix "[?]")
2440 (string= prefix "[@]"))))
2441 ;; Don't mark possibles directories ending with . or ..
2442 ;; and also autosave files/links.
2443 (unless
2444 (and (or (anything-file-completion-source-p)
2445 (equal src "Files from Current Directory"))
2446 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2447 (anything-make-visible-mark))))
2448 (forward-line 1) (end-of-line))))
2449 (anything-mark-current-line)
2450 (message "%s candidates marked" (length anything-marked-candidates))))
2452 ;;;###autoload
2453 (defun anything-unmark-all ()
2454 "Unmark all candidates in all sources of current anything session."
2455 (interactive)
2456 (with-anything-window
2457 (let ((len (length anything-marked-candidates)))
2458 (save-excursion
2459 (anything-clear-visible-mark))
2460 (setq anything-marked-candidates nil)
2461 (anything-mark-current-line)
2462 (message "%s candidates unmarked" len))))
2464 ;;;###autoload
2465 (defun anything-toggle-all-marks ()
2466 "Toggle all marks.
2467 Mark all visible candidates of current source or unmark all candidates
2468 visible or invisible in all sources of current anything session"
2469 (interactive)
2470 (let ((marked (anything-marked-candidates)))
2471 (if (and (>= (length marked) 1)
2472 (with-anything-window anything-visible-mark-overlays))
2473 (anything-unmark-all)
2474 (anything-mark-all))))
2478 ;;; Buffers
2481 (defun anything-c-buffer-list ()
2482 "Return the list of names of buffers with boring buffers filtered out.
2483 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2484 The first buffer in the list will be the last recently used
2485 buffer that is not the current buffer."
2486 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2487 (append (cdr buffers) (list (car buffers)))))
2489 (defvar anything-c-source-buffers
2490 '((name . "Buffers")
2491 (candidates . anything-c-buffer-list)
2492 (type . buffer)))
2493 ;; (anything 'anything-c-source-buffers)
2495 (defvar anything-c-source-buffer-not-found
2496 '((name . "Create buffer")
2497 (dummy)
2498 (filtered-candidate-transformer (lambda (cands source)
2499 (list anything-pattern)))
2500 (action . (lambda (candidate)
2501 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2502 ;; (anything 'anything-c-source-buffer-not-found)
2504 ;;; Buffers-list (was buffers+)
2507 (eval-when-compile (require 'dired))
2509 (defun anything-c-highlight-buffers (buffers)
2510 (loop for i in buffers
2511 for buf = (get-buffer i)
2512 for bfname = (buffer-file-name buf)
2513 collect
2514 (cond (;; A dired buffer.
2515 (rassoc buf dired-buffers)
2516 (propertize i 'face 'anything-ff-directory
2517 'help-echo (car (rassoc buf dired-buffers))))
2518 ;; A buffer file modified somewhere outside of emacs.
2519 ((and bfname (not (file-remote-p bfname))
2520 (file-exists-p bfname)
2521 (not (verify-visited-file-modtime buf)))
2522 (propertize i 'face 'anything-buffer-saved-out
2523 'help-echo bfname))
2524 ;; A new buffer file not already saved on disk.
2525 ((and bfname (not (file-remote-p bfname))
2526 (not (verify-visited-file-modtime buf)))
2527 (propertize i 'face 'anything-buffer-not-saved
2528 'help-echo bfname))
2529 ;; A Remote buffer file modified and not saved on disk.
2530 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2531 (let ((prefix (propertize
2532 " " 'display
2533 (propertize "@ " 'face 'anything-ff-prefix))))
2534 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2535 'help-echo bfname)) i)))
2536 ;; A buffer file modified and not saved on disk.
2537 ((and bfname (buffer-modified-p buf))
2538 (propertize i 'face 'anything-ff-symlink
2539 'help-echo bfname))
2540 ;; A remote buffer file not modified and saved on disk.
2541 ((and bfname (file-remote-p bfname))
2542 (let ((prefix (propertize
2543 " " 'display
2544 (propertize "@ " 'face 'anything-ff-prefix))))
2545 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2546 'help-echo bfname)) i)))
2547 ;; A buffer file not modified and saved on disk.
2548 (bfname
2549 (propertize i 'face 'font-lock-type-face
2550 'help-echo bfname))
2551 ;; Any non--file buffer.
2552 (t (propertize i 'face 'italic)))))
2555 (defvar anything-c-source-buffers-list
2556 '((name . "Buffers")
2557 (candidates . anything-c-buffer-list)
2558 (type . buffer)
2559 (match anything-c-buffer-match-major-mode)
2560 (diff-action . anything-buffer-toggle-diff)
2561 (revert-action . anything-buffer-revert-and-update)
2562 (save-action . anything-buffer-save-and-update)
2563 (candidate-transformer
2564 anything-c-skip-current-buffer
2565 anything-c-skip-boring-buffers
2566 anything-c-highlight-buffers)
2567 (persistent-action . anything-c-buffers-list-persistent-action)
2568 (volatile)
2569 (mode-line . anything-buffer-mode-line-string)
2570 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2571 ;; (anything 'anything-c-source-buffers-list)
2573 (defun anything-c-buffer-match-major-mode (candidate)
2574 "Match maybe buffer by major-mode.
2575 If you give a major-mode or partial major-mode,
2576 it will list all buffers of this major-mode and/or buffers with name
2577 matching this major-mode.
2578 If you add a space after major-mode and then a space,
2579 it will match all buffers of the major-mode
2580 before space matching pattern after space.
2581 If you give a pattern which doesn't match a major-mode, it will search buffer
2582 with name matching pattern."
2583 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2584 (buf (get-buffer cand)))
2585 (when buf
2586 (with-current-buffer buf
2587 (let ((mjm (symbol-name major-mode))
2588 (split (split-string anything-pattern)))
2589 (cond ((string-match "\\s-$" anything-pattern)
2590 (string-match (car split) mjm))
2591 ((string-match "\\s-" anything-pattern)
2592 (and (string-match (car split) mjm)
2593 (string-match (cadr split) cand)))
2594 (t (or (string-match anything-pattern mjm)
2595 (string-match anything-pattern cand)))))))))
2597 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2598 "Query replace in marked buffers.
2599 If REGEXP-FLAG is given use `query-replace-regexp'."
2600 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2601 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2602 (bufs (anything-marked-candidates)))
2603 (loop
2604 with replace = (query-replace-read-from prompt regexp-flag)
2605 with tostring = (unless (consp replace)
2606 (query-replace-read-to
2607 replace prompt regexp-flag))
2608 for buf in bufs
2610 (save-window-excursion
2611 (anything-c-switch-to-buffer buf)
2612 (save-excursion
2613 (let ((case-fold-search t))
2614 (goto-char (point-min))
2615 (if (consp replace)
2616 (apply fn (list (car replace) (cdr replace)))
2617 (apply fn (list replace tostring)))))))))
2619 (defun anything-c-buffer-query-replace-regexp (candidate)
2620 (anything-c-buffer-query-replace-1 'regexp))
2622 (defun anything-c-buffer-query-replace (candidate)
2623 (anything-c-buffer-query-replace-1))
2625 (defun anything-buffer-toggle-diff (candidate)
2626 "Toggle diff buffer CANDIDATE with it's file."
2627 (if (get-buffer-window "*Diff*")
2628 (kill-buffer "*Diff*")
2629 (diff-buffer-with-file (get-buffer candidate))))
2631 ;;;###autoload
2632 (defun anything-buffer-diff-persistent ()
2633 "Toggle diff buffer without quitting anything."
2634 (interactive)
2635 (anything-execute-persistent-action 'diff-action))
2637 (defun anything-buffer-revert-and-update (candidate)
2638 (let ((marked (anything-marked-candidates)))
2639 (loop for buf in marked do (anything-revert-buffer buf))
2640 (anything-force-update candidate)))
2642 ;;;###autoload
2643 (defun anything-buffer-revert-persistent ()
2644 "Revert buffer without quitting anything."
2645 (interactive)
2646 (anything-execute-persistent-action 'revert-action 'onewindow))
2648 (defun anything-buffer-save-and-update (candidate)
2649 (let ((marked (anything-marked-candidates))
2650 (enable-recursive-minibuffers t))
2651 (loop for buf in marked do
2652 (with-current-buffer (get-buffer buf)
2653 (save-buffer)))
2654 (anything-force-update candidate)))
2656 ;;;###autoload
2657 (defun anything-buffer-save-persistent ()
2658 "Save buffer without quitting anything."
2659 (interactive)
2660 (anything-execute-persistent-action 'save-action 'onewindow))
2662 ;;;###autoload
2663 (defun anything-buffer-run-kill-buffers ()
2664 "Run kill buffer action from `anything-c-source-buffers-list'."
2665 (interactive)
2666 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2668 ;;;###autoload
2669 (defun anything-buffer-run-grep ()
2670 "Run Grep action from `anything-c-source-buffers-list'."
2671 (interactive)
2672 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2674 ;;;###autoload
2675 (defun anything-buffer-run-zgrep ()
2676 "Run Grep action from `anything-c-source-buffers-list'."
2677 (interactive)
2678 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2680 ;;;###autoload
2681 (defun anything-buffer-run-query-replace-regexp ()
2682 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2683 (interactive)
2684 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2686 ;;;###autoload
2687 (defun anything-buffer-run-query-replace ()
2688 "Run Query replace action from `anything-c-source-buffers-list'."
2689 (interactive)
2690 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2692 ;;;###autoload
2693 (defun anything-buffer-switch-other-window ()
2694 "Run switch to other window action from `anything-c-source-buffers-list'."
2695 (interactive)
2696 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2698 ;;;###autoload
2699 (defun anything-buffer-switch-other-frame ()
2700 "Run switch to other frame action from `anything-c-source-buffers-list'."
2701 (interactive)
2702 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2704 ;;;###autoload
2705 (defun anything-buffer-switch-to-elscreen ()
2706 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2707 (interactive)
2708 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2710 ;;;###autoload
2711 (defun anything-buffer-run-ediff ()
2712 "Run ediff action from `anything-c-source-buffers-list'."
2713 (interactive)
2714 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2716 (defun anything-buffer-run-ediff-merge ()
2717 "Run ediff action from `anything-c-source-buffers-list'."
2718 (interactive)
2719 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2721 (defun anything-c-buffers-persistent-kill (buffer)
2722 "Persistent action to kill buffer."
2723 (with-current-buffer (get-buffer buffer)
2724 (if (and (buffer-modified-p)
2725 (buffer-file-name (current-buffer)))
2726 (progn
2727 (save-buffer)
2728 (kill-buffer buffer))
2729 (kill-buffer buffer)))
2730 (anything-delete-current-selection))
2732 (defun anything-c-buffers-list-persistent-action (candidate)
2733 (if current-prefix-arg
2734 (anything-c-buffers-persistent-kill candidate)
2735 (anything-c-switch-to-buffer candidate)))
2738 ;;;; <File>
2741 ;;; File name history
2742 (defvar anything-c-source-file-name-history
2743 '((name . "File Name History")
2744 (candidates . file-name-history)
2745 (match anything-c-match-on-basename)
2746 (type . file)))
2747 ;; (anything 'anything-c-source-file-name-history)
2749 ;;; Files in current dir
2752 (defvar anything-c-source-files-in-current-dir
2753 '((name . "Files from Current Directory")
2754 (candidates . (lambda ()
2755 (with-anything-current-buffer
2756 (directory-files (anything-c-current-directory)))))
2757 ;; volatile is not needed, I think.
2758 (type . file)))
2759 ;; (anything 'anything-c-source-files-in-current-dir)
2761 (defun anything-c-highlight-files (files)
2762 (loop for i in files
2763 if (file-directory-p i)
2764 collect (propertize (file-name-nondirectory i)
2765 'face 'anything-ff-directory
2766 'help-echo (expand-file-name i))
2767 else
2768 collect (propertize (file-name-nondirectory i)
2769 'face 'anything-ff-file
2770 'help-echo (expand-file-name i))))
2772 (defvar anything-c-source-files-in-current-dir+
2773 '((name . "Files from Current Directory")
2774 (candidates . (lambda ()
2775 (with-anything-current-buffer
2776 (directory-files (anything-c-current-directory) t))))
2777 (candidate-transformer anything-c-highlight-files)
2778 ;; volatile is not needed, I think.
2779 (type . file)))
2780 ;; (anything 'anything-c-source-files-in-current-dir+)
2784 ;;; Anything-find-files - The anything files browser.
2787 ;; Internal.
2788 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2789 "*The doc that is inserted in the Name header of a find-files or dired source.")
2790 (defvar anything-ff-auto-update-flag nil
2791 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2792 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2793 (defvar anything-ff-last-expanded nil
2794 "Store last expanded directory or file.")
2795 (defvar anything-ff-default-directory nil)
2796 (defvar anything-ff-history nil)
2797 (defvar anything-ff-cand-to-mark nil)
2800 (defvar anything-c-source-find-files
2801 `((name . "Find Files")
2802 (header-name . (lambda (name)
2803 (concat name anything-c-find-files-doc-header)))
2804 ;; It is needed for filenames with capital letters
2805 (disable-shortcuts)
2806 (init . (lambda ()
2807 (setq anything-ff-auto-update-flag
2808 anything-ff-auto-update-initial-value)))
2809 (candidates . anything-find-files-get-candidates)
2810 (filtered-candidate-transformer anything-c-find-files-transformer)
2811 (image-action1 . anything-ff-rotate-image-left)
2812 (image-action2 . anything-ff-rotate-image-right)
2813 (toggle-basename . anything-ff-toggle-basename)
2814 (properties-action . anything-ff-properties)
2815 (toggle-auto-update . anything-ff-toggle-auto-update)
2816 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2817 (persistent-action . anything-find-files-persistent-action)
2818 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2819 (mode-line . anything-ff-mode-line-string)
2820 (volatile)
2821 (candidate-number-limit . 9999)
2822 (action-transformer . anything-find-files-action-transformer)
2823 (action
2824 . ,(delq
2826 `(("Find File" . anything-c-find-file-or-marked)
2827 ("Find file in Dired" . anything-c-point-file-in-dired)
2828 ,(and (locate-library "elscreen")
2829 '("Find file in Elscreen" . anything-elscreen-find-file))
2830 ,(and (locate-library "popwin")
2831 '("Find file in popup window" . popwin:find-file))
2832 ("Checksum File" . anything-ff-checksum)
2833 ("Complete at point `M-tab'"
2834 . anything-c-insert-file-name-completion-at-point)
2835 ("Open file externally `C-c C-x, C-u to choose'"
2836 . anything-c-open-file-externally)
2837 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2838 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2839 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2840 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2841 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2842 . anything-find-files-eshell-command-on-file)
2843 ("Find file as root" . anything-find-file-as-root)
2844 ("Find file in hex dump" . hexl-find-file)
2845 ("Ediff File `C-='" . anything-find-files-ediff-files)
2846 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2847 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2848 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2849 ("Copy file(s) Async" . anything-ff-copy-async)
2850 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2851 ("Serial rename files" . anything-ff-serial-rename)
2852 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2853 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2854 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2855 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2856 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2857 ("Find file other window `C-o'" . find-file-other-window)
2858 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2859 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2860 ("Print File `C-c p'" . anything-ff-print)
2861 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2862 ;; (anything 'anything-c-source-find-files)
2864 (defun anything-find-files-set-prompt-for-action (action files)
2865 "Set prompt for action ACTION for FILES."
2866 (let ((len (length files)))
2867 (format "%s *%s File(s)\n%s to: "
2868 action len
2869 (mapconcat (lambda (f)
2870 (format "- %s\n" f)) files ""))))
2872 (defun anything-dwim-target-directory ()
2873 "Return value of `default-directory' of buffer in other window.
2874 If there is only one window return the value ot `default-directory'
2875 for current buffer."
2876 (with-anything-current-buffer
2877 (let ((num-windows (length (window-list))))
2878 (if (> num-windows 1)
2879 (save-window-excursion
2880 (other-window 1)
2881 default-directory)
2882 (car anything-ff-history)))))
2884 (defun anything-find-files-do-action (action)
2885 "Generic function for creating action from `anything-c-source-find-files'.
2886 ACTION must be an action supported by `anything-dired-action'."
2887 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2888 (anything-marked-candidates)))
2889 (cand (anything-get-selection)) ; Target
2890 (prompt (anything-find-files-set-prompt-for-action
2891 (capitalize (symbol-name action)) ifiles))
2892 (parg anything-current-prefix-arg)
2893 (dest (anything-c-read-file-name
2894 prompt
2895 :preselect (if anything-ff-transformer-show-only-basename
2896 (anything-c-basename cand) cand)
2897 :initial-input (anything-dwim-target-directory)
2898 :history (anything-find-files-history :comp-read nil))))
2899 (anything-dired-action
2900 dest :files ifiles :action action :follow parg)))
2902 (defun anything-find-files-copy (candidate)
2903 "Copy files from `anything-find-files'."
2904 (anything-find-files-do-action 'copy))
2906 (defun anything-find-files-rename (candidate)
2907 "Rename files from `anything-find-files'."
2908 (anything-find-files-do-action 'rename))
2910 (defun anything-find-files-symlink (candidate)
2911 "Symlink files from `anything-find-files'."
2912 (anything-find-files-do-action 'symlink))
2914 (defun anything-find-files-relsymlink (candidate)
2915 "Relsymlink files from `anything-find-files'."
2916 (anything-find-files-do-action 'relsymlink))
2918 (defun anything-find-files-hardlink (candidate)
2919 "Hardlink files from `anything-find-files'."
2920 (anything-find-files-do-action 'hardlink))
2922 (defun anything-find-files-byte-compile (candidate)
2923 "Byte compile elisp files from `anything-find-files'."
2924 (let ((files (anything-marked-candidates))
2925 (parg anything-current-prefix-arg))
2926 (loop for fname in files
2927 do (byte-compile-file fname parg))))
2929 (defun anything-find-files-load-files (candidate)
2930 "Load elisp files from `anything-find-files'."
2931 (let ((files (anything-marked-candidates)))
2932 (loop for fname in files
2933 do (load fname))))
2935 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2936 "Generic function to ediff/merge files in `anything-find-files'."
2937 (let ((bname (anything-c-basename candidate))
2938 (prompt (if merge "Ediff Merge `%s' With File: "
2939 "Ediff `%s' With File: "))
2940 (fun (if merge 'ediff-merge-files 'ediff-files)))
2941 (funcall fun
2942 candidate
2943 (condition-case quit
2944 (anything-c-read-file-name
2945 (format prompt bname))
2946 (quit ;; Hit C-g ask user to fallback to locate.
2947 (if (y-or-n-p "Search file for ediff with locate? ")
2948 (anything-c-locate-read-file-name
2949 (format prompt bname)
2950 ;; Check if -b option is available.
2951 (if (and (eq system-type 'windows-nt)
2952 (string-match "^es" anything-c-locate-command))
2953 bname
2954 (concat bname " -b")))
2955 (error "Error: Ediff Operation aborted")))))))
2957 (defun anything-find-files-ediff-files (candidate)
2958 (anything-find-files-ediff-files-1 candidate))
2960 (defun anything-find-files-ediff-merge-files (candidate)
2961 (anything-find-files-ediff-files-1 candidate 'merge))
2963 (defun anything-find-files-grep (candidate)
2964 "Default action to grep files from `anything-find-files'."
2965 (anything-do-grep-1 (anything-marked-candidates)
2966 anything-current-prefix-arg))
2968 (defun anything-ff-zgrep (candidate)
2969 "Default action to zgrep files from `anything-find-files'."
2970 (let ((prefarg anything-current-prefix-arg)
2971 (ls (anything-marked-candidates)))
2972 (anything-ff-zgrep-1 ls prefarg)))
2974 (defun anything-ff-pdfgrep (candidate)
2975 "Default action to pdfgrep files from `anything-find-files'."
2976 (let ((cands (loop for file in (anything-marked-candidates)
2977 if (or (string= (file-name-extension file) "pdf")
2978 (string= (file-name-extension file) "PDF"))
2979 collect file))
2980 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2981 (when cands
2982 (anything-do-pdfgrep-1 cands))))
2984 (defun anything-ff-etags-select (candidate)
2985 "Default action to jump to etags from `anything-find-files'."
2986 (when (get-buffer anything-action-buffer)
2987 (kill-buffer anything-action-buffer))
2988 (let ((default-directory anything-ff-default-directory))
2989 (anything-c-etags-select anything-current-prefix-arg)))
2991 (defun anything-find-files-switch-to-hist (candidate)
2992 "Switch to anything-find-files history."
2993 (anything-find-files t))
2995 ;;; Asynchronous copy of files.
2998 (defun anything-c-copy-files-async-1 (flist dest)
2999 "Copy a list of Files FLIST to DEST asynchronously.
3000 It use another emacs process to do the job.
3001 Communication with background emacs is done with temp file
3002 `anything-c-copy-files-async-log-file'."
3003 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3004 "-Q" "--batch" "--eval"
3005 (format "(progn
3006 (require 'dired) (require 'cl)
3007 (let ((dired-recursive-copies 'always)
3008 failures success
3009 (ovw-count 0)
3010 (cpf-count 0))
3011 (dolist (f '%S)
3012 (condition-case err
3013 (let ((file-exists (file-exists-p
3014 (expand-file-name
3015 (file-name-nondirectory (directory-file-name f))
3016 (file-name-directory
3017 (file-name-as-directory \"%s\"))))))
3018 (dired-copy-file f \"%s\" t)
3019 (if file-exists
3020 (progn (push (cons \"Overwriting\" f) success)
3021 (incf ovw-count))
3022 (push (cons \"Copying\" f) success)
3023 (incf cpf-count)))
3024 (file-error
3025 (push (dired-make-relative
3026 (expand-file-name
3027 (file-name-nondirectory (directory-file-name f))
3028 (file-name-directory \"%s\")))
3029 failures))))
3030 (with-current-buffer (find-file-noselect \"%s\")
3031 (erase-buffer)
3032 (when failures
3033 (dolist (fail (reverse failures))
3034 (insert (concat \"Failed to copy \" fail \"\n\"))))
3035 (when success
3036 (loop for (a . s) in (reverse success) do
3037 (insert (concat a \" \" s \" to %s done\n\"))))
3038 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3039 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3040 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3041 (save-buffer))))"
3042 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3044 (defun anything-c-copy-async-with-log (flist dest)
3045 "Copy file list FLIST to DEST showing log.
3046 Log is send to `anything-c-copy-files-async-log-file'.
3047 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3048 (declare (special auto-revert-interval))
3049 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3050 (set (make-local-variable 'auto-revert-interval) 1)
3051 (erase-buffer)
3052 (insert "Wait copying files...\n")
3053 (sit-for 0.5) (save-buffer)
3054 (goto-char (point-max))
3055 (auto-revert-mode 1)
3056 (anything-c-copy-files-async-1 flist dest))
3058 (defun anything-ff-copy-async (candidate)
3059 "Anything find files action to copy files async.
3060 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3061 (let* ((flist (anything-marked-candidates))
3062 (dest (anything-c-read-file-name
3063 (anything-find-files-set-prompt-for-action
3064 "Copy Async" flist)
3065 :preselect candidate
3066 :initial-input (car anything-ff-history)
3067 :history (anything-find-files-history :comp-read nil))))
3068 (anything-c-copy-async-with-log flist dest)))
3070 (defvar eshell-command-aliases-list nil)
3071 (defvar anything-eshell-command-on-file-input-history nil)
3072 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3073 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3075 Basename of CANDIDATE can be a wild-card.
3076 If MAP is given run `eshell-command' on all marked files at once,
3077 Otherwise, run `eshell-command' on each marked files.
3079 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3080 `eshell-command-aliases-list' will not be loaded first time you use this."
3081 (when (or eshell-command-aliases-list
3082 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3083 (and eshell-command-aliases-list (eshell-read-aliases-list))
3084 (let* ((cand-list (anything-marked-candidates))
3085 (default-directory (or anything-ff-default-directory
3086 ;; If candidate is an url *-ff-default-directory is nil
3087 ;; so keep value of default-directory.
3088 default-directory))
3089 (command (anything-comp-read
3090 "Command: "
3091 (loop for (a . c) in eshell-command-aliases-list
3092 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3093 collect (propertize a 'help-echo (car c)) into ls
3094 finally return (sort ls 'string<))
3095 :buffer "*esh command on file*"
3096 :name "Eshell command"
3097 :input-history
3098 'anything-eshell-command-on-file-input-history))
3099 (com-value (car (assoc-default command eshell-command-aliases-list))))
3100 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3101 (> (length cand-list) 1))
3102 ;; Run eshell-command with ALL marked files as arguments.
3103 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3104 (eshell-command (format "%s %s" command mapfiles)))
3105 ;; Run eshell-command on EACH marked files.
3106 (loop
3107 for i in cand-list
3108 for bn = (anything-c-basename i)
3109 for files = (if (and bn (string-match "^\*" bn))
3110 ;; Assume if fname is a wildcard
3111 ;; cand-list have a length of 1.
3112 (mapconcat
3113 'shell-quote-argument
3114 (file-expand-wildcards i t) " ")
3115 (format "'%s'" i))
3116 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3117 ;; This allow to enter other args AFTER filename
3118 ;; i.e <command %s some_more_args>
3119 (format command files)
3120 (format "%s %s" command files))
3121 do (eshell-command com))))))
3123 (defun anything-find-files-eshell-command-on-file (candidate)
3124 "Run `eshell-command' on CANDIDATE or marked candidates.
3125 See `anything-find-files-eshell-command-on-file-1' for more info."
3126 (anything-find-files-eshell-command-on-file-1
3127 candidate anything-current-prefix-arg))
3129 (defun anything-ff-switch-to-eshell (candidate)
3130 "Switch to eshell and cd to `anything-ff-default-directory'."
3131 (flet ((cd-eshell ()
3132 (goto-char (point-max))
3133 (insert
3134 (format "cd '%s'" anything-ff-default-directory))
3135 (eshell-send-input)))
3136 (if (get-buffer "*eshell*")
3137 (progn
3138 (anything-c-switch-to-buffer "*eshell*")
3139 (cd-eshell))
3140 (call-interactively 'eshell)
3141 (cd-eshell))))
3143 (defun anything-ff-serial-rename-action (method)
3144 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3145 See `anything-ff-serial-rename-1'."
3146 (let* ((cands (anything-marked-candidates))
3147 (name (read-string "NewName: "))
3148 (start (read-number "StartAtNumber: "))
3149 (extension (read-string "Extension: " (file-name-extension (car cands))))
3150 (dir (expand-file-name
3151 (anything-c-read-file-name
3152 "Serial Rename to directory: " :initial-input
3153 (expand-file-name anything-ff-default-directory)))))
3154 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3155 (length cands) dir name))
3156 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3157 (anything-find-files-1 dir))))
3159 (defun anything-ff-member-directory-p (file directory)
3160 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3161 (cur-dir (expand-file-name (file-name-as-directory directory))))
3162 (string= dir-file cur-dir)))
3164 (defun* anything-ff-serial-rename-1
3165 (directory collection new-name start-at-num extension &key (method 'rename))
3166 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3167 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3168 EXTENSION is the file extension to use, in empty prompt,
3169 reuse the original extension of file.
3170 METHOD can be one of rename, copy or symlink.
3171 Files will be renamed if they are files of current directory, otherwise they
3172 will be treated with METHOD.
3173 Default METHOD is rename."
3174 ;; Maybe remove directories selected by error in collection.
3175 (setq collection (remove-if 'file-directory-p collection))
3176 (flet ((symlink-file (file dest)
3177 (let ((flist (list file)))
3178 (anything-dired-action
3179 dest :action 'symlink :files flist))))
3181 (let* ((tmp-dir (file-name-as-directory
3182 (concat (file-name-as-directory directory)
3183 (symbol-name (gensym "tmp")))))
3184 (fn (case method
3185 (copy 'copy-file)
3186 (symlink 'symlink-file)
3187 (rename 'rename-file)
3188 (t (error "Error: Unknow method %s" method)))))
3189 (make-directory tmp-dir)
3190 (loop for i in collection
3191 for count from start-at-num
3192 for fnum = (if (< count 10) "0%s" "%s")
3193 for nname = (concat tmp-dir new-name (format fnum count)
3194 (if (not (string= extension ""))
3195 (format ".%s" (replace-regexp-in-string
3196 "[.]" "" extension))
3197 (file-name-extension i 'dot)))
3198 do (if (anything-ff-member-directory-p i directory)
3199 (rename-file i nname)
3200 (funcall fn i nname)))
3201 (loop with dirlist = (directory-files
3202 tmp-dir t directory-files-no-dot-files-regexp)
3203 for f in dirlist do
3204 (if (file-symlink-p f)
3205 (symlink-file (file-truename f)
3206 (concat (file-name-as-directory directory)
3207 (anything-c-basename f)))
3208 (rename-file f directory)))
3209 (delete-directory tmp-dir t))))
3211 (defun anything-ff-serial-rename (candidate)
3212 "Serial rename all marked files to `anything-ff-default-directory'.
3213 Rename only file of current directory, and symlink files coming from
3214 other directories.
3215 See `anything-ff-serial-rename-1'."
3216 (anything-ff-serial-rename-action 'rename))
3218 (defun anything-ff-serial-rename-by-symlink (candidate)
3219 "Serial rename all marked files to `anything-ff-default-directory'.
3220 Rename only file of current directory, and symlink files coming from
3221 other directories.
3222 See `anything-ff-serial-rename-1'."
3223 (anything-ff-serial-rename-action 'symlink))
3225 (defun anything-ff-serial-rename-by-copying (candidate)
3226 "Serial rename all marked files to `anything-ff-default-directory'.
3227 Rename only file of current directory, and copy files coming from
3228 other directories.
3229 See `anything-ff-serial-rename-1'."
3230 (anything-ff-serial-rename-action 'copy))
3232 (defun anything-c-quit-and-execute-action (action)
3233 "Quit current anything session and execute ACTION."
3234 (setq anything-saved-action action)
3235 (anything-exit-minibuffer))
3237 (defun anything-ff-toggle-auto-update (candidate)
3238 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3239 (message "[Auto expansion %s]"
3240 (if anything-ff-auto-update-flag "enabled" "disabled")))
3242 ;;;###autoload
3243 (defun anything-ff-run-toggle-auto-update ()
3244 (interactive)
3245 (anything-execute-persistent-action 'toggle-auto-update))
3247 ;;;###autoload
3248 (defun anything-ff-run-switch-to-history ()
3249 "Run Switch to history action from `anything-c-source-find-files'."
3250 (interactive)
3251 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3253 ;;;###autoload
3254 (defun anything-ff-run-grep ()
3255 "Run Grep action from `anything-c-source-find-files'."
3256 (interactive)
3257 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3259 ;;;###autoload
3260 (defun anything-ff-run-pdfgrep ()
3261 "Run Pdfgrep action from `anything-c-source-find-files'."
3262 (interactive)
3263 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3265 ;;;###autoload
3266 (defun anything-ff-run-zgrep ()
3267 "Run Grep action from `anything-c-source-find-files'."
3268 (interactive)
3269 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3271 ;;;###autoload
3272 (defun anything-ff-run-copy-file ()
3273 "Run Copy file action from `anything-c-source-find-files'."
3274 (interactive)
3275 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3277 ;;;###autoload
3278 (defun anything-ff-run-rename-file ()
3279 "Run Rename file action from `anything-c-source-find-files'."
3280 (interactive)
3281 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3283 ;;;###autoload
3284 (defun anything-ff-run-byte-compile-file ()
3285 "Run Byte compile file action from `anything-c-source-find-files'."
3286 (interactive)
3287 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3289 ;;;###autoload
3290 (defun anything-ff-run-load-file ()
3291 "Run Load file action from `anything-c-source-find-files'."
3292 (interactive)
3293 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3295 ;;;###autoload
3296 (defun anything-ff-run-eshell-command-on-file ()
3297 "Run eshell command on file action from `anything-c-source-find-files'."
3298 (interactive)
3299 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3301 ;;;###autoload
3302 (defun anything-ff-run-ediff-file ()
3303 "Run Ediff file action from `anything-c-source-find-files'."
3304 (interactive)
3305 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3307 ;;;###autoload
3308 (defun anything-ff-run-ediff-merge-file ()
3309 "Run Ediff merge file action from `anything-c-source-find-files'."
3310 (interactive)
3311 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3313 ;;;###autoload
3314 (defun anything-ff-run-symlink-file ()
3315 "Run Symlink file action from `anything-c-source-find-files'."
3316 (interactive)
3317 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3319 ;;;###autoload
3320 (defun anything-ff-run-delete-file ()
3321 "Run Delete file action from `anything-c-source-find-files'."
3322 (interactive)
3323 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3325 ;;;###autoload
3326 (defun anything-ff-run-complete-fn-at-point ()
3327 "Run complete file name action from `anything-c-source-find-files'."
3328 (interactive)
3329 (anything-c-quit-and-execute-action
3330 'anything-c-insert-file-name-completion-at-point))
3332 ;;;###autoload
3333 (defun anything-ff-run-switch-to-eshell ()
3334 "Run switch to eshell action from `anything-c-source-find-files'."
3335 (interactive)
3336 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3338 ;;;###autoload
3339 (defun anything-ff-run-switch-other-window ()
3340 "Run switch to other window action from `anything-c-source-find-files'."
3341 (interactive)
3342 (anything-c-quit-and-execute-action 'find-file-other-window))
3344 ;;;###autoload
3345 (defun anything-ff-run-switch-other-frame ()
3346 "Run switch to other frame action from `anything-c-source-find-files'."
3347 (interactive)
3348 (anything-c-quit-and-execute-action 'find-file-other-frame))
3350 ;;;###autoload
3351 (defun anything-ff-run-open-file-externally ()
3352 "Run open file externally command action from `anything-c-source-find-files'."
3353 (interactive)
3354 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3356 (defun anything-ff-locate (candidate)
3357 "Locate action function for `anything-find-files'."
3358 (let ((input (concat (anything-c-basename
3359 (expand-file-name
3360 candidate
3361 anything-ff-default-directory))
3362 ;; The locate '-b' option doesn't exists
3363 ;; in everything.
3364 (unless (and (eq system-type 'windows-nt)
3365 (string-match "^es" anything-c-locate-command))
3366 " -b")))
3367 (anything-mp-highlight-delay 0.7))
3368 (anything-locate-1 anything-current-prefix-arg input)))
3370 ;;;###autoload
3371 (defun anything-ff-run-locate ()
3372 "Run locate action from `anything-c-source-find-files'."
3373 (interactive)
3374 (anything-c-quit-and-execute-action 'anything-ff-locate))
3376 ;;;###autoload
3377 (defun anything-ff-run-gnus-attach-files ()
3378 "Run gnus attach files command action from `anything-c-source-find-files'."
3379 (interactive)
3380 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3382 ;;;###autoload
3383 (defun anything-ff-run-etags ()
3384 "Run Etags command action from `anything-c-source-find-files'."
3385 (interactive)
3386 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3389 (defun anything-ff-print (candidate)
3390 "Print marked files.
3391 You have to set in order
3392 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3394 e.g:
3395 \(setq lpr-command \"gtklp\"\)
3396 \(setq lpr-switches '(\"-P\")\)
3397 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3399 Same as `dired-do-print' but for anything."
3400 (let* ((file-list (anything-marked-candidates))
3401 (len (length file-list))
3402 (printer-name (if anything-ff-printer-list
3403 (anything-comp-read
3404 "Printer: " anything-ff-printer-list)
3405 printer-name))
3406 (command (read-string
3407 (format "Print *%s File(s):\n%s with: "
3409 (mapconcat
3410 (lambda (f) (format "- %s\n" f))
3411 file-list ""))
3412 (when (and lpr-command
3413 (or lpr-switches
3414 printer-name))
3415 (mapconcat 'identity
3416 (cons lpr-command
3417 (append (if (stringp lpr-switches)
3418 (list lpr-switches)
3419 lpr-switches)
3420 (list printer-name)))
3421 " "))))
3422 (file-args (mapconcat #'(lambda (x)
3423 (format "'%s'" x))
3424 file-list " "))
3425 (cmd-line (concat command " " file-args)))
3426 (if command
3427 (start-process-shell-command "anything-print" nil cmd-line)
3428 (error "Error: Please verify your printer settings in Emacs."))))
3430 ;;;###autoload
3431 (defun anything-ff-run-print-file ()
3432 "Run Print file action from `anything-c-source-find-files'."
3433 (interactive)
3434 (anything-c-quit-and-execute-action 'anything-ff-print))
3436 (defun anything-ff-checksum (file)
3437 "Calculate the checksum of FILE.
3438 Provide completion on different algorithms to use on Emacs24.
3439 On Emacs23 only 'sha1' is available.
3440 The checksum is copied to kill-ring."
3441 (let ((algo-list (and (fboundp 'secure-hash)
3442 '(md5 sha1 sha224 sha256 sha384 sha512))))
3443 (kill-new
3444 (if algo-list
3445 (secure-hash (intern
3446 (anything-comp-read
3447 "Algorithm: " algo-list))
3448 file)
3449 (sha1 (with-temp-buffer
3450 (insert-file-contents file)
3451 (buffer-string)))))
3452 (message "Checksum copied to kill-ring.")))
3454 (defun anything-ff-toggle-basename (candidate)
3455 (setq anything-ff-transformer-show-only-basename
3456 (not anything-ff-transformer-show-only-basename))
3457 (let ((target (if anything-ff-transformer-show-only-basename
3458 (anything-c-basename candidate) candidate)))
3459 (anything-force-update target)))
3461 (defun anything-ff-run-toggle-basename ()
3462 (interactive)
3463 (anything-execute-persistent-action 'toggle-basename))
3465 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3466 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3467 If LEVEL is positive reduce from end else from beginning.
3468 If UNIX-CLOSE is non--nil close filename with /.
3469 If EXPAND is non--nil expand-file-name."
3470 (let* ((exp-fname (expand-file-name fname))
3471 (fname-list (split-string (if (or (string= fname "~/") expand)
3472 exp-fname fname) "/" t))
3473 (len (length fname-list))
3474 (pop-list (if (< level 0)
3475 (subseq fname-list (* level -1))
3476 (subseq fname-list 0 (- len level))))
3477 (result (mapconcat 'identity pop-list "/"))
3478 (empty (string= result "")))
3479 (when unix-close (setq result (concat result "/")))
3480 (if (string-match "^~" result)
3481 (if (string= result "~/") "~/" result)
3482 (if (< level 0)
3483 (if empty "../" (concat "../" result))
3484 (cond ((eq system-type 'windows-nt)
3485 (if empty "c:/" result))
3486 (empty "/")
3488 (concat "/" result)))))))
3490 ;; Internal
3491 (defvar anything-file-completion-sources
3492 '("Find Files" "find-file" "Copy Files"
3493 "dired-do-copy" "dired-do-rename"
3494 "dired-do-symlink" "dired-do-hardlink"
3495 "write-file" "insert-file" "dired"
3496 "find-alternate-file" "find-alternate-file-other-window"
3497 "find-file-read-only" "list-directory"
3498 "Read File Name History" "mml-attach-file"
3499 "Rename Files" "Symlink Files" "elscreen-find-file"
3500 "Hardlink Files" "Write File" "dvc-bookmarks-find-file-in-tree"
3501 "Insert File" "Read File Name" "visit-tags-table")
3502 "Sources that use the *find-files mechanism can be added here.
3503 You should not modify this yourself and know what you do if you do so.")
3505 (defun anything-file-completion-source-p ()
3506 "Test if current source is a dired or find-files source."
3507 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3508 (loop for i in anything-file-completion-sources
3509 thereis (string= cur-source i))))
3511 (defun anything-find-files-down-one-level (arg)
3512 "Go down one level like unix command `cd ..'.
3513 If prefix numeric arg is given go ARG level down."
3514 (interactive "p")
3515 (when (and (anything-file-completion-source-p)
3516 (not (anything-ff-invalid-tramp-name-p)))
3517 (with-anything-window
3518 (setq anything-follow-mode nil))
3519 ;; When going to precedent level we want to be at the line
3520 ;; corresponding to actual directory, so store this info
3521 ;; in `anything-ff-last-expanded'.
3522 (if (and (not (file-directory-p anything-pattern))
3523 (file-exists-p anything-pattern))
3524 (setq anything-ff-last-expanded anything-pattern)
3525 (setq anything-ff-last-expanded anything-ff-default-directory))
3526 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3527 :unix-close t :expand t)))
3528 (anything-set-pattern new-pattern))))
3530 (defun anything-ff-retrieve-last-expanded ()
3531 "Move overlay to last visited directory `anything-ff-last-expanded'.
3532 This happen after using `anything-find-files-down-one-level',
3533 or hitting C-z on \"..\"."
3534 (when (and anything-ff-last-expanded
3535 (anything-file-completion-source-p))
3536 (let ((dirname (if anything-ff-transformer-show-only-basename
3537 (anything-c-basename
3538 (directory-file-name anything-ff-last-expanded))
3539 (directory-file-name anything-ff-last-expanded))))
3540 (with-anything-window
3541 (when (or (re-search-forward (concat dirname "$") nil t)
3542 (re-search-forward
3543 (concat anything-ff-last-expanded "$") nil t))
3544 (forward-line 0)
3545 (anything-mark-current-line)))
3546 (setq anything-ff-last-expanded nil))))
3547 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3549 ;; Auto-update - anything-find-files auto expansion of directories.
3551 (defun anything-ff-update-when-only-one-matched ()
3552 "Expand to directory when sole completion.
3553 When only one candidate is remaining and it is a directory,
3554 expand to this directory."
3555 (when (and anything-ff-auto-update-flag
3556 (anything-file-completion-source-p)
3557 (not (anything-ff-invalid-tramp-name-p)))
3558 (let* ((history-p (string= (assoc-default
3559 'name (anything-get-current-source))
3560 "Read File Name History"))
3561 (pat (if (string-match tramp-file-name-regexp
3562 anything-pattern)
3563 (anything-create-tramp-name anything-pattern)
3564 anything-pattern))
3565 (completed-p (string= (file-name-as-directory pat)
3566 anything-ff-default-directory)))
3567 (when (and (or
3568 ;; Only one candidate remaining
3569 ;; and at least 2 char in basename.
3570 (and (<= (anything-approximate-candidate-number) 2)
3571 (>= (length (anything-c-basename anything-pattern)) 2))
3572 ;; Already completed.
3573 completed-p)
3574 (not history-p)) ; Don't try to auto complete in history.
3575 (with-anything-window
3576 (let ((cur-cand (prog2
3577 (unless completed-p
3578 ;; Only one non--existing candidate
3579 ;; and one directory candidate, move to it.
3580 (anything-next-line))
3581 (anything-get-selection))))
3582 (when (file-directory-p cur-cand)
3583 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3584 ;; Maybe we are here because completed-p is true
3585 ;; but check this again to be sure. (Windows fix)
3586 (<= (anything-approximate-candidate-number) 2)) ; [2]
3587 ;; If after going to next line the candidate
3588 ;; is not one of "." or ".." [1]
3589 ;; and only one candidate is remaining [2],
3590 ;; assume candidate is a new directory to expand, and do it.
3591 (anything-set-pattern (file-name-as-directory cur-cand))
3592 ;; The candidate is one of "." or ".."
3593 ;; that mean we have entered the last letter of the directory name
3594 ;; in prompt, so expansion is already done, just add the "/" at end
3595 ;; of name unless anything-pattern ends with "."
3596 ;; (i.e we are writing something starting with ".")
3597 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3598 (anything-set-pattern
3599 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3600 (expand-file-name (file-name-as-directory anything-pattern)))))
3601 (anything-check-minibuffer-input-1))))))))
3602 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3604 ;; Allow expanding to home directory or root
3605 ;; when entering respectively "~/" or "//" at end of pattern.
3606 ;; e.g /home/thierry/labo/anything-config-qp/~/
3607 ;; will expand to "~/"
3608 ;; and /home/thierry/labo/anything-config-qp//
3609 ;; will expand to "/"
3610 (defun anything-ff-auto-expand-to-home-or-root ()
3611 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3612 This happen only in function using sources that are
3613 `anything-file-completion-source-p' compliant."
3614 (when (and (anything-file-completion-source-p)
3615 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3616 anything-pattern))
3617 (let ((match (match-string 1 anything-pattern)))
3618 (cond ((string= match "//")
3619 (if (eq system-type 'windows-nt)
3620 (setq anything-pattern "c:/")
3621 (setq anything-pattern "/")))
3622 ((string= match "/~/")
3623 (if (eq system-type 'windows-nt)
3624 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3625 (setq anything-pattern "~/")))
3626 ((string= match "/./")
3627 (setq anything-pattern
3628 (with-anything-current-buffer
3629 (expand-file-name default-directory))))))
3630 (setq anything-ff-default-directory anything-pattern)
3631 ;; For some reasons, i must use here with-current-buffer => mini buffer
3632 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3633 (with-current-buffer (window-buffer (minibuffer-window))
3634 (delete-minibuffer-contents)
3635 (insert anything-pattern))))
3637 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3639 (defun anything-c-point-file-in-dired (file)
3640 "Put point on filename FILE in dired buffer."
3641 (dired (file-name-directory file))
3642 (dired-goto-file file))
3644 (defun anything-create-tramp-name (fname)
3645 "Build filename for `anything-pattern' like /su:: or /sudo::."
3646 (apply #'tramp-make-tramp-file-name
3647 (loop with v = (tramp-dissect-file-name fname)
3648 for i across v collect i)))
3650 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3651 "Get a list of hosts for tramp method found in `anything-pattern'.
3652 Argument PATTERN default to `anything-pattern', it is here only for debugging
3653 purpose."
3654 (when (string-match tramp-file-name-regexp pattern)
3655 (let ((method (match-string 1 pattern))
3656 (tn (match-string 0 pattern))
3657 (all-methods (mapcar 'car tramp-methods)))
3658 (remove-duplicates
3659 (loop for (f . h) in (tramp-get-completion-function method)
3660 append (loop for e in (funcall f (car h))
3661 for host = (and (consp e) (cadr e))
3662 when (and host (not (member host all-methods)))
3663 collect (concat tn host)))
3664 :test 'equal))))
3666 (defun anything-ff-before-action-hook-fn ()
3667 "Exit anything when user try to execute action on an invalid tramp fname."
3668 (let ((cand (anything-get-selection)))
3669 (when (and (anything-file-completion-source-p)
3670 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3671 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3672 (error "Error: Unknow file or directory `%s'" cand))))
3673 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3675 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3676 "Return non--nil when PATTERN is an invalid tramp filename."
3677 (string= (anything-ff-set-pattern pattern)
3678 "Invalid tramp file name"))
3680 (defun anything-ff-set-pattern (pattern)
3681 "Handle tramp filenames in `anything-pattern'."
3682 (let ((methods (mapcar 'car tramp-methods))
3683 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3684 cur-method tramp-name)
3685 (cond ((string= pattern "") "")
3686 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3687 (with-anything-current-buffer
3688 (expand-file-name default-directory)))
3689 ((string-match ".*\\(~//\\|//\\)$" pattern)
3690 (if (eq system-type 'windows-nt) "c:/" "/"))
3691 ((string-match "^~\\|.*/~/$" pattern)
3692 (let* ((home (expand-file-name (getenv "HOME"))))
3693 (replace-match home nil t pattern)))
3694 ;; Match "/method:maybe_hostname:"
3695 ((and (string-match reg pattern)
3696 (setq cur-method (match-string 1 pattern))
3697 (member cur-method methods))
3698 (setq tramp-name (anything-create-tramp-name
3699 (match-string 0 pattern)))
3700 (replace-match tramp-name nil t pattern))
3701 ;; Match "/hostname:"
3702 ((and (string-match tramp-file-name-regexp pattern)
3703 (setq cur-method (match-string 1 pattern))
3704 (and cur-method (not (member cur-method methods))))
3705 (setq tramp-name (anything-create-tramp-name
3706 (match-string 0 pattern)))
3707 (replace-match tramp-name nil t pattern))
3708 ;; Match "/method:" in this case don't try to connect.
3709 ((and (not (string-match reg pattern))
3710 (string-match tramp-file-name-regexp pattern)
3711 (member (match-string 1 pattern) methods))
3712 "Invalid tramp file name") ; Write in anything-buffer.
3713 ;; PATTERN is a directory, end it with "/".
3714 ;; This will make PATTERN not ending yet with "/"
3715 ;; candidate for `anything-ff-default-directory',
3716 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3717 ;; when descending level.
3718 ((file-directory-p pattern)
3719 (file-name-as-directory pattern))
3720 ;; Return PATTERN unchanged.
3721 (t pattern))))
3723 (defun anything-find-files-get-candidates ()
3724 "Create candidate list for `anything-c-source-find-files'."
3725 (let* ((path (anything-ff-set-pattern anything-pattern))
3726 (path-name-dir (if (file-directory-p path)
3727 (file-name-as-directory path)
3728 (file-name-directory path)))
3729 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3730 (set-text-properties 0 (length path) nil path)
3731 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3732 ;; like that the actual value (e.g /ssh:) is passed to
3733 ;; `anything-ff-tramp-hostnames'.
3734 (unless (string= path "Invalid tramp file name")
3735 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3736 (setq anything-ff-default-directory
3737 (if (string= anything-pattern "")
3738 (if (eq system-type 'windows-nt) "c:/" "/")
3739 (unless (string-match ffap-url-regexp path)
3740 ;; If path is an url *default-directory have to be nil.
3741 path-name-dir)))
3742 (cond ((string= path "Invalid tramp file name")
3743 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3744 (prog2
3745 ;; `anything-pattern' have not been modified yet.
3746 ;; Set it here to the value of `path' that should be now
3747 ;; "Invalid tramp file name" and set the candidates list
3748 ;; to ("Invalid tramp file name") to make `anything-pattern'
3749 ;; match single candidate "Invalid tramp file name".
3750 (setq anything-pattern path)
3751 ;; "Invalid tramp file name" is now printed
3752 ;; in `anything-buffer'.
3753 (list path))))
3754 ((or (file-regular-p path)
3755 (and (not (file-exists-p path)) (string-match "/$" path))
3756 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3757 (list path))
3758 ((string= path "") (directory-files "/" t))
3759 ((and (file-directory-p path) (not (file-readable-p path)))
3760 (list (format "Opening directory: access denied, `%s'" path)))
3761 ((file-directory-p path) (directory-files path t))
3763 (append (list path) (directory-files path-name-dir t))))))
3765 (defun anything-ff-transform-fname-for-completion (fname)
3766 "Return FNAME with it's basename modified as a regexp.
3767 e.g foo => f.*o.*o .
3768 If basename contain one or more space or FNAME is a valid directory name
3769 return FNAME unchanged."
3770 (let ((bn (anything-c-basename fname)))
3771 (if (or (not anything-ff-smart-completion)
3772 (string-match "\\s-" bn)
3773 (string-match "/$" fname) ; Allow mkdir.
3774 (file-directory-p fname))
3775 fname ; Fall back to match-plugin.
3776 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3777 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3778 (concat (file-name-directory fname) bn))))
3780 (defun anything-ff-save-history ()
3781 "Store the last value of `anything-ff-default-directory' \
3782 in `anything-ff-history'."
3783 (when (and anything-ff-default-directory
3784 (anything-file-completion-source-p))
3785 (push anything-ff-default-directory anything-ff-history)))
3786 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3788 (defun anything-ff-valid-symlink-p (file)
3789 (file-exists-p (file-truename file)))
3791 (defun anything-ff-properties (candidate)
3792 "Show file properties of CANDIDATE in a tooltip or message."
3793 (let ((type (anything-ff-attributes candidate :type t))
3794 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3795 (if (window-system)
3796 (tooltip-show
3797 (concat
3798 (anything-c-basename candidate) ": \n"
3799 "Type: " type "\n"
3800 (when (string= type "symlink")
3801 (format "True name: '%s'\n"
3802 (cond ((string-match "^\.#" (anything-c-basename candidate))
3803 "Autosave symlink")
3804 ((anything-ff-valid-symlink-p candidate)
3805 (file-truename candidate))
3806 (t "Invalid Symlink"))))
3807 dired-line))
3808 (message dired-line) (sit-for 5))))
3810 ;;;###autoload
3811 (defun anything-ff-properties-persistent ()
3812 "Show properties without quitting anything."
3813 (interactive)
3814 (anything-execute-persistent-action 'properties-action))
3816 (defun anything-ff-kill-buffer-fname (candidate)
3817 (let* ((buf (get-file-buffer candidate))
3818 (buf-name (buffer-name buf)))
3819 (if buf
3820 (progn
3821 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3822 (message "No buffer to kill"))))
3824 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3825 "Find file CANDIDATE or kill it's buffer if it is visible.
3826 Never kill `anything-current-buffer'.
3827 Never kill buffer modified.
3828 This is called normally on third hit of \
3829 \\<anything-map>\\[anything-execute-persistent-action]
3830 in `anything-find-files-persistent-action'."
3831 (let* ((buf (get-file-buffer candidate))
3832 (buf-name (buffer-name buf)))
3833 (if (and buf (get-buffer-window buf)
3834 (not (eq buf (get-buffer anything-current-buffer)))
3835 (not (buffer-modified-p buf)))
3836 (progn
3837 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3838 (find-file candidate))))
3840 ;;;###autoload
3841 (defun anything-ff-run-kill-buffer-persistent ()
3842 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3843 (interactive)
3844 (anything-execute-persistent-action 'kill-buffer-fname))
3846 (defun anything-ff-human-size (size)
3847 "Return a string showing SIZE of a file in human readable form.
3848 SIZE can be an integer or a float depending it's value.
3849 `file-attributes' will take care of that to avoid overflow error.
3850 KBSIZE if a floating point number, default value is 1024.0."
3851 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3852 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3853 (K (cons "K" (/ size anything-ff-default-kbsize)))
3854 (B (cons "B" size)))
3855 (loop with result = B
3856 for (a . b) in
3857 (loop for (x . y) in (list M G K B)
3858 unless (< y 1) collect (cons x y))
3859 when (< b (cdr result)) do (setq result (cons a b))
3860 finally return (if (string= (car result) "B")
3861 (format "%s" size)
3862 (format "%.1f%s" (cdr result) (car result))))))
3864 (defun* anything-ff-attributes
3865 (file &key type links uid gid access-time modif-time
3866 status size mode gid-change inode device-num dired human-size)
3867 "Easy interface for `file-attributes'."
3868 (let ((all (destructuring-bind
3869 (type links uid gid access-time modif-time
3870 status size mode gid-change inode device-num)
3871 (file-attributes file 'string)
3872 (list :type type
3873 :links links
3874 :uid uid
3875 :gid gid
3876 :access-time access-time
3877 :modif-time modif-time
3878 :status status
3879 :size size
3880 :mode mode
3881 :gid-change gid-change
3882 :inode inode
3883 :device-num device-num))))
3884 (cond (type
3885 (let ((result (getf all :type)))
3886 (cond ((stringp result)
3887 "symlink")
3888 (result "directory")
3889 (t "file"))))
3890 (links (getf all :links))
3891 (uid (getf all :uid))
3892 (gid (getf all :gid))
3893 (access-time
3894 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3895 (modif-time
3896 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3897 (status
3898 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3899 (size (if human-size (anything-ff-human-size (getf all :size))
3900 (getf all :size)))
3901 (mode (getf all :mode))
3902 (gid-change (getf all :gid-change))
3903 (inode (getf all :inode))
3904 (device-num (getf all :device-num))
3905 (dired
3906 (concat
3907 (getf all :mode) " "
3908 (number-to-string (getf all :links)) " "
3909 (getf all :uid) ":"
3910 (getf all :gid) " "
3911 (if human-size (anything-ff-human-size (getf all :size))
3912 (int-to-string (getf all :size))) " "
3913 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3914 (t all))))
3916 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3917 "Return filename FNAME maybe prefixed with [?] or [@].
3918 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3919 existing filename or valid symlink and there is no need to test it.
3920 NEW-FILE when non--nil mean FNAME is a non existing file and
3921 return FNAME prefixed with [?]."
3922 (let* ((prefix-new (propertize
3923 " " 'display
3924 (propertize "[?]" 'face 'anything-ff-prefix)))
3925 (prefix-url (propertize
3926 " " 'display
3927 (propertize "[@]" 'face 'anything-ff-prefix))))
3928 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3929 ((string-match ffap-url-regexp fname)
3930 (concat prefix-url " " fname))
3931 ((or new-file (not (file-exists-p fname)))
3932 (concat prefix-new " " fname)))))
3934 (defun anything-c-find-files-transformer (files sources)
3935 "Transformer for `anything-c-source-find-files'.
3936 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3937 is non--nil."
3938 (if (and (string-match tramp-file-name-regexp anything-pattern)
3939 anything-ff-tramp-not-fancy)
3940 (if anything-ff-transformer-show-only-basename
3941 (loop for i in files collect
3942 (if (string-match "[.]\\{1,2\\}$" i)
3943 i (cons (anything-c-basename i) i)))
3944 files)
3945 (anything-ff-highlight-files files sources)))
3947 (defun anything-ff-highlight-files (files sources)
3948 "Candidate transformer for `anything-c-source-find-files' without icons."
3949 (loop for i in files
3950 for disp = (if (and anything-ff-transformer-show-only-basename
3951 (not (string-match "[.]\\{1,2\\}$" i))
3952 (not (string-match ffap-url-regexp i)))
3953 (anything-c-basename i) i)
3954 collect
3955 (cond ((and (stringp (car (file-attributes i)))
3956 (not (anything-ff-valid-symlink-p i))
3957 (not (string-match "^\.#" (anything-c-basename i))))
3958 (cons (anything-ff-prefix-filename
3959 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3961 ((stringp (car (file-attributes i)))
3962 (cons (anything-ff-prefix-filename
3963 (propertize disp 'face 'anything-ff-symlink) t)
3965 ((eq t (car (file-attributes i)))
3966 (cons (anything-ff-prefix-filename
3967 (propertize disp 'face 'anything-ff-directory) t)
3969 ((file-executable-p i)
3970 (cons (anything-ff-prefix-filename
3971 (propertize disp 'face 'anything-ff-executable) t)
3973 ((file-exists-p i)
3974 (cons (anything-ff-prefix-filename
3975 (propertize disp 'face 'anything-ff-file) t)
3978 (cons (anything-ff-prefix-filename
3979 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3980 i)))))
3982 (defun anything-find-files-action-transformer (actions candidate)
3983 "Action transformer for `anything-c-source-find-files'."
3984 (cond ((with-anything-current-buffer
3985 (eq major-mode 'message-mode))
3986 (append (subseq actions 0 4)
3987 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3988 (subseq actions 4)))
3989 ((string-match (image-file-name-regexp) candidate)
3990 (append (subseq actions 0 4)
3991 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3992 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3993 (subseq actions 4)))
3994 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3995 (car it) candidate))
3996 (append (subseq actions 0 4)
3997 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3998 . anything-find-files-byte-compile)
3999 ("Load File(s) `M-L'" . anything-find-files-load-files))
4000 (subseq actions 4)))
4001 ((and (string-match "\.html?$" candidate)
4002 (file-exists-p candidate))
4003 (append (subseq actions 0 4)
4004 '(("Browse url file" . browse-url-of-file))
4005 (subseq actions 5)))
4006 ((or (string= (file-name-extension candidate) "pdf")
4007 (string= (file-name-extension candidate) "PDF"))
4008 (append (subseq actions 0 4)
4009 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4010 (subseq actions 5)))
4011 (t actions)))
4013 (defun anything-ff-gnus-attach-files (candidate)
4014 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4015 (let ((flist (anything-marked-candidates)))
4016 (gnus-dired-attach flist)))
4018 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4019 "Rotate current image at NUM-ARG degrees.
4020 This is a destructive operation on FILE made by external tool mogrify."
4021 (declare (special image-dired-display-image-buffer))
4022 (setq file (file-truename file)) ; For symlinked images.
4023 ;; When FILE is not an image-file, do nothing.
4024 (when (string-match (image-file-name-regexp) file)
4025 (if (executable-find "mogrify")
4026 (progn
4027 (shell-command (format "mogrify -rotate %s %s"
4028 (or num-arg 90)
4029 (shell-quote-argument file)))
4030 (when (buffer-live-p image-dired-display-image-buffer)
4031 (kill-buffer image-dired-display-image-buffer))
4032 (image-dired-display-image file)
4033 (message nil)
4034 (display-buffer (get-buffer image-dired-display-image-buffer)))
4035 (error "mogrify not found"))))
4037 (defun anything-ff-rotate-image-left (candidate)
4038 "Rotate image file CANDIDATE left.
4039 This affect directly file CANDIDATE."
4040 (anything-ff-rotate-current-image-1 candidate -90))
4042 (defun anything-ff-rotate-image-right (candidate)
4043 "Rotate image file CANDIDATE right.
4044 This affect directly file CANDIDATE."
4045 (anything-ff-rotate-current-image-1 candidate))
4047 (defun anything-ff-rotate-left-persistent ()
4048 "Rotate image left without quitting anything."
4049 (interactive)
4050 (anything-execute-persistent-action 'image-action1))
4052 (defun anything-ff-rotate-right-persistent ()
4053 "Rotate image right without quitting anything."
4054 (interactive)
4055 (anything-execute-persistent-action 'image-action2))
4057 (defun anything-ff-exif-data (candidate)
4058 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4059 (if (and anything-ff-exif-data-program
4060 (executable-find anything-ff-exif-data-program))
4061 (shell-command-to-string (format "%s %s %s"
4062 anything-ff-exif-data-program
4063 anything-ff-exif-data-program-args
4064 candidate))
4065 (format "No program %s found to extract exif"
4066 anything-ff-exif-data-program)))
4068 (defun anything-find-files-persistent-action (candidate)
4069 "Open subtree CANDIDATE without quitting anything.
4070 If CANDIDATE is not a directory expand CANDIDATE filename.
4071 If CANDIDATE is alone, open file CANDIDATE filename.
4072 That's mean:
4073 First hit on C-z expand CANDIDATE second hit open file.
4074 If a prefix arg is given or `anything-follow-mode' is on open file."
4075 (let ((follow (buffer-local-value
4076 'anything-follow-mode
4077 (get-buffer-create anything-buffer)))
4078 (new-pattern (anything-get-selection))
4079 (num-lines-buf (with-current-buffer anything-buffer
4080 (count-lines (point-min) (point-max)))))
4081 (flet ((insert-in-minibuffer (fname)
4082 (with-selected-window (minibuffer-window)
4083 (unless follow
4084 (delete-minibuffer-contents)
4085 (set-text-properties 0 (length fname) nil fname)
4086 (insert fname)))))
4087 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4088 "Invalid tramp file name")
4089 (string-match tramp-file-name-regexp candidate))
4090 ;; First hit insert hostname and
4091 ;; second hit insert ":" and expand.
4092 (if (string= candidate anything-pattern)
4093 (insert-in-minibuffer (concat candidate ":"))
4094 (insert-in-minibuffer candidate)))
4095 (;; A symlink directory, expand it's truename.
4096 (and (file-directory-p candidate) (file-symlink-p candidate))
4097 (insert-in-minibuffer (file-name-as-directory
4098 (file-truename
4099 (expand-file-name candidate)))))
4100 ;; A directory, open it.
4101 ((file-directory-p candidate)
4102 (when (string= (anything-c-basename candidate) "..")
4103 (setq anything-ff-last-expanded anything-ff-default-directory))
4104 (insert-in-minibuffer (file-name-as-directory
4105 (expand-file-name candidate))))
4106 ;; A symlink file, expand to it's true name. (first hit)
4107 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4108 (insert-in-minibuffer (file-truename candidate)))
4109 ;; A regular file, expand it, (first hit)
4110 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4111 (insert-in-minibuffer new-pattern))
4112 ;; An image file and it is the second hit on C-z,
4113 ;; show the file in `image-dired'.
4114 ((string-match (image-file-name-regexp) candidate)
4115 (when (buffer-live-p image-dired-display-image-buffer)
4116 (kill-buffer image-dired-display-image-buffer))
4117 (image-dired-display-image candidate)
4118 (message nil)
4119 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4120 (with-current-buffer image-dired-display-image-buffer
4121 (let ((exif-data (anything-ff-exif-data candidate)))
4122 (image-dired-update-property 'help-echo exif-data))))
4123 ;; Allow browsing archive on avfs fs.
4124 ;; Assume volume is already mounted with mountavfs.
4125 ((and anything-ff-avfs-directory
4126 (string-match
4127 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4128 (file-name-directory candidate))
4129 (anything-ff-file-compressed-p candidate))
4130 (insert-in-minibuffer (concat candidate "#")))
4131 ;; On second hit we open file.
4132 ;; On Third hit we kill it's buffer maybe.
4134 (anything-ff-kill-or-find-buffer-fname candidate))))))
4136 (defun anything-ff-file-compressed-p (candidate)
4137 "Whether CANDIDATE is a compressed file or not."
4138 (member (file-name-extension candidate)
4139 anything-ff-file-compressed-list))
4141 (defun anything-c-insert-file-name-completion-at-point (candidate)
4142 "Insert file name completion at point."
4143 (with-anything-current-buffer
4144 (if buffer-read-only
4145 (error "Error: Buffer `%s' is read-only" (buffer-name))
4146 (let* ((end (point))
4147 (guess (substring-no-properties (thing-at-point 'filename)))
4148 (beg (- (point) (length guess)))
4149 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4150 (string-match-p "^[^\~]" guess))))
4151 (set-text-properties 0 (length candidate) nil candidate)
4152 (if (and guess (not (string= guess ""))
4153 (string-match-p "^~\\|/.*" guess))
4154 (progn
4155 (delete-region beg end)
4156 (insert (if full-path-p
4157 (expand-file-name candidate)
4158 (abbreviate-file-name candidate))))
4159 (error "Aborting completion: No valid file name at point"))))))
4161 (defun* anything-find-files-history (&key (comp-read t))
4162 "The `anything-find-files' history.
4163 Show the first `anything-ff-history-max-length' elements of
4164 `anything-ff-history' in an `anything-comp-read'."
4165 (let ((history (when anything-ff-history
4166 (anything-fast-remove-dups anything-ff-history
4167 :test 'equal))))
4168 (when history
4169 (setq anything-ff-history
4170 (if (>= (length history) anything-ff-history-max-length)
4171 (subseq history 0 anything-ff-history-max-length)
4172 history))
4173 (if comp-read
4174 (anything-comp-read
4175 "Switch to Directory: "
4176 anything-ff-history
4177 :name "Anything Find Files History"
4178 :must-match t)
4179 anything-ff-history))))
4181 (defun anything-find-files-1 (fname &optional preselect)
4182 "Find FNAME with `anything' completion.
4183 Like `find-file' but with `anything' support.
4184 Use it for non--interactive calls of `anything-find-files'."
4185 (when (get-buffer anything-action-buffer)
4186 (kill-buffer anything-action-buffer))
4187 (let ((anything-mp-highlight-delay nil)
4188 ;; Be sure we don't erase the precedent minibuffer if some.
4189 (anything-ff-auto-update-initial-value
4190 (not (minibuffer-window-active-p (minibuffer-window))))
4191 anything-samewindow)
4192 (anything-1 :sources 'anything-c-source-find-files
4193 :input fname
4194 :preselect preselect
4195 :keymap anything-find-files-map
4196 :prompt "Find Files or Url: "
4197 :buffer "*Anything Find Files*")))
4200 (defun anything-find-files-initial-input (&optional input)
4201 "Return INPUT if present, otherwise try to guess it."
4202 (or (and input (expand-file-name input))
4203 (anything-find-files-input
4204 (ffap-guesser)
4205 (thing-at-point 'filename))))
4207 (defun anything-find-files-input (fap tap)
4208 "Default input of `anything-find-files'."
4209 (let* ((def-dir (anything-c-current-directory))
4210 (lib (anything-find-library-at-point))
4211 (url (anything-ff-find-url-at-point))
4212 (file-p (and fap (not (string= fap ""))
4213 (file-exists-p fap)
4214 tap (not (string= tap ""))
4215 (file-exists-p
4216 (file-name-directory (expand-file-name tap def-dir))))))
4217 (cond (lib) ; e.g we are inside a require sexp.
4218 (url) ; String at point is an hyperlink.
4219 (file-p (expand-file-name tap def-dir))
4220 (t (and (not (string= fap "")) fap)))))
4222 (defun anything-c-current-directory ()
4223 "Return current-directory name at point.
4224 Useful in dired buffers when there is inserted subdirs."
4225 (if (eq major-mode 'dired-mode)
4226 (dired-current-directory)
4227 default-directory))
4229 (defun anything-ff-find-url-at-point ()
4230 "Try to find link to an url in text-property at point."
4231 (let* ((he (get-text-property (point) 'help-echo))
4232 (ov (overlays-at (point)))
4233 (ov-he (and ov (overlay-get
4234 (car (overlays-at (point))) 'help-echo)))
4235 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4236 (nt-prop (get-text-property (point) 'nt-link)))
4237 ;; Org link.
4238 (when (and (stringp he) (string-match "^LINK: " he))
4239 (setq he (replace-match "" t t he)))
4240 (loop for i in (list he ov-he w3m-l nt-prop)
4241 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4243 (defun anything-find-library-at-point ()
4244 "Try to find library path at point.
4245 Find inside `require' and `declare-function' sexp."
4246 (require 'find-func)
4247 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4248 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4249 (sexp (and beg-sexp end-sexp
4250 (buffer-substring-no-properties
4251 (1+ beg-sexp) (1- end-sexp)))))
4252 (ignore-errors
4253 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4254 (find-library-name
4255 (replace-regexp-in-string
4256 "'\\|\)\\|\(" ""
4257 ;; If require use third arg, ignore it,
4258 ;; always use library path found in `load-path'.
4259 (second (split-string (match-string 0 sexp))))))
4260 ((and sexp (string-match-p "^declare-function" sexp))
4261 (find-library-name
4262 (replace-regexp-in-string
4263 "\"\\|ext:" ""
4264 (third (split-string sexp)))))
4265 (t nil)))))
4267 ;;; Anything completion for `write-file'.==> C-x C-w
4268 (defvar anything-c-source-write-file
4269 `((name . "Write File")
4270 (header-name . (lambda (name)
4271 (concat name anything-c-find-files-doc-header)))
4272 ;; It is needed for filenames with capital letters
4273 (disable-shortcuts)
4274 (candidates . anything-find-files-get-candidates)
4275 (filtered-candidate-transformer anything-c-find-files-transformer)
4276 (persistent-action . anything-find-files-persistent-action)
4277 (persistent-help . "Expand Candidate")
4278 (volatile)
4279 (action .
4280 (("Write File" . (lambda (candidate)
4281 (write-file candidate 'confirm)))))))
4283 ;;; Anything completion for `insert-file'.==> C-x i
4284 (defvar anything-c-source-insert-file
4285 `((name . "Insert File")
4286 (header-name . (lambda (name)
4287 (concat name anything-c-find-files-doc-header)))
4288 ;; It is needed for filenames with capital letters
4289 (disable-shortcuts)
4290 (candidates . anything-find-files-get-candidates)
4291 (filtered-candidate-transformer anything-c-find-files-transformer)
4292 (persistent-action . anything-find-files-persistent-action)
4293 (persistent-help . "Expand Candidate")
4294 (volatile)
4295 (action .
4296 (("Insert File" . (lambda (candidate)
4297 (when (y-or-n-p (format "Really insert %s in %s "
4298 candidate anything-current-buffer))
4299 (insert-file-contents candidate))))))))
4301 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4302 (defvar anything-c-source-copy-files
4303 `((name . "Copy Files")
4304 (header-name . (lambda (name)
4305 (concat name anything-c-find-files-doc-header)))
4306 ;; It is needed for filenames with capital letters
4307 (disable-shortcuts)
4308 (candidates . anything-find-files-get-candidates)
4309 (filtered-candidate-transformer anything-c-find-files-transformer)
4310 (persistent-action . anything-find-files-persistent-action)
4311 (persistent-help . "Expand Candidate")
4312 (volatile)
4313 (action .
4314 (("Copy File"
4315 . (lambda (candidate)
4316 (anything-dired-action candidate :action 'copy)))
4317 ("Copy and Follow"
4318 . (lambda (candidate)
4319 (anything-dired-action candidate :action 'copy :follow t)))))))
4322 (defvar anything-c-source-rename-files
4323 `((name . "Rename Files")
4324 (header-name . (lambda (name)
4325 (concat name anything-c-find-files-doc-header)))
4326 ;; It is needed for filenames with capital letters
4327 (disable-shortcuts)
4328 (candidates . anything-find-files-get-candidates)
4329 (filtered-candidate-transformer anything-c-find-files-transformer)
4330 (persistent-action . anything-find-files-persistent-action)
4331 (persistent-help . "Expand Candidate")
4332 (volatile)
4333 (action .
4334 (("Rename File"
4335 . (lambda (candidate)
4336 (anything-dired-action candidate :action 'rename)))
4337 ("Rename and Follow"
4338 . (lambda (candidate)
4339 (anything-dired-action candidate :action 'rename :follow t)))))))
4341 (defvar anything-c-source-symlink-files
4342 `((name . "Symlink Files")
4343 (header-name . (lambda (name)
4344 (concat name anything-c-find-files-doc-header)))
4345 ;; It is needed for filenames with capital letters
4346 (disable-shortcuts)
4347 (candidates . anything-find-files-get-candidates)
4348 (filtered-candidate-transformer anything-c-find-files-transformer)
4349 (persistent-action . anything-find-files-persistent-action)
4350 (persistent-help . "Expand Candidate")
4351 (volatile)
4352 (action
4353 . (("Symlink File"
4354 . (lambda (candidate)
4355 (anything-dired-action candidate :action 'symlink)))
4356 ("RelSymlink File"
4357 . (lambda (candidate)
4358 (anything-dired-action candidate :action 'relsymlink)))))))
4361 (defvar anything-c-source-hardlink-files
4362 `((name . "Hardlink Files")
4363 (header-name . (lambda (name)
4364 (concat name anything-c-find-files-doc-header)))
4365 ;; It is needed for filenames with capital letters
4366 (disable-shortcuts)
4367 (candidates . anything-find-files-get-candidates)
4368 (filtered-candidate-transformer anything-c-find-files-transformer)
4369 (persistent-action . anything-find-files-persistent-action)
4370 (persistent-help . "Expand Candidate")
4371 (volatile)
4372 (action
4373 . (("Hardlink File"
4374 . (lambda (candidate)
4375 (anything-dired-action candidate :action 'hardlink)))))))
4377 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4378 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4379 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4380 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4381 (let ((fn (case action
4382 ('copy 'dired-copy-file)
4383 ('rename 'dired-rename-file)
4384 ('symlink 'make-symbolic-link)
4385 ('relsymlink 'dired-make-relative-symlink)
4386 ('hardlink 'dired-hardlink)))
4387 (marker (case action
4388 ((copy rename) dired-keep-marker-copy)
4389 ('symlink dired-keep-marker-symlink)
4390 ('relsymlink dired-keep-marker-relsymlink)
4391 ('hardlink dired-keep-marker-hardlink)))
4392 (dirflag (and (= (length files) 1)
4393 (file-directory-p (car files))
4394 (not (file-directory-p candidate)))))
4395 (dired-create-files
4396 fn (symbol-name action) files
4397 ;; CANDIDATE is the destination.
4398 (if (file-directory-p candidate)
4399 ;; When CANDIDATE is a directory, build file-name in this directory.
4400 ;; Else we use CANDIDATE.
4401 #'(lambda (from)
4402 (expand-file-name (file-name-nondirectory from) candidate))
4403 #'(lambda (from) candidate))
4404 marker)
4405 (when (and follow (not (get-buffer dired-log-buffer)))
4406 (let ((target (directory-file-name candidate)))
4407 (unwind-protect
4408 (progn
4409 (setq anything-ff-cand-to-mark
4410 (anything-get-dest-fnames-from-list files candidate dirflag))
4411 (if (and dirflag (eq action 'rename))
4412 (anything-find-files-1 (file-name-directory target)
4413 (if anything-ff-transformer-show-only-basename
4414 (anything-c-basename target) target))
4415 (anything-find-files-1 (expand-file-name candidate))))
4416 (setq anything-ff-cand-to-mark nil))))))
4419 (defun anything-c-basename (fname)
4420 "Resolve basename of file or directory named FNAME."
4421 (file-name-nondirectory (directory-file-name fname)))
4423 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4424 "Transform filenames of FLIST to abs of DEST-CAND.
4425 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4426 members of FLIST."
4427 ;; At this point files have been renamed/copied at destination.
4428 ;; That's mean DEST-CAND exists.
4429 (loop
4430 with dest = (expand-file-name dest-cand)
4431 for src in flist
4432 for basename-src = (anything-c-basename src)
4433 for fname = (cond (rename-dir-flag (directory-file-name dest))
4434 ((file-directory-p dest)
4435 (concat (file-name-as-directory dest) basename-src))
4436 (t dest))
4437 when (file-exists-p fname)
4438 collect fname into tmp-list
4439 finally return (sort tmp-list 'string<)))
4441 (defun anything-ff-maybe-mark-candidates ()
4442 "Mark all candidates of list `anything-ff-cand-to-mark'."
4443 (when (and (string= (assoc-default 'name (anything-get-current-source))
4444 (assoc-default 'name anything-c-source-find-files))
4445 anything-ff-cand-to-mark)
4446 (with-anything-window
4447 (while anything-ff-cand-to-mark
4448 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4449 (progn
4450 (anything-make-visible-mark)
4451 (anything-next-line)
4452 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4453 (anything-next-line)))
4454 (unless (anything-this-visible-mark)
4455 (anything-prev-visible-mark)))))
4457 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4459 (defun* anything-dired-do-action-on-file (&key action)
4460 (let* ((files (dired-get-marked-files))
4461 (len (length files))
4462 (fname (if (> len 1)
4463 (format "* %d Files" len)
4464 (car files)))
4465 (source (case action
4466 ('copy 'anything-c-source-copy-files)
4467 ('rename 'anything-c-source-rename-files)
4468 ('symlink 'anything-c-source-symlink-files)
4469 ('hardlink 'anything-c-source-hardlink-files)))
4470 (prompt-fm (case action
4471 ('copy "Copy %s to: ")
4472 ('rename "Rename %s to: ")
4473 ('symlink "Symlink %s to: ")
4474 ('hardlink "Hardlink %s to: ")))
4475 (buffer (case action
4476 ('copy "*Anything Copy Files*")
4477 ('rename "*Anything Rename Files*")
4478 ('symlink "*Anything Symlink Files*")
4479 ('hardlink "*Anything Hardlink Files*")))
4480 (anything-mp-highlight-delay nil))
4481 (anything-1 :sources source
4482 :input (or (dired-dwim-target-directory)
4483 (expand-file-name (anything-c-current-directory)))
4484 :preselect (dired-get-filename)
4485 :prompt (format prompt-fm fname)
4486 :keymap anything-c-read-file-map
4487 :buffer buffer)))
4489 ;;;###autoload
4490 (define-minor-mode anything-dired-mode ()
4491 "Enable anything completion in Dired functions.
4492 Bindings affected are C, R, S, H.
4493 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4494 :group 'anything-config
4495 :global t
4496 (if anything-dired-mode
4497 (progn
4498 (substitute-key-definition
4499 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4500 (substitute-key-definition
4501 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4502 (substitute-key-definition
4503 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4504 (substitute-key-definition
4505 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4506 (substitute-key-definition
4507 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4508 (substitute-key-definition
4509 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4510 (substitute-key-definition
4511 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4512 (substitute-key-definition
4513 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4515 (defalias 'anything-dired-bindings 'anything-dired-mode)
4517 (defun* anything-c-read-file-name (prompt
4518 &key
4519 (name "Read File Name")
4520 (initial-input (expand-file-name default-directory))
4521 (buffer "*Anything Completions*")
4522 test
4523 (preselect nil)
4524 (history nil)
4525 (marked-candidates nil)
4526 (alistp t)
4527 (persistent-action 'anything-find-files-persistent-action)
4528 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4529 "Anything `read-file-name' emulation.
4530 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4531 (when (get-buffer anything-action-buffer)
4532 (kill-buffer anything-action-buffer))
4533 (let ((anything-mp-highlight-delay nil)
4534 ;; Be sure we don't erase the underlying minibuffer if some.
4535 (anything-ff-auto-update-initial-value
4536 (not (minibuffer-window-active-p (minibuffer-window))))
4537 anything-same-window
4538 (hist (and history (anything-comp-read-get-candidates
4539 history nil nil alistp))))
4540 (flet ((action-fn (candidate)
4541 (if marked-candidates
4542 (anything-marked-candidates)
4543 (identity candidate))))
4544 (or (anything-1
4545 :sources
4546 `(((name . ,(format "%s History" name))
4547 (header-name . (lambda (name)
4548 (concat name anything-c-find-files-doc-header)))
4549 (disable-shortcuts)
4550 (mode-line . anything-read-file-name-mode-line-string)
4551 (candidates . hist)
4552 (persistent-action . ,persistent-action)
4553 (persistent-help . ,persistent-help)
4554 (action . ,'action-fn))
4555 ((name . ,name)
4556 (header-name . (lambda (name)
4557 (concat name anything-c-find-files-doc-header)))
4558 ;; It is needed for filenames with capital letters
4559 (disable-shortcuts)
4560 (mode-line . anything-read-file-name-mode-line-string)
4561 (candidates . (lambda ()
4562 (let ((seq (anything-find-files-get-candidates)))
4563 (if test
4564 (loop for fname in seq
4565 when (funcall test fname) collect fname)
4566 seq))))
4567 (filtered-candidate-transformer anything-c-find-files-transformer)
4568 (persistent-action . ,persistent-action)
4569 (candidate-number-limit . 9999)
4570 (toggle-auto-update . anything-ff-toggle-auto-update)
4571 (persistent-help . ,persistent-help)
4572 (volatile)
4573 (action . ,'action-fn)))
4574 :input initial-input
4575 :prompt prompt
4576 :keymap anything-c-read-file-map
4577 :resume 'noresume
4578 :buffer buffer
4579 :preselect preselect)
4580 (keyboard-quit)))))
4583 ;;; File Cache
4584 (defvar anything-c-file-cache-initialized-p nil)
4586 (defvar anything-c-file-cache-files nil)
4588 (defvar anything-c-source-file-cache
4589 '((name . "File Cache")
4590 (init
4591 . (lambda ()
4592 (require 'filecache nil t)
4593 (unless anything-c-file-cache-initialized-p
4594 (setq anything-c-file-cache-files
4595 (loop for item in file-cache-alist append
4596 (destructuring-bind (base &rest dirs) item
4597 (loop for dir in dirs collect
4598 (concat dir base)))))
4599 (defadvice file-cache-add-file (after file-cache-list activate)
4600 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4601 (setq anything-c-file-cache-initialized-p t))))
4602 (candidates . anything-c-file-cache-files)
4603 (match anything-c-match-on-basename)
4604 (type . file)))
4605 ;; (anything 'anything-c-source-file-cache)
4608 ;;; Locate
4611 ;; NOTE for WINDOZE users:
4612 ;; You have to install Everything with his command line interface here:
4613 ;; http://www.voidtools.com/download.php
4615 (defun anything-locate-1 (&optional localdb init)
4616 "Generic function to run Locate.
4617 if LOCALDB is non--nil search and use a local locate db file.
4618 INIT is a string to use as initial input in prompt.
4619 See `anything-locate-with-db' and `anything-locate'."
4620 (anything-locate-with-db
4621 (and localdb
4622 (anything-c-read-file-name
4623 "LocateDBFiles: "
4624 :marked-candidates t
4625 :preselect anything-locate-db-file-regexp
4626 :test #'(lambda (x)
4627 (if anything-locate-db-file-regexp
4628 ;; Select only locate db files and directories
4629 ;; to allow navigation.
4630 (or (string-match
4631 anything-locate-db-file-regexp x)
4632 (file-directory-p x))
4633 x))))
4634 init))
4635 ;; (anything-locate-1 t)
4637 (defun anything-locate-with-db (&optional db initial-input)
4638 "Run locate -d DB.
4639 If DB is not given or nil use locate without -d option.
4640 Argument DB can be given as a string or list of db files.
4641 Argument INITIAL-INPUT is a string to use as initial-input.
4642 See also `anything-locate'."
4643 (when (and db (stringp db)) (setq db (list db)))
4644 (let ((anything-c-locate-command
4645 (if db
4646 (replace-regexp-in-string
4647 "locate"
4648 (format "locate -d %s"
4649 (mapconcat 'identity
4650 ;; Remove eventually
4651 ;; marked directories by error.
4652 (loop for i in db
4653 unless (file-directory-p i)
4654 collect i) ":"))
4655 anything-c-locate-command)
4656 anything-c-locate-command)))
4657 (anything-1 :sources 'anything-c-source-locate
4658 :buffer "*anything locate*"
4659 :input initial-input
4660 :keymap anything-generic-files-map)))
4661 ;; (anything-locate-with-db "~/locate.db")
4663 (defun anything-c-locate-init ()
4664 "Initialize async locate process for `anything-c-source-locate'."
4665 (setq mode-line-format
4666 '(" " mode-line-buffer-identification " "
4667 (line-number-mode "%l") " "
4668 (:eval (propertize "(Locate Process Running) "
4669 'face '((:foreground "red"))))))
4670 (prog1
4671 (start-process-shell-command "locate-process" nil
4672 (format anything-c-locate-command
4673 anything-pattern))
4674 (set-process-sentinel (get-process "locate-process")
4675 #'(lambda (process event)
4676 (when (string= event "finished\n")
4677 (with-anything-window
4678 (force-mode-line-update nil)
4679 (anything-update-move-first-line)))))))
4681 (defvar anything-c-source-locate
4682 '((name . "Locate")
4683 (candidates . anything-c-locate-init)
4684 (type . file)
4685 (properties-action . anything-ff-properties)
4686 (requires-pattern . 3)
4687 (candidate-number-limit . 9999)
4688 (mode-line . anything-generic-file-mode-line-string)
4689 (delayed))
4690 "Find files matching the current input pattern with locate.")
4691 ;; (anything 'anything-c-source-locate)
4693 (defun anything-c-locate-read-file-name (prompt &optional init)
4694 "Search a file with locate and return it's filename.
4695 Use argument PROMPT and INIT for `anything' arguments
4696 prompt and input."
4697 (anything-1 :sources
4698 '((name . "Locate")
4699 (candidates . anything-c-locate-init)
4700 (action . identity)
4701 (properties-action . anything-ff-properties)
4702 (requires-pattern . 3)
4703 (candidate-number-limit . 9999)
4704 (mode-line . anything-generic-file-mode-line-string)
4705 (delayed))
4706 :prompt prompt
4707 :input init
4708 :buffer "*anything locate rfn*"))
4712 ;;; Anything Incremental Grep.
4715 ;; Allow to grep incrementally with anything interface.
4716 ;; It allow also to Grep files recursively without using 'find' shell command.
4717 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4718 (defvar anything-c-grep-default-command
4719 "grep -d skip %e -niH -e %p %f"
4720 "Default grep format command for `anything-do-grep-1'.
4721 Where:
4722 '%e' format spec is for --exclude or --include grep options.
4723 '%p' format spec is for pattern.
4724 '%f' format spec is for filenames.")
4726 (defvar anything-c-grep-default-recurse-command
4727 "grep -d recurse %e -niH -e %p %f"
4728 "Default recursive grep format command for `anything-do-grep-1'.
4729 See `anything-c-grep-default-command' for format specs.")
4731 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4733 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4735 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4737 (defvar anything-c-grep-debug-command-line nil
4738 "Turn on anything grep command-line debugging when non--nil.")
4740 (defvar anything-c-zgrep-recurse-flag nil)
4742 (defvar anything-c-grep-history nil)
4744 (defvar anything-c-grep-max-length-history 100
4745 "*Max number of elements to save in `anything-c-grep-history'.")
4747 (defun anything-c-grep-prepare-candidates (candidates)
4748 "Prepare filenames and directories CANDIDATES for grep command line."
4749 ;; If one or more candidate is a directory, search in all files
4750 ;; of this candidate (e.g /home/user/directory/*).
4751 ;; If r option is enabled search also in subdidrectories.
4752 ;; We need here to expand wildcards to support crap windows filenames
4753 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4754 (if anything-c-zgrep-recurse-flag
4755 (mapconcat 'shell-quote-argument candidates " ")
4756 (loop for i in candidates append
4757 (cond ( ;; Candidate is a directory and we use recursion.
4758 (and (file-directory-p i)
4759 (anything-c-grep-recurse-p))
4760 (list (expand-file-name i)))
4761 ;; Candidate is a directory, search in all files.
4762 ((file-directory-p i)
4763 (file-expand-wildcards
4764 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4765 ;; Candidate is a file or wildcard and we use recursion, use the
4766 ;; current directory instead of candidate.
4767 ((and (or (file-exists-p i) (string-match "\*" i))
4768 (anything-c-grep-recurse-p))
4769 (list (expand-file-name
4770 (directory-file-name ; Needed for windoze.
4771 (file-name-directory (directory-file-name i))))))
4772 ;; Candidate use wildcard.
4773 ((string-match "^\*" (anything-c-basename i))
4774 (file-expand-wildcards i t))
4775 ;; Else should be one or more file.
4776 (t (list i))) into all-files
4777 finally return
4778 (mapconcat 'shell-quote-argument all-files " "))))
4780 (defun anything-c-grep-recurse-p ()
4781 "Check if `anything-do-grep-1' have switched to recursive."
4782 (let ((args (replace-regexp-in-string
4783 "grep" "" anything-c-grep-default-command)))
4784 (string-match-p "r\\|recurse" args)))
4786 (defun anything-c-grep-init (only-files &optional include zgrep)
4787 "Start an asynchronous grep process in ONLY-FILES list."
4788 (let* ((fnargs (anything-c-grep-prepare-candidates
4789 (if (file-remote-p anything-ff-default-directory)
4790 (mapcar #'(lambda (x)
4791 (file-remote-p x 'localname))
4792 only-files)
4793 only-files)))
4794 (ignored-files (mapconcat
4795 #'(lambda (x)
4796 (concat "--exclude=" (shell-quote-argument x)))
4797 grep-find-ignored-files " "))
4798 (ignored-dirs (mapconcat
4799 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4800 #'(lambda (x)
4801 (concat "--exclude-dir=" (shell-quote-argument x)))
4802 grep-find-ignored-directories " "))
4803 (exclude (if (anything-c-grep-recurse-p)
4804 (concat (or include ignored-files) " " ignored-dirs)
4805 ignored-files))
4806 (cmd-line (format-spec
4807 anything-c-grep-default-command
4808 (delq nil
4809 (list (unless zgrep (cons ?e exclude))
4810 (cons ?p (shell-quote-argument anything-pattern))
4811 (cons ?f fnargs))))))
4812 (when anything-c-grep-debug-command-line
4813 (with-current-buffer (get-buffer-create "*any grep debug*")
4814 (goto-char (point-max))
4815 (insert (concat ">>> " cmd-line "\n\n"))))
4816 (setq mode-line-format
4817 '(" " mode-line-buffer-identification " "
4818 (line-number-mode "%l") " "
4819 (:eval (when (get-process "grep-process")
4820 (propertize "[Grep Process Running] "
4821 'face 'anything-grep-running)))))
4822 (force-mode-line-update nil)
4823 (prog1
4824 (let ((default-directory anything-ff-default-directory))
4825 (start-file-process-shell-command "grep-process" nil cmd-line))
4826 (message nil)
4827 (set-process-sentinel
4828 (get-process "grep-process")
4829 #'(lambda (process event)
4830 (when (string= event "finished\n")
4831 (with-anything-window
4832 (anything-update-move-first-line)
4833 (setq mode-line-format
4834 '(" " mode-line-buffer-identification " "
4835 (line-number-mode "%l") " "
4836 (:eval (propertize
4837 (format "[Grep Process Finished - (%s results)] "
4838 (let ((nlines (1- (count-lines
4839 (point-min)
4840 (point-max)))))
4841 (if (> nlines 0) nlines 0)))
4842 'face 'anything-grep-finish))))
4843 (force-mode-line-update nil))))))))
4845 (defun anything-c-grep-action (candidate &optional where mark)
4846 "Define a default action for `anything-do-grep' on CANDIDATE.
4847 WHERE can be one of other-window, elscreen, other-frame."
4848 (let* ((split (anything-c-grep-split-line candidate))
4849 (lineno (string-to-number (nth 1 split)))
4850 (loc-fname (car split))
4851 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4852 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4853 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4854 (fname (if tramp-host
4855 (concat tramp-prefix loc-fname) loc-fname)))
4856 (case where
4857 (other-window (find-file-other-window fname))
4858 (elscreen (anything-elscreen-find-file fname))
4859 (other-frame (find-file-other-frame fname))
4860 (t (find-file fname)))
4861 (anything-goto-line lineno)
4862 (when mark
4863 (set-marker (mark-marker) (point))
4864 (push-mark (point) 'nomsg))
4865 ;; Save history
4866 (unless (or anything-in-persistent-action
4867 (string= anything-pattern ""))
4868 (setq anything-c-grep-history
4869 (cons anything-pattern
4870 (delete anything-pattern anything-c-grep-history)))
4871 (when (> (length anything-c-grep-history)
4872 anything-c-grep-max-length-history)
4873 (setq anything-c-grep-history
4874 (delete (car (last anything-c-grep-history))
4875 anything-c-grep-history))))))
4877 (defun anything-c-grep-other-window (candidate)
4878 "Jump to result in other window from anything grep."
4879 (anything-c-grep-action candidate 'other-window))
4881 (defun anything-c-grep-other-frame (candidate)
4882 "Jump to result in other frame from anything grep."
4883 (anything-c-grep-action candidate 'other-frame))
4885 (defun anything-c-grep-jump-elscreen (candidate)
4886 "Jump to result in elscreen from anything grep."
4887 (anything-c-grep-action candidate 'elscreen))
4889 (defun anything-c-grep-save-results (candidate)
4890 "Save anything grep result in a `grep-mode' buffer."
4891 (let ((buf "*grep*")
4892 new-buf)
4893 (when (get-buffer buf)
4894 (setq new-buf (read-string "GrepBufferName: " buf))
4895 (loop for b in (anything-c-buffer-list)
4896 when (and (string= new-buf b)
4897 (not (y-or-n-p
4898 (format "Buffer `%s' already exists overwrite? "
4899 new-buf))))
4900 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4901 (setq buf new-buf))
4902 (with-current-buffer (get-buffer-create buf)
4903 (let ((inhibit-read-only t))
4904 (erase-buffer)
4905 (insert "-*- mode: grep -*-\n\n"
4906 (format "Grep Results for `%s':\n\n" anything-pattern))
4907 (save-excursion
4908 (insert (with-current-buffer anything-buffer
4909 (forward-line 1)
4910 (buffer-substring (point) (point-max))))
4911 (grep-mode))))
4912 (message "Anything Grep Results saved in `%s' buffer" buf)))
4914 (defun anything-c-grep-persistent-action (candidate)
4915 "Persistent action for `anything-do-grep'.
4916 With a prefix arg record CANDIDATE in `mark-ring'."
4917 (if current-prefix-arg
4918 (anything-c-grep-action candidate nil 'mark)
4919 (anything-c-grep-action candidate))
4920 (anything-match-line-color-current-line))
4922 (defun anything-c-grep-guess-extensions (files)
4923 "Try to guess file extensions in FILES list when using grep recurse.
4924 These extensions will be added to command line with --include arg of grep."
4925 (loop
4926 with glob-list = nil
4927 with lst = (if (file-directory-p (car files))
4928 (directory-files
4929 (car files) nil
4930 directory-files-no-dot-files-regexp)
4931 files)
4932 for i in lst
4933 for ext = (file-name-extension i t)
4934 for glob = (and ext (not (string= ext ""))
4935 (concat "*" ext))
4936 unless (or (not glob)
4937 (member glob glob-list)
4938 (member glob grep-find-ignored-files))
4939 collect glob into glob-list
4940 finally return glob-list))
4942 (defun anything-do-grep-1 (only &optional recurse zgrep)
4943 "Launch grep with a list of ONLY files.
4944 When RECURSE is given use -r option of grep and prompt user
4945 to set the --include args of grep.
4946 You can give more than one arg separated by space.
4947 e.g *.el *.py *.tex.
4948 If it's empty --exclude `grep-find-ignored-files' is used instead."
4949 (let* ((anything-compile-source-functions
4950 ;; rule out anything-match-plugin because the input is one regexp.
4951 (delq 'anything-compile-source--match-plugin
4952 (copy-sequence anything-compile-source-functions)))
4953 (exts (anything-c-grep-guess-extensions only))
4954 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4955 (include-files (and recurse (not zgrep)
4956 (read-string "OnlyExt(*.[ext]): "
4957 globs)))
4958 ;; Set `minibuffer-history' AFTER includes-files
4959 ;; to avoid storing wild-cards here.
4960 (minibuffer-history anything-c-grep-history)
4961 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4962 (recurse anything-c-grep-default-recurse-command)
4963 (zgrep anything-c-default-zgrep-command)
4964 (t anything-c-grep-default-command)))
4965 ;; Disable match-plugin and use here own highlighting.
4966 (anything-mp-highlight-delay nil))
4967 (when include-files
4968 (setq include-files
4969 (and (not (string= include-files ""))
4970 (mapconcat #'(lambda (x)
4971 (concat "--include=" (shell-quote-argument x)))
4972 (split-string include-files) " "))))
4973 ;; When called as action from an other source e.g *-find-files
4974 ;; we have to kill action buffer.
4975 (when (get-buffer anything-action-buffer)
4976 (kill-buffer anything-action-buffer))
4977 ;; `anything-find-files' haven't already started,
4978 ;; give a default value to `anything-ff-default-directory'.
4979 (setq anything-ff-default-directory (or anything-ff-default-directory
4980 default-directory))
4981 (anything-1
4982 :sources
4983 `(((name . "Grep (C-c ? Help)")
4984 (candidates
4985 . (lambda ()
4986 (funcall anything-c-grep-default-function only include-files zgrep)))
4987 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4988 (candidate-number-limit . 9999)
4989 (mode-line . anything-grep-mode-line-string)
4990 (jump-persistent . anything-c-grep-persistent-action)
4991 (action . ,(delq
4993 `(("Find File" . anything-c-grep-action)
4994 ("Find file other frame" . anything-c-grep-other-frame)
4995 ,(and (locate-library "elscreen")
4996 '("Find file in Elscreen"
4997 . anything-c-grep-jump-elscreen))
4998 ("Save results in grep buffer" . anything-c-grep-save-results)
4999 ("Find file other window" . anything-c-grep-other-window))))
5000 (persistent-action . anything-c-grep-persistent-action)
5001 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5002 (requires-pattern . 3)
5003 (delayed)))
5004 :keymap anything-c-grep-map
5005 :buffer "*anything grep*")))
5007 (defun anything-ff-zgrep-1 (flist recursive)
5008 (unwind-protect
5009 (let* ((def-dir (or anything-ff-default-directory
5010 default-directory))
5011 (only (if recursive
5012 (or (gethash def-dir anything-c-rzgrep-cache)
5013 (puthash
5014 def-dir
5015 (anything-c-walk-directory
5016 def-dir
5017 :directories nil
5018 :path 'full
5019 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5020 anything-c-rzgrep-cache))
5021 flist)))
5022 (when recursive (setq anything-c-zgrep-recurse-flag t))
5023 (anything-do-grep-1 only recursive 'zgrep))
5024 (setq anything-c-zgrep-recurse-flag nil)))
5026 (defun anything-c-grep-split-line (line)
5027 "Split a grep output line."
5028 (let (beg fname lineno str)
5029 ;; Don't print until grep line is valid.
5030 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5031 (with-temp-buffer
5032 (insert line)
5033 (goto-char (point-min))
5034 (setq beg (point))
5035 (forward-char 2)
5036 (re-search-forward ":" nil t)
5037 (setq fname (buffer-substring-no-properties beg (1- (point))))
5038 (setq beg (point))
5039 (re-search-forward ":" nil t)
5040 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5041 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5042 (list fname lineno str))))
5044 (defun anything-c-grep-cand-transformer (candidates sources)
5045 "Filtered candidate transformer function for `anything-do-grep'."
5046 (loop for i in candidates
5047 for split = (and i (anything-c-grep-split-line i))
5048 for fname = (car split)
5049 for lineno = (nth 1 split)
5050 for str = (nth 2 split)
5051 when (and fname lineno str)
5052 collect
5053 (cons (concat (propertize (file-name-nondirectory fname)
5054 'face 'anything-grep-file
5055 'help-echo fname) ":"
5056 (propertize lineno 'face 'anything-grep-lineno) ":"
5057 (anything-c-grep-highlight-match str))
5058 i)))
5060 (defun anything-c-grep-highlight-match (str)
5061 "Highlight in string STR all occurences matching `anything-pattern'."
5062 (condition-case nil
5063 (with-temp-buffer
5064 (insert str)
5065 (goto-char (point-min))
5066 (while (and (re-search-forward anything-pattern nil t)
5067 (> (- (match-end 0) (match-beginning 0)) 0))
5068 (add-text-properties
5069 (match-beginning 0) (match-end 0)
5070 '(face anything-grep-match)))
5071 (buffer-string))
5072 (error nil)))
5074 ;; Go to next or precedent file (common to etags and grep).
5075 (defun anything-c-goto-next-or-prec-file (n)
5076 "Go to next or precedent candidate file in anything grep/etags buffers.
5077 If N is positive go forward otherwise go backward."
5078 (with-anything-window
5079 (let* ((current-line-list (split-string
5080 (buffer-substring
5081 (point-at-bol)
5082 (point-at-eol)) ":"))
5083 (current-fname (nth 0 current-line-list))
5084 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5085 (catch 'break
5086 (while (not (funcall fn-b-o-f))
5087 (forward-line n) ; Go forward or backward depending of n value.
5088 (unless (search-forward current-fname (point-at-eol) t)
5089 (anything-mark-current-line)
5090 (throw 'break nil))))
5091 (cond ((and (eq n 1) (eobp))
5092 (re-search-backward ".")
5093 (forward-line 0)
5094 (anything-mark-current-line))
5095 ((and (< n 1) (bobp))
5096 (forward-line 1)
5097 (anything-mark-current-line))))))
5099 ;;;###autoload
5100 (defun anything-c-goto-precedent-file ()
5101 "Go to precedent file in anything grep/etags buffers."
5102 (interactive)
5103 (anything-c-goto-next-or-prec-file -1))
5105 ;;;###autoload
5106 (defun anything-c-goto-next-file ()
5107 "Go to precedent file in anything grep/etags buffers."
5108 (interactive)
5109 (anything-c-goto-next-or-prec-file 1))
5111 ;;;###autoload
5112 (defun anything-c-grep-run-persistent-action ()
5113 "Run grep persistent action from `anything-do-grep-1'."
5114 (interactive)
5115 (anything-execute-persistent-action 'jump-persistent))
5117 ;;;###autoload
5118 (defun anything-c-grep-run-default-action ()
5119 "Run grep default action from `anything-do-grep-1'."
5120 (interactive)
5121 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5123 ;;;###autoload
5124 (defun anything-c-grep-run-other-window-action ()
5125 "Run grep goto other window action from `anything-do-grep-1'."
5126 (interactive)
5127 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5129 ;;;###autoload
5130 (defun anything-c-grep-run-save-buffer ()
5131 "Run grep save results action from `anything-do-grep-1'."
5132 (interactive)
5133 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5135 ;; Grep buffers
5136 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5137 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5138 If one of selected buffers is not a file--buffer,
5139 it is ignored and grep will run on all others file--buffers.
5140 If only one candidate is selected and it is not a file--buffer,
5141 switch to this buffer and run `anything-occur'.
5142 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5143 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5144 (cands (if prefarg
5145 (buffer-list)
5146 (anything-marked-candidates)))
5147 (win-conf (current-window-configuration))
5148 ;; Non--fname buffers are ignored.
5149 (bufs (loop for buf in cands
5150 for fname = (buffer-file-name (get-buffer buf))
5151 when fname
5152 collect (expand-file-name fname))))
5153 (if bufs
5154 (if zgrep
5155 (anything-do-grep-1 bufs nil 'zgrep)
5156 (anything-do-grep-1 bufs))
5157 ;; bufs is empty, thats mean we have only CANDIDATE
5158 ;; and it is not a buffer-filename, fallback to occur.
5159 (anything-c-switch-to-buffer candidate)
5160 (when (get-buffer anything-action-buffer)
5161 (kill-buffer anything-action-buffer))
5162 (anything-occur)
5163 (when (eq anything-exit-status 1)
5164 (set-window-configuration win-conf)))))
5166 (defun anything-c-grep-buffers (candidate)
5167 "Action to grep buffers."
5168 (anything-c-grep-buffers-1 candidate))
5170 (defun anything-c-zgrep-buffers (candidate)
5171 "Action to zgrep buffers."
5172 (anything-c-grep-buffers-1 candidate 'zgrep))
5175 ;;; Anything interface for pdfgrep
5176 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5177 ;; and a pdf-reader (e.g xpdf) are needed.
5179 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5180 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5181 (defvar anything-c-pdfgrep-debug-command-line nil)
5183 (defun anything-c-pdfgrep-init (only-files)
5184 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5185 (let* ((fnargs (anything-c-grep-prepare-candidates
5186 (if (file-remote-p anything-ff-default-directory)
5187 (mapcar #'(lambda (x)
5188 (file-remote-p x 'localname))
5189 only-files)
5190 only-files)))
5191 (cmd-line (format anything-c-pdfgrep-default-command
5192 anything-pattern
5193 fnargs)))
5194 (when anything-c-pdfgrep-debug-command-line
5195 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5196 (goto-char (point-max))
5197 (insert (concat ">>> " cmd-line "\n\n"))))
5198 (setq mode-line-format
5199 '(" " mode-line-buffer-identification " "
5200 (line-number-mode "%l") " "
5201 (:eval (propertize "(Pdfgrep Process Running) "
5202 'face '((:foreground "red"))))))
5203 (prog1
5204 (let ((default-directory anything-ff-default-directory))
5205 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5206 (message nil)
5207 (set-process-sentinel
5208 (get-process "pdfgrep-process")
5209 #'(lambda (process event)
5210 (when (string= event "finished\n")
5211 (with-anything-window
5212 (anything-update-move-first-line))
5213 (force-mode-line-update nil)))))))
5216 (defun anything-do-pdfgrep-1 (only)
5217 "Launch pdfgrep with a list of ONLY files."
5218 (unless (executable-find "pdfgrep")
5219 (error "Error: No such program `pdfgrep'."))
5220 (let* ((anything-compile-source-functions
5221 ;; rule out anything-match-plugin because the input is one regexp.
5222 (delq 'anything-compile-source--match-plugin
5223 (copy-sequence anything-compile-source-functions)))
5224 ;; Disable match-plugin and use here own highlighting.
5225 (anything-mp-highlight-delay nil))
5226 ;; When called as action from an other source e.g *-find-files
5227 ;; we have to kill action buffer.
5228 (when (get-buffer anything-action-buffer)
5229 (kill-buffer anything-action-buffer))
5230 ;; If `anything-find-files' haven't already started,
5231 ;; give a default value to `anything-ff-default-directory'.
5232 (setq anything-ff-default-directory (or anything-ff-default-directory
5233 default-directory))
5234 (anything-1
5235 :sources
5236 `(((name . "PdfGrep")
5237 (candidates
5238 . (lambda ()
5239 (funcall anything-c-pdfgrep-default-function only)))
5240 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5241 (candidate-number-limit . 9999)
5242 (mode-line . anything-pdfgrep-mode-line-string)
5243 (action . anything-c-pdfgrep-action)
5244 (persistent-help . "Jump to PDF Page")
5245 (requires-pattern . 3)
5246 (delayed)))
5247 :keymap anything-c-pdfgrep-map
5248 :buffer "*anything grep*")))
5251 (defun anything-c-pdfgrep-action (candidate)
5252 (let* ((split (anything-c-grep-split-line candidate))
5253 (pageno (nth 1 split))
5254 (fname (car split)))
5255 (start-file-process-shell-command
5256 "pdf-reader" nil
5257 (format-spec anything-c-pdfgrep-default-read-command
5258 (list (cons ?f fname) (cons ?p pageno))))))
5260 (defun anything-do-pdfgrep ()
5261 (interactive)
5262 (let ((only (anything-c-read-file-name
5263 "Search in file(s): "
5264 :marked-candidates t
5265 :test #'(lambda (file)
5266 (or (string= (file-name-extension file) "pdf")
5267 (string= (file-name-extension file) "PDF")
5268 (file-directory-p file)))
5269 :preselect (or (dired-get-filename nil t)
5270 (buffer-file-name (current-buffer)))))
5271 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5272 (anything-do-pdfgrep-1 only)))
5275 ;; Yank text at point.
5278 ;; Internal
5279 (defvar anything-yank-point nil)
5281 ;;;###autoload
5282 (defun anything-yank-text-at-point ()
5283 "Yank text at point in minibuffer."
5284 (interactive)
5285 (let (input)
5286 (flet ((insert-in-minibuffer (word)
5287 (with-selected-window (minibuffer-window)
5288 (let ((str anything-pattern))
5289 (delete-minibuffer-contents)
5290 (set-text-properties 0 (length word) nil word)
5291 (insert (concat str word))))))
5292 (with-anything-current-buffer
5293 ;; Start to initial point if C-w have never been hit.
5294 (unless anything-yank-point (setq anything-yank-point (point)))
5295 (and anything-yank-point (goto-char anything-yank-point))
5296 (forward-word 1)
5297 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5298 (setq anything-yank-point (point))) ; End of last forward-word
5299 (insert-in-minibuffer input))))
5301 (defun anything-reset-yank-point ()
5302 (setq anything-yank-point nil))
5304 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5305 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5308 ;;; Recentf files
5311 (defvar anything-c-source-recentf
5312 '((name . "Recentf")
5313 (init . (lambda ()
5314 (require 'recentf)
5315 (or recentf-mode (recentf-mode 1))))
5316 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5317 (candidates . recentf-list)
5318 (match anything-c-match-on-basename)
5319 (type . file))
5320 "See (info \"(emacs)File Conveniences\").
5321 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5322 ;; (anything 'anything-c-source-recentf)
5324 ;;; ffap
5325 (eval-when-compile (require 'ffap))
5326 (defvar anything-c-source-ffap-guesser
5327 '((name . "File at point")
5328 (init . (lambda () (require 'ffap)))
5329 (candidates . (lambda ()
5330 (anything-aif
5331 (with-anything-current-buffer
5332 (ffap-guesser))
5333 (list it))))
5334 (type . file)))
5335 ;; (anything 'anything-c-source-ffap-guesser)
5337 ;;; ffap with line number
5338 (defun anything-c-ffap-file-line-at-point ()
5339 "Get (FILENAME . LINENO) at point."
5340 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5341 (save-excursion
5342 (beginning-of-line)
5343 (when (and (search-forward it nil t)
5344 (looking-at ":\\([0-9]+\\)"))
5345 (cons it (string-to-number (match-string 1)))))))
5347 (defvar anything-c-ffap-line-location nil
5348 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5349 It is cleared after jumping line.")
5351 (defun anything-c-ffap-line-candidates ()
5352 (with-anything-current-buffer
5353 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5354 (when anything-c-ffap-line-location
5355 (destructuring-bind (file . line) anything-c-ffap-line-location
5356 (list (cons (format "%s (line %d)" file line) file)))))
5358 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5359 (defun anything-c-ffap-line-goto-line ()
5360 (when (car anything-c-ffap-line-location)
5361 (unwind-protect
5362 (ignore-errors
5363 (with-selected-window
5364 (get-buffer-window
5365 (get-file-buffer (car anything-c-ffap-line-location)))
5366 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5367 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5368 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5370 (defvar anything-c-source-ffap-line
5371 '((name . "File/Lineno at point")
5372 (init . (lambda () (require 'ffap)))
5373 (candidates . anything-c-ffap-line-candidates)
5374 (type . file)))
5375 ;; (anything 'anything-c-source-ffap-line)
5377 ;;; list of files gleaned from every dired buffer
5378 (defun anything-c-files-in-all-dired-candidates ()
5379 (save-excursion
5380 (mapcan
5381 (lambda (dir)
5382 (cond ((listp dir) ;filelist
5383 dir)
5384 ((equal "" (file-name-nondirectory dir)) ;dir
5385 (directory-files dir t))
5386 (t ;wildcard
5387 (file-expand-wildcards dir t))))
5388 (delq nil
5389 (mapcar (lambda (buf)
5390 (set-buffer buf)
5391 (when (eq major-mode 'dired-mode)
5392 (if (consp dired-directory)
5393 (cdr dired-directory) ;filelist
5394 dired-directory))) ;dir or wildcard
5395 (buffer-list))))))
5396 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5398 (defvar anything-c-source-files-in-all-dired
5399 '((name . "Files in all dired buffer.")
5400 (candidates . anything-c-files-in-all-dired-candidates)
5401 (type . file)))
5402 ;; (anything 'anything-c-source-files-in-all-dired)
5404 (defvar anything-c-source-filelist
5405 '((name . "FileList")
5406 (grep-candidates . anything-c-filelist-file-name)
5407 (candidate-number-limit . 200)
5408 (requires-pattern . 4)
5409 (type . file))
5410 "Source to find files instantly.
5411 See `anything-c-filelist-file-name' docstring for usage.")
5414 ;;;; <info>
5415 ;;; Info pages
5416 (defvar anything-c-info-pages nil
5417 "All info pages on system.
5418 Will be calculated the first time you invoke anything with this
5419 source.")
5421 (defun anything-c-info-pages-init ()
5422 "Collect candidates for initial Info node Top."
5423 (if anything-c-info-pages
5424 anything-c-info-pages
5425 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5426 topics)
5427 (require 'info)
5428 (with-temp-buffer
5429 (Info-find-node "dir" "top")
5430 (goto-char (point-min))
5431 (while (re-search-forward info-topic-regexp nil t)
5432 (push (match-string-no-properties 1) topics))
5433 (kill-buffer))
5434 (setq anything-c-info-pages topics))))
5436 (defvar anything-c-source-info-pages
5437 `((name . "Info Pages")
5438 (init . anything-c-info-pages-init)
5439 (candidates . anything-c-info-pages)
5440 (action . (("Show with Info" .(lambda (node-str)
5441 (info (replace-regexp-in-string
5442 "^[^:]+: " "" node-str))))))
5443 (requires-pattern . 2)))
5444 ;; (anything 'anything-c-source-info-pages)
5447 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5448 (defun anything-c-describe-attributes (anything-attribute)
5449 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5450 Same as `anything-describe-anything-attribute' but with anything completion."
5451 (interactive (list (intern
5452 (anything-comp-read
5453 "Describe anything attribute: "
5454 (mapcar 'symbol-name anything-additional-attributes)
5455 :must-match t
5456 :persistent-action
5457 #'(lambda (candidate)
5458 (with-output-to-temp-buffer "*Help*"
5459 (princ (get (intern candidate) 'anything-attrdoc))))))))
5460 (with-output-to-temp-buffer "*Help*"
5461 (princ (get anything-attribute 'anything-attrdoc))))
5464 ;;; Use info-index plug-in.
5467 ;; Note that `name' attribute is not needed since
5468 ;; `anything-c-insert-summary' have been removed.
5469 ;; Info Elisp
5470 (defvar anything-c-source-info-elisp
5471 '((name . "Info index: elisp")
5472 (info-index . "elisp")))
5473 ;; (anything 'anything-c-source-info-elisp)
5475 ;; Info-Common-Lisp
5476 (defvar anything-c-source-info-cl
5477 '((name . "Info index: cl")
5478 (info-index . "cl")))
5479 ;; (anything 'anything-c-source-info-cl)
5481 ;; Info Index org
5482 (defvar anything-c-source-info-org
5483 '((name . "Info index: org")
5484 (info-index . "org")))
5485 ;; (anything 'anything-c-source-info-org)
5487 ;; Info Index gnus
5488 (defvar anything-c-source-info-gnus
5489 '((name . "Info index: Gnus")
5490 (info-index . "gnus")))
5492 ;; Info Index ratpoison
5493 (defvar anything-c-source-info-ratpoison
5494 '((name . "Info index: ratpoison")
5495 (info-index . "ratpoison")))
5496 ;; (anything 'anything-c-source-info-ratpoison)
5498 ;; Info Index zsh
5499 (defvar anything-c-source-info-zsh
5500 '((name . "Info index: zsh")
5501 (info-index . "zsh")))
5502 ;; (anything 'anything-c-source-info-zsh)
5504 ;; Info Index bash
5505 (defvar anything-c-source-info-bash
5506 '((name . "Info index: bash")
5507 (info-index . "bash")))
5508 ;; (anything 'anything-c-source-info-bash)
5510 ;; Info Index coreutils
5511 (defvar anything-c-source-info-coreutils
5512 '((name . "Info index: coreutils")
5513 (info-index . "coreutils")))
5514 ;; (anything 'anything-c-source-info-coreutils)
5516 ;; Info Index fileutils
5517 (defvar anything-c-source-info-fileutils
5518 '((name . "Info index: fileutils")
5519 (info-index . "fileutils")))
5520 ;; (anything 'anything-c-source-info-fileutils)
5522 ;; Info Index find
5523 (defvar anything-c-source-info-find
5524 '((name . "Info index: find")
5525 (info-index . "find")))
5526 ;; (anything 'anything-c-source-info-find)
5528 ;; Info Index sh-utils
5529 (defvar anything-c-source-info-sh-utils
5530 '((name . "Info index: sh-utils")
5531 (info-index . "sh-utils")))
5532 ;; (anything 'anything-c-source-info-sh-utils)
5534 ;; Info Index textutils
5535 (defvar anything-c-source-info-textutils
5536 '((name . "Info index: textutils")
5537 (info-index . "textutils")))
5538 ;; (anything 'anything-c-source-info-textutils)
5540 ;; Info Index libc
5541 (defvar anything-c-source-info-libc
5542 '((name . "Info index: libc")
5543 (info-index . "libc")))
5544 ;; (anything 'anything-c-source-info-libc)
5546 ;; Info Index make
5547 (defvar anything-c-source-info-make
5548 '((name . "Info index: make")
5549 (info-index . "make")))
5550 ;; (anything 'anything-c-source-info-make)
5552 ;; Info Index automake
5553 (defvar anything-c-source-info-automake
5554 '((name . "Info index: automake")
5555 (info-index . "automake")))
5556 ;; (anything 'anything-c-source-info-automake)
5558 ;; Info Index autoconf
5559 (defvar anything-c-source-info-autoconf
5560 '((name . "Info index: autoconf")
5561 (info-index . "autoconf")))
5562 ;; (anything 'anything-c-source-info-autoconf)
5564 ;; Info Index emacs-lisp-intro
5565 (defvar anything-c-source-info-emacs-lisp-intro
5566 '((name . "Info index: emacs-lisp-intro")
5567 (info-index . "emacs-lisp-intro")))
5568 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5570 ;; Info Index emacs
5571 (defvar anything-c-source-info-emacs
5572 '((name . "Info index: emacs")
5573 (info-index . "emacs")))
5574 ;; (anything 'anything-c-source-info-emacs)
5576 ;; Info Index elib
5577 (defvar anything-c-source-info-elib
5578 '((name . "Info index: elib")
5579 (info-index . "elib")))
5580 ;; (anything 'anything-c-source-info-elib)
5582 ;; Info Index eieio
5583 (defvar anything-c-source-info-eieio
5584 '((name . "Info index: eieio")
5585 (info-index . "eieio")))
5586 ;; (anything 'anything-c-source-info-eieio)
5588 ;; Info Index gauche-refe
5589 (defvar anything-c-source-info-gauche-refe
5590 '((name . "Info index: gauche")
5591 (info-index . "gauche-refe")))
5592 ;; (anything 'anything-c-source-info-gauche-refe)
5594 ;; Info Index guile
5595 (defvar anything-c-source-info-guile
5596 '((name . "Info index: guile")
5597 (info-index . "guile")))
5598 ;; (anything 'anything-c-source-info-guile)
5600 ;; Info Index guile-tut
5601 (defvar anything-c-source-info-guile-tut
5602 '((name . "Info index: guile-tut")
5603 (info-index . "guile-tut")))
5604 ;; (anything 'anything-c-source-info-guile-tut)
5606 ;; Info Index goops
5607 (defvar anything-c-source-info-goops
5608 '((name . "Info index: goops")
5609 (info-index . "goops")))
5610 ;; (anything 'anything-c-source-info-goops)
5612 ;; Info Index screen
5613 (defvar anything-c-source-info-screen
5614 '((name . "Info index: screen")
5615 (info-index . "screen")
5616 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5617 ;; (anything 'anything-c-source-info-screen)
5619 ;; Info Index latex
5620 (defvar anything-c-source-info-latex
5621 '((name . "Info index: latex")
5622 (info-index . "latex")))
5623 ;; (anything 'anything-c-source-info-latex)
5625 ;; Info Index gawk
5626 (defvar anything-c-source-info-gawk
5627 '((name . "Info index: gawk")
5628 (info-index . "gawk")))
5629 ;; (anything 'anything-c-source-info-gawk)
5631 ;; Info Index sed
5632 (defvar anything-c-source-info-sed
5633 '((name . "Info index: sed")
5634 (info-index . "sed")))
5635 ;; (anything 'anything-c-source-info-sed)
5637 ;; Info Index m4
5638 (defvar anything-c-source-info-m4
5639 '((name . "Info index: m4")
5640 (info-index . "m4")))
5641 ;; (anything 'anything-c-source-info-m4)
5643 ;; Info Index wget
5644 (defvar anything-c-source-info-wget
5645 '((name . "Info index: wget")
5646 (info-index . "wget")))
5647 ;; (anything 'anything-c-source-info-wget)
5649 ;; Info Index binutils
5650 (defvar anything-c-source-info-binutils
5651 '((name . "Info index: binutils")
5652 (info-index . "binutils")))
5653 ;; (anything 'anything-c-source-info-binutils)
5655 ;; Info Index as
5656 (defvar anything-c-source-info-as
5657 '((name . "Info index: as")
5658 (info-index . "as")))
5659 ;; (anything 'anything-c-source-info-as)
5661 ;; Info Index bfd
5662 (defvar anything-c-source-info-bfd
5663 '((name . "Info index: bfd")
5664 (info-index . "bfd")))
5665 ;; (anything 'anything-c-source-info-bfd)
5667 ;; Info Index gprof
5668 (defvar anything-c-source-info-gprof
5669 '((name . "Info index: gprof")
5670 (info-index . "gprof")))
5671 ;; (anything 'anything-c-source-info-gprof)
5673 ;; Info Index ld
5674 (defvar anything-c-source-info-ld
5675 '((name . "Info index: ld")
5676 (info-index . "ld")))
5677 ;; (anything 'anything-c-source-info-ld)
5679 ;; Info Index diff
5680 (defvar anything-c-source-info-diff
5681 '((name . "Info index: diff")
5682 (info-index . "diff")))
5683 ;; (anything 'anything-c-source-info-diff)
5685 ;; Info Index flex
5686 (defvar anything-c-source-info-flex
5687 '((name . "Info index: flex")
5688 (info-index . "flex")))
5689 ;; (anything 'anything-c-source-info-flex)
5691 ;; Info Index grep
5692 (defvar anything-c-source-info-grep
5693 '((name . "Info index: grep")
5694 (info-index . "grep")))
5695 ;; (anything 'anything-c-source-info-grep)
5697 ;; Info Index gzip
5698 (defvar anything-c-source-info-gzip
5699 '((name . "Info index: gzip")
5700 (info-index . "gzip")))
5701 ;; (anything 'anything-c-source-info-gzip)
5703 ;; Info Index libtool
5704 (defvar anything-c-source-info-libtool
5705 '((name . "Info index: libtool")
5706 (info-index . "libtool")))
5707 ;; (anything 'anything-c-source-info-libtool)
5709 ;; Info Index texinfo
5710 (defvar anything-c-source-info-texinfo
5711 '((name . "Info index: texinfo")
5712 (info-index . "texinfo")))
5713 ;; (anything 'anything-c-source-info-texinfo)
5715 ;; Info Index info
5716 (defvar anything-c-source-info-info
5717 '((name . "Info index: info")
5718 (info-index . "info")))
5719 ;; (anything 'anything-c-source-info-info)
5721 ;; Info Index gdb
5722 (defvar anything-c-source-info-gdb
5723 '((name . "Info index: gdb")
5724 (info-index . "gdb")))
5725 ;; (anything 'anything-c-source-info-gdb)
5727 ;; Info Index stabs
5728 (defvar anything-c-source-info-stabs
5729 '((name . "Info index: stabs")
5730 (info-index . "stabs")))
5731 ;; (anything 'anything-c-source-info-stabs)
5733 ;; Info Index cvsbook
5734 (defvar anything-c-source-info-cvsbook
5735 '((name . "Info index: cvsbook")
5736 (info-index . "cvsbook")))
5737 ;; (anything 'anything-c-source-info-cvsbook)
5739 ;; Info Index cvs
5740 (defvar anything-c-source-info-cvs
5741 '((name . "Info index: cvs")
5742 (info-index . "cvs")))
5743 ;; (anything 'anything-c-source-info-cvs)
5745 ;; Info Index bison
5746 (defvar anything-c-source-info-bison
5747 '((name . "Info index: bison")
5748 (info-index . "bison")))
5749 ;; (anything 'anything-c-source-info-bison)
5751 ;; Info Index id-utils
5752 (defvar anything-c-source-info-id-utils
5753 '((name . "Info index: id-utils")
5754 (info-index . "id-utils")))
5755 ;; (anything 'anything-c-source-info-id-utils)
5757 ;; Info Index global
5758 (defvar anything-c-source-info-global
5759 '((name . "Info index: global")
5760 (info-index . "global")))
5761 ;; (anything 'anything-c-source-info-global)
5764 ;;; Man and woman UI
5767 (defvar anything-c-man-pages nil
5768 "All man pages on system.
5769 Will be calculated the first time you invoke anything with this
5770 source.")
5772 (defun anything-c-man-default-action (candidate)
5773 "Default action for jumping to a woman or man page from anything."
5774 (let ((wfiles (woman-file-name-all-completions candidate)))
5775 (condition-case err
5776 (if (> (length wfiles) 1)
5777 (woman-find-file
5778 (anything-comp-read
5779 "ManFile: " wfiles :must-match t))
5780 (woman candidate))
5781 ;; If woman is unable to format correctly
5782 ;; use man instead.
5783 (error (kill-buffer) ; Kill woman buffer.
5784 (let ((Man-notify-method 'meek))
5785 (Man-getpage-in-background candidate))))))
5787 (defvar anything-c-source-man-pages
5788 `((name . "Manual Pages")
5789 (candidates . (lambda ()
5790 (if anything-c-man-pages
5791 anything-c-man-pages
5792 ;; XEmacs doesn't have a woman :)
5793 (setq anything-c-man-pages
5794 (ignore-errors
5795 (require 'woman)
5796 (woman-file-name "")
5797 (sort (mapcar 'car woman-topic-all-completions)
5798 'string-lessp))))))
5799 (action ("Show with Woman" . anything-c-man-default-action))
5800 ;; Woman does not work OS X
5801 ;; http://xahlee.org/emacs/modernization_man_page.html
5802 (action-transformer . (lambda (actions candidate)
5803 (if (eq system-type 'darwin)
5804 '(("Show with Man" . man))
5805 actions)))
5806 (requires-pattern . 2)))
5807 ;; (anything 'anything-c-source-man-pages)
5810 ;;;; <Command>
5811 ;;; Anything M-x - Enhanced M-x UI
5814 ;; Another replacement of `M-x' that act exactly like the
5815 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5816 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5817 ;; anything invocation.
5818 ;; Documentation of commands available without quitting,
5819 ;; Show keybindings of commands.
5820 ;; Show history.
5821 (defvar anything-M-x-input-history nil)
5823 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5824 "Return alist of MODE-MAP."
5825 (loop for key being the key-seqs of mode-map using (key-bindings com)
5826 for str-key = (key-description key)
5827 for ismenu = (string-match "<menu-bar>" str-key)
5828 unless ismenu collect (cons str-key com)))
5830 (defun anything-get-mode-map-from-mode (mode)
5831 "Guess the mode-map name according to MODE.
5832 Some modes don't use conventional mode-map name
5833 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5834 Return nil if no mode-map found."
5835 (loop
5836 ;; Start with a conventional mode-map name.
5837 with mode-map = (intern-soft (format "%s-map" mode))
5838 with mode-string = (symbol-name mode)
5839 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5840 while (not mode-map)
5841 for count downfrom (length mode-name)
5842 ;; Return when no result after parsing entire string.
5843 when (eq count 0) return nil
5844 for sub-name = (substring mode-name 0 count)
5845 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5846 finally return mode-map))
5848 (defun anything-M-x-current-mode-map-alist ()
5849 "Return mode-map alist of current `major-mode'."
5850 (let ((map (anything-get-mode-map-from-mode major-mode)))
5851 (when (and map (boundp map))
5852 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5855 (defun anything-M-x-transformer (candidates sources)
5856 "filtered-candidate-transformer to show bindings in emacs commands.
5857 Show global bindings and local bindings according to current `major-mode'."
5858 (with-anything-current-buffer
5859 (loop
5860 with local-map = (anything-M-x-current-mode-map-alist)
5861 for cand in candidates
5862 for local-key = (car (rassq cand local-map))
5863 for key = (substitute-command-keys (format "\\[%s]" cand))
5864 collect
5865 (cons (cond ((and (string-match "^M-x" key) local-key)
5866 (format "%s (%s)"
5867 cand (propertize
5868 local-key
5869 'face 'anything-M-x-key-face)))
5870 ((string-match "^M-x" key) cand)
5871 (t (format "%s (%s)"
5872 cand (propertize
5874 'face 'anything-M-x-key-face))))
5875 cand) into ls
5876 finally return
5877 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5880 ;;; Complex command history
5883 (defvar anything-c-source-complex-command-history
5884 '((name . "Complex Command History")
5885 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5886 (type . sexp)))
5887 ;; (anything 'anything-c-source-complex-command-history)
5889 ;;; M-x history (not related to `anything-M-x')
5892 (defvar anything-c-source-extended-command-history
5893 '((name . "Emacs Commands History")
5894 (candidates . extended-command-history)
5895 (type . command)))
5896 ;; (anything 'anything-c-source-extended-command-history)
5898 ;;; Emacs commands (Basic source for emacs commands)
5901 (defvar anything-c-source-emacs-commands
5902 '((name . "Emacs Commands")
5903 (candidates . (lambda ()
5904 (let (commands)
5905 (mapatoms (lambda (a)
5906 (if (commandp a)
5907 (push (symbol-name a)
5908 commands))))
5909 (sort commands 'string-lessp))))
5910 (type . command)
5911 (requires-pattern . 2))
5912 "Source for completing and invoking Emacs commands.
5913 A command is a function with interactive spec that can
5914 be invoked with `M-x'.
5916 To get non-interactive functions listed, use
5917 `anything-c-source-emacs-functions'.")
5918 ;; (anything 'anything-c-source-emacs-commands)
5921 ;;;; <Function>
5922 ;;; Emacs functions
5925 (defvar anything-c-source-emacs-functions
5926 '((name . "Emacs Functions")
5927 (candidates . (lambda ()
5928 (let (commands)
5929 (mapatoms (lambda (a)
5930 (if (functionp a)
5931 (push (symbol-name a) commands))))
5932 (sort commands 'string-lessp))))
5933 (type . function)
5934 (requires-pattern . 2))
5935 "Source for completing Emacs functions.")
5936 ;; (anything 'anything-c-source-emacs-functions)
5938 ;;; With abbrev expansion
5939 ;;; Similar to my exec-abbrev-cmd.el
5940 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5941 (defvar anything-c-function-abbrev-regexp nil
5942 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5943 Regexp built from the current `anything-pattern' interpreting it
5944 as abbreviation.
5945 Only for internal use.")
5947 (defun anything-c-match-function-by-abbrev (candidate)
5948 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5950 Abbreviations are made by taking the first character from each
5951 word in the function's name, e.g. \"bb\" is an abbrev for
5952 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5953 (string-match anything-c-function-abbrev-regexp candidate))
5955 (defvar anything-c-source-emacs-functions-with-abbrevs
5956 (append anything-c-source-emacs-functions
5957 '((match anything-c-match-function-by-abbrev
5958 anything-c-string-match))
5959 '((init
5960 . (lambda ()
5961 (defadvice anything-update
5962 (before anything-c-update-function-abbrev-regexp activate)
5963 (let ((char-list (append anything-pattern nil))
5964 (str "^"))
5965 (dolist (c char-list)
5966 (setq str (concat str (list c) "[^-]*-")))
5967 (setq str (concat (substring str 0 (1- (length str))) "$"))
5968 (setq anything-c-function-abbrev-regexp str))))))))
5969 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5971 (defvar anything-c-source-advice
5972 '((name . "Function Advice")
5973 (candidates . anything-c-advice-candidates)
5974 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5975 (persistent-action . anything-c-advice-persistent-action)
5976 (multiline)
5977 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5978 ;; (anything 'anything-c-source-advice)
5979 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5980 ;; (testadvice)
5982 (defun anything-c-advice-candidates ()
5983 (require 'advice)
5984 (loop for (fname) in ad-advised-functions
5985 for function = (intern fname)
5986 append
5987 (loop for class in ad-advice-classes append
5988 (loop for advice in (ad-get-advice-info-field function class)
5989 for enabled = (ad-advice-enabled advice)
5990 collect
5991 (cons (format
5992 "%s %s %s"
5993 (if enabled "Enabled " "Disabled")
5994 (propertize fname 'face 'font-lock-function-name-face)
5995 (ad-make-single-advice-docstring advice class nil))
5996 (list function class advice))))))
5998 (defun anything-c-advice-persistent-action (func-class-advice)
5999 (if current-prefix-arg
6000 (anything-c-advice-toggle func-class-advice)
6001 (describe-function (car func-class-advice))))
6003 (defun anything-c-advice-toggle (func-class-advice)
6004 (destructuring-bind (function class advice) func-class-advice
6005 (cond ((ad-advice-enabled advice)
6006 (ad-advice-set-enabled advice nil)
6007 (message "Disabled"))
6008 (t ;disabled
6009 (ad-advice-set-enabled advice t)
6010 (message "Enabled")))
6011 (ad-activate function)
6012 (and anything-in-persistent-action
6013 (anything-c-advice-update-current-display-string))))
6015 (defun anything-c-advice-update-current-display-string ()
6016 (anything-edit-current-selection
6017 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6018 ((looking-at "Enabled") "Disabled")))
6019 realvalue)
6020 (when newword
6021 (delete-region (point) (progn (forward-word 1) (point)))
6022 (insert newword)))))
6025 ;;;; <Variable>
6026 ;;; Emacs variables
6029 (defvar anything-c-source-emacs-variables
6030 '((name . "Emacs Variables")
6031 (candidates . (lambda ()
6032 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6033 (type . variable)
6034 (requires-pattern . 2))
6035 "Source for completing Emacs variables.")
6036 ;; (anything 'anything-c-source-emacs-variables)
6039 ;;; LaCarte
6040 (defvar anything-c-source-lacarte
6041 '((name . "Lacarte")
6042 (init . (lambda () (require 'lacarte )))
6043 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6044 (candidate-number-limit . 9999)
6045 (action . anything-c-call-interactively))
6046 "Needs lacarte.el.
6048 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6049 ;; (anything 'anything-c-source-lacarte)
6052 ;;; Bookmarks
6055 ;; Bind some faces for bookmarks.
6056 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6057 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6058 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6060 (eval-when-compile (require 'bookmark))
6061 (defvar anything-c-source-bookmarks
6062 '((name . "Bookmarks")
6063 (init . (lambda ()
6064 (require 'bookmark)))
6065 (candidates . bookmark-all-names)
6066 (type . bookmark))
6067 "See (info \"(emacs)Bookmarks\").")
6068 ;; (anything 'anything-c-source-bookmarks)
6070 ;;; bookmark-set
6071 (defvar anything-c-source-bookmark-set
6072 '((name . "Set Bookmark")
6073 (dummy)
6074 (action . bookmark-set))
6075 "See (info \"(emacs)Bookmarks\").")
6076 ;; (anything 'anything-c-source-bookmark-set)
6078 ;;; Visible Bookmarks
6079 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6082 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6083 (defvar anything-c-source-bm
6084 '((name . "Visible Bookmarks")
6085 (init . anything-c-bm-init)
6086 (candidates-in-buffer)
6087 (type . line))
6088 "Needs bm.el.
6090 http://www.nongnu.org/bm/")
6092 (defun anything-c-bm-init ()
6093 "Init function for `anything-c-source-bm'."
6094 (when (require 'bm nil t)
6095 (with-no-warnings
6096 (let ((bookmarks (bm-lists))
6097 (buf (anything-candidate-buffer 'global)))
6098 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6099 '< :key 'overlay-start))
6100 (let ((start (overlay-start bm))
6101 (end (overlay-end bm))
6102 (annotation (or (overlay-get bm 'annotation) "")))
6103 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6104 (let ((str (format "%5d: [%s]: %s\n"
6105 (line-number-at-pos start)
6106 annotation
6107 (buffer-substring start (1- end)))))
6108 (with-current-buffer buf (insert str))))))))))
6110 ;;; Special bookmarks
6111 (defvar anything-c-source-bookmarks-ssh
6112 '((name . "Bookmarks-ssh")
6113 (init . (lambda ()
6114 (require 'bookmark)))
6115 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6116 (type . bookmark))
6117 "See (info \"(emacs)Bookmarks\").")
6118 ;; (anything 'anything-c-source-bookmarks-ssh)
6120 (defvar anything-c-source-bookmarks-su
6121 '((name . "Bookmarks-root")
6122 (init . (lambda ()
6123 (require 'bookmark)))
6124 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6125 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6127 (type . bookmark))
6128 "See (info \"(emacs)Bookmarks\").")
6129 ;; (anything 'anything-c-source-bookmarks-su)
6131 (defvar anything-c-source-bookmarks-local
6132 '((name . "Bookmarks-Local")
6133 (init . (lambda ()
6134 (require 'bookmark)))
6135 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6136 (filtered-candidate-transformer
6137 anything-c-adaptive-sort
6138 anything-c-highlight-bookmark)
6139 (type . bookmark))
6140 "See (info \"(emacs)Bookmarks\").")
6141 ;; (anything 'anything-c-source-bookmarks-local)
6143 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6144 (let* ((lis-all (bookmark-all-names))
6145 (lis-loc (cond (local (loop for i in lis-all
6146 unless (string-match "^(ssh)\\|^(su)" i)
6147 collect i))
6148 (su (loop for i in lis-all
6149 when (string-match "^(su)" i)
6150 collect i))
6151 (sudo (loop for i in lis-all
6152 when (string-match "^(sudo)" i)
6153 collect i))
6154 (ssh (loop for i in lis-all
6155 when (string-match "^(ssh)" i)
6156 collect i)))))
6157 (sort lis-loc 'string-lessp)))
6159 (defun anything-c-bookmark-root-logged-p ()
6160 (catch 'break
6161 (dolist (i (mapcar #'buffer-name (buffer-list)))
6162 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6163 (throw 'break t)))))
6165 (defun anything-c-highlight-bookmark-su (files source)
6166 (if (anything-c-bookmark-root-logged-p)
6167 (anything-c-highlight-bookmark files source)
6168 (anything-c-highlight-not-logged files source)))
6170 (defun anything-c-highlight-not-logged (files source)
6171 (loop for i in files
6172 collect (propertize i 'face anything-c-bookmarks-face3)))
6174 (defun anything-c-highlight-bookmark (bookmarks source)
6175 "Used as `candidate-transformer' to colorize bookmarks.
6176 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6177 (loop for i in bookmarks
6178 for isfile = (bookmark-get-filename i)
6179 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6180 (bmkext-get-buffer-name i))
6181 for handlerp = (and (fboundp 'bookmark-get-handler)
6182 (bookmark-get-handler i))
6183 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6184 (bmkext-w3m-bookmark-p i))
6185 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6186 (bmkext-gnus-bookmark-p i))
6187 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6188 (bmkext-man-bookmark-p i))
6189 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6190 (bmkext-woman-bookmark-p i))
6191 for handlerp = (bookmark-get-handler i)
6192 for isannotation = (bookmark-get-annotation i)
6193 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6194 for isinfo = (eq handlerp 'Info-bookmark-jump)
6195 ;; Add a * if bookmark have annotation
6196 if (and isannotation (not (string-equal isannotation "")))
6197 do (setq i (concat "*" i))
6198 collect (cond (;; info buffers
6199 isinfo
6200 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6201 (;; w3m buffers
6202 isw3m
6203 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6204 (;; gnus buffers
6205 isgnus
6206 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6207 (;; Man Woman
6208 (or iswoman isman)
6209 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6210 (;; Addressbook
6211 isabook
6212 (propertize i 'face '((:foreground "Tomato"))))
6213 (;; directories
6214 (and isfile (file-directory-p isfile))
6215 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6216 (;; regular files
6218 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6222 ;;; Sources to filter bookmark-extensions bookmarks.
6225 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6226 ;; If you want to enable google-maps in addressbook you will need
6227 ;; Julien Danjou google-maps-el package available here:
6228 ;; http://julien.danjou.info/google-maps-el.html
6230 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6231 "Return a filtered `bookmark-alist' sorted alphabetically."
6232 (loop
6233 with alist = (if args
6234 (apply #'(lambda (x) (funcall fn x)) args)
6235 (funcall fn))
6236 for i in alist
6237 for b = (car i)
6238 collect b into sa
6239 finally return (sort sa 'string-lessp)))
6241 ;;; Addressbook.
6244 (defvar anything-c-source-bmkext-addressbook
6245 '((name . "Bookmark Addressbook")
6246 (init . (lambda ()
6247 (require 'bookmark-extensions)
6248 (bookmark-maybe-load-default-file)))
6249 (candidates . anything-c-bmkext-addressbook-setup-alist)
6250 (persistent-action
6251 . (lambda (candidate)
6252 (let ((bmk (anything-bookmark-get-bookmark-from-name
6253 candidate)))
6254 (bookmark--jump-via bmk 'pop-to-buffer))))
6255 (persistent-help . "Show contact - Prefix with C-u to append")
6256 (filtered-candidate-transformer
6257 anything-c-adaptive-sort
6258 anything-c-highlight-bookmark)
6259 (action . (("Show Contact(s)"
6260 . (lambda (candidate)
6261 (let* ((contacts (anything-marked-candidates))
6262 (current-prefix-arg (or anything-current-prefix-arg
6263 (> (length contacts) 1))))
6264 (bookmark-jump
6265 (anything-bookmark-get-bookmark-from-name (car contacts)))
6266 (anything-aif (cdr contacts)
6267 (loop for bmk in it do
6268 (bookmark-jump
6269 (anything-bookmark-get-bookmark-from-name bmk)))))))
6270 ("Send Mail"
6271 . (lambda (candidate)
6272 (let* ((contacts (anything-marked-candidates))
6273 (bmk (anything-bookmark-get-bookmark-from-name
6274 (car contacts)))
6275 (append (message-buffers)))
6276 (if append
6277 (addressbook-set-mail-buffer1 bmk 'append)
6278 (addressbook-set-mail-buffer1 bmk))
6279 (setq contacts (cdr contacts))
6280 (when contacts
6281 (loop for bmk in contacts do
6282 (addressbook-set-mail-buffer1 bmk 'append))))))
6283 ("Edit Bookmark"
6284 . (lambda (candidate)
6285 (let ((bmk (anything-bookmark-get-bookmark-from-name
6286 candidate)))
6287 (addressbook-bookmark-edit
6288 (assoc bmk bookmark-alist)))))
6289 ("Insert Email at point"
6290 . (lambda (candidate)
6291 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6292 candidate))
6293 (mlist (split-string
6294 (assoc-default
6295 'email (assoc bmk bookmark-alist))
6296 ", ")))
6297 (insert
6298 (if (> (length mlist) 1)
6299 (anything-comp-read
6300 "Insert Mail Address: " mlist :must-match t)
6301 (car mlist))))))
6302 ("Show annotation"
6303 . (lambda (candidate)
6304 (let ((bmk (anything-bookmark-get-bookmark-from-name
6305 candidate)))
6306 (bookmark-show-annotation bmk))))
6307 ("Edit annotation"
6308 . (lambda (candidate)
6309 (let ((bmk (anything-bookmark-get-bookmark-from-name
6310 candidate)))
6311 (bookmark-edit-annotation bmk))))
6312 ("Show Google map"
6313 . (lambda (candidate)
6314 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6315 candidate))
6316 (full-bmk (assoc bmk bookmark-alist)))
6317 (addressbook-google-map full-bmk))))))))
6320 (defun anything-c-bmkext-addressbook-setup-alist ()
6321 "Specialized filter function for bookmarks w3m."
6322 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6324 ;; W3m bookmarks from bookmark-extensions.
6325 (defvar anything-c-source-bookmark-w3m
6326 '((name . "Bookmark W3m")
6327 (init . (lambda ()
6328 (require 'bookmark-extensions)
6329 (bookmark-maybe-load-default-file)))
6330 (candidates . anything-c-bookmark-w3m-setup-alist)
6331 (filtered-candidate-transformer
6332 anything-c-adaptive-sort
6333 anything-c-highlight-bookmark)
6334 (type . bookmark)))
6335 ;; (anything 'anything-c-source-bookmark-w3m)
6337 (defun anything-c-bookmark-w3m-setup-alist ()
6338 "Specialized filter function for bookmarks w3m."
6339 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6341 ;; Images
6342 (defvar anything-c-source-bookmark-images
6343 '((name . "Bookmark Images")
6344 (init . (lambda ()
6345 (require 'bookmark-extensions)
6346 (bookmark-maybe-load-default-file)))
6347 (candidates . anything-c-bookmark-images-setup-alist)
6348 (filtered-candidate-transformer
6349 anything-c-adaptive-sort
6350 anything-c-highlight-bookmark)
6351 (type . bookmark)))
6352 ;; (anything 'anything-c-source-bookmark-images)
6354 (defun anything-c-bookmark-images-setup-alist ()
6355 "Specialized filter function for images bookmarks."
6356 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6358 ;; Woman Man
6359 (defvar anything-c-source-bookmark-man
6360 '((name . "Bookmark Woman&Man")
6361 (init . (lambda ()
6362 (require 'bookmark-extensions)
6363 (bookmark-maybe-load-default-file)))
6364 (candidates . anything-c-bookmark-man-setup-alist)
6365 (filtered-candidate-transformer
6366 anything-c-adaptive-sort
6367 anything-c-highlight-bookmark)
6368 (type . bookmark)))
6369 ;; (anything 'anything-c-source-bookmark-man)
6371 (defun anything-c-bookmark-man-setup-alist ()
6372 "Specialized filter function for bookmarks w3m."
6373 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6374 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6376 ;; Gnus
6377 (defvar anything-c-source-bookmark-gnus
6378 '((name . "Bookmark Gnus")
6379 (init . (lambda ()
6380 (require 'bookmark-extensions)
6381 (bookmark-maybe-load-default-file)))
6382 (candidates . anything-c-bookmark-gnus-setup-alist)
6383 (filtered-candidate-transformer
6384 anything-c-adaptive-sort
6385 anything-c-highlight-bookmark)
6386 (type . bookmark)))
6387 ;; (anything 'anything-c-source-bookmark-gnus)
6389 (defun anything-c-bookmark-gnus-setup-alist ()
6390 "Specialized filter function for bookmarks gnus."
6391 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6393 ;; Info
6394 (defvar anything-c-source-bookmark-info
6395 '((name . "Bookmark Info")
6396 (init . (lambda ()
6397 (require 'bookmark-extensions)
6398 (bookmark-maybe-load-default-file)))
6399 (candidates . anything-c-bookmark-info-setup-alist)
6400 (filtered-candidate-transformer
6401 anything-c-adaptive-sort
6402 anything-c-highlight-bookmark)
6403 (type . bookmark)))
6404 ;; (anything 'anything-c-source-bookmark-info)
6406 (defun anything-c-bookmark-info-setup-alist ()
6407 "Specialized filter function for bookmarks info."
6408 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6410 ;; Local Files&directories
6411 (defvar anything-c-source-bookmark-files&dirs
6412 '((name . "Bookmark Files&Directories")
6413 (init . (lambda ()
6414 (require 'bookmark-extensions)
6415 (bookmark-maybe-load-default-file)))
6416 (candidates . anything-c-bookmark-local-files-setup-alist)
6417 (filtered-candidate-transformer
6418 anything-c-adaptive-sort
6419 anything-c-highlight-bookmark)
6420 (type . bookmark)))
6421 ;; (anything 'anything-c-source-bookmark-files&dirs)
6423 (defun anything-c-bookmark-local-files-setup-alist ()
6424 "Specialized filter function for bookmarks locals files."
6425 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6427 ;; Su Files&directories
6428 (defvar anything-c-source-bookmark-su-files&dirs
6429 '((name . "Bookmark Root-Files&Directories")
6430 (init . (lambda ()
6431 (require 'bookmark-extensions)
6432 (bookmark-maybe-load-default-file)))
6433 (candidates . anything-c-bookmark-su-files-setup-alist)
6434 (filtered-candidate-transformer
6435 anything-c-adaptive-sort
6436 anything-c-highlight-bookmark-su)
6437 (type . bookmark)))
6438 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6440 (defun anything-c-bookmark-su-files-setup-alist ()
6441 "Specialized filter function for bookmarks su/sudo files."
6442 (declare (special bmkext-su-or-sudo-regexp))
6443 (loop
6444 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6445 for i in l
6446 for isfile = (bookmark-get-filename i)
6447 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6448 (save-match-data
6449 (string-match tramp-file-name-regexp isfile)))
6450 for issu = (and istramp
6451 (string-match bmkext-su-or-sudo-regexp isfile))
6452 if issu
6453 collect i))
6455 ;; Ssh Files&directories
6456 (defvar anything-c-source-bookmark-ssh-files&dirs
6457 '((name . "Bookmark Ssh-Files&Directories")
6458 (init . (lambda ()
6459 (require 'bookmark-extensions)
6460 (bookmark-maybe-load-default-file)))
6461 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6462 (filtered-candidate-transformer . anything-c-adaptive-sort)
6463 (type . bookmark)))
6464 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6466 (defun anything-c-bookmark-ssh-files-setup-alist ()
6467 "Specialized filter function for bookmarks ssh files."
6468 (loop
6469 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6470 for i in l
6471 for isfile = (bookmark-get-filename i)
6472 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6473 (save-match-data
6474 (string-match tramp-file-name-regexp isfile)))
6475 for isssh = (and istramp
6476 (string-match "/ssh:" isfile))
6477 if isssh
6478 collect i))
6482 ;;; Firefox bookmarks
6485 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6486 ;; (only for firefox versions >=3)
6487 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6488 ;; to true:
6489 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6490 ;; You should have now:
6491 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6493 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6494 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6496 (defun anything-get-firefox-user-init-dir ()
6497 "Guess the default Firefox user directory name."
6498 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6499 (moz-user-dir
6500 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6501 (goto-char (point-min))
6502 (prog1
6503 (when (search-forward "Path=" nil t)
6504 (buffer-substring-no-properties (point) (point-at-eol)))
6505 (kill-buffer)))))
6506 (file-name-as-directory (concat moz-dir moz-user-dir))))
6508 (defun anything-guess-firefox-bookmark-file ()
6509 "Return the path of the Firefox bookmarks file."
6510 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6512 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6513 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6514 (let (bookmarks-alist url title)
6515 (with-temp-buffer
6516 (insert-file-contents file)
6517 (goto-char (point-min))
6518 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6519 (forward-line 0)
6520 (when (re-search-forward url-regexp nil t)
6521 (setq url (match-string 0)))
6522 (when (re-search-forward bmk-regexp nil t)
6523 (setq title (match-string 1)))
6524 (push (cons title url) bookmarks-alist)
6525 (forward-line)))
6526 (nreverse bookmarks-alist)))
6528 (defvar anything-c-firefox-bookmarks-alist nil)
6529 (defvar anything-c-source-firefox-bookmarks
6530 '((name . "Firefox Bookmarks")
6531 (init . (lambda ()
6532 (setq anything-c-firefox-bookmarks-alist
6533 (anything-html-bookmarks-to-alist
6534 (anything-guess-firefox-bookmark-file)
6535 anything-firefox-bookmark-url-regexp
6536 anything-firefox-bookmarks-regexp))))
6537 (candidates . (lambda ()
6538 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6539 (filtered-candidate-transformer
6540 anything-c-adaptive-sort
6541 anything-c-highlight-firefox-bookmarks)
6542 (action . (("Browse Url Firefox"
6543 . (lambda (candidate)
6544 (browse-url-firefox
6545 (anything-c-firefox-bookmarks-get-value candidate))))
6546 ("Browse Url w3m"
6547 . (lambda (candidate)
6548 (w3m-browse-url
6549 (anything-c-firefox-bookmarks-get-value candidate))))
6550 ("Copy Url"
6551 . (lambda (elm)
6552 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6554 ;; (anything 'anything-c-source-firefox-bookmarks)
6556 (defun anything-c-firefox-bookmarks-get-value (elm)
6557 (assoc-default elm anything-c-firefox-bookmarks-alist))
6559 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6560 (loop for i in bookmarks
6561 collect (propertize
6562 i 'face '((:foreground "YellowGreen"))
6563 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6567 ;;; W3m bookmark - anything interface.
6570 ;; Some users have the emacs-w3m library in load-path
6571 ;; without having the w3m executable :-;
6572 ;; So check if w3m program is present before trying to load
6573 ;; emacs-w3m.
6574 (eval-when-compile
6575 (when (executable-find "w3m")
6576 (require 'w3m-bookmark nil t)))
6578 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6579 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6580 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6581 (defvar anything-c-w3m-bookmarks-alist nil)
6582 (defvar anything-c-source-w3m-bookmarks
6583 '((name . "W3m Bookmarks")
6584 (init . (lambda ()
6585 (setq anything-c-w3m-bookmarks-alist
6586 (anything-html-bookmarks-to-alist
6587 w3m-bookmark-file
6588 anything-w3m-bookmark-url-regexp
6589 anything-w3m-bookmarks-regexp))))
6590 (candidates . (lambda ()
6591 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6592 (filtered-candidate-transformer
6593 anything-c-adaptive-sort
6594 anything-c-highlight-w3m-bookmarks)
6595 (action . (("Browse Url"
6596 . (lambda (candidate)
6597 (anything-c-w3m-browse-bookmark candidate)))
6598 ("Copy Url"
6599 . (lambda (elm)
6600 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6601 ("Browse Url Firefox"
6602 . (lambda (candidate)
6603 (anything-c-w3m-browse-bookmark candidate t)))
6604 ("Delete Bookmark"
6605 . (lambda (candidate)
6606 (anything-c-w3m-delete-bookmark candidate)))
6607 ("Rename Bookmark"
6608 . (lambda (candidate)
6609 (anything-c-w3m-rename-bookmark candidate)))))
6610 (persistent-action . (lambda (candidate)
6611 (if current-prefix-arg
6612 (anything-c-w3m-browse-bookmark candidate t)
6613 (anything-c-w3m-browse-bookmark candidate nil t))))
6614 (persistent-help . "Open URL with emacs-w3m in new tab / \
6615 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6616 "Needs w3m and emacs-w3m.
6618 http://w3m.sourceforge.net/
6619 http://emacs-w3m.namazu.org/")
6621 ;; (anything 'anything-c-source-w3m-bookmarks)
6623 (defun anything-c-w3m-bookmarks-get-value (elm)
6624 (replace-regexp-in-string
6625 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6627 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6628 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6629 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6630 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6632 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6633 (loop for i in bookmarks
6634 collect (propertize
6635 i 'face 'anything-w3m-bookmarks-face
6636 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6639 (defun anything-c-w3m-delete-bookmark (elm)
6640 "Delete w3m bookmark from `w3m-bookmark-file'."
6641 (with-current-buffer
6642 (find-file-literally w3m-bookmark-file)
6643 (goto-char (point-min))
6644 (when (re-search-forward elm nil t)
6645 (beginning-of-line)
6646 (delete-region (point)
6647 (line-end-position))
6648 (delete-blank-lines))
6649 (save-buffer)
6650 (kill-buffer)))
6652 (defun anything-c-w3m-rename-bookmark (elm)
6653 "Rename w3m bookmark in `w3m-bookmark-file'."
6654 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6655 (new-title (read-string "NewTitle: " old-title)))
6656 (with-current-buffer
6657 (find-file-literally w3m-bookmark-file)
6658 (goto-char (point-min))
6659 (when (re-search-forward (concat elm "<") nil t)
6660 (goto-char (1- (point)))
6661 (delete-char (- (length old-title)))
6662 (insert new-title))
6663 (save-buffer)
6664 (kill-buffer))))
6667 ;;;; <Library>
6668 ;;; Elisp library scan
6671 (defvar anything-c-source-elisp-library-scan
6672 '((name . "Elisp libraries (Scan)")
6673 (init . (anything-c-elisp-library-scan-init))
6674 (candidates-in-buffer)
6675 (action ("Find library"
6676 . (lambda (candidate) (find-file (find-library-name candidate))))
6677 ("Find library other window"
6678 . (lambda (candidate)
6679 (find-file-other-window (find-library-name candidate))))
6680 ("Load library"
6681 . (lambda (candidate) (load-library candidate))))))
6682 ;; (anything 'anything-c-source-elisp-library-scan)
6684 (defun anything-c-elisp-library-scan-init ()
6685 "Init anything buffer status."
6686 (let ((anything-buffer (anything-candidate-buffer 'global))
6687 (library-list (anything-c-elisp-library-scan-list)))
6688 (with-current-buffer anything-buffer
6689 (dolist (library library-list)
6690 (insert (format "%s\n" library))))))
6692 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6693 "Do completion for file names passed to `locate-file'.
6694 DIRS is directory to search path.
6695 STRING is string to match."
6696 ;; Use `load-path' as path when ignore `dirs'.
6697 (or dirs (setq dirs load-path))
6698 ;; Init with blank when ignore `string'.
6699 (or string (setq string ""))
6700 ;; Get library list.
6701 (let ((string-dir (file-name-directory string))
6702 ;; File regexp that suffix match `load-file-rep-suffixes'.
6703 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6704 name
6705 names)
6706 (dolist (dir dirs)
6707 (unless dir
6708 (setq dir default-directory))
6709 (if string-dir
6710 (setq dir (expand-file-name string-dir dir)))
6711 (when (file-directory-p dir)
6712 (dolist (file (file-name-all-completions
6713 (file-name-nondirectory string) dir))
6714 ;; Suffixes match `load-file-rep-suffixes'.
6715 (setq name (if string-dir (concat string-dir file) file))
6716 (if (string-match match-regexp name)
6717 (add-to-list 'names name)))))
6718 names))
6721 ;;;; <Programming>
6725 ;;; Imenu
6728 (defvar anything-c-imenu-delimiter " / ")
6730 (defvar anything-c-imenu-index-filter nil)
6731 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6733 (defvar anything-c-cached-imenu-alist nil)
6734 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6736 (defvar anything-c-cached-imenu-candidates nil)
6737 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6739 (defvar anything-c-cached-imenu-tick nil)
6740 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6742 (eval-when-compile (require 'imenu))
6743 (setq imenu-auto-rescan t)
6745 (defun anything-imenu-create-candidates (entry)
6746 "Create candidates with ENTRY."
6747 (if (listp (cdr entry))
6748 (mapcan
6749 (lambda (sub)
6750 (if (consp (cdr sub))
6751 (mapcar
6752 (lambda (subentry)
6753 (concat (car entry) anything-c-imenu-delimiter subentry))
6754 (anything-imenu-create-candidates sub))
6755 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6756 (cdr entry))
6757 (list entry)))
6759 (defvar anything-c-source-imenu
6760 '((name . "Imenu")
6761 (init . (lambda () (require 'imenu)))
6762 (candidates . anything-c-imenu-candidates)
6763 (persistent-action . (lambda (elm)
6764 (anything-c-imenu-default-action elm)
6765 (unless (fboundp 'semantic-imenu-tag-overlay)
6766 (anything-match-line-color-current-line))))
6767 (persistent-help . "Show this entry")
6768 (action . anything-c-imenu-default-action))
6769 "See (info \"(emacs)Imenu\")")
6771 ;; (anything 'anything-c-source-imenu)
6773 (defun anything-c-imenu-candidates ()
6774 (with-anything-current-buffer
6775 (let ((tick (buffer-modified-tick)))
6776 (if (eq anything-c-cached-imenu-tick tick)
6777 anything-c-cached-imenu-candidates
6778 (setq imenu--index-alist nil)
6779 (setq anything-c-cached-imenu-tick tick
6780 anything-c-cached-imenu-candidates
6781 (ignore-errors
6782 (mapcan
6783 'anything-imenu-create-candidates
6784 (setq anything-c-cached-imenu-alist
6785 (let ((index (imenu--make-index-alist)))
6786 (if anything-c-imenu-index-filter
6787 (funcall anything-c-imenu-index-filter index)
6788 index))))))
6789 (setq anything-c-cached-imenu-candidates
6790 (mapcar #'(lambda (x)
6791 (if (stringp x)
6793 (car x)))
6794 anything-c-cached-imenu-candidates))))))
6796 (setq imenu-default-goto-function 'imenu-default-goto-function)
6797 (defun anything-c-imenu-default-action (elm)
6798 "The default action for `anything-c-source-imenu'."
6799 (let ((path (split-string elm anything-c-imenu-delimiter))
6800 (alist anything-c-cached-imenu-alist))
6801 (dolist (elm path)
6802 (setq alist (assoc elm alist)))
6803 (imenu alist)))
6807 ;;; Ctags
6810 (defvar anything-c-ctags-modes
6811 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6812 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6813 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6815 (defun anything-c-source-ctags-init ()
6816 (when (and buffer-file-name
6817 (memq major-mode anything-c-ctags-modes)
6818 (anything-current-buffer-is-modified))
6819 (with-current-buffer (anything-candidate-buffer 'local)
6820 (call-process-shell-command
6821 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6822 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6823 anything-buffer-file-name)
6824 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6825 nil (current-buffer))
6826 (goto-char (point-min))
6827 (forward-line 2)
6828 (delete-region (point-min) (point))
6829 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6830 for lineno-start = (point)
6831 for lineno = (buffer-substring
6832 lineno-start
6833 (1- (search-forward "," (point-at-eol) t)))
6835 (beginning-of-line)
6836 (insert (format "%5s:" lineno))
6837 (search-forward "\177" (point-at-eol) t)
6838 (delete-region (1- (point)) (point-at-eol))
6839 (forward-line 1)))))
6841 (defvar anything-c-source-ctags
6842 '((name . "Exuberant ctags")
6843 (init . anything-c-source-ctags-init)
6844 (candidates-in-buffer)
6845 (adjust)
6846 (type . line))
6847 "Needs Exuberant Ctags.
6849 http://ctags.sourceforge.net/")
6850 ;; (anything 'anything-c-source-ctags)
6853 ;;; Etags
6856 ;; anything-etags.el is deprecated, if this file is found,
6857 ;; warn user at compile time.
6858 (eval-when-compile
6859 (when (locate-library "anything-etags.el")
6860 (display-warning
6861 '(anything-config)
6862 "You are using obsolete library `anything-etags.el' and should remove it."
6863 :warning)))
6865 (defvar anything-c-etags-tag-file-dir nil
6866 "Etags file directory.")
6867 (defvar anything-c-etags-mtime-alist nil
6868 "Store the last modification time of etags files here.")
6869 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6870 "Cache content of etags files used here for faster access.")
6872 (defun anything-c-etags-get-tag-file (&optional directory)
6873 "Return the path of etags file if found."
6874 ;; Get tag file from `default-directory' or upper directory.
6875 (let ((current-dir (anything-c-etags-find-tag-file-directory
6876 (or directory default-directory))))
6877 ;; Return nil if not find tag file.
6878 (when current-dir
6879 ;; Set tag file directory.
6880 (setq anything-c-etags-tag-file-dir current-dir)
6881 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6883 (defun anything-c-etags-find-tag-file-directory (current-dir)
6884 "Try to find the directory containing tag file.
6885 If not found in CURRENT-DIR search in upper directory."
6886 (flet ((file-exists? (dir)
6887 (let ((tag-path (expand-file-name
6888 anything-c-etags-tag-file-name dir)))
6889 (and (stringp tag-path)
6890 (file-exists-p tag-path)
6891 (file-readable-p tag-path)))))
6892 (loop with count = 0
6893 until (file-exists? current-dir)
6894 ;; Return nil if outside the value of
6895 ;; `anything-c-etags-tag-file-search-limit'.
6896 if (= count anything-c-etags-tag-file-search-limit)
6897 do (return nil)
6898 ;; Or search upper directories.
6899 else
6900 do (incf count)
6901 (setq current-dir (expand-file-name (concat current-dir "../")))
6902 finally return current-dir)))
6904 (defun anything-c-source-etags-header-name (x)
6905 "Create header name for this anything etags session."
6906 (concat "Etags in "
6907 (with-anything-current-buffer
6908 (anything-c-etags-get-tag-file))))
6910 (defmacro anything-c-etags-create-buffer (file)
6911 "Create the `anything-buffer' based on contents of etags tag FILE."
6912 `(let* ((tag-fname ,file)
6914 (split (with-current-buffer (find-file-noselect tag-fname)
6915 (prog1
6916 (split-string (buffer-string) "\n" 'omit-nulls)
6917 (setq max (line-number-at-pos (point-max)))
6918 (kill-buffer))))
6919 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6920 (loop
6921 with fname
6922 with cand
6923 for i in split for count from 0
6924 for elm = (unless (string-match "^\x0c" i)
6925 (anything-aif (string-match "\177" i)
6926 (substring i 0 it)
6928 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6929 (setq fname (match-string 1 elm)))
6930 (elm (setq cand (concat fname ": " elm)))
6931 (t (setq cand nil)))
6932 when cand do (progn
6933 (insert (concat cand "\n"))
6934 (progress-reporter-update progress-reporter count)))))
6936 (defun anything-c-etags-init ()
6937 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6938 If no entry in cache, create one."
6939 (let ((tagfile (anything-c-etags-get-tag-file)))
6940 (when tagfile
6941 (with-current-buffer (anything-candidate-buffer 'global)
6942 (anything-aif (gethash tagfile anything-c-etags-cache)
6943 ;; An entry is present in cache, insert it.
6944 (insert it)
6945 ;; No entry, create a new buffer using content of tag file (slower).
6946 (anything-c-etags-create-buffer tagfile)
6947 ;; Store content of buffer in cache.
6948 (puthash tagfile (buffer-string) anything-c-etags-cache)
6949 ;; Store or set the last modification of tag file.
6950 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6951 ;; If an entry exists modify it.
6952 (setcdr it (anything-c-etags-mtime tagfile))
6953 ;; No entry create a new one.
6954 (add-to-list 'anything-c-etags-mtime-alist
6955 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6957 (defvar anything-c-source-etags-select
6958 '((name . "Etags")
6959 (header-name . anything-c-source-etags-header-name)
6960 (init . anything-c-etags-init)
6961 (candidates-in-buffer)
6962 (search . (anything-c-etags-search-fn))
6963 (mode-line . anything-etags-mode-line-string)
6964 (action . anything-c-etags-default-action)
6965 (persistent-action . (lambda (candidate)
6966 (anything-c-etags-default-action candidate)
6967 (anything-match-line-color-current-line))))
6968 "Anything source for Etags.")
6970 (defun anything-c-etags-search-fn (pattern)
6971 "Search function for `anything-c-source-etags-select'."
6972 (re-search-forward
6973 (if anything-c-etags-use-regexp-search
6974 (format anything-c-etags-search-regexp pattern)
6975 pattern)
6976 nil t))
6978 (defun anything-c-etags-default-action (candidate)
6979 "Anything default action to jump to an etags entry."
6980 (let* ((split (split-string candidate ": "))
6981 (fname (expand-file-name
6982 (car split) anything-c-etags-tag-file-dir))
6983 (elm (cadr split)))
6984 (find-file fname)
6985 (goto-char (point-min))
6986 (search-forward elm nil t)
6987 (goto-char (match-beginning 0))))
6989 (defun anything-c-etags-mtime (file)
6990 "Last modification time of etags tag FILE."
6991 (cadr (nth 5 (file-attributes file))))
6993 (defun anything-c-etags-file-modified-p (file)
6994 "Check if tag FILE have been modified in this session.
6995 If FILE is nil return nil."
6996 (let ((last-modif (and file
6997 (assoc-default file anything-c-etags-mtime-alist))))
6998 (and last-modif
6999 (/= last-modif (anything-c-etags-mtime file)))))
7003 ;;; Semantic
7006 (defvar anything-semantic-candidates nil)
7008 (defun anything-semantic-construct-candidates (tags depth)
7009 (when (require 'semantic nil t)
7010 (apply
7011 'append
7012 (mapcar
7013 (lambda (tag)
7014 (if (listp tag)
7015 (let ((type (semantic-tag-type tag))
7016 (class (semantic-tag-class tag)))
7017 (if (or (and (stringp type)
7018 (or (string= type "class")
7019 (string= type "namespace")))
7020 (eq class 'function)
7021 (eq class 'variable))
7022 (cons (cons (concat (make-string (* depth 2) ?\s)
7023 (semantic-format-tag-summarize tag nil t))
7024 tag)
7025 (anything-semantic-construct-candidates
7026 (semantic-tag-components tag) (1+ depth)))))))
7027 tags))))
7029 (defun anything-semantic-default-action (candidate)
7030 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7031 (semantic-go-to-tag tag)))
7033 (defvar anything-c-source-semantic
7034 '((name . "Semantic Tags")
7035 (init . (lambda ()
7036 (setq anything-semantic-candidates
7037 (ignore-errors (anything-semantic-construct-candidates
7038 (semantic-fetch-tags) 0)))))
7039 (candidates . (lambda ()
7040 (if anything-semantic-candidates
7041 (mapcar 'car anything-semantic-candidates))))
7042 (persistent-action . (lambda (elm)
7043 (anything-semantic-default-action elm)
7044 (anything-match-line-color-current-line)))
7045 (persistent-help . "Show this entry")
7046 (action . anything-semantic-default-action)
7047 "Needs semantic in CEDET.
7049 http://cedet.sourceforge.net/semantic.shtml
7050 http://cedet.sourceforge.net/"))
7052 ;; (anything 'anything-c-source-semantic)
7055 ;;; Anything interface of `simple-call-tree.el'.
7057 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7059 ;; Function is called by
7060 (defvar anything-c-source-simple-call-tree-functions-callers
7061 '((name . "Function is called by")
7062 (init . anything-c-simple-call-tree-functions-callers-init)
7063 (multiline)
7064 (candidates . anything-c-simple-call-tree-candidates)
7065 (persistent-action . anything-c-simple-call-tree-persistent-action)
7066 (persistent-help . "Show function definitions by rotation")
7067 (action ("Find definition selected by persistent-action" .
7068 anything-c-simple-call-tree-find-definition)))
7069 "Needs simple-call-tree.el.
7070 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7072 (defvar anything-c-simple-call-tree-tick nil)
7073 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7074 (defun anything-c-simple-call-tree-analyze-maybe ()
7075 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7076 (simple-call-tree-analyze)
7077 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7079 (defun anything-c-simple-call-tree-init-base (function message)
7080 (require 'simple-call-tree)
7081 (with-no-warnings
7082 (when (anything-current-buffer-is-modified)
7083 (anything-c-simple-call-tree-analyze-maybe)
7084 (let ((list (funcall function simple-call-tree-alist)))
7085 (with-current-buffer (anything-candidate-buffer 'local)
7086 (dolist (entry list)
7087 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7088 (insert (car entry) message
7089 (if (string= funcs " ")
7090 " no functions."
7091 funcs)
7092 "\n\n"))))))))
7094 (defun anything-c-simple-call-tree-functions-callers-init ()
7095 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7096 " is called by\n"))
7098 (defun anything-c-simple-call-tree-candidates ()
7099 (with-current-buffer (anything-candidate-buffer)
7100 (split-string (buffer-string) "\n\n")))
7102 (defvar anything-c-simple-call-tree-related-functions nil)
7103 (defvar anything-c-simple-call-tree-function-index 0)
7104 (defun anything-c-simple-call-tree-persistent-action (candidate)
7105 (unless (eq last-command 'anything-execute-persistent-action)
7106 (setq anything-c-simple-call-tree-related-functions
7107 (delete "no functions."
7108 (split-string
7109 (replace-regexp-in-string " \\| is called by\\| calls "
7110 "" candidate)
7111 "\n")))
7112 (setq anything-c-simple-call-tree-function-index -1))
7113 (incf anything-c-simple-call-tree-function-index)
7114 (anything-c-simple-call-tree-find-definition candidate))
7116 (defun anything-c-simple-call-tree-find-definition (candidate)
7117 (find-function
7118 (intern
7119 (nth (mod anything-c-simple-call-tree-function-index
7120 (length anything-c-simple-call-tree-related-functions))
7121 anything-c-simple-call-tree-related-functions))))
7123 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7125 ;;; Function calls
7126 (defvar anything-c-source-simple-call-tree-callers-functions
7127 '((name . "Function calls")
7128 (init . anything-c-simple-call-tree-callers-functions-init)
7129 (multiline)
7130 (candidates . anything-c-simple-call-tree-candidates)
7131 (persistent-action . anything-c-simple-call-tree-persistent-action)
7132 (persistent-help . "Show function definitions by rotation")
7133 (action ("Find definition selected by persistent-action" .
7134 anything-c-simple-call-tree-find-definition)))
7135 "Needs simple-call-tree.el.
7136 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7138 (defun anything-c-simple-call-tree-callers-functions-init ()
7139 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7141 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7145 ;;; Anything UI of auto-document.el
7147 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7149 ;; Commands/Options with doc
7150 (defvar anything-c-auto-document-data nil)
7151 (make-variable-buffer-local 'anything-c-auto-document-data)
7152 (defvar anything-c-source-commands-and-options-in-file
7153 '((name . "Commands/Options in file")
7154 (header-name
7155 . (lambda (x) (format "Commands/Options in %s"
7156 (buffer-local-value 'buffer-file-name
7157 anything-current-buffer))))
7158 (candidates . anything-command-and-options-candidates)
7159 (multiline)
7160 (action . imenu))
7161 "List Commands and Options with doc. It needs auto-document.el .
7163 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7165 (eval-when-compile (require 'auto-document nil t))
7166 (defun anything-command-and-options-candidates ()
7167 (with-anything-current-buffer
7168 (when (and (require 'auto-document nil t)
7169 (eq major-mode 'emacs-lisp-mode)
7170 (or (anything-current-buffer-is-modified)
7171 (not anything-c-auto-document-data)))
7172 (or imenu--index-alist (imenu--make-index-alist t))
7173 (setq anything-c-auto-document-data
7174 (destructuring-bind (commands options)
7175 (adoc-construct anything-current-buffer)
7176 (append
7177 (loop for (command . doc) in commands
7178 for cmdname = (symbol-name command)
7179 collect
7180 (cons
7181 (format "Command: %s\n %s"
7182 (propertize cmdname 'face font-lock-function-name-face)
7183 (adoc-first-line doc))
7184 (assoc cmdname imenu--index-alist)))
7185 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7186 for (option doc default) in options
7187 for optname = (symbol-name option)
7188 collect
7189 (cons
7190 (format "Option: %s\n %s\n default = %s"
7191 (propertize optname 'face font-lock-variable-name-face)
7192 (adoc-first-line doc)
7193 (adoc-prin1-to-string default))
7194 (assoc optname
7195 var-alist)))))))
7196 anything-c-auto-document-data))
7198 ;; (anything 'anything-c-source-commands-and-options-in-file)
7201 ;;;; <Color and Face>
7204 ;;; Customize Face
7207 (defvar anything-c-source-customize-face
7208 '((name . "Customize Face")
7209 (init . (lambda ()
7210 (unless (anything-candidate-buffer)
7211 (save-window-excursion (list-faces-display))
7212 (anything-candidate-buffer (get-buffer "*Faces*")))))
7213 (candidates-in-buffer)
7214 (get-line . buffer-substring)
7215 (action . (lambda (line)
7216 (customize-face (intern (car (split-string line))))))
7217 (requires-pattern . 3))
7218 "See (info \"(emacs)Faces\")")
7219 ;; (anything 'anything-c-source-customize-face)
7221 ;;; Colors browser
7224 (defvar anything-c-source-colors
7225 '((name . "Colors")
7226 (init . (lambda () (unless (anything-candidate-buffer)
7227 (save-window-excursion (list-colors-display))
7228 (anything-candidate-buffer (get-buffer "*Colors*")))))
7229 (candidates-in-buffer)
7230 (get-line . buffer-substring)
7231 (action
7232 ("Copy Name" . (lambda (candidate)
7233 (kill-new (anything-c-colors-get-name candidate))))
7234 ("Copy RGB" . (lambda (candidate)
7235 (kill-new (anything-c-colors-get-rgb candidate))))
7236 ("Insert Name" . (lambda (candidate)
7237 (with-anything-current-buffer
7238 (insert (anything-c-colors-get-name candidate)))))
7239 ("Insert RGB" . (lambda (candidate)
7240 (with-anything-current-buffer
7241 (insert (anything-c-colors-get-rgb candidate))))))))
7242 ;; (anything 'anything-c-source-colors)
7244 (defun anything-c-colors-get-name (candidate)
7245 "Get color name."
7246 (replace-regexp-in-string
7247 " " ""
7248 (with-temp-buffer
7249 (insert (capitalize candidate))
7250 (goto-char (point-min))
7251 (search-forward-regexp "\\s-\\{2,\\}")
7252 (delete-region (point) (point-max))
7253 (buffer-string))))
7255 (defun anything-c-colors-get-rgb (candidate)
7256 "Get color RGB."
7257 (replace-regexp-in-string
7258 " " ""
7259 (with-temp-buffer
7260 (insert (capitalize candidate))
7261 (goto-char (point-max))
7262 (search-backward-regexp "\\s-\\{2,\\}")
7263 (delete-region (point) (point-min))
7264 (buffer-string))))
7267 ;;;; <Search Engine>
7268 ;;; Tracker desktop search
7269 (defvar anything-c-source-tracker-search
7270 '((name . "Tracker Search")
7271 (candidates . (lambda ()
7272 (start-process "tracker-search-process" nil
7273 "tracker-search"
7274 anything-pattern)))
7275 (type . file)
7276 (requires-pattern . 3)
7277 (delayed))
7278 "Source for retrieving files matching the current input pattern
7279 with the tracker desktop search.")
7280 ;; (anything 'anything-c-source-tracker-search)
7282 ;;; Spotlight (MacOS X desktop search)
7283 (defvar anything-c-source-mac-spotlight
7284 '((name . "mdfind")
7285 (candidates
7286 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7287 (type . file)
7288 (requires-pattern . 3)
7289 (delayed))
7290 "Source for retrieving files via Spotlight's command line
7291 utility mdfind.")
7292 ;; (anything 'anything-c-source-mac-spotlight)
7294 ;;; Picklist
7295 (defvar anything-c-source-picklist
7296 '((name . "Picklist")
7297 (candidates . (lambda () (mapcar 'car picklist-list)))
7298 (type . file)))
7299 ;; (anything 'anything-c-source-picklist)
7303 ;;; Kill ring
7306 (defvar anything-c-source-kill-ring
7307 '((name . "Kill Ring")
7308 (init . (lambda () (anything-attrset 'last-command last-command)))
7309 (candidates . anything-c-kill-ring-candidates)
7310 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7311 (action . anything-c-kill-ring-action)
7312 (last-command)
7313 (migemo)
7314 (multiline))
7315 "Source for browse and insert contents of kill-ring.")
7317 (defun anything-c-kill-ring-candidates ()
7318 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7319 unless (or (< (length kill) anything-kill-ring-threshold)
7320 (string-match "^[\\s\\t]+$" kill))
7321 collect kill))
7323 (defun anything-c-kill-ring-transformer (candidates source)
7324 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7325 (loop for i in candidates
7326 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7327 if (and anything-c-kill-ring-max-lines-number
7328 (> nlines anything-c-kill-ring-max-lines-number))
7329 collect (cons
7330 (with-temp-buffer
7331 (insert i)
7332 (goto-char (point-min))
7333 (concat
7334 (buffer-substring
7335 (point-min)
7336 (save-excursion
7337 (forward-line anything-c-kill-ring-max-lines-number)
7338 (point)))
7339 "[...]")) i)
7340 else collect i))
7342 (defun anything-c-kill-ring-action (str)
7343 "Insert STR in `kill-ring' and set STR to the head.
7344 If this action is executed just after `yank',
7345 replace with STR as yanked string."
7346 (setq kill-ring (delete str kill-ring))
7347 (if (not (eq (anything-attr 'last-command) 'yank))
7348 (insert-for-yank str)
7349 ;; from `yank-pop'
7350 (let ((inhibit-read-only t)
7351 (before (< (point) (mark t))))
7352 (if before
7353 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7354 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7355 (setq yank-undo-function nil)
7356 (set-marker (mark-marker) (point) (current-buffer))
7357 (insert-for-yank str)
7358 ;; Set the window start back where it was in the yank command,
7359 ;; if possible.
7360 (set-window-start (selected-window) yank-window-start t)
7361 (if before
7362 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7363 ;; It is cleaner to avoid activation, even though the command
7364 ;; loop would deactivate the mark because we inserted text.
7365 (goto-char (prog1 (mark t)
7366 (set-marker (mark-marker) (point) (current-buffer)))))))
7367 (kill-new str))
7369 ;; (anything 'anything-c-source-kill-ring)
7372 ;;;; <Mark ring>
7373 ;; DO NOT include these sources in `anything-sources' use
7374 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7375 ;; `anything-all-mark-rings' instead.
7377 (defun anything-c-source-mark-ring-candidates ()
7378 (flet ((get-marks (pos)
7379 (save-excursion
7380 (goto-char pos)
7381 (beginning-of-line)
7382 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7383 (when (string= "" line)
7384 (setq line "<EMPTY LINE>"))
7385 (format "%7d: %s" (line-number-at-pos) line)))))
7386 (with-anything-current-buffer
7387 (loop
7388 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7389 with recip = nil
7390 for i in marks
7391 for m = (get-marks i)
7392 unless (member m recip)
7393 collect m into recip
7394 finally return recip))))
7396 (defvar anything-mark-ring-cache nil)
7397 (defvar anything-c-source-mark-ring
7398 '((name . "mark-ring")
7399 (init . (lambda ()
7400 (setq anything-mark-ring-cache
7401 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7402 (candidates . (lambda ()
7403 (anything-aif anything-mark-ring-cache
7404 it)))
7405 (action . (("Goto line"
7406 . (lambda (candidate)
7407 (anything-goto-line (string-to-number candidate))))))
7408 (persistent-action . (lambda (candidate)
7409 (anything-goto-line (string-to-number candidate))
7410 (anything-match-line-color-current-line)))
7411 (persistent-help . "Show this line")))
7413 ;; (anything 'anything-c-source-mark-ring)
7415 ;;; Global-mark-ring
7416 (defvar anything-c-source-global-mark-ring
7417 '((name . "global-mark-ring")
7418 (candidates . anything-c-source-global-mark-ring-candidates)
7419 (action . (("Goto line"
7420 . (lambda (candidate)
7421 (let ((items (split-string candidate ":")))
7422 (anything-c-switch-to-buffer (second items))
7423 (anything-goto-line (string-to-number (car items))))))))
7424 (persistent-action . (lambda (candidate)
7425 (let ((items (split-string candidate ":")))
7426 (anything-c-switch-to-buffer (second items))
7427 (anything-goto-line (string-to-number (car items)))
7428 (anything-match-line-color-current-line))))
7429 (persistent-help . "Show this line")))
7431 (defun anything-c-source-global-mark-ring-candidates ()
7432 (flet ((buf-fn (m)
7433 (with-current-buffer (marker-buffer m)
7434 (goto-char m)
7435 (beginning-of-line)
7436 (let (line)
7437 (if (string= "" line)
7438 (setq line "<EMPTY LINE>")
7439 (setq line (car (split-string (thing-at-point 'line)
7440 "[\n\r]"))))
7441 (format "%7d:%s: %s"
7442 (line-number-at-pos) (marker-buffer m) line)))))
7443 (loop
7444 with marks = global-mark-ring
7445 with recip = nil
7446 for i in marks
7447 for gm = (unless (or (string-match
7448 "^ " (format "%s" (marker-buffer i)))
7449 (null (marker-buffer i)))
7450 (buf-fn i))
7451 when (and gm (not (member gm recip)))
7452 collect gm into recip
7453 finally return recip)))
7455 ;; (anything 'anything-c-source-global-mark-ring)
7458 ;;;; <Register>
7459 ;;; Insert from register
7460 (defvar anything-c-source-register
7461 '((name . "Registers")
7462 (candidates . anything-c-register-candidates)
7463 (action-transformer . anything-c-register-action-transformer)
7464 (multiline)
7465 (action))
7466 "See (info \"(emacs)Registers\")")
7468 (defun anything-c-register-candidates ()
7469 "Collecting register contents and appropriate commands."
7470 (loop for (char . val) in register-alist
7471 for key = (single-key-description char)
7472 for string-actions =
7473 (cond
7474 ((numberp val)
7475 (list (int-to-string val)
7476 'insert-register
7477 'increment-register))
7478 ((markerp val)
7479 (let ((buf (marker-buffer val)))
7480 (if (null buf)
7481 (list "a marker in no buffer")
7482 (list (concat
7483 "a buffer position:"
7484 (buffer-name buf)
7485 ", position "
7486 (int-to-string (marker-position val)))
7487 'jump-to-register
7488 'insert-register))))
7489 ((and (consp val) (window-configuration-p (car val)))
7490 (list "window configuration."
7491 'jump-to-register))
7492 ((and (consp val) (frame-configuration-p (car val)))
7493 (list "frame configuration."
7494 'jump-to-register))
7495 ((and (consp val) (eq (car val) 'file))
7496 (list (concat "file:"
7497 (prin1-to-string (cdr val))
7498 ".")
7499 'jump-to-register))
7500 ((and (consp val) (eq (car val) 'file-query))
7501 (list (concat "file:a file-query reference: file "
7502 (car (cdr val))
7503 ", position "
7504 (int-to-string (car (cdr (cdr val))))
7505 ".")
7506 'jump-to-register))
7507 ((consp val)
7508 (let ((lines (format "%4d" (length val))))
7509 (list (format "%s: %s\n" lines
7510 (truncate-string-to-width
7511 (mapconcat 'identity (list (car val))
7512 ;; (mapconcat (lambda (y) y) val
7513 "^J") (- (window-width) 15)))
7514 'insert-register)))
7515 ((stringp val)
7516 (list ;; without properties
7517 (substring-no-properties val)
7518 'insert-register
7519 'append-to-register
7520 'prepend-to-register))
7522 "GARBAGE!"))
7523 collect (cons (format "register %3s: %s" key (car string-actions))
7524 (cons char (cdr string-actions)))))
7526 (defun anything-c-register-action-transformer (actions register-and-functions)
7527 "Decide actions by the contents of register."
7528 (loop with func-actions =
7529 '((insert-register
7530 "Insert Register" .
7531 (lambda (c) (insert-register (car c))))
7532 (jump-to-register
7533 "Jump to Register" .
7534 (lambda (c) (jump-to-register (car c))))
7535 (append-to-register
7536 "Append Region to Register" .
7537 (lambda (c) (append-to-register
7538 (car c) (region-beginning) (region-end))))
7539 (prepend-to-register
7540 "Prepend Region to Register" .
7541 (lambda (c) (prepend-to-register
7542 (car c) (region-beginning) (region-end))))
7543 (increment-register
7544 "Increment Prefix Arg to Register" .
7545 (lambda (c) (increment-register
7546 anything-current-prefix-arg (car c)))))
7547 for func in (cdr register-and-functions)
7548 for cell = (assq func func-actions)
7549 when cell
7550 collect (cdr cell)))
7552 ;; (anything 'anything-c-source-register)
7555 ;;; Latex completion
7556 (defun anything-c-latex-math-candidates ()
7557 "Collect candidates for latex math completion."
7558 (declare (special LaTeX-math-menu))
7559 (loop for i in (cddr LaTeX-math-menu)
7560 for elm = (loop for s in i when (vectorp s)
7561 collect (cons (aref s 0) (aref s 1)))
7562 append elm))
7564 (defvar anything-c-source-latex-math
7565 '((name . "Latex Math Menu")
7566 (init . (lambda ()
7567 (with-anything-current-buffer
7568 (LaTeX-math-mode 1))))
7569 (candidate-number-limit . 9999)
7570 (candidates . anything-c-latex-math-candidates)
7571 (action . (lambda (candidate)
7572 (call-interactively candidate)))))
7575 ;;;; <Headline Extraction>
7576 (defvar anything-c-source-fixme
7577 '((name . "TODO/FIXME/DRY comments")
7578 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7579 (adjust)
7580 (recenter))
7581 "Show TODO/FIXME/DRY comments in current file.")
7582 ;; (anything 'anything-c-source-fixme)
7584 (defvar anything-c-source-rd-headline
7585 '((name . "RD HeadLine")
7586 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7587 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7588 (migemo)
7589 (subexp . 1))
7590 "Show RD headlines.
7592 RD is Ruby's POD.
7593 http://en.wikipedia.org/wiki/Ruby_Document_format")
7594 ;; (anything 'anything-c-source-rd-headline)
7596 (defvar anything-c-source-oddmuse-headline
7597 '((name . "Oddmuse HeadLine")
7598 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7599 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7600 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7601 (migemo)
7602 (subexp . 1))
7603 "Show Oddmuse headlines, such as EmacsWiki.")
7604 ;; (anything 'anything-c-source-oddmuse-headline)
7606 (defvar anything-c-source-emacs-source-defun
7607 '((name . "Emacs Source DEFUN")
7608 (headline . "DEFUN\\|DEFVAR")
7609 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7610 (or buffer-file-name ""))))
7611 "Show DEFUN/DEFVAR in Emacs C source file.")
7612 ;; (anything 'anything-c-source-emacs-source-defun)
7614 (defvar anything-c-source-emacs-lisp-expectations
7615 '((name . "Emacs Lisp Expectations")
7616 (headline . "(desc[ ]\\|(expectations")
7617 (condition . (eq major-mode 'emacs-lisp-mode)))
7618 "Show descriptions (desc) in Emacs Lisp Expectations.
7620 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7621 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7623 (defvar anything-c-source-emacs-lisp-toplevels
7624 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7625 (headline . "^(\\|(@\\*\\|^;;;;")
7626 (get-line . buffer-substring)
7627 (condition . (eq major-mode 'emacs-lisp-mode))
7628 (adjust))
7629 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7630 linkd.el is optional because linkd stars are extracted by regexp.
7631 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7632 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7635 ;;; Anything yaoddmuse
7637 ;; Be sure to have yaoddmuse.el installed
7638 ;; install-elisp may be required if you want to install elisp file from here.
7639 (defvar anything-yaoddmuse-use-cache-file nil)
7640 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7641 (defvar anything-c-yaoddmuse-ew-cache nil)
7643 (defun anything-yaoddmuse-get-candidates ()
7644 (declare (special yaoddmuse-pages-hash))
7645 (if anything-yaoddmuse-use-cache-file
7646 (ignore-errors
7647 (unless anything-c-yaoddmuse-ew-cache
7648 (load anything-c-yaoddmuse-cache-file)
7649 (setq anything-c-yaoddmuse-ew-cache
7650 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7651 anything-c-yaoddmuse-ew-cache)
7652 (yaoddmuse-update-pagename t)
7653 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7655 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7656 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7657 (candidates . anything-yaoddmuse-get-candidates)
7658 (action . (("Edit page" . (lambda (candidate)
7659 (yaoddmuse-edit "EmacsWiki" candidate)))
7660 ("Browse page"
7661 . (lambda (candidate)
7662 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7663 ("Browse page other window"
7664 . (lambda (candidate)
7665 (if (one-window-p)
7666 (split-window-vertically))
7667 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7668 ("Browse diff"
7669 . (lambda (candidate)
7670 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7671 ("Copy URL"
7672 . (lambda (candidate)
7673 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7674 (message "Have copy page %s's URL to yank." candidate)))
7675 ("Create page"
7676 . (lambda (candidate)
7677 (yaoddmuse-edit "EmacsWiki" anything-input)))
7678 ("Update cache"
7679 . (lambda (candidate)
7680 (if anything-yaoddmuse-use-cache-file
7681 (progn
7682 (anything-yaoddmuse-cache-pages t)
7683 (setq anything-c-yaoddmuse-ew-cache
7684 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7685 (yaoddmuse-update-pagename))))))
7686 (action-transformer anything-c-yaoddmuse-action-transformer))
7687 "Needs yaoddmuse.el.
7689 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7691 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7693 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7694 '((name . "Yaoddmuse Post library (EmacsWiki)")
7695 (init . (anything-yaoddmuse-init))
7696 (candidates-in-buffer)
7697 (action . (("Post library and Browse"
7698 . (lambda (candidate)
7699 (yaoddmuse-post-file
7700 (find-library-name candidate)
7701 "EmacsWiki"
7702 (file-name-nondirectory (find-library-name candidate))
7703 nil t)))
7704 ("Post library"
7705 . (lambda (candidate)
7706 (yaoddmuse-post-file
7707 (find-library-name candidate)
7708 "EmacsWiki"
7709 (file-name-nondirectory
7710 (find-library-name candidate))))))))
7711 "Needs yaoddmuse.el.
7713 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7715 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7717 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7718 "Allow the use of `install-elisp' only on elisp files."
7719 (if (string-match "\.el$" candidate)
7720 (append actions '(("Install Elisp"
7721 . (lambda (elm)
7722 (install-elisp-from-emacswiki elm)))))
7723 actions))
7725 ;;;###autoload
7726 (defun anything-yaoddmuse-cache-pages (&optional load)
7727 "Fetch the list of files on emacswiki and create cache file.
7728 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7729 (interactive)
7730 (declare (special yaoddmuse-pages-hash))
7731 (yaoddmuse-update-pagename)
7732 (save-excursion
7733 (find-file anything-c-yaoddmuse-cache-file)
7734 (erase-buffer)
7735 (insert "(puthash \"EmacsWiki\" '(")
7736 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7738 (insert (concat "(\"" (car i) "\") ")))
7739 (insert ") yaoddmuse-pages-hash)\n")
7740 (save-buffer)
7741 (kill-buffer (current-buffer))
7742 (when (or current-prefix-arg
7743 load)
7744 (load anything-c-yaoddmuse-cache-file))))
7746 (defun anything-yaoddmuse-init ()
7747 "Init anything buffer status."
7748 (let ((anything-buffer (anything-candidate-buffer 'global))
7749 (library-list (yaoddmuse-get-library-list)))
7750 (with-current-buffer anything-buffer
7751 ;; Insert library name.
7752 (dolist (library library-list)
7753 (insert (format "%s\n" library)))
7754 ;; Sort lines.
7755 (sort-lines nil (point-min) (point-max)))))
7758 ;;; Eev anchors
7759 (defvar anything-c-source-eev-anchor
7760 '((name . "Anchors")
7761 (candidates
7762 . (lambda ()
7763 (ignore-errors
7764 (with-anything-current-buffer
7765 (loop initially (goto-char (point-min))
7766 while (re-search-forward
7767 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7768 for anchor = (match-string-no-properties 1)
7769 collect (cons (format "%5d:%s"
7770 (line-number-at-pos (match-beginning 0))
7771 (format ee-anchor-format anchor))
7772 anchor))))))
7773 (persistent-action . (lambda (item)
7774 (ee-to item)
7775 (anything-match-line-color-current-line)))
7776 (persistent-help . "Show this entry")
7777 (action . (("Goto link" . ee-to)))))
7778 ;; (anything 'anything-c-source-eev-anchor)
7781 ;;; Org headlines
7784 (defvar anything-c-source-org-headline
7785 `((name . "Org HeadLine")
7786 (headline
7787 ,@(mapcar
7788 (lambda (num)
7789 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7790 num))
7791 (number-sequence 1 8)))
7792 (condition . (eq major-mode 'org-mode))
7793 (migemo)
7794 (subexp . 1)
7795 (persistent-action . (lambda (elm)
7796 (anything-c-action-line-goto elm)
7797 (org-cycle)))
7798 (action-transformer
7799 . (lambda (actions candidate)
7800 '(("Go to Line" . anything-c-action-line-goto)
7801 ("Refile to this Headline" . anything-c-org-headline-refile)
7802 ("Insert Link to This Headline"
7803 . anything-c-org-headline-insert-link-to-headline)))))
7804 "Show Org headlines.
7805 org-mode is very very much extended text-mode/outline-mode.
7807 See (find-library \"org.el\")
7808 See http://orgmode.org for the latest version.")
7809 ;; (anything 'anything-c-source-org-headline)
7811 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7812 (insert
7813 (save-excursion
7814 (anything-goto-line (car lineno-and-content))
7815 (and (looking-at org-complex-heading-regexp)
7816 (org-make-link-string (concat "*" (match-string 4)))))))
7818 (defun anything-c-org-headline-refile (lineno-and-content)
7819 "Refile current org entry to LINENO-AND-CONTENT."
7820 (with-anything-current-buffer
7821 (org-cut-subtree)
7822 (anything-goto-line (car lineno-and-content))
7823 (org-end-of-subtree t t)
7824 (let ((org-yank-adjusted-subtrees t))
7825 (org-yank))))
7828 ;;; Org keywords
7831 (defvar anything-c-source-org-keywords
7832 '((name . "Org Keywords")
7833 (init . anything-c-org-keywords-init)
7834 (candidates . anything-c-org-keywords-candidates)
7835 (action . anything-c-org-keywords-insert)
7836 (persistent-action . anything-c-org-keywords-show-help)
7837 (persistent-help . "Show an example and info page to describe this keyword.")
7838 (keywords-examples)
7839 (keywords)))
7840 ;; (anything 'anything-c-source-org-keywords)
7842 (defvar anything-c-org-keywords-info-location
7843 '(("#+TITLE:" . "(org)Export options")
7844 ("#+AUTHOR:" . "(org)Export options")
7845 ("#+DATE:" . "(org)Export options")
7846 ("#+EMAIL:" . "(org)Export options")
7847 ("#+DESCRIPTION:" . "(org)Export options")
7848 ("#+KEYWORDS:" . "(org)Export options")
7849 ("#+LANGUAGE:" . "(org)Export options")
7850 ("#+TEXT:" . "(org)Export options")
7851 ("#+TEXT:" . "(org)Export options")
7852 ("#+OPTIONS:" . "(org)Export options")
7853 ("#+BIND:" . "(org)Export options")
7854 ("#+LINK_UP:" . "(org)Export options")
7855 ("#+LINK_HOME:" . "(org)Export options")
7856 ("#+LATEX_HEADER:" . "(org)Export options")
7857 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7858 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7859 ("#+INFOJS_OPT" . "(org)Javascript support")
7860 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7861 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7862 ("#+ORGTBL" . "(org)Radio tables")
7863 ("#+HTML:" . "(org)Quoting HTML tags")
7864 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7865 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7866 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7867 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7868 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7869 ("#+BEGIN_SRC" . "(org)Literal examples")
7870 ("#+CAPTION" . "(org)Tables in HTML export")
7871 ("#+LABEL" . "(org)Tables in LaTeX export")
7872 ("#+ATTR_HTML" . "(org)Links")
7873 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7875 (defun anything-c-org-keywords-init ()
7876 (unless (anything-attr 'keywords-examples)
7877 (require 'org)
7878 (anything-attrset 'keywords-examples
7879 (append
7880 (mapcar
7881 (lambda (x)
7882 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7883 (cons (match-string 2 x) (match-string 1 x)))
7884 (org-split-string (org-get-current-options) "\n"))
7885 (mapcar 'list org-additional-option-like-keywords)))
7886 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7888 (defun anything-c-org-keywords-candidates ()
7889 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7890 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7891 (anything-attr 'keywords)))
7893 (defun anything-c-org-keywords-insert (keyword)
7894 (cond ((and (string-match "BEGIN" keyword)
7895 (anything-region-active-p))
7896 (let ((beg (region-beginning))
7897 (end (region-end)))
7898 (goto-char end)
7899 (insert "\n#+" (replace-regexp-in-string
7900 "BEGIN" "END" keyword) "\n")
7901 (goto-char beg)
7902 (insert "#+" keyword " ")
7903 (save-excursion (insert "\n"))))
7904 ((string-match "BEGIN" keyword)
7905 (insert "#+" keyword " ")
7906 (save-excursion
7907 (insert "\n#+" (replace-regexp-in-string
7908 "BEGIN" "END" keyword) "\n")))
7909 (t (insert "#+" keyword " "))))
7911 (defun anything-c-org-keywords-show-help (keyword)
7912 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7913 "(org)In-buffer settings"))
7914 (search-forward (concat "#+" keyword) nil t)
7915 (anything-persistent-highlight-point)
7916 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7920 ;;; bbdb
7923 (defvar bbdb-records)
7924 (defvar bbdb-buffer-name)
7926 (defun anything-c-bbdb-candidates ()
7927 "Return a list of all names in the bbdb database. The format
7928 is \"Firstname Lastname\"."
7929 (mapcar (lambda (bbdb-record)
7930 (replace-regexp-in-string
7931 "\\s-+$" ""
7932 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7933 (bbdb-records)))
7935 (defun anything-c-bbdb-create-contact (actions candidate)
7936 "Action transformer that returns only an entry to add the
7937 current `anything-pattern' as new contact. All other actions are
7938 removed."
7939 (if (string= candidate "*Add to contacts*")
7940 '(("Add to contacts" . (lambda (actions)
7941 (bbdb-create-internal
7942 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7943 (read-from-minibuffer "Company: ")
7944 (read-from-minibuffer "Email: ")
7947 (read-from-minibuffer "Note: ")))))
7948 actions))
7950 (defun anything-c-bbdb-get-record (candidate)
7951 "Return record that match CANDIDATE."
7952 (bbdb candidate nil)
7953 (set-buffer "*BBDB*")
7954 (bbdb-current-record))
7956 (defvar anything-c-bbdb-name nil
7957 "Only for internal use.")
7959 (defvar anything-c-source-bbdb
7960 '((name . "BBDB")
7961 (candidates . anything-c-bbdb-candidates)
7962 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7963 ("View person's data" . anything-c-bbdb-view-person-action))
7964 (filtered-candidate-transformer . (lambda (candidates source)
7965 (setq anything-c-bbdb-name anything-pattern)
7966 (if (not candidates)
7967 (list "*Add to contacts*")
7968 candidates)))
7969 (action-transformer . (lambda (actions candidate)
7970 (anything-c-bbdb-create-contact actions candidate))))
7971 "Needs BBDB.
7973 http://bbdb.sourceforge.net/")
7974 ;; (anything 'anything-c-source-bbdb)
7976 (defun anything-c-bbdb-view-person-action (candidate)
7977 "View BBDB data of single CANDIDATE or marked candidates."
7978 (anything-aif (anything-marked-candidates)
7979 (let ((bbdb-append-records (length it)))
7980 (dolist (i it)
7981 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7982 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7984 (defun anything-c-bbdb-collect-mail-addresses ()
7985 "Return a list of all mail addresses of records in bbdb buffer."
7986 (with-current-buffer bbdb-buffer-name
7987 (loop for i in bbdb-records
7988 if (bbdb-record-net (car i))
7989 collect (bbdb-dwim-net-address (car i)))))
7991 (defun anything-c-bbdb-compose-mail (candidate)
7992 "Compose a mail with all records of bbdb buffer."
7993 (anything-c-bbdb-view-person-action candidate)
7994 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7995 (address-str (mapconcat 'identity address-list ",\n ")))
7996 (compose-mail address-str)))
7999 ;;; Evaluation Result
8002 ;; Internal
8003 (defvar anything-eldoc-active-minibuffers-list nil)
8004 (defvar anything-eval-expression-input-history nil)
8006 (defvar anything-c-source-evaluation-result
8007 '((name . "Evaluation Result")
8008 (disable-shortcuts)
8009 (dummy)
8010 (multiline)
8011 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8012 (filtered-candidate-transformer . (lambda (candidates source)
8013 (list
8014 (condition-case nil
8015 (with-anything-current-buffer
8016 (pp-to-string
8017 (eval (read anything-pattern))))
8018 (error "Error")))))
8019 (action . (("Copy result to kill-ring" . (lambda (candidate)
8020 (with-current-buffer anything-buffer
8021 (let ((end (save-excursion
8022 (goto-char (point-max))
8023 (search-backward "\n")
8024 (point))))
8025 (kill-region (point) end)))))
8026 ("copy sexp to kill-ring" . (lambda (candidate)
8027 (kill-new anything-input)))))))
8028 ;; (anything 'anything-c-source-evaluation-result)
8030 (defun anything-eval-new-line-and-indent ()
8031 (interactive)
8032 (newline) (lisp-indent-line))
8034 (defun anything-eldoc-store-minibuffer ()
8035 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8036 (with-selected-window (minibuffer-window)
8037 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8039 (defun anything-eldoc-show-in-eval ()
8040 "Return eldoc in mode-line for current minibuffer input."
8041 (let ((buf (with-selected-window (minibuffer-window)
8042 (buffer-name))))
8043 (when (member buf anything-eldoc-active-minibuffers-list)
8044 (let* ((str-all (with-current-buffer buf
8045 (minibuffer-completion-contents)))
8046 (sym (when str-all
8047 (with-temp-buffer
8048 (insert str-all)
8049 (goto-char (point-max))
8050 (unless (looking-back ")\\|\"") (forward-char -1))
8051 (eldoc-current-symbol))))
8052 (info-fn (eldoc-fnsym-in-current-sexp))
8053 (doc (or (eldoc-get-var-docstring sym)
8054 (eldoc-get-fnsym-args-string
8055 (car info-fn) (cadr info-fn)))))
8056 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8058 (defun anything-c-eldoc-show-in-mode-line (str)
8059 "Show string STR in mode-line."
8060 (save-window-excursion
8061 (with-current-buffer anything-buffer
8062 (let ((mode-line-format (concat " " str)))
8063 (force-mode-line-update)
8064 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8065 (force-mode-line-update))))
8067 ;;; Calculation Result
8070 (defvar anything-c-source-calculation-result
8071 '((name . "Calculation Result")
8072 (dummy)
8073 (filtered-candidate-transformer . (lambda (candidates source)
8074 (list
8075 (condition-case nil
8076 (calc-eval anything-pattern)
8077 (error "error")))))
8078 (action ("Copy result to kill-ring" . kill-new))))
8079 ;; (anything 'anything-c-source-calculation-result)
8082 ;;; Google Suggestions
8085 ;; Internal
8086 (defvar anything-ggs-max-length-real-flag 0)
8087 (defvar anything-ggs-max-length-num-flag 0)
8089 (defun anything-c-google-suggest-fetch (input)
8090 "Fetch suggestions for INPUT from XML buffer.
8091 Return an alist with elements like (data . number_results)."
8092 (setq anything-ggs-max-length-real-flag 0
8093 anything-ggs-max-length-num-flag 0)
8094 (let ((request (concat anything-c-google-suggest-url
8095 (url-hexify-string input))))
8096 (flet ((fetch ()
8097 (loop
8098 with result-alist = (xml-get-children
8099 (car (xml-parse-region
8100 (point-min) (point-max)))
8101 'CompleteSuggestion)
8102 for i in result-alist
8103 for data = (cdr (caadr (assoc 'suggestion i)))
8104 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8105 for lqueries = (length (anything-c-ggs-set-number-result
8106 nqueries))
8107 for ldata = (length data)
8109 (progn
8110 (when (> ldata anything-ggs-max-length-real-flag)
8111 (setq anything-ggs-max-length-real-flag ldata))
8112 (when (> lqueries anything-ggs-max-length-num-flag)
8113 (setq anything-ggs-max-length-num-flag lqueries)))
8114 collect (cons data nqueries) into cont
8115 finally return cont)))
8116 (if anything-google-suggest-use-curl-p
8117 (with-temp-buffer
8118 (call-process "curl" nil t nil request)
8119 (fetch))
8120 (with-current-buffer
8121 (url-retrieve-synchronously request)
8122 (fetch))))))
8124 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8125 "Set candidates with result and number of google results found."
8126 (let ((suggestions
8127 (loop with suggested-results = (anything-c-google-suggest-fetch
8128 (or (and request-prefix
8129 (concat request-prefix " " anything-pattern))
8130 anything-pattern))
8131 for (real . numresult) in suggested-results
8132 ;; Prepare number of results with ","
8133 for fnumresult = (anything-c-ggs-set-number-result numresult)
8134 ;; Calculate number of spaces to add before fnumresult
8135 ;; if it is smaller than longest result
8136 ;; `anything-ggs-max-length-num-flag'.
8137 ;; e.g 1,234,567
8138 ;; 345,678
8139 ;; To be sure it is aligned properly.
8140 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8141 (- anything-ggs-max-length-num-flag (length fnumresult))
8143 ;; Add now the spaces before fnumresult.
8144 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8145 for interval = (- anything-ggs-max-length-real-flag (length real))
8146 for spaces = (make-string (+ 2 interval) ? )
8147 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8148 collect (cons display real))))
8149 (if (loop for (disp . dat) in suggestions
8150 thereis (equal dat anything-pattern))
8151 suggestions
8152 ;; if there is no suggestion exactly matching the input then
8153 ;; prepend a Search on Google item to the list
8154 (append
8155 suggestions
8156 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8157 anything-input))))))
8159 (defun anything-c-ggs-set-number-result (num)
8160 (if num
8161 (progn
8162 (and (numberp num) (setq num (number-to-string num)))
8163 (loop for i in (reverse (split-string num "" t))
8164 for count from 1
8165 append (list i) into C
8166 when (= count 3)
8167 append (list ",") into C
8168 and do (setq count 0)
8169 finally return
8170 (replace-regexp-in-string
8171 "^," "" (mapconcat 'identity (reverse C) ""))))
8172 "?"))
8174 (defvar anything-c-google-suggest-default-browser-function nil
8175 "*The browse url function you prefer to use with google suggest.
8176 When nil, use the first browser function available
8177 See `anything-browse-url-default-browser-alist'.")
8179 (defun anything-c-google-suggest-action (candidate)
8180 "Default action to jump to a google suggested candidate."
8181 (let ((arg (concat anything-c-google-suggest-search-url
8182 (url-hexify-string candidate))))
8183 (anything-aif anything-c-google-suggest-default-browser-function
8184 (funcall it arg)
8185 (anything-c-browse-url arg))))
8187 (defvar anything-c-google-suggest-default-function
8188 'anything-c-google-suggest-set-candidates
8189 "Default function to use in anything google suggest.")
8191 (defvar anything-c-source-google-suggest
8192 '((name . "Google Suggest")
8193 (candidates . (lambda ()
8194 (funcall anything-c-google-suggest-default-function)))
8195 (action . (("Google Search" . anything-c-google-suggest-action)))
8196 (volatile)
8197 (requires-pattern . 3)
8198 (delayed)))
8200 (defun anything-c-google-suggest-emacs-lisp ()
8201 "Try to emacs lisp complete with google suggestions."
8202 (anything-c-google-suggest-set-candidates "emacs lisp"))
8204 ;; (anything 'anything-c-source-google-suggest)
8206 ;;; Yahoo suggestions
8209 (defun anything-c-yahoo-suggest-fetch (input)
8210 "Fetch Yahoo suggestions for INPUT from XML buffer.
8211 Return an alist with elements like (data . number_results)."
8212 (let ((request (concat anything-c-yahoo-suggest-url
8213 (url-hexify-string input))))
8214 (flet ((fetch ()
8215 (loop
8216 with result-alist = (xml-get-children
8217 (car (xml-parse-region (point-min) (point-max)))
8218 'Result)
8219 for i in result-alist
8220 collect (caddr i))))
8221 (with-current-buffer
8222 (url-retrieve-synchronously request)
8223 (fetch)))))
8225 (defun anything-c-yahoo-suggest-set-candidates ()
8226 "Set candidates with Yahoo results found."
8227 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8228 (or suggestions
8229 (append
8230 suggestions
8231 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8232 anything-input))))))
8234 (defun anything-c-yahoo-suggest-action (candidate)
8235 "Default action to jump to a Yahoo suggested candidate."
8236 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8237 (url-hexify-string candidate))))
8239 (defvar anything-c-source-yahoo-suggest
8240 '((name . "Yahoo Suggest")
8241 (candidates . anything-c-yahoo-suggest-set-candidates)
8242 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8243 (volatile)
8244 (requires-pattern . 3)
8245 (delayed)))
8247 ;; (anything 'anything-c-source-yahoo-suggest)
8250 ;;; Web browser functions.
8253 (require 'browse-url)
8254 ;; If default setting of `w3m-command' is not
8255 ;; what you want you and you modify it, you will have to reeval
8256 ;; also `anything-browse-url-default-browser-alist'.
8257 (defvar w3m-command "/usr/bin/w3m")
8258 (defvar anything-c-home-url "http://www.google.fr"
8259 "*Default url to use as home url.")
8261 (defvar ac-browse-url-chromium-program "chromium-browser")
8262 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8263 (defvar anything-browse-url-default-browser-alist
8264 `((,w3m-command . w3m-browse-url)
8265 (,browse-url-firefox-program . browse-url-firefox)
8266 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8267 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8268 (,browse-url-kde-program . browse-url-kde)
8269 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8270 (,browse-url-mozilla-program . browse-url-mozilla)
8271 (,browse-url-galeon-program . browse-url-galeon)
8272 (,browse-url-netscape-program . browse-url-netscape)
8273 (,browse-url-mosaic-program . browse-url-mosaic)
8274 (,browse-url-xterm-program . browse-url-text-xterm))
8275 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8277 (defun* anything-c-generic-browser (url name &rest args)
8278 "Browse URL with NAME browser."
8279 (let ((proc (concat name " " url)))
8280 (message "Starting %s..." name)
8281 (apply 'start-process proc nil name
8282 (append args (list url)))
8283 (set-process-sentinel
8284 (get-process proc)
8285 #'(lambda (process event)
8286 (when (string= event "finished\n")
8287 (message "%s process %s" process event))))))
8289 (defun ac-browse-url-chromium (url)
8290 "Browse URL with google chrome browser."
8291 (interactive "sURL: ")
8292 (anything-c-generic-browser
8293 url ac-browse-url-chromium-program))
8295 (defun ac-browse-url-uzbl (url &optional ignore)
8296 "Browse URL with uzbl browser."
8297 (interactive "sURL: ")
8298 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8300 (defun anything-browse-url-default-browser (url &rest args)
8301 "Find the first available browser and ask it to load URL."
8302 (let ((default-browser-fn
8303 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8304 thereis (and exe (executable-find exe) fn))))
8305 (if default-browser-fn
8306 (apply default-browser-fn url args)
8307 (error "No usable browser found"))))
8309 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8310 "Default command to browse URL."
8311 (if browse-url-browser-function
8312 (browse-url url)
8313 (anything-browse-url-default-browser url)))
8316 ;;; Surfraw
8318 ;; Need external program surfraw.
8319 ;; <http://surfraw.alioth.debian.org/>
8321 (defvar anything-surfraw-default-browser-function nil
8322 "*The browse url function you prefer to use with surfraw.
8323 When nil, fallback to `browse-url-browser-function'.")
8325 ;; Internal
8326 (defvar anything-surfraw-engines-history nil)
8327 (defvar anything-surfraw-input-history nil)
8329 (defun anything-c-build-elvi-list ()
8330 "Return list of all engines and descriptions handled by surfraw."
8331 (cdr
8332 (with-temp-buffer
8333 (call-process "surfraw" nil t nil
8334 "-elvi")
8335 (split-string (buffer-string) "\n"))))
8338 ;;; Emms
8341 (defun anything-emms-stream-edit-bookmark (elm)
8342 "Change the information of current emms-stream bookmark from anything."
8343 (declare (special emms-stream-list))
8344 (let* ((cur-buf anything-current-buffer)
8345 (bookmark (assoc elm emms-stream-list))
8346 (name (read-from-minibuffer "Description: "
8347 (nth 0 bookmark)))
8348 (url (read-from-minibuffer "URL: "
8349 (nth 1 bookmark)))
8350 (fd (read-from-minibuffer "Feed Descriptor: "
8351 (int-to-string (nth 2 bookmark))))
8352 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8353 (format "%s" (car (last bookmark))))))
8354 (save-excursion
8355 (emms-streams)
8356 (when (re-search-forward (concat "^" name) nil t)
8357 (beginning-of-line)
8358 (emms-stream-delete-bookmark)
8359 (emms-stream-add-bookmark name url (string-to-number fd) type)
8360 (emms-stream-save-bookmarks-file)
8361 (emms-stream-quit)
8362 (anything-c-switch-to-buffer cur-buf)))))
8364 (defun anything-emms-stream-delete-bookmark (elm)
8365 "Delete an emms-stream bookmark from anything."
8366 (let* ((cur-buf anything-current-buffer)
8367 (bookmark (assoc elm emms-stream-list))
8368 (name (nth 0 bookmark)))
8369 (save-excursion
8370 (emms-streams)
8371 (when (re-search-forward (concat "^" name) nil t)
8372 (beginning-of-line)
8373 (emms-stream-delete-bookmark)
8374 (emms-stream-save-bookmarks-file)
8375 (emms-stream-quit)
8376 (anything-c-switch-to-buffer cur-buf)))))
8378 (defvar anything-c-source-emms-streams
8379 '((name . "Emms Streams")
8380 (init . (lambda ()
8381 (emms-stream-init)))
8382 (candidates . (lambda ()
8383 (declare (special emms-stream-list))
8384 (mapcar 'car emms-stream-list)))
8385 (action . (("Play" . (lambda (elm)
8386 (declare (special emms-stream-list))
8387 (let* ((stream (assoc elm emms-stream-list))
8388 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8389 (url (second stream)))
8390 (funcall fn url))))
8391 ("Delete" . anything-emms-stream-delete-bookmark)
8392 ("Edit" . anything-emms-stream-edit-bookmark)))
8393 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8394 ;; (anything 'anything-c-source-emms-streams)
8396 ;; Don't forget to set `emms-source-file-default-directory'
8397 (defvar anything-c-source-emms-dired
8398 '((name . "Music Directory")
8399 (candidates . (lambda ()
8400 (cddr (directory-files emms-source-file-default-directory))))
8401 (action .
8402 (("Play Directory" . (lambda (item)
8403 (emms-play-directory
8404 (expand-file-name
8405 item
8406 emms-source-file-default-directory))))
8407 ("Open dired in file's directory" . (lambda (item)
8408 (anything-c-open-dired
8409 (expand-file-name
8410 item
8411 emms-source-file-default-directory))))))
8412 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8413 ;; (anything 'anything-c-source-emms-dired)
8416 (defun anything-c-emms-files-modifier (candidates source)
8417 (let ((current-playlist (with-current-emms-playlist
8418 (loop
8419 with cur-list = (emms-playlist-tracks-in-region
8420 (point-min) (point-max))
8421 for i in cur-list
8422 collect (assoc-default 'name i)))))
8423 (loop for i in candidates
8424 if (member (cdr i) current-playlist)
8425 collect (cons (propertize (car i)
8426 'face 'anything-emms-playlist)
8427 (cdr i)) into lis
8428 else collect i into lis
8429 finally return lis)))
8431 (defun anything-c-emms-play-current-playlist ()
8432 "Play current playlist."
8433 (with-current-emms-playlist
8434 (emms-playlist-first)
8435 (emms-playlist-mode-play-smart)))
8437 (defvar anything-c-source-emms-files
8438 '((name . "Emms files")
8439 (candidates . (lambda ()
8440 (loop for v being the hash-values in emms-cache-db
8441 for name = (assoc-default 'name v)
8442 for artist = (or (assoc-default 'info-artist v) "unknown")
8443 for genre = (or (assoc-default 'info-genre v) "unknown")
8444 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8445 for song = (or (assoc-default 'info-title v) "unknown")
8446 for info = (concat artist " - " genre " - " tracknum ": " song)
8447 unless (string-match "^http:" name) collect (cons info name))))
8448 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8449 (action . (("Play file" . emms-play-file)
8450 ("Add to Playlist and play (C-u clear current)"
8451 . (lambda (candidate)
8452 (when anything-current-prefix-arg
8453 (emms-playlist-current-clear))
8454 (emms-playlist-new)
8455 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8456 (unless emms-player-playing-p
8457 (anything-c-emms-play-current-playlist))))))))
8459 ;; (anything 'anything-c-source-emms-files)
8462 ;;; Jabber Contacts (jabber.el)
8463 (defun anything-c-jabber-online-contacts ()
8464 "List online Jabber contacts."
8465 (with-no-warnings
8466 (let (jids)
8467 (dolist (item (jabber-concat-rosters) jids)
8468 (when (get item 'connected)
8469 (push (if (get item 'name)
8470 (cons (get item 'name) item)
8471 (cons (symbol-name item) item)) jids))))))
8473 (defvar anything-c-source-jabber-contacts
8474 '((name . "Jabber Contacts")
8475 (init . (lambda () (require 'jabber)))
8476 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8477 (action . (lambda (x)
8478 (jabber-chat-with
8479 (jabber-read-account)
8480 (symbol-name
8481 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8482 ;; (anything 'anything-c-source-jabber-contacts)
8486 ;;; Call source.
8487 (defvar anything-source-select-buffer "*anything source select*")
8488 (defvar anything-c-source-call-source
8489 `((name . "Call anything source")
8490 (candidate-number-limit)
8491 (candidates
8492 . (lambda ()
8493 (loop for vname in (all-completions "anything-c-source-" obarray)
8494 for var = (intern vname)
8495 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8496 if name collect
8497 (cons (format "%s `%s'"
8498 name (propertize vname 'face 'font-lock-variable-name-face))
8499 var))))
8500 (action
8501 . (("Invoke anything with selected source"
8503 (lambda (candidate)
8504 (setq anything-candidate-number-limit 9999)
8505 (anything candidate nil nil nil nil
8506 anything-source-select-buffer)))
8507 ("Describe variable" . describe-variable)
8508 ("Find variable" . find-variable)))
8509 (persistent-action . describe-variable)
8510 (persistent-help . "Show description of this source")))
8511 ;; (anything 'anything-c-source-call-source)
8513 (defun anything-call-source-from-anything ()
8514 "Call anything source within `anything' session."
8515 (interactive)
8516 (setq anything-input-idle-delay 0)
8517 (anything-set-sources '(anything-c-source-call-source)))
8519 ;;; Execute Preconfigured anything.
8520 (defvar anything-c-source-anything-commands
8521 '((name . "Preconfigured Anything")
8522 (candidates . anything-c-anything-commands-candidates)
8523 (type . command)
8524 (candidate-number-limit)))
8525 ;; (anything 'anything-c-source-anything-commands)
8527 (defun anything-c-anything-commands-candidates ()
8528 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8529 collect (cons (if (where-is-internal cmd nil t)
8530 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8531 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8532 cmd)))
8535 ;;; Occur
8538 (defun anything-c-occur-init ()
8539 "Create the initial anything occur buffer.
8540 If region is active use region as buffer contents
8541 instead of whole buffer."
8542 (with-current-buffer (anything-candidate-buffer 'global)
8543 (erase-buffer)
8544 (let ((buf-contents
8545 (with-anything-current-buffer
8546 (if (anything-region-active-p)
8547 (buffer-substring (region-beginning) (region-end))
8548 (buffer-substring (point-min) (point-max))))))
8549 (insert buf-contents))))
8551 (defun anything-c-occur-get-line (s e)
8552 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8554 (defun anything-c-occur-query-replace-regexp (candidate)
8555 "Query replace regexp starting from CANDIDATE.
8556 If region is active ignore CANDIDATE and replace only in region.
8557 With a prefix arg replace only matches surrounded by word boundaries,
8558 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8559 (let ((regexp anything-input))
8560 (unless (anything-region-active-p)
8561 (anything-c-action-line-goto candidate))
8562 (apply 'query-replace-regexp
8563 (anything-c-query-replace-args regexp))))
8565 (defvar anything-c-source-occur
8566 '((name . "Occur")
8567 (init . anything-c-occur-init)
8568 (candidates-in-buffer)
8569 (migemo)
8570 (get-line . anything-c-occur-get-line)
8571 (display-to-real . anything-c-display-to-real-line)
8572 (action . (("Go to Line" . anything-c-action-line-goto)
8573 ("Query replace regexp (C-u Not inside word.)"
8574 . anything-c-occur-query-replace-regexp)))
8575 (recenter)
8576 (requires-pattern . 1)
8577 (delayed)
8578 (volatile)))
8579 ;; (anything 'anything-c-source-occur)
8582 ;;; Anything browse code.
8583 (defun anything-c-browse-code-get-line (beg end)
8584 "Select line if it match the regexp corresponding to current `major-mode'.
8585 Line is parsed for BEG position to END position."
8586 (let ((str-line (buffer-substring beg end))
8587 (regexp (assoc-default major-mode
8588 anything-c-browse-code-regexp-alist))
8589 (num-line (if (string= anything-pattern "") beg (1- beg))))
8590 (when (and regexp (string-match regexp str-line))
8591 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8594 (defvar anything-c-source-browse-code
8595 '((name . "Browse code")
8596 (init . (lambda ()
8597 (anything-candidate-buffer anything-current-buffer)
8598 (with-anything-current-buffer
8599 (jit-lock-fontify-now))))
8600 (candidate-number-limit . 9999)
8601 (candidates-in-buffer)
8602 (get-line . anything-c-browse-code-get-line)
8603 (type . line)
8604 (recenter)))
8607 ;; Do many actions for input
8608 (defvar anything-c-source-create
8609 '((name . "Create")
8610 (dummy)
8611 (action)
8612 (action-transformer . anything-create--actions))
8613 "Do many create actions from `anything-pattern'.
8614 See also `anything-create--actions'.")
8615 ;; (anything 'anything-c-source-create)
8617 (defun anything-create-from-anything ()
8618 "Run `anything-create' from `anything' as a fallback."
8619 (interactive)
8620 (anything-run-after-quit 'anything-create nil anything-pattern))
8622 (defun anything-create--actions (&rest ignored)
8623 "Default actions for `anything-create' / `anything-c-source-create'."
8624 (remove-if-not
8625 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8626 (append anything-create--actions-private
8627 '(("find-file" . find-file)
8628 ("find-file other window" . find-file-other-window)
8629 ("New buffer" . anything-c-switch-to-buffer)
8630 ("New buffer other window" . switch-to-buffer-other-window)
8631 ("Bookmark Set" . bookmark-set)
8632 ("Set Register" .
8633 (lambda (x) (set-register (read-char "Register: ") x)))
8634 ("Insert Linkd star" . linkd-insert-star)
8635 ("Insert Linkd Tag" . linkd-insert-tag)
8636 ("Insert Linkd Link" . linkd-insert-link)
8637 ("Insert Linkd Lisp" . linkd-insert-lisp)
8638 ("Insert Linkd Wiki" . linkd-insert-wiki)
8639 ("Google Search" . google)))))
8642 ;; Minibuffer History
8645 (defvar anything-c-source-minibuffer-history
8646 '((name . "Minibuffer History")
8647 (header-name . (lambda (name)
8648 (format "%s (%s)" name minibuffer-history-variable)))
8649 (candidates
8650 . (lambda ()
8651 (let ((history (loop
8652 for i in (symbol-value minibuffer-history-variable)
8653 unless (string= "" i) collect i)))
8654 (if (consp (car history))
8655 (mapcar 'prin1-to-string history)
8656 history))))
8657 (migemo)
8658 (action . insert)))
8659 ;; (anything 'anything-c-source-minibuffer-history)
8662 ;;; Elscreen
8665 (defvar anything-c-source-elscreen
8666 '((name . "Elscreen")
8667 (candidates . (lambda ()
8668 (if (cdr (elscreen-get-screen-to-name-alist))
8669 (sort
8670 (loop for sname in (elscreen-get-screen-to-name-alist)
8671 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8672 finally (return lst))
8673 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8674 (action . (("Change Screen".
8675 (lambda (candidate)
8676 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8677 ("Kill Screen(s)".
8678 (lambda (candidate)
8679 (dolist (i (anything-marked-candidates))
8680 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8681 (elscreen-kill))))
8682 ("Only Screen".
8683 (lambda (candidate)
8684 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8685 (elscreen-kill-others)))))))
8686 ;; (anything 'anything-c-source-elscreen)
8689 ;;;; <System>
8691 ;;; Top (process)
8692 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8693 "Top command (batch mode). %s is replaced with `frame-width'.")
8694 (defvar anything-c-source-top
8695 '((name . "Top (Press C-c C-u to refresh)")
8696 (init . anything-c-top-init)
8697 (candidates-in-buffer)
8698 (display-to-real . anything-c-top-display-to-real)
8699 (update . anything-c-top-update)
8700 (persistent-action . anything-c-top-sh-persistent-action)
8701 (persistent-help . "SIGTERM")
8702 (action
8703 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8704 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8705 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8706 ;; (anything 'anything-c-source-top)
8708 (defun anything-c-top-sh (cmd)
8709 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8711 (defun anything-c-top-sh-persistent-action (pid)
8712 (delete-other-windows)
8713 (anything-c-top-sh (format "kill -TERM %s" pid))
8714 (anything-force-update))
8716 (defun anything-c-top-init ()
8717 (with-current-buffer (anything-candidate-buffer 'global)
8718 (call-process-shell-command
8719 (format anything-c-top-command
8720 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8721 nil (current-buffer))))
8723 (defun anything-c-top-display-to-real (line)
8724 (car (split-string line)))
8726 (defun anything-c-top-update ()
8727 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8728 (anything-c-top-init)))
8730 ;;; Timers
8731 (defvar anything-c-source-absolute-time-timers
8732 '((name . "Absolute Time Timers")
8733 (candidates . timer-list)
8734 (type . timer)))
8735 ;; (anything 'anything-c-source-absolute-time-timers)
8737 (defvar anything-c-source-idle-time-timers
8738 '((name . "Idle Time Timers")
8739 (candidates . timer-idle-list)
8740 (type . timer)))
8741 ;; (anything 'anything-c-source-idle-time-timers)
8743 (defun anything-c-timer-real-to-display (timer)
8744 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8745 (append timer nil) ;use `append' to convert vector->list
8746 (format "%s repeat=%5S %s(%s)"
8747 (let ((time (list t1 t2 t3)))
8748 (if idle-delay
8749 (format-time-string "idle-for=%5s" time)
8750 (format-time-string "%m/%d %T" time)))
8751 repeat-delay
8752 func
8753 (mapconcat 'prin1-to-string args " "))))
8755 ;;; X RandR resolution change
8756 ;;; FIXME I do not care multi-display.
8757 (defvar anything-c-xrandr-output "VGA")
8758 (defvar anything-c-xrandr-screen "0")
8759 (defvar anything-c-source-xrandr-change-resolution
8760 '((name . "Change Resolution")
8761 (candidates
8762 . (lambda ()
8763 (with-temp-buffer
8764 (call-process "xrandr" nil (current-buffer) nil
8765 "--screen" anything-c-xrandr-screen "-q")
8766 (goto-char 1)
8767 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8768 collect (match-string 1)))))
8769 (action
8770 ("Change Resolution" . (lambda (mode)
8771 (call-process "xrandr" nil nil nil
8772 "--screen" anything-c-xrandr-screen
8773 "--output" anything-c-xrandr-output
8774 "--mode" mode))))))
8775 ;; (anything 'anything-c-source-xrandr-change-resolution)
8777 ;;; Xfont selection
8780 (defun anything-c-persistent-xfont-action (elm)
8781 "Show current font temporarily"
8782 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8783 (default-font elm))
8784 (unwind-protect
8785 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8786 (set-frame-font current-font))))
8788 (defvar anything-c-xfonts-cache nil)
8789 (defvar anything-c-source-xfonts
8790 '((name . "X Fonts")
8791 (init . (lambda ()
8792 (unless anything-c-xfonts-cache
8793 (setq anything-c-xfonts-cache
8794 (x-list-fonts "*")))))
8795 (candidates . anything-c-xfonts-cache)
8796 (action . (("Copy to kill ring" . (lambda (elm)
8797 (kill-new elm)))
8798 ("Set Font" . (lambda (elm)
8799 (kill-new elm)
8800 (set-frame-font elm 'keep-size)
8801 (message "New font have been copied to kill ring")))))
8802 (persistent-action . anything-c-persistent-xfont-action)
8803 (persistent-help . "Switch to this font temporarily")))
8804 ;; (anything 'anything-c-source-xfonts)
8806 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8809 (defvar anything-c-ucs-max-len 0)
8810 (defun anything-c-calculate-ucs-max-len ()
8811 "Calculate the length of longest `ucs-names' candidate."
8812 (loop with count = 0
8813 for (n . v) in (ucs-names)
8814 for len = (length n)
8815 if (> len count)
8816 do (setq count len)
8817 finally return count))
8819 (defun anything-c-ucs-init ()
8820 "Initialize an anything buffer with ucs symbols.
8821 Only math* symbols are collected."
8822 (unless (> anything-c-ucs-max-len 0)
8823 (setq anything-c-ucs-max-len
8824 (anything-c-calculate-ucs-max-len)))
8825 (with-current-buffer (anything-candidate-buffer
8826 (get-buffer-create "*anything ucs*"))
8827 ;; `ucs-names' fn will not run again, data is cached in
8828 ;; var `ucs-names'.
8829 (loop for (n . v) in (ucs-names)
8830 for len = (length n)
8831 for diff = (+ (- anything-c-ucs-max-len len) 2)
8832 unless (string= "" n)
8833 do (progn (insert (concat
8834 n ":"
8835 (make-string
8836 diff ? )))
8837 (ucs-insert v)
8838 (insert "\n")))))
8840 (defun anything-c-ucs-forward-char (candidate)
8841 (with-anything-current-buffer
8842 (forward-char 1)))
8844 (defun anything-c-ucs-backward-char (candidate)
8845 (with-anything-current-buffer
8846 (forward-char -1)))
8848 (defun anything-c-ucs-delete-backward (candidate)
8849 (with-anything-current-buffer
8850 (delete-char -1)))
8852 (defun anything-c-ucs-insert-char (candidate)
8853 (with-anything-current-buffer
8854 (insert
8855 (replace-regexp-in-string
8856 " " ""
8857 (cadr (split-string candidate ":"))))))
8859 (defun anything-c-ucs-persistent-insert ()
8860 (interactive)
8861 (anything-execute-persistent-action 'action-insert))
8863 (defun anything-c-ucs-persistent-forward ()
8864 (interactive)
8865 (anything-execute-persistent-action 'action-forward))
8867 (defun anything-c-ucs-persistent-backward ()
8868 (interactive)
8869 (anything-execute-persistent-action 'action-back))
8871 (defun anything-c-ucs-persistent-delete ()
8872 (interactive)
8873 (anything-execute-persistent-action 'action-delete))
8875 (defvar anything-c-source-ucs
8876 '((name . "Ucs names")
8877 (init . anything-c-ucs-init)
8878 (candidate-number-limit . 9999)
8879 (candidates-in-buffer)
8880 (mode-line . anything-c-ucs-mode-line-string)
8881 (action-insert . anything-c-ucs-insert-char)
8882 (action-forward . anything-c-ucs-forward-char)
8883 (action-back . anything-c-ucs-backward-char)
8884 (action-delete . anything-c-ucs-delete-backward)
8885 (action . (("Insert" . anything-c-ucs-insert-char)
8886 ("Forward char" . anything-c-ucs-forward-char)
8887 ("Backward char" . anything-c-ucs-backward-char)
8888 ("Delete char backward" . anything-c-ucs-delete-backward))))
8889 "Source for collecting `ucs-names' math symbols.")
8892 ;;; Emacs process
8895 (defvar anything-c-source-emacs-process
8896 '((name . "Emacs Process")
8897 (candidates . (lambda () (mapcar #'process-name (process-list))))
8898 (persistent-action . (lambda (elm)
8899 (delete-process (get-process elm))
8900 (anything-delete-current-selection)))
8901 (persistent-help . "Kill Process")
8902 (action ("Kill Process" . (lambda (elm)
8903 (delete-process (get-process elm)))))))
8904 ;; (anything 'anything-c-source-emacs-process)
8906 ;;; World time
8909 (defvar anything-c-source-time-world
8910 '((name . "Time World List")
8911 (init . (lambda ()
8912 (let ((anything-buffer (anything-candidate-buffer 'global)))
8913 (with-current-buffer anything-buffer
8914 (display-time-world-display display-time-world-list)))))
8915 (candidates-in-buffer)))
8919 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8922 (defvar anything-c-source-apt
8923 '((name . "APT")
8924 (init . anything-c-apt-init)
8925 (candidates-in-buffer)
8926 (candidate-transformer anything-c-apt-candidate-transformer)
8927 (display-to-real . anything-c-apt-display-to-real)
8928 (requires-pattern . 2)
8929 (update . anything-c-apt-refresh)
8930 (action
8931 ("Show package description" . anything-c-apt-cache-show)
8932 ("Install package" . anything-c-apt-install)
8933 ("Remove package" . anything-c-apt-uninstall)
8934 ("Purge package" . anything-c-apt-purge))
8935 (persistent-action . anything-c-apt-persistent-action)
8936 (persistent-help . "Show package description")))
8937 ;; (anything 'anything-c-source-apt)
8939 (defvar anything-c-apt-query "emacs")
8940 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8941 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8942 (defvar anything-c-apt-installed-packages nil)
8943 (defvar anything-c-apt-all-packages nil)
8944 (defvar anything-c-apt-input-history nil)
8946 (defun anything-c-apt-refresh ()
8947 "Refresh installed candidates list."
8948 (setq anything-c-apt-installed-packages nil)
8949 (setq anything-c-apt-all-packages nil))
8951 (defun anything-c-apt-persistent-action (candidate)
8952 "Persistent action for APT source."
8953 (anything-c-apt-cache-show candidate))
8955 (defun anything-c-apt-candidate-transformer (candidates)
8956 "Show installed candidates in a different color."
8957 (loop
8958 with all
8959 for cand in candidates
8960 for name = (anything-c-apt-display-to-real cand)
8961 if (member name anything-c-apt-installed-packages)
8962 collect (propertize cand 'face 'anything-apt-installed) into all
8963 else collect cand into all finally return all))
8965 (defun anything-c-apt-init ()
8966 "Initialize list of debian packages."
8967 (let ((query ""))
8968 (unless (and anything-c-apt-installed-packages
8969 anything-c-apt-all-packages)
8970 (message "Loading package list...")
8971 (setq anything-c-apt-installed-packages
8972 (with-temp-buffer
8973 (call-process-shell-command "dpkg --get-selections"
8974 nil (current-buffer))
8975 (loop for i in (split-string (buffer-string) "\n" t)
8976 collect (car (split-string i)))))
8977 (setq anything-c-apt-all-packages
8978 (with-current-buffer
8979 (anything-candidate-buffer
8980 (get-buffer-create (format "*anything-apt*")))
8981 (erase-buffer)
8982 (call-process-shell-command
8983 (format anything-c-apt-search-command query)
8984 nil (current-buffer))))
8985 (message "Loading package list done")
8986 (sit-for 0.5))))
8988 (defun anything-c-apt-display-to-real (line)
8989 "Return only name of a debian package.
8990 LINE is displayed like:
8991 package name - description."
8992 (car (split-string line " - ")))
8994 (defun anything-c-shell-command-if-needed (command)
8995 "Run shell command COMMAND to describe package.
8996 If a buffer named COMMAND already exists, just switch to it."
8997 (let ((buf (get-buffer command)))
8998 (anything-c-switch-to-buffer (get-buffer-create command))
8999 (unless buf (insert (shell-command-to-string command)))))
9001 (defun anything-c-apt-cache-show (package)
9002 "Show information on apt package PACKAGE."
9003 (anything-c-shell-command-if-needed
9004 (format anything-c-apt-show-command package)))
9006 (defun anything-c-apt-install (package)
9007 "Run 'apt-get install' shell command on PACKAGE."
9008 (anything-c-apt-generic-action :action 'install))
9010 (defun anything-c-apt-uninstall (package)
9011 "Run 'apt-get remove' shell command on PACKAGE."
9012 (anything-c-apt-generic-action :action 'uninstall))
9014 (defun anything-c-apt-purge (package)
9015 "Run 'apt-get purge' shell command on PACKAGE."
9016 (anything-c-apt-generic-action :action 'purge))
9018 (defun* anything-c-apt-generic-action (&key action)
9019 "Run 'apt-get ACTION'.
9020 Support install, remove and purge actions."
9021 (ansi-term (getenv "SHELL") "anything apt")
9022 (term-line-mode)
9023 (let ((command (case action
9024 ('install "sudo apt-get install ")
9025 ('uninstall "sudo apt-get remove ")
9026 ('purge "sudo apt-get purge ")
9027 (t (error "Unknow action"))))
9028 (beg (point))
9030 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9031 (anything-marked-candidates) " ")))
9032 (goto-char (point-max))
9033 (insert (concat command cand-list))
9034 (setq end (point))
9035 (if (y-or-n-p (format "%s package" (symbol-name action)))
9036 (progn
9037 (setq anything-c-external-commands-list nil)
9038 (setq anything-c-apt-installed-packages nil)
9039 (term-char-mode) (term-send-input))
9040 (delete-region beg end) (term-send-eof) (kill-buffer))))
9042 ;; (anything-c-apt-install "jed")
9045 ;;; Anything UI for gentoo portage.
9048 (defvar anything-c-gentoo-use-flags nil)
9049 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9050 (defvar anything-c-cache-gentoo nil)
9051 (defvar anything-c-cache-world nil)
9052 (defvar anything-c-source-gentoo
9053 '((name . "Portage sources")
9054 (init . (lambda ()
9055 (get-buffer-create anything-c-gentoo-buffer)
9056 (unless anything-c-cache-gentoo
9057 (anything-c-gentoo-setup-cache))
9058 (unless anything-c-cache-world
9059 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9060 (anything-c-gentoo-init-list)))
9061 (candidates-in-buffer)
9062 (match . identity)
9063 (candidate-transformer anything-c-highlight-world)
9064 (action . (("Show package" . (lambda (elm)
9065 (anything-c-gentoo-eshell-action elm "eix")))
9066 ("Show history" . (lambda (elm)
9067 (if (member elm anything-c-cache-world)
9068 (anything-c-gentoo-eshell-action elm "genlop -qe")
9069 (message "No infos on packages not yet installed"))))
9070 ("Copy in kill-ring" . kill-new)
9071 ("insert at point" . insert)
9072 ("Browse HomePage" . (lambda (elm)
9073 (let ((urls (anything-c-gentoo-get-url elm)))
9074 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9075 ("Show extra infos" . (lambda (elm)
9076 (if (member elm anything-c-cache-world)
9077 (anything-c-gentoo-eshell-action elm "genlop -qi")
9078 (message "No infos on packages not yet installed"))))
9079 ("Show use flags" . (lambda (elm)
9080 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9081 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9082 (font-lock-mode 1)))
9083 ("Run emerge pretend" . (lambda (elm)
9084 (anything-c-gentoo-eshell-action elm "emerge -p")))
9085 ("Emerge" . (lambda (elm)
9086 (anything-gentoo-install elm :action 'install)))
9087 ("Unmerge" . (lambda (elm)
9088 (anything-gentoo-install elm :action 'uninstall)))
9089 ("Show dependencies" . (lambda (elm)
9090 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9091 ("Show related files" . (lambda (elm)
9092 (anything-c-gentoo-default-action elm "equery" "files")))
9093 ("Refresh" . (lambda (elm)
9094 (anything-c-gentoo-setup-cache)
9095 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9097 ;; (anything 'anything-c-source-gentoo)
9099 (defun* anything-gentoo-install (candidate &key action)
9100 (setq anything-c-external-commands-list nil)
9101 (ansi-term (getenv "SHELL") "Gentoo emerge")
9102 (term-line-mode)
9103 (let ((command (case action
9104 ('install "sudo emerge -av ")
9105 ('uninstall "sudo emerge -avC ")
9106 (t (error "Unknow action"))))
9107 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9108 (beg (point)) end)
9109 (goto-char (point-max))
9110 (insert (concat command elms))
9111 (setq end (point))
9112 (term-char-mode) (term-send-input)))
9114 (defun anything-c-gentoo-default-action (elm command &rest args)
9115 "Gentoo default action that use `anything-c-gentoo-buffer'."
9116 (if (member elm anything-c-cache-world)
9117 (progn
9118 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9119 (erase-buffer)
9120 (let ((com-list (append args (list elm))))
9121 (apply #'call-process command nil t nil
9122 com-list)))
9123 (message "No infos on packages not yet installed")))
9125 (defvar anything-c-source-use-flags
9126 '((name . "Use Flags")
9127 (init . (lambda ()
9128 (unless anything-c-gentoo-use-flags
9129 (anything-c-gentoo-setup-use-flags-cache))
9130 (anything-c-gentoo-get-use)))
9131 (candidates-in-buffer)
9132 (match . identity)
9133 (candidate-transformer anything-c-highlight-local-use)
9134 (action . (("Description"
9135 . (lambda (elm)
9136 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9137 (erase-buffer)
9138 (apply #'call-process "euse" nil t nil
9139 `("-i"
9140 ,elm))
9141 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9142 (font-lock-mode 1)))
9143 ("Enable"
9144 . (lambda (elm)
9145 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9146 ("Disable"
9147 . (lambda (elm)
9148 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9149 ("Remove"
9150 . (lambda (elm)
9151 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9152 ("Show which dep use this flag"
9153 . (lambda (elm)
9154 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9155 (erase-buffer)
9156 (apply #'call-process "equery" nil t nil
9157 `("-C"
9159 ,elm))))))))
9162 ;; (anything 'anything-c-source-use-flags)
9164 (defun anything-c-gentoo-init-list ()
9165 "Initialize buffer with all packages in Portage."
9166 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9167 (buf (anything-candidate-buffer 'portage-buf)))
9168 (with-current-buffer buf
9169 (dolist (i anything-c-cache-gentoo)
9170 (insert (concat i "\n"))))))
9172 (defun anything-c-gentoo-setup-cache ()
9173 "Set up `anything-c-cache-gentoo'"
9174 (setq anything-c-cache-gentoo
9175 (split-string (with-temp-buffer
9176 (call-process "eix" nil t nil
9177 "--only-names")
9178 (buffer-string)))))
9180 (defun anything-c-gentoo-eshell-action (elm command)
9181 (when (get-buffer "*EShell Command Output*")
9182 (kill-buffer "*EShell Command Output*"))
9183 (message "Wait searching...")
9184 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9185 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9186 (progn
9187 (save-window-excursion
9188 (pop-to-buffer "*scratch*")
9189 (eshell-command (format "%s %s" command elm)))
9190 (pop-to-buffer "*EShell Command Output*"))
9191 (eshell-command (format "%s %s" command elm)))))
9193 (defun anything-c-gentoo-get-use ()
9194 "Initialize buffer with all use flags."
9195 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9196 (buf (anything-candidate-buffer 'use-buf)))
9197 (with-current-buffer buf
9198 (dolist (i anything-c-gentoo-use-flags)
9199 (insert (concat i "\n"))))))
9202 (defun anything-c-gentoo-setup-use-flags-cache ()
9203 "Setup `anything-c-gentoo-use-flags'"
9204 (setq anything-c-gentoo-use-flags
9205 (split-string (with-temp-buffer
9206 (call-process "eix" nil t nil
9207 "--print-all-useflags")
9208 (buffer-string)))))
9210 (defun anything-c-gentoo-get-url (elm)
9211 "Return a list of urls from eix output."
9212 (loop
9213 with url-list = (split-string
9214 (with-temp-buffer
9215 (call-process "eix" nil t nil
9216 elm "--format" "<homepage>\n")
9217 (buffer-string)))
9218 with all
9219 for i in url-list
9220 when (and (string-match "^http://.*" i)
9221 (not (member i all)))
9222 collect i into all
9223 finally return all))
9225 (defun anything-c-gentoo-get-world ()
9226 "Return list of all installed package on your system."
9227 (split-string (with-temp-buffer
9228 (call-process "qlist" nil t nil
9229 "-I")
9230 (buffer-string))))
9232 (defun anything-c-gentoo-get-local-use ()
9233 (split-string (with-temp-buffer
9234 (call-process "portageq" nil t nil
9235 "envvar"
9236 "USE")
9237 (buffer-string))))
9240 (defun anything-c-highlight-world (eix)
9241 "Highlight all installed package."
9242 (loop for i in eix
9243 if (member i anything-c-cache-world)
9244 collect (propertize i 'face 'anything-gentoo-match-face)
9245 else
9246 collect i))
9248 (defun anything-c-highlight-local-use (use-flags)
9249 (let ((local-uses (anything-c-gentoo-get-local-use)))
9250 (loop for i in use-flags
9251 if (member i local-uses)
9252 collect (propertize i 'face 'anything-gentoo-match-face)
9253 else
9254 collect i)))
9258 ;;; Anything ratpoison UI
9261 (defvar anything-c-source-ratpoison-commands
9262 '((name . "Ratpoison Commands")
9263 (init . anything-c-ratpoison-commands-init)
9264 (candidates-in-buffer)
9265 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9266 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9267 (candidate-number-limit)))
9268 ;; (anything 'anything-c-source-ratpoison-commands)
9270 (defun anything-c-ratpoison-commands-init ()
9271 (unless (anything-candidate-buffer)
9272 (with-current-buffer (anything-candidate-buffer 'global)
9273 ;; with ratpoison prefix key
9274 (save-excursion
9275 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9276 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9277 (replace-match "<ratpoison> \\1: \\2"))
9278 (goto-char (point-max))
9279 ;; direct binding
9280 (save-excursion
9281 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9282 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9283 (replace-match "\\1: \\2")))))
9285 (defun anything-c-ratpoison-commands-display-to-real (display)
9286 (and (string-match ": " display)
9287 (substring display (match-end 0))))
9289 (defun anything-c-ratpoison-commands-execute (candidate)
9290 (call-process "ratpoison" nil nil nil "-ic" candidate))
9294 ;;; Anything `completing-read' replacement
9297 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9298 "Convert COLLECTION to list removing elements that don't match TEST.
9299 See `anything-comp-read' about supported COLLECTION arguments.
9301 SORT-FN is a predicate to sort COLLECTION.
9303 ALISTP when non--nil will not use `all-completions' to collect
9304 candidates because it doesn't handle alists correctly for anything.
9305 i.e In `all-completions' the keys \(cars of elements\)
9306 are the possible completions. In anything we want to use the cdr instead
9307 like \(display . real\).
9308 See docstring of `all-completions' for more info.
9310 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9311 (let ((cands
9312 (cond ((and (eq collection obarray) test)
9313 (all-completions "" collection test))
9314 ((and (vectorp collection) test)
9315 (loop for i across collection when (funcall test i) collect i))
9316 ((vectorp collection)
9317 (loop for i across collection collect i))
9318 ((and alistp test)
9319 (loop for i in collection when (funcall test i) collect i))
9320 ((and (symbolp collection) (boundp collection))
9321 (symbol-value collection))
9322 (alistp collection)
9323 ((and collection test)
9324 (all-completions "" collection test))
9325 (t (all-completions "" collection)))))
9326 (if sort-fn (sort cands sort-fn) cands)))
9328 (defun anything-cr-default-transformer (candidates source)
9329 "Default filter candidate function for `anything-comp-read'.
9330 Do nothing, just return candidate list unmodified."
9331 candidates)
9333 (defun* anything-comp-read (prompt collection
9334 &key
9335 test
9336 initial-input
9337 default
9338 preselect
9339 (buffer "*Anything Completions*")
9340 must-match
9341 (requires-pattern 0)
9342 (history nil)
9343 input-history
9344 (persistent-action nil)
9345 (persistent-help "DoNothing")
9346 (name "Anything Completions")
9347 candidates-in-buffer
9348 exec-when-only-one
9349 (volatile t)
9350 sort
9351 (fc-transformer 'anything-cr-default-transformer)
9352 (marked-candidates nil)
9353 (alistp t))
9354 "Anything `completing-read' emulation.
9356 PROMPT is the prompt name to use.
9357 COLLECTION can be a list, vector, obarray or hash-table.
9358 It can be also a function that receives three arguments:
9359 the values string, predicate and t. See `all-completions' for more details.
9361 Keys description:
9363 TEST: A predicate called with one arg i.e candidate.
9364 INITIAL-INPUT: Same as initial-input arg in `anything'.
9365 PRESELECT: See preselect arg of `anything'.
9366 DEFAULT: This option is used only for compatibility with regular
9367 Emacs `completing-read'.
9368 BUFFER: Name of anything-buffer.
9369 MUST-MATCH: Candidate selected must be one of COLLECTION.
9370 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9371 HISTORY: A list containing specific history, default is nil.
9372 When it is non--nil, all elements of HISTORY are displayed in
9373 a special source before COLLECTION.
9374 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9375 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9376 NAME: The name related to this local source.
9377 VOLATILE: Use volatile attribute \(enabled by default\).
9378 SORT: A predicate to give to `sort' e.g `string-lessp'.
9379 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9380 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9381 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9382 CANDIDATES-IN-BUFFER: when non--nil use a source build with
9383 `anything-candidates-in-buffer' which is much faster. It is enabled by default.
9384 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9386 Any prefix args passed during `anything-comp-read' invocation will be recorded
9387 in `anything-current-prefix-arg', otherwise if prefix args where given before
9388 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9389 That's mean you can pass prefix args before or after calling a command
9390 that use `anything-comp-read' See `anything-M-x' for example."
9391 (when (get-buffer anything-action-buffer)
9392 (kill-buffer anything-action-buffer))
9393 (flet ((action-fn (candidate)
9394 (if marked-candidates
9395 (anything-marked-candidates)
9396 (identity candidate))))
9397 (let* ((src-hist `((name . ,(format "%s History" name))
9398 (candidates
9399 . (lambda ()
9400 (let ((all (anything-comp-read-get-candidates
9401 history nil nil ,alistp)))
9402 (anything-fast-remove-dups
9403 (if (and default (not (string= default "")))
9404 (delq nil (cons default (delete default all)))
9405 all)
9406 :test 'equal))))
9407 (filtered-candidate-transformer
9408 . (lambda (candidates sources)
9409 (loop for i in candidates
9410 do (set-text-properties 0 (length i) nil i)
9411 collect i)))
9412 (persistent-action . ,persistent-action)
9413 (persistent-help . ,persistent-help)
9414 (action . ,'action-fn)))
9415 (src `((name . ,name)
9416 (candidates
9417 . (lambda ()
9418 (let ((cands (anything-comp-read-get-candidates
9419 collection test sort alistp)))
9420 (unless (or must-match (string= anything-pattern ""))
9421 (setq cands (append (list anything-pattern) cands)))
9422 (if (and default (not (string= default "")))
9423 (delq nil (cons default (delete default cands)))
9424 cands))))
9425 (filtered-candidate-transformer ,fc-transformer)
9426 (requires-pattern . ,requires-pattern)
9427 (persistent-action . ,persistent-action)
9428 (persistent-help . ,persistent-help)
9429 (action . ,'action-fn)))
9430 (src-1 `((name . ,name)
9431 (init
9432 . (lambda ()
9433 (let ((cands (anything-comp-read-get-candidates
9434 collection test sort alistp)))
9435 (unless (or must-match (string= anything-pattern ""))
9436 (setq cands (append (list anything-pattern) cands)))
9437 (with-current-buffer (anything-candidate-buffer 'global)
9438 (loop for i in
9439 (if (and default (not (string= default "")))
9440 (delq nil (cons default (delete default cands)))
9441 cands)
9442 do (insert (concat i "\n")))))))
9443 (candidates-in-buffer)
9444 (filtered-candidate-transformer ,fc-transformer)
9445 (requires-pattern . ,requires-pattern)
9446 (persistent-action . ,persistent-action)
9447 (persistent-help . ,persistent-help)
9448 (action . ,'action-fn)))
9449 (src-list (delq nil (list (and history src-hist)
9450 (if candidates-in-buffer
9451 src-1
9452 (if volatile
9453 (append src '((volatile)))
9454 src)))))
9455 (anything-execute-action-at-once-if-one exec-when-only-one))
9457 (anything-1
9458 :sources src-list
9459 :input initial-input
9460 :default default
9461 :preselect preselect
9462 :prompt prompt
9463 :resume 'noresume
9464 :history input-history
9465 :buffer buffer)
9466 (unless (or (eq anything-exit-status 1) must-match)
9467 default)
9468 (keyboard-quit)))))
9470 ;; Generic completing-read
9472 ;; Support also function as collection.
9473 ;; e.g M-x man is supported.
9474 ;; Support hash-table and vectors as collection.
9475 ;; NOTE:
9476 ;; Some crap emacs functions may not be supported
9477 ;; like ffap-alternate-file (bad use of completing-read)
9478 ;; and maybe others.
9479 ;; Provide a mode `anything-completion-mode' which turn on
9480 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9482 (defvar anything-completion-mode-string " AC")
9484 (defvar anything-completion-mode-quit-message
9485 "Anything completion disabled")
9487 (defvar anything-completion-mode-start-message
9488 "Anything completion enabled")
9490 ;;; Specialized handlers
9493 (defun anything-completing-read-symbols
9494 (prompt collection test require-match init
9495 hist default inherit-input-method name buffer)
9496 "Specialized function for fast symbols completion in `ac-mode'."
9498 (anything-1
9499 :sources `((name . ,name)
9500 (init . (lambda ()
9501 (with-current-buffer (anything-candidate-buffer 'global)
9502 (goto-char (point-min))
9503 (when (and default (stringp default)
9504 ;; Some defaults args result as
9505 ;; (symbol-name nil) == "nil".
9506 ;; e.g debug-on-entry.
9507 (not (string= default "nil"))
9508 (not (string= default "")))
9509 (insert (concat default "\n")))
9510 (loop with all = (all-completions "" collection test)
9511 for sym in all
9512 unless (and default (eq sym default))
9513 do (insert (concat sym "\n"))))))
9514 (persistent-action . anything-lisp-completion-persistent-action)
9515 (persistent-help . "Show brief doc in mode-line")
9516 (candidates-in-buffer)
9517 (action . identity))
9518 :prompt prompt
9519 :buffer buffer
9520 :input init
9521 :history hist
9522 :resume 'noresume
9523 :default (or default ""))
9524 (keyboard-quit)))
9527 ;;; Generic completing read
9530 (defun anything-completing-read-default-1
9531 (prompt collection test require-match
9532 init hist default inherit-input-method
9533 name buffer &optional cands-in-buffer exec-when-only-one)
9534 "Call `anything-comp-read' with same args as `completing-read'.
9535 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9536 method which is faster.
9537 It should be used when candidate list don't need to rebuild dynamically."
9538 (let ((history (or (car-safe hist) hist)))
9539 (anything-comp-read
9540 prompt collection
9541 :test test
9542 :fc-transformer 'anything-completing-read-default-transformer
9543 :history history
9544 :input-history history
9545 :must-match require-match
9546 :alistp nil
9547 :name name
9548 :candidates-in-buffer cands-in-buffer
9549 :exec-when-only-one exec-when-only-one
9550 :buffer buffer
9551 ;; If DEF is not provided, fallback to empty string
9552 ;; to avoid `thing-at-point' to be appended on top of list
9553 :default (or default "")
9554 :initial-input init)))
9556 (defun anything-completing-read-default-transformer (candidates source)
9557 ;; In regular `completing-read'
9558 ;; when a candidate is a cons cell
9559 ;; the car is used. Anything use
9560 ;; normally the cdr, so modify that
9561 ;; to fit `completing-read'.
9562 (loop for i in candidates
9563 for cand = (if (consp i) (car i) i)
9564 do (set-text-properties 0 (length cand) nil cand)
9565 collect cand))
9567 (defun anything-completing-read-with-cands-in-buffer
9568 (prompt collection test require-match
9569 init hist default inherit-input-method
9570 name buffer)
9571 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9572 ;; Some commands like find-tag may use `read-file-name' from inside
9573 ;; the calculation of collection. in this case it clash with
9574 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9575 ;; So (re)calculate collection outside of main anything-session.
9576 (setq collection (all-completions "" collection))
9577 (anything-completing-read-default-1 prompt collection test require-match
9578 init hist default inherit-input-method
9579 name buffer t))
9581 (defun* anything-completing-read-default
9582 (prompt collection &optional
9583 predicate require-match
9584 initial-input hist def
9585 inherit-input-method)
9586 "An anything replacement of `completing-read'.
9587 This function should be used only as a `completing-read-function'.
9589 Don't use it directly, use instead `anything-comp-read' in your programs.
9591 See documentation of `completing-read' and `all-completions' for details."
9592 (declare (special anything-completion-mode))
9593 (let* ((current-command this-command)
9594 (str-command (symbol-name current-command))
9595 (buf-name (format "*ac-mode-%s*" str-command))
9596 (entry (assq current-command
9597 anything-completing-read-handlers-alist))
9598 (def-com (cdr-safe entry))
9599 (str-defcom (and def-com (symbol-name def-com)))
9600 (def-args (list prompt collection predicate require-match
9601 initial-input hist def inherit-input-method))
9602 ;; Append the two extra args needed to set the buffer and source name
9603 ;; in anything specialized functions.
9604 (any-args (append def-args (list str-command buf-name)))
9605 anything-completion-mode-start-message ; Be quiet
9606 anything-completion-mode-quit-message
9607 (minibuffer-completion-table collection)
9608 (minibuffer-completion-predicate predicate))
9609 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9610 (unless (or (not entry) def-com)
9611 ;; An entry in *read-handlers-alist exists but have
9612 ;; a nil value, so we exit from here, disable `ac-mode'
9613 ;; and run the command again with it original behavior.
9614 ;; `ac-mode' will be restored on exit.
9615 (return-from anything-completing-read-default
9616 (unwind-protect
9617 (progn
9618 (ac-mode -1)
9619 (call-interactively current-command))
9620 (ac-mode 1))))
9621 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9622 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9623 (when (or (eq def-com 'completing-read)
9624 ;; All specialized functions are prefixed by "anything"
9625 (and (stringp str-defcom)
9626 (not (string-match "^anything" str-defcom))))
9627 (ac-mode -1))
9628 (unwind-protect
9629 (cond (;; An anything specialized function exists, run it.
9630 (and def-com anything-completion-mode)
9631 (apply def-com any-args))
9632 (;; Try to handle `ido-completing-read' everywhere.
9633 (and def-com (eq def-com 'ido-completing-read))
9634 (setcar (memq collection def-args)
9635 (all-completions "" collection predicate))
9636 (apply def-com def-args))
9637 (;; User set explicitely `completing-read' or something similar
9638 ;; in *read-handlers-alist, use this with exactly the same
9639 ;; args as in `completing-read'.
9640 ;; If we are here `anything-completion-mode' is now disabled.
9641 def-com
9642 (apply def-com def-args))
9643 (t ; Fall back to classic `anything-comp-read'.
9644 (anything-completing-read-default-1
9645 prompt collection predicate require-match
9646 initial-input hist def inherit-input-method
9647 str-command buf-name)))
9648 (ac-mode 1)
9649 ;; When exiting minibuffer, `this-command' is set to
9650 ;; `anything-exit-minibuffer', which is unwanted when starting
9651 ;; on another `completing-read', so restore `this-command' to
9652 ;; initial value when exiting.
9653 (setq this-command current-command))))
9655 (defun* anything-generic-read-file-name
9656 (prompt &optional dir default-filename mustmatch initial predicate)
9657 "An anything replacement of `read-file-name'."
9658 (declare (special anything-completion-mode))
9659 (let* ((default (and default-filename
9660 (if (listp default-filename)
9661 (car default-filename)
9662 default-filename)))
9663 (init (or default initial dir default-directory))
9664 (ini-input (and init (expand-file-name init)))
9665 (current-command this-command)
9666 (str-command (symbol-name current-command))
9667 (buf-name (format "*ac-mode-%s*" str-command))
9668 (entry (assq current-command
9669 anything-completing-read-handlers-alist))
9670 (def-com (cdr-safe entry))
9671 (str-defcom (symbol-name def-com))
9672 (def-args (list prompt dir default-filename mustmatch initial predicate))
9673 ;; Append the two extra args needed to set the buffer and source name
9674 ;; in anything specialized functions.
9675 (any-args (append def-args (list str-command buf-name)))
9676 (ido-state ido-mode)
9677 anything-completion-mode-start-message ; Be quiet
9678 anything-completion-mode-quit-message ; Same here
9679 fname)
9680 ;; Some functions that normally call `completing-read' can switch
9681 ;; brutally to `read-file-name' (e.g find-tag), in this case
9682 ;; the anything specialized function will fail because it is build
9683 ;; for `completing-read', so set it to 'incompatible to be sure
9684 ;; we switch to `anything-c-read-file-name' and don't try to call it
9685 ;; with wrong number of args.
9686 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9687 (setq def-com 'incompatible))
9688 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9689 (unless (or (not entry) def-com)
9690 (return-from anything-completing-read-default
9691 (unwind-protect
9692 (progn
9693 (ac-mode -1)
9694 (call-interactively current-command))
9695 (ac-mode 1))))
9696 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9697 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9698 (when (or (eq def-com 'read-file-name)
9699 (eq def-com 'ido-read-file-name)
9700 (and (stringp str-defcom)
9701 (not (string-match "^anything" str-defcom))))
9702 (ac-mode -1))
9703 (unwind-protect
9704 (setq fname
9705 (cond (;; A specialized function exists, run it
9706 ;; with the two extra args specific to anything..
9707 (and def-com anything-completion-mode
9708 (not (eq def-com 'ido-read-file-name))
9709 (not (eq def-com 'incompatible)))
9710 (apply def-com any-args))
9711 (;; Def-com value is `ido-read-file-name'
9712 ;; run it with default args.
9713 (and def-com (eq def-com 'ido-read-file-name))
9714 (ido-mode 1)
9715 (apply def-com def-args))
9716 (;; Def-com value is `read-file-name'
9717 ;; run it with default args.
9718 (eq def-com 'read-file-name)
9719 (apply def-com def-args))
9720 (t ; Fall back to classic `anything-c-read-file-name'.
9721 (anything-c-read-file-name
9722 prompt
9723 :name str-command
9724 :buffer buf-name
9725 :initial-input (expand-file-name init dir)
9726 :alistp nil
9727 :test predicate))))
9728 (ac-mode 1)
9729 (ido-mode (if ido-state 1 -1))
9730 ;; Same comment as in `anything-completing-read-default'.
9731 (setq this-command current-command))
9732 (if (and mustmatch (not (file-exists-p fname)))
9733 (if (y-or-n-p "File does not exists, create buffer?")
9734 fname (error "Abort file does not exists"))
9735 fname)))
9737 ;;;###autoload
9738 (define-minor-mode anything-completion-mode
9739 "Toggle generic anything completion.
9741 All functions in Emacs that use `completing-read'
9742 or `read-file-name' and friends will use anything interface
9743 when this mode is turned on.
9744 However you can modify this behavior for functions of your choice
9745 with `anything-completing-read-handlers-alist'.
9747 Called with a positive arg, turn on unconditionally, with a
9748 negative arg turn off.
9749 You can turn it on with `ac-mode'.
9751 Some crap emacs functions may not be supported,
9752 e.g `ffap-alternate-file' and maybe others
9753 You can add such functions to `anything-completing-read-handlers-alist'
9754 with a nil value.
9756 Note: This mode will work only partially on Emacs23."
9757 :group 'anything
9758 :global t
9759 :lighter anything-completion-mode-string
9760 (declare (special completing-read-function))
9761 (if anything-completion-mode
9762 (progn
9763 (setq completing-read-function 'anything-completing-read-default
9764 read-file-name-function 'anything-generic-read-file-name)
9765 (message anything-completion-mode-start-message))
9766 (setq completing-read-function (and (fboundp 'completing-read-default)
9767 'completing-read-default)
9768 read-file-name-function (and (fboundp 'read-file-name-default)
9769 'read-file-name-default))
9770 (message anything-completion-mode-quit-message)))
9772 (defalias 'ac-mode 'anything-completion-mode)
9776 ;;; Eshell completion.
9778 ;; Enable like this in .emacs:
9780 ;; (add-hook 'eshell-mode-hook
9781 ;; #'(lambda ()
9782 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9784 (defvar anything-c-source-esh
9785 '((name . "Eshell completions")
9786 (init . (lambda ()
9787 (setq pcomplete-current-completions nil
9788 pcomplete-last-completion-raw nil)
9789 ;; Eshell-command add this hook in all minibuffers
9790 ;; Remove it for the anything one. (Fixed in Emacs24)
9791 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9792 (candidates . anything-esh-get-candidates)
9793 (action . anything-ec-insert))
9794 "Anything source for Eshell completion.")
9796 ;; Internal.
9797 (defvar anything-ec-target "")
9798 (defun anything-ec-insert (candidate)
9799 "Insert CANDIDATE at point.
9800 This is the same as `ac-insert', just inlined here for compatibility."
9801 (let ((pt (point)))
9802 (when (and anything-ec-target
9803 (search-backward anything-ec-target nil t)
9804 (string= (buffer-substring (point) pt) anything-ec-target))
9805 (delete-region (point) pt)))
9806 (insert candidate))
9808 (defun anything-esh-get-candidates ()
9809 "Get candidates for eshell completion using `pcomplete'."
9810 (catch 'pcompleted
9811 (let* ((pcomplete-stub)
9812 pcomplete-seen pcomplete-norm-func
9813 pcomplete-args pcomplete-last pcomplete-index
9814 (pcomplete-autolist pcomplete-autolist)
9815 (pcomplete-suffix-list pcomplete-suffix-list))
9816 (with-anything-current-buffer
9817 (loop
9818 with table = (pcomplete-completions)
9819 with entry = (condition-case nil
9820 ;; For Emacs24
9821 (try-completion anything-pattern (pcomplete-entries))
9822 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9823 (error
9825 (let ((fc (car (last (pcomplete-parse-arguments)))))
9826 ;; Check if last arg require fname completion.
9827 (and (file-name-directory fc) fc))))
9828 for i in (if (listp table) table ; Emacs23 or commands.
9829 (all-completions pcomplete-stub table)) ; Emacs24
9830 for file-cand = (and entry
9831 (if (file-remote-p i) i
9832 (expand-file-name i (file-name-directory entry))))
9833 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9834 collect file-cand into ls
9835 else collect i into ls
9836 finally return
9837 (if (and entry (not (string= entry "")) (file-exists-p entry))
9838 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9840 ;;; Eshell history.
9843 (defvar anything-c-source-eshell-history
9844 '((name . "Eshell history")
9845 (init . (lambda ()
9846 (let (eshell-hist-ignoredups)
9847 ;; Dump the content's of hist file
9848 ;; to `eshell-history-ring'.
9849 (eshell-read-history eshell-history-file-name)
9850 ;; And now write the content's of ring to file.
9851 (eshell-write-history eshell-history-file-name t)
9852 (with-current-buffer (anything-candidate-buffer 'global)
9853 (insert-file-contents eshell-history-file-name)))
9854 ;; Same comment as in `anything-c-source-esh'
9855 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9856 (candidates-in-buffer)
9857 (filtered-candidate-transformer . (lambda (candidates sources)
9858 (reverse candidates)))
9859 (candidate-number-limit . 9999)
9860 (action . (lambda (candidate)
9861 (eshell-kill-input)
9862 (insert candidate))))
9863 "Anything source for Eshell history.")
9866 ;;; Show completion - an alternative of anything-show-completion.el.
9868 ;; Provide show completion with macro `with-anything-show-completion'.
9871 ;; Called each time cursor move in anything-buffer.
9872 (defun anything-c-show-completion ()
9873 (with-anything-current-buffer
9874 (overlay-put anything-c-show-completion-overlay
9875 'display (anything-get-selection))))
9877 (defun anything-c-show-completion-init-overlay (beg end)
9878 (and anything-c-turn-on-show-completion
9879 (setq anything-c-show-completion-overlay (make-overlay beg end))
9880 (overlay-put anything-c-show-completion-overlay
9881 'face 'anything-lisp-show-completion)))
9883 (defmacro with-anything-show-completion (beg end &rest body)
9884 "Show anything candidate in an overlay at point.
9885 BEG and END are the beginning and end position of the current completion
9886 in `anything-current-buffer'.
9887 BODY is an anything call where we want to enable show completion.
9888 If `anything-c-turn-on-show-completion' is nil just do nothing."
9889 (declare (indent 2) (debug t))
9890 `(let ((anything-move-selection-after-hook
9891 (and anything-c-turn-on-show-completion
9892 (append (list 'anything-c-show-completion)
9893 anything-move-selection-after-hook))))
9894 (unwind-protect
9895 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9896 ,@body)
9897 (and anything-c-turn-on-show-completion
9898 (delete-overlay anything-c-show-completion-overlay)))))
9901 ;;; Lisp symbol completion.
9904 ;;;###autoload
9905 (defun anything-lisp-completion-at-point ()
9906 "Anything lisp symbol completion at point."
9907 (interactive)
9908 (let* ((data (lisp-completion-at-point))
9909 (beg (car data))
9910 (end (point)) ; 'cadr data' is wrong when no space after point.
9911 (plist (nthcdr 3 data))
9912 (pred (plist-get plist :predicate))
9913 (lgst-len 0)
9914 (target (and beg end (buffer-substring-no-properties beg end)))
9915 (candidates (all-completions target (nth 2 data) pred))
9916 (anything-quit-if-no-candidate t)
9917 (anything-execute-action-at-once-if-one t)
9918 (anything-match-plugin-enabled
9919 (member 'anything-compile-source--match-plugin
9920 anything-compile-source-functions)))
9921 (if candidates
9922 (with-anything-show-completion beg end
9923 ;; Overlay is initialized now in anything-current-buffer.
9924 (anything-1
9925 :sources
9926 '((name . "Lisp completion")
9927 (init . (lambda ()
9928 (with-current-buffer (anything-candidate-buffer 'global)
9929 (loop for sym in candidates
9930 for len = (length sym)
9931 when (> len lgst-len) do (setq lgst-len len)
9932 do (insert (concat sym "\n"))))))
9933 (candidates-in-buffer)
9934 (persistent-action . anything-lisp-completion-persistent-action)
9935 (persistent-help . "Show brief doc in mode-line")
9936 (filtered-candidate-transformer anything-lisp-completion-transformer)
9937 (action . (lambda (candidate)
9938 (delete-region beg end)
9939 (insert candidate))))
9940 :input (if anything-match-plugin-enabled (concat target " ") target)))
9941 (message "[No Match]"))))
9943 (defun anything-lisp-completion-persistent-action (candidate)
9944 (let ((cursor-in-echo-area t)
9945 mode-line-in-non-selected-windows)
9946 (anything-c-eldoc-show-in-mode-line
9947 (propertize
9948 (anything-c-get-first-line-documentation
9949 (intern candidate))
9950 'face 'anything-lisp-completion-info))))
9952 (defun anything-lisp-completion-transformer (candidates source)
9953 "Anything candidates transformer for lisp completion."
9954 (declare (special lgst-len))
9955 (loop for c in candidates
9956 for sym = (intern c)
9957 for annot = (cond ((commandp sym) " (Com)")
9958 ((fboundp sym) " (Fun)")
9959 ((boundp sym) " (Var)")
9960 ((facep sym) " (Face)"))
9961 for spaces = (make-string (- lgst-len (length c)) ? )
9962 collect (cons (concat c spaces annot) c)))
9964 (defun anything-c-get-first-line-documentation (sym)
9965 "Return first line documentation of symbol SYM.
9966 If SYM is not documented, return \"Not documented\"."
9967 (let ((doc (cond ((fboundp sym)
9968 (documentation sym t))
9969 ((boundp sym)
9970 (documentation-property sym 'variable-documentation t))
9971 ((facep sym)
9972 (face-documentation sym))
9973 (t nil))))
9974 (if (and doc (not (string= doc ""))
9975 ;; `documentation' return "\n\n(args...)"
9976 ;; for CL-style functions.
9977 (not (string-match-p "^\n\n" doc)))
9978 (car (split-string doc "\n"))
9979 "Not documented")))
9981 ;;; File completion.
9983 ;; Complete file name at point.
9984 (defun anything-c-thing-before-point ()
9985 "Get symbol name before point.
9986 Borrowed from anything-complete.el, inlined here for compatibility."
9987 (save-excursion
9988 (let ((beg (point)))
9989 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9990 (when (re-search-backward
9991 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9992 (buffer-substring-no-properties beg (match-end 0))))))
9994 ;;;###autoload
9995 (defun anything-c-complete-file-name-at-point ()
9996 "Complete file name at point."
9997 (interactive)
9998 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9999 (end (point))
10000 (beg (- (point) (length init)))
10001 (anything-quit-if-no-candidate t)
10002 (anything-execute-action-at-once-if-one t)
10003 completion)
10004 (with-anything-show-completion beg end
10005 (setq completion (anything-c-read-file-name "FileName: "
10006 :initial-input init)))
10007 (anything-c-insert-file-name-completion-at-point completion)))
10009 ;; Internal
10010 (defvar anything-lisp-completion-counter 0)
10011 ;;;###autoload
10012 (defun anything-lisp-completion-at-point-or-indent (arg)
10013 "First call indent and second call complete lisp symbol.
10014 The second call should happen before `anything-lisp-completion-or-indent-delay',
10015 after this delay, next call will indent again.
10016 After completion, next call is always indent.
10017 See that like click and double mouse click.
10018 One hit indent, two quick hits maybe indent and complete."
10019 (interactive "P")
10020 ;; Be sure `indent-for-tab-command' will not try
10021 ;; to use `completion-at-point'.
10022 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10023 t tab-always-indent)))
10024 (incf anything-lisp-completion-counter)
10025 (unwind-protect
10026 (if (> anything-lisp-completion-counter 1)
10027 (anything-lisp-completion-or-file-name-at-point)
10028 (indent-for-tab-command arg))
10029 ;; After `anything-lisp-completion-or-indent-delay' seconds
10030 ;; reset to 0.
10031 (run-with-timer anything-lisp-completion-or-indent-delay nil
10032 #'(lambda ()
10033 (setq anything-lisp-completion-counter 0)))
10034 ;; Always reset to 0 at second hit.
10035 (when (eq anything-lisp-completion-counter 2)
10036 (setq anything-lisp-completion-counter 0)))))
10038 ;;;###autoload
10039 (defun anything-lisp-completion-or-file-name-at-point ()
10040 "Complete lisp symbol or filename at point.
10041 Filename completion happen if filename is started in
10042 or between double quotes."
10043 (interactive)
10044 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10045 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10046 (save-excursion (search-backward "\"" (point-at-bol) t)))
10047 (anything-c-complete-file-name-at-point)
10048 (anything-lisp-completion-at-point))))
10050 (defun anything-c-apropos-init (test default)
10051 "Init candidates buffer for `anything-c-apropos' sources."
10052 (with-current-buffer (anything-candidate-buffer 'global)
10053 (goto-char (point-min))
10054 (when (and default (stringp default)
10055 ;; Some defaults args result as
10056 ;; (symbol-name nil) == "nil".
10057 ;; e.g debug-on-entry.
10058 (not (string= default "nil"))
10059 (funcall test (intern default)))
10060 (insert (concat default "\n")))
10061 (loop with all = (all-completions "" obarray test)
10062 for sym in all
10063 unless (and default (eq sym default))
10064 do (insert (concat sym "\n")))))
10067 ;;; Run Externals commands within Emacs with anything completion
10070 (defvar anything-external-command-history nil)
10072 (defun anything-c-external-commands-list-1 (&optional sort)
10073 "Returns a list of all external commands the user can execute.
10074 If `anything-c-external-commands-list' is non-nil it will
10075 return its contents. Else it calculates all external commands
10076 and sets `anything-c-external-commands-list'."
10077 (if anything-c-external-commands-list
10078 anything-c-external-commands-list
10079 (setq anything-c-external-commands-list
10080 (loop
10081 with paths = (split-string (getenv "PATH") path-separator)
10082 with completions = ()
10083 for dir in paths
10084 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10085 for lsdir = (loop for i in (directory-files dir t)
10086 for bn = (file-name-nondirectory i)
10087 when (and (not (member bn completions))
10088 (not (file-directory-p i))
10089 (file-executable-p i))
10090 collect bn)
10091 append lsdir into completions
10092 finally return (if sort (sort completions 'string-lessp) completions)))))
10094 (defun anything-run-or-raise (exe &optional file)
10095 "Generic command that run asynchronously EXE.
10096 If EXE is already running just jump to his window if `anything-raise-command'
10097 is non--nil.
10098 When FILE argument is provided run EXE with FILE.
10099 In this case EXE must be provided as \"EXE %s\"."
10100 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10101 "%s" "" exe))))
10102 (proc (if file (concat real-com " " file) real-com)))
10103 (if (get-process proc)
10104 (if anything-raise-command
10105 (shell-command (format anything-raise-command real-com))
10106 (error "Error: %s is already running" real-com))
10107 (when (loop for i in anything-c-external-commands-list thereis real-com)
10108 (message "Starting %s..." real-com)
10109 (if file
10110 (start-process-shell-command
10111 proc nil (format exe (shell-quote-argument file)))
10112 (start-process-shell-command proc nil real-com))
10113 (set-process-sentinel
10114 (get-process proc)
10115 #'(lambda (process event)
10116 (when (and (string= event "finished\n")
10117 anything-raise-command
10118 (not (anything-c-get-pid-from-process-name real-com)))
10119 (shell-command (format anything-raise-command "emacs")))
10120 (message "%s process...Finished." process))))
10121 (setq anything-c-external-commands-list
10122 (cons real-com
10123 (delete real-com anything-c-external-commands-list))))))
10127 ;;; Generic action functions
10130 (defun anything-c-file-buffers (filename)
10131 "Returns a list of buffer names corresponding to FILENAME."
10132 (let ((name (expand-file-name filename))
10133 (buf-list ()))
10134 (dolist (buf (buffer-list) buf-list)
10135 (let ((bfn (buffer-file-name buf)))
10136 (when (and bfn (string= name bfn))
10137 (push (buffer-name buf) buf-list))))))
10139 (defun anything-revert-buffer (candidate)
10140 (with-current-buffer candidate
10141 (when (or (buffer-modified-p)
10142 (not (verify-visited-file-modtime
10143 (get-buffer candidate))))
10144 (revert-buffer t t))))
10146 (defun anything-revert-marked-buffers (ignore)
10147 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10149 (defun anything-kill-marked-buffers (ignore)
10150 (mapc 'kill-buffer (anything-marked-candidates)))
10152 (defun anything-c-delete-file (file)
10153 "Delete the given file after querying the user.
10154 Ask to kill buffers associated with that file, too."
10155 (let ((buffers (anything-c-file-buffers file)))
10156 (if (< emacs-major-version 24)
10157 ;; `dired-delete-file' in Emacs versions < 24
10158 ;; doesn't support delete-by-moving-to-trash
10159 ;; so use `delete-directory' and `delete-file'
10160 ;; that handle it.
10161 (cond ((and (not (file-symlink-p file))
10162 (file-directory-p file)
10163 (directory-files file t dired-re-no-dot))
10164 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10165 (delete-directory file 'recursive)))
10166 ((and (not (file-symlink-p file))
10167 (file-directory-p file))
10168 (delete-directory file))
10169 (t (delete-file file)))
10170 (dired-delete-file
10171 file 'dired-recursive-deletes delete-by-moving-to-trash))
10172 (when buffers
10173 (dolist (buf buffers)
10174 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10175 (kill-buffer buf))))))
10177 (defun anything-get-mailcap-for-file (filename)
10178 "Get the command to use for FILENAME from mailcap files.
10179 The command is like <command %s> and is meant to use with `format'."
10180 (mailcap-parse-mailcaps)
10181 (let* ((ext (file-name-extension filename))
10182 (mime (when ext (mailcap-extension-to-mime ext)))
10183 (result (when mime (mailcap-mime-info mime))))
10184 ;; If elisp file have no associations in .mailcap
10185 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10186 (when (stringp result) result)))
10188 (defun anything-get-default-program-for-file (filename)
10189 "Try to find a default program to open FILENAME.
10190 Try first in `anything-c-external-programs-associations' and then in mailcap file
10191 if nothing found return nil."
10192 (let* ((ext (file-name-extension filename))
10193 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10194 (cond ((and def-prog (not (string= def-prog "")))
10195 (concat def-prog " %s"))
10196 ((and anything-c-default-external-file-browser
10197 (file-directory-p filename))
10198 (concat anything-c-default-external-file-browser " %s"))
10199 (t (anything-get-mailcap-for-file filename)))))
10201 (defun anything-c-open-file-externally (file)
10202 "Open FILE with an external program.
10203 Try to guess which program to use with `anything-get-default-program-for-file'.
10204 If not found or a prefix arg is given query the user which tool to use."
10205 (let* ((fname (expand-file-name file))
10206 (collection (anything-c-external-commands-list-1 'sort))
10207 (def-prog (anything-get-default-program-for-file fname))
10208 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10209 ;; Prefix arg or no default program.
10210 (prog1
10211 (anything-comp-read
10212 "Program: " collection
10213 :must-match t
10214 :name "Open file Externally"
10215 :history anything-external-command-history)
10216 ;; Always prompt to set this program as default.
10217 (setq def-prog nil))
10218 ;; No prefix arg or default program exists.
10219 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10220 (program (concat real-prog-name " %s")))
10221 (unless (or def-prog ; Association exists, no need to record it.
10222 ;; Don't try to record non--filenames associations (e.g urls).
10223 (not (file-exists-p fname)))
10224 (when
10225 (y-or-n-p
10226 (format
10227 "Do you want to make `%s' the default program for this kind of files? "
10228 real-prog-name))
10229 (anything-aif (assoc (file-name-extension fname)
10230 anything-c-external-programs-associations)
10231 (setq anything-c-external-programs-associations
10232 (delete it anything-c-external-programs-associations)))
10233 (push (cons (file-name-extension fname)
10234 (read-string
10235 "Program (Add args maybe and confirm): " real-prog-name))
10236 anything-c-external-programs-associations)
10237 (customize-save-variable 'anything-c-external-programs-associations
10238 anything-c-external-programs-associations)))
10239 (anything-run-or-raise program file)
10240 (setq anything-external-command-history
10241 (cons real-prog-name
10242 (delete real-prog-name
10243 (loop for i in anything-external-command-history
10244 when (executable-find i) collect i))))))
10246 (defun anything-c-find-file-or-marked (candidate)
10247 "Open file CANDIDATE or open anything marked files in background."
10248 (let ((marked (anything-marked-candidates))
10249 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10250 (find-file-wildcards nil))
10251 (if (> (length marked) 1)
10252 ;; Open all marked files in background and display
10253 ;; the first one.
10254 (progn (mapc 'find-file-noselect (cdr marked))
10255 (find-file (car marked)))
10256 (if (and (not (file-exists-p candidate))
10257 (and ffap-url-regexp
10258 (not (string-match ffap-url-regexp candidate)))
10259 (string-match "/$" candidate))
10260 ;; A a non--existing filename ending with /
10261 ;; Create a directory and jump to it.
10262 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10263 (let ((dirfname (directory-file-name candidate)))
10264 (if (file-exists-p dirfname)
10265 (error "Mkdir: Unable to create directory `%s': file exists."
10266 (anything-c-basename dirfname))
10267 (make-directory candidate 'parent)))
10268 (anything-find-files-1 candidate))
10269 ;; A non--existing filename NOT ending with / or
10270 ;; an existing filename, create or jump to it.
10271 (find-file-at-point (car marked))))))
10273 (defun anything-delete-marked-files (ignore)
10274 (let* ((files (anything-marked-candidates))
10275 (len (length files)))
10276 (if (not (y-or-n-p
10277 (format "Delete *%s File(s):\n%s"
10279 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10280 (message "(No deletions performed)")
10281 (dolist (i files)
10282 (set-text-properties 0 (length i) nil i)
10283 (anything-c-delete-file i))
10284 (message "%s File(s) deleted" len))))
10286 (defun anything-ediff-marked-buffers (candidate &optional merge)
10287 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10288 With optional arg MERGE call `ediff-merge-buffers'."
10289 (let ((lg-lst (length (anything-marked-candidates)))
10290 buf1 buf2)
10291 (case lg-lst
10293 (error "Error:You have to mark at least 1 buffer"))
10295 (setq buf1 anything-current-buffer
10296 buf2 (first (anything-marked-candidates))))
10298 (setq buf1 (first (anything-marked-candidates))
10299 buf2 (second (anything-marked-candidates))))
10301 (error "Error:To much buffers marked!")))
10302 (if merge
10303 (ediff-merge-buffers buf1 buf2)
10304 (ediff-buffers buf1 buf2))))
10306 (defun anything-ediff-marked-buffers-merge (candidate)
10307 "Ediff merge `anything-current-buffer' with CANDIDATE.
10308 See `anything-ediff-marked-buffers'."
10309 (anything-ediff-marked-buffers candidate t))
10311 (defun anything-bookmark-get-bookmark-from-name (bmk)
10312 "Return bookmark name even if it is a bookmark with annotation.
10313 e.g prepended with *.
10314 Return nil if bmk is not a valid bookmark."
10315 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10316 (if (assoc bookmark bookmark-alist)
10317 bookmark
10318 (when (assoc bmk bookmark-alist)
10319 bmk))))
10321 (defun anything-delete-marked-bookmarks (ignore)
10322 "Delete this bookmark or all marked bookmarks."
10323 (dolist (i (anything-marked-candidates))
10324 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10325 'batch)))
10327 (defun anything-require-or-error (feature function)
10328 (or (require feature nil t)
10329 (error "Need %s to use `%s'." feature function)))
10331 (defun anything-find-buffer-on-elscreen (candidate)
10332 "Open buffer in new screen, if marked buffers open all in elscreens."
10333 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10334 (anything-aif (anything-marked-candidates)
10335 (dolist (i it)
10336 (let ((target-screen (elscreen-find-screen-by-buffer
10337 (get-buffer i) 'create)))
10338 (elscreen-goto target-screen)))
10339 (let ((target-screen (elscreen-find-screen-by-buffer
10340 (get-buffer candidate) 'create)))
10341 (elscreen-goto target-screen))))
10343 (defun anything-elscreen-find-file (file)
10344 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10345 (elscreen-find-file file))
10347 ;;;###autoload
10348 (defun w32-shell-execute-open-file (file)
10349 (interactive "fOpen file:")
10350 (with-no-warnings
10351 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10352 "/" "\\"
10353 (replace-regexp-in-string ; strip cygdrive paths
10354 "/cygdrive/\\(.\\)" "\\1:"
10355 file nil nil) nil t))))
10357 (defun anything-c-open-file-with-default-tool (file)
10358 "Open FILE with the default tool on this platform."
10359 (if (eq system-type 'windows-nt)
10360 (w32-shell-execute-open-file file)
10361 (start-process "anything-c-open-file-with-default-tool"
10363 (cond ((eq system-type 'gnu/linux)
10364 "xdg-open")
10365 ((or (eq system-type 'darwin) ;; Mac OS X
10366 (eq system-type 'macos)) ;; Mac OS 9
10367 "open"))
10368 file)))
10370 (defun anything-c-open-dired (file)
10371 "Opens a dired buffer in FILE's directory. If FILE is a
10372 directory, open this directory."
10373 (if (file-directory-p file)
10374 (dired file)
10375 (dired (file-name-directory file))
10376 (dired-goto-file file)))
10378 (defun anything-c-display-to-real-line (candidate)
10379 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10380 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10381 (error "Line number not found")))
10383 (defun anything-c-action-line-goto (lineno-and-content)
10384 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10385 (append lineno-and-content
10386 (list (if (and (anything-attr-defined 'target-file)
10387 (not anything-in-persistent-action))
10388 'find-file-other-window
10389 'find-file)))))
10391 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10392 (apply #'anything-goto-file-line
10393 (if (stringp file-line-content)
10394 ;; Case: filtered-candidate-transformer is skipped
10395 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10396 file-line-content)))
10398 (require 'compile)
10399 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10400 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10402 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10403 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10404 (let ((filename (match-string 1 candidate))
10405 (lineno (match-string 2 candidate))
10406 (content (match-string 3 candidate)))
10407 (cons (format "%s:%s\n %s"
10408 (propertize filename 'face compilation-info-face)
10409 (propertize lineno 'face compilation-line-face)
10410 content)
10411 (list (expand-file-name
10412 filename
10413 (or (anything-interpret-value (anything-attr 'default-directory))
10414 (and (anything-candidate-buffer)
10415 (buffer-local-value
10416 'default-directory (anything-candidate-buffer)))))
10417 (string-to-number lineno) content)))))
10419 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10420 (anything-aif (anything-attr 'before-jump-hook)
10421 (funcall it))
10422 (when file (funcall find-file-function file))
10423 (if (anything-attr-defined 'adjust)
10424 (anything-c-goto-line-with-adjustment lineno content)
10425 (anything-goto-line lineno))
10426 (unless (anything-attr-defined 'recenter)
10427 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10428 (anything-aif (anything-attr 'after-jump-hook)
10429 (funcall it))
10430 (when anything-in-persistent-action
10431 (anything-match-line-color-current-line)))
10433 (defun anything-find-file-as-root (candidate)
10434 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10436 (defun anything-find-many-files (ignore)
10437 (mapc 'find-file (anything-marked-candidates)))
10439 ;; borrowed from etags.el
10440 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10441 (defun anything-c-goto-line-with-adjustment (line line-content)
10442 (let ((startpos)
10443 offset found pat)
10444 ;; This constant is 1/2 the initial search window.
10445 ;; There is no sense in making it too small,
10446 ;; since just going around the loop once probably
10447 ;; costs about as much as searching 2000 chars.
10448 (setq offset 1000
10449 found nil
10450 pat (concat (if (eq selective-display t)
10451 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10452 (regexp-quote line-content)))
10453 ;; If no char pos was given, try the given line number.
10454 (setq startpos (progn (anything-goto-line line) (point)))
10455 (or startpos (setq startpos (point-min)))
10456 ;; First see if the tag is right at the specified location.
10457 (goto-char startpos)
10458 (setq found (looking-at pat))
10459 (while (and (not found)
10460 (progn
10461 (goto-char (- startpos offset))
10462 (not (bobp))))
10463 (setq found
10464 (re-search-forward pat (+ startpos offset) t)
10465 offset (* 3 offset))) ; expand search window
10466 (or found
10467 (re-search-forward pat nil t)
10468 (error "not found")))
10469 ;; Position point at the right place
10470 ;; if the search string matched an extra Ctrl-m at the beginning.
10471 (and (eq selective-display t)
10472 (looking-at "\^m")
10473 (forward-char 1))
10474 (beginning-of-line))
10476 (anything-document-attribute 'default-directory "type . file-line"
10477 "`default-directory' to interpret file.")
10478 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10479 "Function to call before jumping to the target location.")
10480 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10481 "Function to call after jumping to the target location.")
10482 (anything-document-attribute 'adjust "type . file-line"
10483 "Search around line matching line contents.")
10484 (anything-document-attribute 'recenter "type . file-line / line"
10485 "`recenter' after jumping.")
10486 (anything-document-attribute 'target-file "type . line"
10487 "Goto line of target-file.")
10489 ;;;###autoload
10490 (defun anything-c-call-interactively (cmd-or-name)
10491 "Execute CMD-OR-NAME as Emacs command.
10492 It is added to `extended-command-history'.
10493 `anything-current-prefix-arg' is used as the command's prefix argument."
10494 (setq extended-command-history
10495 (cons (anything-c-stringify cmd-or-name)
10496 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10497 (let ((current-prefix-arg anything-current-prefix-arg)
10498 (cmd (anything-c-symbolify cmd-or-name)))
10499 (if (stringp (symbol-function cmd))
10500 (execute-kbd-macro (symbol-function cmd))
10501 (setq this-command cmd)
10502 (call-interactively cmd))))
10504 ;;;###autoload
10505 (defun anything-c-set-variable (var)
10506 "Set value to VAR interactively."
10507 (interactive)
10508 (let ((sym (anything-c-symbolify var)))
10509 (set sym (eval-minibuffer (format "Set %s: " var)
10510 (prin1-to-string (symbol-value sym))))))
10511 ;; (setq hh 12)
10512 ;; (anything-c-set-variable 'hh)
10516 ;;; Persistent Action Helpers
10519 (defvar anything-match-line-overlay-face nil)
10520 (defvar anything-match-line-overlay nil)
10522 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10523 "Highlight and underline current position"
10524 (let ((args (list (or start (line-beginning-position))
10525 (or end (1+ (line-end-position)))
10526 buf)))
10527 (if (not anything-match-line-overlay)
10528 (setq anything-match-line-overlay (apply 'make-overlay args))
10529 (apply 'move-overlay anything-match-line-overlay args)))
10530 (overlay-put anything-match-line-overlay
10531 'face (or face anything-match-line-overlay-face))
10532 (when rec
10533 (goto-char start)
10534 (recenter)))
10536 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10539 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10541 (defun anything-match-line-cleanup ()
10542 (when anything-match-line-overlay
10543 (delete-overlay anything-match-line-overlay)
10544 (setq anything-match-line-overlay nil)))
10546 (defun anything-match-line-update ()
10547 (when anything-match-line-overlay
10548 (delete-overlay anything-match-line-overlay)
10549 (anything-match-line-color-current-line)))
10551 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10552 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10555 ;;; Actions Transformers
10558 ;;; Files
10559 (defun anything-c-transform-file-load-el (actions candidate)
10560 "Add action to load the file CANDIDATE if it is an emacs lisp
10561 file. Else return ACTIONS unmodified."
10562 (if (member (file-name-extension candidate) '("el" "elc"))
10563 (append actions '(("Load Emacs Lisp File" . load-file)))
10564 actions))
10566 (defun anything-c-transform-file-browse-url (actions candidate)
10567 "Add an action to browse the file CANDIDATE if it in a html
10568 file or URL. Else return ACTIONS unmodified."
10569 (let ((browse-action '("Browse with Browser" . browse-url)))
10570 (cond ((string-match "^http\\|^ftp" candidate)
10571 (cons browse-action actions))
10572 ((string-match "\\.html?$" candidate)
10573 (append actions (list browse-action)))
10574 (t actions))))
10576 ;;; Function
10577 (defun anything-c-transform-function-call-interactively (actions candidate)
10578 "Add an action to call the function CANDIDATE interactively if
10579 it is a command. Else return ACTIONS unmodified."
10580 (if (commandp (intern-soft candidate))
10581 (append actions '(("Call Interactively"
10583 anything-c-call-interactively)))
10584 actions))
10586 ;;;; S-Expressions
10587 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10588 "If CANDIDATE's `car' is a command, then add an action to
10589 evaluate it and put it onto the `command-history'."
10590 (if (commandp (car (read candidate)))
10591 ;; Make it first entry
10592 (cons '("Eval and put onto command-history" .
10593 (lambda (sexp)
10594 (let ((sym (read sexp)))
10595 (eval sym)
10596 (setq command-history
10597 (cons sym command-history)))))
10598 actions)
10599 actions))
10602 ;;; Candidate Transformers
10605 ;;; Buffers
10606 (defun anything-c-skip-boring-buffers (buffers)
10607 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10609 (defun anything-c-skip-current-buffer (buffers)
10610 (if anything-allow-skipping-current-buffer
10611 (remove (buffer-name anything-current-buffer) buffers)
10612 buffers))
10614 (defun anything-c-shadow-boring-buffers (buffers)
10615 "Buffers matching `anything-c-boring-buffer-regexp' will be
10616 displayed with the `file-name-shadow' face if available."
10617 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10619 (defvar anything-c-buffer-display-string-functions
10620 '(anything-c-buffer-display-string--compilation
10621 anything-c-buffer-display-string--shell
10622 anything-c-buffer-display-string--eshell)
10623 "Functions to setup display string for buffer.
10625 Function has one argument, buffer name.
10626 If it returns string, use it.
10627 If it returns nil, display buffer name.
10628 See `anything-c-buffer-display-string--compilation' for example.")
10630 (defun anything-c-transform-buffer-display-string (buffers)
10631 "Setup display string for buffer candidates
10632 using `anything-c-buffer-display-string-functions'."
10633 (loop for buf in buffers
10634 if (consp buf)
10635 collect buf
10636 else
10637 for disp = (progn (set-buffer buf)
10638 (run-hook-with-args-until-success
10639 'anything-c-buffer-display-string-functions buf))
10640 collect (if disp (cons disp buf) buf)))
10642 (defun anything-c-buffer-display-string--compilation (buf)
10643 (anything-aif (car compilation-arguments)
10644 (format "%s: %s [%s]" buf it default-directory)))
10646 (defun anything-c-buffer-display-string--eshell (buf)
10647 (declare (special eshell-history-ring))
10648 (when (eq major-mode 'eshell-mode)
10649 (format "%s: %s [%s]" buf
10650 (ignore-errors (ring-ref eshell-history-ring 0))
10651 default-directory)))
10653 (defun anything-c-buffer-display-string--shell (buf)
10654 (when (eq major-mode 'shell-mode)
10655 (format "%s: %s [%s]" buf
10656 (ignore-errors (ring-ref comint-input-ring 0))
10657 default-directory)))
10659 ;;; Files
10660 (defun anything-c-shadow-boring-files (files)
10661 "Files matching `anything-c-boring-file-regexp' will be
10662 displayed with the `file-name-shadow' face if available."
10663 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10665 (defun anything-c-skip-boring-files (files)
10666 "Files matching `anything-c-boring-file-regexp' will be skipped."
10667 (anything-c-skip-entries files anything-c-boring-file-regexp))
10668 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10670 (defun anything-c-skip-current-file (files)
10671 "Current file will be skipped."
10672 (remove (buffer-file-name anything-current-buffer) files))
10674 (defun anything-c-w32-pathname-transformer (args)
10675 "Change undesirable features of windows pathnames to ones more acceptable to
10676 other candidate transformers."
10677 (if (eq system-type 'windows-nt)
10678 (mapcar (lambda (x)
10679 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10680 (mapcar (lambda (y)
10681 (replace-regexp-in-string "\\\\" "/" y)) args))
10682 args))
10684 (defun anything-c-shorten-home-path (files)
10685 "Replaces /home/user with ~."
10686 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10687 (getenv "HOME"))))
10688 (mapcar (lambda (file)
10689 (if (and (stringp file) (string-match home file))
10690 (cons (replace-match "~" nil nil file) file)
10691 file))
10692 files)))
10694 ;;; Functions
10695 (defun anything-c-mark-interactive-functions (functions)
10696 "Mark interactive functions (commands) with (i) after the function name."
10697 (let (list)
10698 (loop for function in functions
10699 do (push (cons (concat function
10700 (when (commandp (intern-soft function)) " (i)"))
10701 function)
10702 list)
10703 finally (return (nreverse list)))))
10706 ;;; Adaptive Sorting of Candidates
10709 ;; Internal
10710 (defvar anything-c-adaptive-done nil
10711 "nil if history information is not yet stored for the current
10712 selection.")
10714 (defvar anything-c-adaptive-history nil
10715 "Contains the stored history information.
10716 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10718 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10719 "Reset `anything-c-adaptive-done' when anything is started."
10720 (when anything-c-use-adaptative-sorting
10721 (setq anything-c-adaptive-done nil)))
10723 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10724 "Store history information when action is executed on selected candidate."
10725 (when anything-c-use-adaptative-sorting
10726 (anything-c-adaptive-store-selection)))
10728 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10729 "Store history information when the user goes to the action buffer."
10730 (when anything-c-use-adaptative-sorting
10731 (anything-c-adaptive-store-selection)))
10733 (defun anything-c-source-use-adaptative-p (&optional source-name)
10734 "Return current source only if it use adaptative history, nil otherwise."
10735 (when anything-c-use-adaptative-sorting
10736 (let* ((source (or source-name (anything-get-current-source)))
10737 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10738 (assoc (assoc-default 'type source)
10739 anything-type-attributes))
10740 (assoc-default 'candidate-transformer
10741 (assoc (assoc-default 'type source)
10742 anything-type-attributes))
10743 (assoc-default 'filtered-candidate-transformer source)
10744 (assoc-default 'candidate-transformer source))))
10745 (if (listp adapt-source)
10746 (when (member 'anything-c-adaptive-sort adapt-source) source)
10747 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10749 (defun anything-c-adaptive-store-selection ()
10750 "Store history information for the selected candidate."
10751 (unless anything-c-adaptive-done
10752 (setq anything-c-adaptive-done t)
10753 (let ((source (anything-c-source-use-adaptative-p)))
10754 (when source
10755 (let* ((source-name (or (assoc-default 'type source)
10756 (assoc-default 'name source)))
10757 (source-info (or (assoc source-name anything-c-adaptive-history)
10758 (progn
10759 (push (list source-name) anything-c-adaptive-history)
10760 (car anything-c-adaptive-history))))
10761 (selection (anything-get-selection))
10762 (selection-info (progn
10763 (setcdr source-info
10764 (cons
10765 (let ((found (assoc selection (cdr source-info))))
10766 (if (not found)
10767 ;; new entry
10768 (list selection)
10770 ;; move entry to the beginning of the
10771 ;; list, so that it doesn't get
10772 ;; trimmed when the history is
10773 ;; truncated
10774 (setcdr source-info
10775 (delete found (cdr source-info)))
10776 found))
10777 (cdr source-info)))
10778 (cadr source-info)))
10779 (pattern-info (progn
10780 (setcdr selection-info
10781 (cons
10782 (let ((found (assoc anything-pattern (cdr selection-info))))
10783 (if (not found)
10784 ;; new entry
10785 (cons anything-pattern 0)
10787 ;; move entry to the beginning of the
10788 ;; list, so if two patterns used the
10789 ;; same number of times then the one
10790 ;; used last appears first in the list
10791 (setcdr selection-info
10792 (delete found (cdr selection-info)))
10793 found))
10794 (cdr selection-info)))
10795 (cadr selection-info))))
10797 ;; increase usage count
10798 (setcdr pattern-info (1+ (cdr pattern-info)))
10800 ;; truncate history if needed
10801 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10802 (setcdr selection-info
10803 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10805 (defun anything-c-adaptative-maybe-load-history ()
10806 (when (and anything-c-use-adaptative-sorting
10807 (file-readable-p anything-c-adaptive-history-file))
10808 (load-file anything-c-adaptive-history-file)))
10810 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10811 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10813 (defun anything-c-adaptive-save-history (&optional arg)
10814 "Save history information to file given by `anything-c-adaptive-history-file'."
10815 (interactive "p")
10816 (when anything-c-use-adaptative-sorting
10817 (with-temp-buffer
10818 (insert
10819 ";; -*- mode: emacs-lisp -*-\n"
10820 ";; History entries used for anything adaptive display.\n")
10821 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10822 (current-buffer))
10823 (insert ?\n)
10824 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10825 (unless arg 'quiet)))))
10827 (defun anything-c-adaptive-sort (candidates source)
10828 "Sort the CANDIDATES for SOURCE by usage frequency.
10829 This is a filtered candidate transformer you can use for the
10830 attribute `filtered-candidate-transformer' of a source in
10831 `anything-sources' or a type in `anything-type-attributes'."
10832 (let* ((source-name (or (assoc-default 'type source)
10833 (assoc-default 'name source)))
10834 (source-info (assoc source-name anything-c-adaptive-history)))
10835 (if source-info
10836 (let ((usage
10837 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10838 ;; pairs
10839 (mapcar (lambda (candidate-info)
10840 (let ((count 0))
10841 (dolist (pattern-info (cdr candidate-info))
10842 (if (not (equal (car pattern-info)
10843 anything-pattern))
10844 (incf count (cdr pattern-info))
10846 ;; if current pattern is equal to the previously
10847 ;; used one then this candidate has priority
10848 ;; (that's why its count is boosted by 10000) and
10849 ;; it only has to compete with other candidates
10850 ;; which were also selected with the same pattern
10851 (setq count (+ 10000 (cdr pattern-info)))
10852 (return)))
10853 (cons (car candidate-info) count)))
10854 (cdr source-info)))
10855 sorted)
10856 (if (and usage (consp usage))
10857 ;; sort the list in descending order, so candidates with highest
10858 ;; priorty come first
10859 (progn
10860 (setq usage (sort usage (lambda (first second)
10861 (> (cdr first) (cdr second)))))
10863 ;; put those candidates first which have the highest usage count
10864 (dolist (info usage)
10865 (when (member* (car info) candidates
10866 :test 'anything-c-adaptive-compare)
10867 (push (car info) sorted)
10868 (setq candidates (remove* (car info) candidates
10869 :test 'anything-c-adaptive-compare))))
10871 ;; and append the rest
10872 (append (reverse sorted) candidates nil))
10873 (message "Your `%s' is maybe corrupted or too old, \
10874 you should reinitialize it with `anything-c-reset-adaptative-history'"
10875 anything-c-adaptive-history-file)
10876 (sit-for 1)
10877 candidates))
10878 ;; if there is no information stored for this source then do nothing
10879 candidates)))
10881 ;;;###autoload
10882 (defun anything-c-reset-adaptative-history ()
10883 "Delete all `anything-c-adaptive-history' and his file.
10884 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10885 (interactive)
10886 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10887 (setq anything-c-adaptive-history nil)
10888 (delete-file anything-c-adaptive-history-file)))
10890 (defun anything-c-adaptive-compare (x y)
10891 "Compare candidates X and Y taking into account that the
10892 candidate can be in (DISPLAY . REAL) format."
10893 (equal (if (listp x)
10894 (cdr x)
10896 (if (listp y)
10897 (cdr y)
10898 y)))
10902 ;;; Outliner
10905 (defvar anything-outline-goto-near-line-flag t)
10906 (defvar anything-outline-using nil)
10907 (defun anything-after-update-hook--outline ()
10908 (if (and (eq anything-outline-using t)
10909 (eq anything-outline-goto-near-line-flag t))
10910 (anything-outline-goto-near-line)))
10911 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10913 (defun anything-outline-goto-near-line ()
10914 (with-anything-window
10915 ;; TODO need consideration whether to update position by every input.
10916 (when t ; (equal anything-pattern "")
10917 (anything-goto-line 2)
10918 (let ((lineno (with-anything-current-buffer
10919 (line-number-at-pos (car anything-current-position)))))
10920 (block exit
10921 (while (<= (progn (skip-chars-forward " ")
10922 (or (number-at-point) lineno))
10923 lineno)
10924 (forward-line 1)
10925 (when (eobp)
10926 (forward-line -1)
10927 (return-from exit))))
10928 (forward-line -1)
10929 (and (bobp) (forward-line 1))
10930 (and (anything-pos-header-line-p) (forward-line -2))
10931 (anything-mark-current-line)))))
10935 ;;; Plug-in
10938 ;; Plug-in: info-index
10939 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10940 (let (result)
10941 (unless (anything-candidate-buffer)
10942 (save-window-excursion
10943 (info file)
10944 (let (Info-history
10945 (tobuf (anything-candidate-buffer 'global))
10946 (infobuf (current-buffer))
10947 s e)
10948 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10949 (Info-goto-node node)
10950 (goto-char (point-min))
10951 (while (search-forward "\n* " nil t)
10952 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10953 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10954 (setq s (point-at-bol)
10955 e (point-at-eol))
10956 (with-current-buffer tobuf
10957 (insert-buffer-substring infobuf s e)
10958 (insert "\n"))))))))))
10960 (defun anything-c-info-goto (node-line)
10961 (Info-goto-node (car node-line))
10962 (anything-goto-line (cdr node-line)))
10964 (defun anything-c-info-display-to-real (line)
10965 (and (string-match
10966 ;; This regexp is stolen from Info-apropos-matches
10967 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10968 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10969 (string-to-number (or (match-string 3 line) "1")))))
10971 (defun anything-c-make-info-source (source file)
10972 `(,@source
10973 (name . ,(concat "Info Index: " file))
10974 (info-file . ,file)
10975 (init . anything-c-info-init)
10976 (display-to-real . anything-c-info-display-to-real)
10977 (get-line . buffer-substring)
10978 (candidates-in-buffer)
10979 (action ("Goto node" . anything-c-info-goto))))
10981 (defun anything-compile-source--info-index (source)
10982 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10983 (anything-c-make-info-source source it)
10984 source))
10985 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10987 (anything-document-attribute 'info-index "info-index plugin"
10988 "Create a source of info index very easily.
10990 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10992 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10993 "Index nodes of info file.
10995 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10996 Some info files are missing index specification.
10998 ex. See `anything-c-source-info-screen'.")
11000 ;; Plug-in: candidates-file
11001 (defun anything-compile-source--candidates-file (source)
11002 (if (assoc-default 'candidates-file source)
11003 `((init anything-p-candidats-file-init
11004 ,@(let ((orig-init (assoc-default 'init source)))
11005 (cond ((null orig-init) nil)
11006 ((functionp orig-init) (list orig-init))
11007 (t orig-init))))
11008 (candidates-in-buffer)
11009 ,@source)
11010 source))
11011 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11013 (defun anything-p-candidats-file-init ()
11014 (destructuring-bind (file &optional updating)
11015 (anything-mklist (anything-attr 'candidates-file))
11016 (setq file (anything-interpret-value file))
11017 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11018 (when updating
11019 (buffer-disable-undo)
11020 (font-lock-mode -1)
11021 (auto-revert-mode 1)))))
11023 (anything-document-attribute 'candidates-file "candidates-file plugin"
11024 "Use a file as the candidates buffer.
11026 1st argument is a filename, string or function name or variable name.
11027 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11029 ;; Plug-in: headline
11030 (defun anything-compile-source--anything-headline (source)
11031 (if (assoc-default 'headline source)
11032 (append '((init . anything-headline-init)
11033 (get-line . buffer-substring)
11034 (type . line))
11035 source
11036 '((candidates-in-buffer)
11037 (persistent-help . "Show this line")))
11038 source))
11039 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11041 (defun anything-headline-init ()
11042 (when (and (anything-current-buffer-is-modified)
11043 (with-anything-current-buffer
11044 (eval (or (anything-attr 'condition) t))))
11045 (anything-headline-make-candidate-buffer
11046 (anything-interpret-value (anything-attr 'headline))
11047 (anything-interpret-value (anything-attr 'subexp)))))
11049 (anything-document-attribute 'headline "Headline plug-in"
11050 "Regexp string for anything-headline to scan.")
11051 (anything-document-attribute 'condition "Headline plug-in"
11052 "A sexp representing the condition to use anything-headline.")
11053 (anything-document-attribute 'subexp "Headline plug-in"
11054 "Display (match-string-no-properties subexp).")
11056 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11057 ;; of regexps.
11059 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11060 ;; 2. Sort this list by start-of-match.
11061 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11063 ;; It's quite brilliantly written.
11067 (defun anything-headline-get-candidates (regexp subexp)
11068 (with-anything-current-buffer
11069 (save-excursion
11070 (goto-char (point-min))
11071 (if (functionp regexp) (setq regexp (funcall regexp)))
11072 (let (hierarchy curhead)
11073 (flet ((matched ()
11074 (if (numberp subexp)
11075 (cons (match-string-no-properties subexp) (match-beginning subexp))
11076 (cons (buffer-substring (point-at-bol) (point-at-eol))
11077 (point-at-bol))))
11078 (hierarchies (headlines)
11079 (1+ (loop for (_ . hierarchy) in headlines
11080 maximize hierarchy)))
11081 (vector-0-n (v n)
11082 (loop for i from 0 to hierarchy
11083 collecting (aref curhead i)))
11084 (arrange (headlines)
11085 (unless (null headlines) ; FIX headlines empty bug!
11086 (loop with curhead = (make-vector (hierarchies headlines) "")
11087 for ((str . pt) . hierarchy) in headlines
11088 do (aset curhead hierarchy str)
11089 collecting
11090 (cons
11091 (format "H%d:%s" (1+ hierarchy)
11092 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11093 pt)))))
11094 (if (listp regexp)
11095 (arrange
11096 (sort
11097 (loop for re in regexp
11098 for hierarchy from 0
11099 do (goto-char (point-min))
11100 appending
11101 (loop
11102 while (re-search-forward re nil t)
11103 collect (cons (matched) hierarchy)))
11104 (lambda (a b) (> (cdar b) (cdar a)))))
11105 (loop while (re-search-forward regexp nil t)
11106 collect (matched))))))))
11109 (defun anything-headline-make-candidate-buffer (regexp subexp)
11110 (with-current-buffer (anything-candidate-buffer 'local)
11111 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11112 do (insert
11113 (format "%5d:%s\n"
11114 (with-anything-current-buffer
11115 (line-number-at-pos pos))
11116 content)))))
11118 (defun anything-headline-goto-position (pos recenter)
11119 (goto-char pos)
11120 (unless recenter
11121 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11124 ;; Plug-in: persistent-help
11125 (defun anything-compile-source--persistent-help (source)
11126 (append source '((header-line . anything-persistent-help-string))))
11127 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11129 (defun anything-persistent-help-string ()
11130 (substitute-command-keys
11131 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11132 (or (anything-interpret-value (anything-attr 'persistent-help))
11133 (anything-aif (or (assoc-default 'persistent-action
11134 (anything-get-current-source))
11135 (assoc-default 'action
11136 (anything-get-current-source)))
11137 (cond ((symbolp it) (symbol-name it))
11138 ((listp it) (or (ignore-errors (caar it)) ""))))
11140 " (keeping session)")))
11142 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11143 "A string to explain persistent-action of this source.
11144 It also accepts a function or a variable name.")
11146 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11148 ;; Plug-in: Type customize
11149 (defun anything-c-uniq-list (lst)
11150 "Like `remove-duplicates' in CL.
11151 But cut deeper duplicates and test by `equal'. "
11152 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11153 (defvar anything-additional-type-attributes nil)
11154 (defun anything-c-arrange-type-attribute (type spec)
11155 "Override type attributes by `define-anything-type-attribute'.
11157 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11159 Example: Set `play-sound-file' as default action
11160 (anything-c-arrange-type-attribute 'file
11161 '((action (\"Play sound\" . play-sound-file)
11162 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11165 (add-to-list 'anything-additional-type-attributes
11166 (cons type
11167 (loop with typeattr = (assoc-default type anything-type-attributes)
11168 for (attr . value) in spec
11169 if (listp value)
11170 collect (cons attr
11171 (anything-c-uniq-list
11172 (loop for v in value
11173 if (eq v 'REST)
11174 append (assoc-default attr typeattr)
11175 else
11176 collect v)))
11177 else
11178 collect (cons attr value)))))
11179 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11181 (defun anything-compile-source--type-customize (source)
11182 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11183 (append it source)
11184 source))
11185 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11187 ;; Plug-in: default-action
11188 (defun anything-compile-source--default-action (source)
11189 (anything-aif (assoc-default 'default-action source)
11190 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11191 source)
11192 source))
11193 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11194 (anything-document-attribute 'default-action "default-action plug-in"
11195 "Default action.")
11198 ;;; Toggle anything-match-plugin
11201 (defvar anything-mp-initial-highlight-delay nil)
11203 ;;;###autoload
11204 (defun anything-c-toggle-match-plugin ()
11205 "Toggle anything-match-plugin."
11206 (interactive)
11207 (let ((anything-match-plugin-enabled
11208 (member 'anything-compile-source--match-plugin
11209 anything-compile-source-functions)))
11210 (flet ((disable-match-plugin ()
11211 (setq anything-compile-source-functions
11212 (delq 'anything-compile-source--match-plugin
11213 anything-compile-source-functions))
11214 (setq anything-mp-initial-highlight-delay
11215 anything-mp-highlight-delay)
11216 (setq anything-mp-highlight-delay nil))
11217 (enable-match-plugin ()
11218 (require 'anything-match-plugin)
11219 (unless anything-mp-initial-highlight-delay
11220 (setq anything-mp-initial-highlight-delay
11221 anything-mp-highlight-delay))
11222 (setq anything-compile-source-functions
11223 (cons 'anything-compile-source--match-plugin
11224 anything-compile-source-functions))
11225 (unless anything-mp-highlight-delay
11226 (setq anything-mp-highlight-delay
11227 anything-mp-initial-highlight-delay))))
11228 (if anything-match-plugin-enabled
11229 (when (y-or-n-p "Really disable match-plugin? ")
11230 (disable-match-plugin)
11231 (message "Anything-match-plugin disabled"))
11232 (when (y-or-n-p "Really enable match-plugin? ")
11233 (enable-match-plugin)
11234 (message "Anything-match-plugin enabled"))))))
11238 ;;; Type Attributes
11241 (define-anything-type-attribute 'buffer
11242 `((action
11243 ("Switch to buffer" . anything-c-switch-to-buffer)
11244 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11245 ("Switch to buffer other window" . switch-to-buffer-other-window)
11246 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11247 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11248 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11249 ("Query replace" . anything-c-buffer-query-replace)
11250 ("View buffer" . view-buffer)
11251 ("Display buffer" . display-buffer)
11252 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11253 ("Revert buffer(s)" . anything-revert-marked-buffers)
11254 ("Insert buffer" . insert-buffer)
11255 ("Kill buffer(s)" . anything-kill-marked-buffers)
11256 ("Diff with file" . diff-buffer-with-file)
11257 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11258 ("Ediff Merge marked buffers" . (lambda (candidate)
11259 (anything-ediff-marked-buffers candidate t))))
11260 (persistent-help . "Show this buffer")
11261 (candidate-transformer anything-c-skip-current-buffer
11262 anything-c-skip-boring-buffers
11263 anything-c-transform-buffer-display-string))
11264 "Buffer or buffer name.")
11266 (define-anything-type-attribute 'file
11267 `((action
11268 ("Find file" . anything-find-many-files)
11269 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11270 ("Find file as root" . anything-find-file-as-root)
11271 ("Find file other window" . find-file-other-window)
11272 ("Find file other frame" . find-file-other-frame)
11273 ("Open dired in file's directory" . anything-c-open-dired)
11274 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11275 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11276 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11277 ("Checksum File" . anything-ff-checksum)
11278 ("Ediff File" . anything-find-files-ediff-files)
11279 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11280 ("View file" . view-file)
11281 ("Insert file" . insert-file)
11282 ("Delete file(s)" . anything-delete-marked-files)
11283 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11284 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11285 ("Find file in hex dump" . hexl-find-file))
11286 (persistent-help . "Show this file")
11287 (action-transformer anything-c-transform-file-load-el
11288 anything-c-transform-file-browse-url)
11289 (candidate-transformer anything-c-w32-pathname-transformer
11290 anything-c-skip-current-file
11291 anything-c-skip-boring-files
11292 anything-c-shorten-home-path))
11293 "File name.")
11295 (let ((actions '(("Describe command" . describe-function)
11296 ("Add command to kill ring" . anything-c-kill-new)
11297 ("Go to command's definition" . find-function)
11298 ("Debug on entry" . debug-on-entry)
11299 ("Cancel debug on entry" . cancel-debug-on-entry)
11300 ("Trace function" . trace-function)
11301 ("Trace function (background)" . trace-function-background)
11302 ("Untrace function" . untrace-function))))
11303 (define-anything-type-attribute 'command
11304 `((action ("Call interactively" . anything-c-call-interactively)
11305 ,@actions)
11306 ;; Sort commands according to their usage count.
11307 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11308 (coerce . anything-c-symbolify)
11309 (persistent-action . describe-function))
11310 "Command. (string or symbol)")
11312 (define-anything-type-attribute 'function
11313 `((action . ,actions)
11314 (action-transformer anything-c-transform-function-call-interactively)
11315 (candidate-transformer anything-c-mark-interactive-functions)
11316 (coerce . anything-c-symbolify))
11317 "Function. (string or symbol)"))
11319 (define-anything-type-attribute 'variable
11320 '((action ("Describe variable" . describe-variable)
11321 ("Add variable to kill ring" . anything-c-kill-new)
11322 ("Go to variable's definition" . find-variable)
11323 ("Set variable" . anything-c-set-variable))
11324 (coerce . anything-c-symbolify))
11325 "Variable.")
11327 (define-anything-type-attribute 'sexp
11328 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11329 ("Add s-expression to kill ring" . kill-new))
11330 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11331 "String representing S-Expressions.")
11333 (define-anything-type-attribute 'bookmark
11334 `((coerce . anything-bookmark-get-bookmark-from-name)
11335 (action
11336 ("Jump to bookmark" . (lambda (bookmark)
11337 (let ((current-prefix-arg anything-current-prefix-arg))
11338 (bookmark-jump bookmark))
11339 (anything-update)))
11340 ("Jump to BM other window" . (lambda (bookmark)
11341 (bookmark-jump-other-window bookmark)
11342 (anything-update)))
11343 ("Bookmark edit annotation" . bookmark-edit-annotation)
11344 ("Bookmark show annotation" . bookmark-show-annotation)
11345 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11346 ,@(and (locate-library "bookmark-extensions")
11347 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11348 ("Rename bookmark" . bookmark-rename)
11349 ("Relocate bookmark" . bookmark-relocate)))
11350 "Bookmark name.")
11352 (define-anything-type-attribute 'line
11353 '((display-to-real . anything-c-display-to-real-line)
11354 (action ("Go to Line" . anything-c-action-line-goto)))
11355 "LINENO:CONTENT string, eg. \" 16:foo\".
11357 Optional `target-file' attribute is a name of target file.
11359 Optional `before-jump-hook' attribute is a function with no
11360 arguments which is called before jumping to position.
11362 Optional `after-jump-hook' attribute is a function with no
11363 arguments which is called after jumping to position.
11365 If `adjust' attribute is specified, searches the line whose
11366 content is CONTENT near the LINENO.
11368 If `recenter' attribute is specified, the line is displayed at
11369 the center of window, otherwise at the top of window.
11372 (define-anything-type-attribute 'file-line
11373 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11374 (multiline)
11375 (action ("Go to" . anything-c-action-file-line-goto)))
11376 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11378 Optional `default-directory' attribute is a default-directory
11379 FILENAME is interpreted.
11381 Optional `before-jump-hook' attribute is a function with no
11382 arguments which is called before jumping to position.
11384 Optional `after-jump-hook' attribute is a function with no
11385 arguments which is called after jumping to position.
11387 If `adjust' attribute is specified, searches the line whose
11388 content is CONTENT near the LINENO.
11390 If `recenter' attribute is specified, the line is displayed at
11391 the center of window, otherwise at the top of window.
11394 (define-anything-type-attribute 'timer
11395 '((real-to-display . anything-c-timer-real-to-display)
11396 (action ("Cancel Timer" . cancel-timer)
11397 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11398 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11399 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11400 (persistent-help . "Describe Function"))
11401 "Timer.")
11404 ;;; Default `anything-sources'
11405 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11406 ;; tend to invoke M-x anything directly. So I offer default setting.
11407 (setq anything-sources
11408 '(anything-c-source-buffers-list
11409 anything-c-source-recentf
11410 anything-c-source-files-in-current-dir+))
11413 ;;; Preconfigured Anything
11416 ;;;###autoload
11417 (defun anything-mini ()
11418 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11419 (interactive)
11420 (anything-other-buffer '(anything-c-source-buffers-list
11421 anything-c-source-recentf
11422 anything-c-source-buffer-not-found)
11423 "*anything mini*"))
11424 ;;;###autoload
11425 (defun anything-for-files ()
11426 "Preconfigured `anything' for opening files.
11427 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11428 (interactive)
11429 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11431 ;;;###autoload
11432 (defun anything-recentf ()
11433 "Preconfigured `anything' for `recentf'."
11434 (interactive)
11435 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11437 ;;;###autoload
11438 (defun anything-info-at-point (arg)
11439 "Preconfigured `anything' for searching info at point.
11440 With a prefix-arg insert symbol at point."
11441 (interactive "P")
11442 (let ((anything-c-google-suggest-default-function
11443 'anything-c-google-suggest-emacs-lisp))
11444 (anything-1 :sources '(anything-c-source-info-elisp
11445 anything-c-source-info-cl
11446 anything-c-source-info-pages
11447 anything-c-source-google-suggest)
11448 :input (and arg (thing-at-point 'symbol))
11449 :buffer "*anything info*")))
11451 ;;;###autoload
11452 (defun anything-info-emacs ()
11453 "Preconfigured anything for Emacs manual index."
11454 (interactive)
11455 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11457 ;;;###autoload
11458 (defun anything-show-kill-ring ()
11459 "Preconfigured `anything' for `kill-ring'.
11460 It is drop-in replacement of `yank-pop'.
11461 You may bind this command to M-y.
11462 First call open the kill-ring browser, next calls move to next line."
11463 (interactive)
11464 (let ((buf "*anything kill-ring*"))
11465 (if (get-buffer-window buf)
11466 (with-anything-window
11467 (if (eq (overlay-end anything-selection-overlay) (point-max))
11468 (anything-beginning-of-buffer)
11469 (anything-next-line)))
11470 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11472 ;;;###autoload
11473 (defun anything-minibuffer-history ()
11474 "Preconfigured `anything' for `minibuffer-history'."
11475 (interactive)
11476 (let ((enable-recursive-minibuffers t))
11477 (anything-other-buffer 'anything-c-source-minibuffer-history
11478 "*anything minibuffer-history*")))
11480 ;;;###autoload
11481 (defun anything-gentoo ()
11482 "Preconfigured `anything' for gentoo linux."
11483 (interactive)
11484 (anything-other-buffer '(anything-c-source-gentoo
11485 anything-c-source-use-flags)
11486 "*anything gentoo*"))
11488 ;;;###autoload
11489 (defun anything-imenu ()
11490 "Preconfigured `anything' for `imenu'."
11491 (interactive)
11492 (anything-1 :sources 'anything-c-source-imenu
11493 :buffer "*anything imenu*"))
11495 ;;;###autoload
11496 (defun anything-google-suggest ()
11497 "Preconfigured `anything' for google search with google suggest."
11498 (interactive)
11499 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11501 ;;;###autoload
11502 (defun anything-yahoo-suggest ()
11503 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11504 (interactive)
11505 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11507 ;;; Converted from anything-show-*-only
11508 ;;;###autoload
11509 (defun anything-for-buffers ()
11510 "Preconfigured `anything' for buffer."
11511 (interactive)
11512 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11514 ;;;###autoload
11515 (defun anything-buffers-list ()
11516 "Enhanced preconfigured `anything' for buffer."
11517 (interactive)
11518 (anything-1 :sources '(anything-c-source-buffers-list
11519 anything-c-source-buffer-not-found)
11520 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11522 ;;;###autoload
11523 (defun anything-bbdb ()
11524 "Preconfigured `anything' for BBDB.
11526 Needs BBDB.
11528 http://bbdb.sourceforge.net/"
11529 (interactive)
11530 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11532 ;;;###autoload
11533 (defun anything-locate (arg)
11534 "Preconfigured `anything' for Locate.
11535 Note: you can add locate options after entering pattern.
11536 See 'man locate' for valid options.
11538 You can specify a specific database with prefix argument ARG \(C-u\).
11539 Many databases can be used: navigate and mark them.
11540 See also `anything-locate-with-db'.
11542 To create a user specific db, use
11543 \"updatedb -l 0 -o db_path -U directory\".
11544 Where db_path is a filename matched by
11545 `anything-locate-db-file-regexp'."
11546 (interactive "P")
11547 (anything-locate-1 arg))
11549 ;;;###autoload
11550 (defun anything-w3m-bookmarks ()
11551 "Preconfigured `anything' for w3m bookmark.
11553 Needs w3m and emacs-w3m.
11555 http://w3m.sourceforge.net/
11556 http://emacs-w3m.namazu.org/"
11557 (interactive)
11558 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11559 "*anything w3m bookmarks*"))
11561 ;;;###autoload
11562 (defun anything-firefox-bookmarks ()
11563 "Preconfigured `anything' for firefox bookmark.
11564 You will have to enable html bookmarks in firefox:
11565 open about:config in firefox and double click on this line to enable value \
11566 to true:
11568 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11570 You should have now:
11572 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11574 After closing firefox, you will be able to browse you bookmarks.
11576 (interactive)
11577 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11578 "*Anything Firefox*"))
11580 ;;;###autoload
11581 (defun anything-colors ()
11582 "Preconfigured `anything' for color."
11583 (interactive)
11584 (anything-other-buffer
11585 '(anything-c-source-colors anything-c-source-customize-face)
11586 "*anything colors*"))
11588 ;;;###autoload
11589 (defun anything-bookmarks ()
11590 "Preconfigured `anything' for bookmarks."
11591 (interactive)
11592 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11594 ;;;###autoload
11595 (defun anything-c-pp-bookmarks ()
11596 "Preconfigured `anything' for bookmarks (pretty-printed)."
11597 (interactive)
11598 (anything-other-buffer '(anything-c-source-bookmarks-local
11599 anything-c-source-bookmarks-su
11600 anything-c-source-bookmarks-ssh)
11601 "*anything pp bookmarks*"))
11603 ;;;###autoload
11604 (defun anything-c-insert-latex-math ()
11605 "Preconfigured anything for latex math symbols completion."
11606 (interactive)
11607 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11609 ;;;###autoload
11610 (defun anything-register ()
11611 "Preconfigured `anything' for Emacs registers."
11612 (interactive)
11613 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11615 ;;;###autoload
11616 (defun anything-man-woman ()
11617 "Preconfigured `anything' for Man and Woman pages."
11618 (interactive)
11619 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11621 ;;;###autoload
11622 (defun anything-org-keywords ()
11623 "Preconfigured `anything' for org keywords."
11624 (interactive)
11625 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11627 ;;;###autoload
11628 (defun anything-emms ()
11629 "Preconfigured `anything' for emms sources."
11630 (interactive)
11631 (anything-1 :sources '(anything-c-source-emms-streams
11632 anything-c-source-emms-files
11633 anything-c-source-emms-dired)
11634 :buffer "*Anything Emms*"))
11636 ;;;###autoload
11637 (defun anything-eev-anchors ()
11638 "Preconfigured `anything' for eev anchors."
11639 (interactive)
11640 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11642 ;;;###autoload
11643 (defun anything-bm-list ()
11644 "Preconfigured `anything' for visible bookmarks.
11646 Needs bm.el
11648 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11649 (interactive)
11650 (let ((anything-outline-using t))
11651 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11653 ;;;###autoload
11654 (defun anything-timers ()
11655 "Preconfigured `anything' for timers."
11656 (interactive)
11657 (anything-other-buffer '(anything-c-source-absolute-time-timers
11658 anything-c-source-idle-time-timers)
11659 "*anything timers*"))
11661 ;;;###autoload
11662 (defun anything-list-emacs-process ()
11663 "Preconfigured `anything' for emacs process."
11664 (interactive)
11665 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11667 ;;;###autoload
11668 (defun anything-occur ()
11669 "Preconfigured Anything for Occur source.
11670 If region is active, search only in region,
11671 otherwise search in whole buffer."
11672 (interactive)
11673 (let ((anything-compile-source-functions
11674 ;; rule out anything-match-plugin because the input is one regexp.
11675 (delq 'anything-compile-source--match-plugin
11676 (copy-sequence anything-compile-source-functions))))
11677 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11679 ;;;###autoload
11680 (defun anything-browse-code ()
11681 "Preconfigured anything to browse code."
11682 (interactive)
11683 (anything-1 :sources 'anything-c-source-browse-code
11684 :buffer "*anything browse code*"
11685 :default (thing-at-point 'symbol)))
11687 ;;;###autoload
11688 (defun anything-org-headlines ()
11689 "Preconfigured anything to show org headlines."
11690 (interactive)
11691 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11693 ;;;###autoload
11694 (defun anything-info-gnus ()
11695 "Preconfigured anything to browse Gnus Manual."
11696 (interactive)
11697 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11699 ;;;###autoload
11700 (defun anything-regexp ()
11701 "Preconfigured anything to build regexps.
11702 `query-replace-regexp' can be run from there against found regexp."
11703 (interactive)
11704 (save-restriction
11705 (let ((anything-compile-source-functions
11706 ;; rule out anything-match-plugin because the input is one regexp.
11707 (delq 'anything-compile-source--match-plugin
11708 (copy-sequence anything-compile-source-functions))))
11709 (when (and (anything-region-active-p)
11710 ;; Don't narrow to region if buffer is already narrowed.
11711 (not (anything-current-buffer-narrowed-p)))
11712 (narrow-to-region (region-beginning) (region-end)))
11713 (anything-1 :sources anything-c-source-regexp
11714 :buffer "*anything regexp*"
11715 :prompt "Regexp: "
11716 :history 'anything-build-regexp-history))))
11718 (defun anything-c-copy-files-async ()
11719 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11720 (interactive)
11721 (let* ((flist (anything-c-read-file-name
11722 "Copy File async: "
11723 :marked-candidates t))
11724 (dest (anything-c-read-file-name
11725 "Copy File async To: "
11726 :preselect (car flist)
11727 :initial-input (car anything-ff-history)
11728 :history (anything-find-files-history :comp-read nil))))
11729 (anything-c-copy-async-with-log flist dest)))
11731 ;;;###autoload
11732 (defun anything-find-files (arg)
11733 "Preconfigured `anything' for anything implementation of `find-file'.
11734 Called with a prefix arg show history if some.
11735 Don't call it from programs, use `anything-find-files-1' instead.
11736 This is the starting point for nearly all actions you can do on files."
11737 (interactive "P")
11738 (let ((any-input (if (and arg anything-ff-history)
11739 (anything-find-files-history)
11740 (anything-find-files-initial-input)))
11741 (presel (buffer-file-name (current-buffer))))
11742 (when (and (eq major-mode 'org-agenda-mode)
11743 org-directory
11744 (not any-input))
11745 (setq any-input (expand-file-name org-directory)))
11746 (set-text-properties 0 (length any-input) nil any-input)
11747 (if any-input
11748 (anything-find-files-1 any-input)
11749 (setq any-input (expand-file-name (anything-c-current-directory)))
11750 (anything-find-files-1
11751 any-input (if anything-ff-transformer-show-only-basename
11752 (and presel (anything-c-basename presel))
11753 presel)))))
11755 ;;;###autoload
11756 (defun anything-write-file ()
11757 "Preconfigured `anything' providing completion for `write-file'."
11758 (interactive)
11759 (let ((anything-mp-highlight-delay nil))
11760 (anything-1 :sources 'anything-c-source-write-file
11761 :input (expand-file-name default-directory)
11762 :prompt "Write buffer to file: "
11763 :buffer "*Anything write file*")))
11765 ;;;###autoload
11766 (defun anything-insert-file ()
11767 "Preconfigured `anything' providing completion for `insert-file'."
11768 (interactive)
11769 (let ((anything-mp-highlight-delay nil))
11770 (anything-1 :sources 'anything-c-source-insert-file
11771 :input (expand-file-name default-directory)
11772 :prompt "Insert file: "
11773 :buffer "*Anything insert file*")))
11775 ;;;###autoload
11776 (defun anything-dired-rename-file ()
11777 "Preconfigured `anything' to rename files from dired."
11778 (interactive)
11779 (anything-dired-do-action-on-file :action 'rename))
11781 ;;;###autoload
11782 (defun anything-dired-copy-file ()
11783 "Preconfigured `anything' to copy files from dired."
11784 (interactive)
11785 (anything-dired-do-action-on-file :action 'copy))
11787 ;;;###autoload
11788 (defun anything-dired-symlink-file ()
11789 "Preconfigured `anything' to symlink files from dired."
11790 (interactive)
11791 (anything-dired-do-action-on-file :action 'symlink))
11793 ;;;###autoload
11794 (defun anything-dired-hardlink-file ()
11795 "Preconfigured `anything' to hardlink files from dired."
11796 (interactive)
11797 (anything-dired-do-action-on-file :action 'hardlink))
11799 ;;;###autoload
11800 (defun anything-do-grep ()
11801 "Preconfigured anything for grep.
11802 Contrarily to Emacs `grep' no default directory is given, but
11803 the full path of candidates in ONLY.
11804 That allow to grep different files not only in `default-directory' but anywhere
11805 by marking them (C-<SPACE>). If one or more directory is selected
11806 grep will search in all files of these directories.
11807 You can use also wildcard in the base name of candidate.
11808 If a prefix arg is given use the -r option of grep.
11809 The prefix arg can be passed before or after start.
11810 See also `anything-do-grep-1'."
11811 (interactive)
11812 (let ((only (anything-c-read-file-name
11813 "Search in file(s): "
11814 :marked-candidates t
11815 :preselect (or (dired-get-filename nil t)
11816 (buffer-file-name (current-buffer)))))
11817 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11818 (anything-do-grep-1 only prefarg)))
11820 ;;;###autoload
11821 (defun anything-do-zgrep (candidate)
11822 "Preconfigured anything for zgrep."
11823 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11824 (ls (anything-c-read-file-name
11825 "Search in file(s): "
11826 :marked-candidates t
11827 :preselect (or (dired-get-filename nil t)
11828 (buffer-file-name (current-buffer))))))
11829 (anything-ff-zgrep-1 ls prefarg)))
11831 (defun anything-c-etags-select (arg)
11832 "Preconfigured anything for etags.
11833 Called with one prefix arg use symbol at point as initial input.
11834 Called with two prefix arg reinitialize cache.
11835 If tag file have been modified reinitialize cache."
11836 (interactive "P")
11837 (let ((tag (anything-c-etags-get-tag-file))
11838 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11839 (anything-quit-if-no-candidate t)
11840 (anything-execute-action-at-once-if-one t)
11841 (anything-compile-source-functions
11842 (if anything-c-etags-use-regexp-search
11843 ;; rule out anything-match-plugin because the input is one regexp.
11844 (delq 'anything-compile-source--match-plugin
11845 (copy-sequence anything-compile-source-functions))
11846 anything-compile-source-functions)))
11847 (when (or (equal arg '(16))
11848 (and anything-c-etags-mtime-alist
11849 (anything-c-etags-file-modified-p tag)))
11850 (remhash tag anything-c-etags-cache))
11851 (if (and tag (file-exists-p tag))
11852 (anything-1 :sources 'anything-c-source-etags-select
11853 :keymap anything-c-etags-map
11854 :input init
11855 :buffer "*anything etags*")
11856 (message "Error: No tag file found, please create one with etags shell command."))))
11858 ;;;###autoload
11859 (defun anything-filelist ()
11860 "Preconfigured `anything' to open files instantly.
11862 See `anything-c-filelist-file-name' docstring for usage."
11863 (interactive)
11864 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11866 ;;;###autoload
11867 (defun anything-filelist+ ()
11868 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11870 This is a replacement for `anything-for-files'.
11871 See `anything-c-filelist-file-name' docstring for usage."
11872 (interactive)
11873 (anything-other-buffer
11874 '(anything-c-source-ffap-line
11875 anything-c-source-ffap-guesser
11876 anything-c-source-buffers-list
11877 anything-c-source-recentf
11878 anything-c-source-bookmarks
11879 anything-c-source-file-cache
11880 anything-c-source-filelist)
11881 "*anything file list*"))
11883 ;;;###autoload
11884 (defun anything-M-x ()
11885 "Preconfigured `anything' for Emacs commands.
11886 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11887 (interactive)
11888 (let* (in-help
11889 help-cand
11890 special-display-buffer-names
11891 special-display-regexps
11892 anything-persistent-action-use-special-display
11893 (history (loop with hist
11894 for i in extended-command-history
11895 for com = (intern i)
11896 when (fboundp com)
11897 collect i into hist finally return hist)))
11898 (flet ((pers-help (candidate)
11899 (let ((hbuf (get-buffer (help-buffer))))
11900 (if (and in-help (string= candidate help-cand))
11901 (progn
11902 ;; When M-x is started from a help buffer,
11903 ;; Don't kill it as it is anything-current-buffer.
11904 (unless (equal hbuf anything-current-buffer)
11905 (kill-buffer hbuf))
11906 (setq in-help nil))
11907 ;; Be sure anything-current-buffer
11908 ;; have not a dedicated window.
11909 (set-window-dedicated-p
11910 (get-buffer-window anything-current-buffer) nil)
11911 (describe-function (intern candidate))
11912 (message nil) ; Erase the new stupid message Type "q"[...]
11913 (setq in-help t))
11914 (setq help-cand candidate))))
11915 (let* ((command
11917 (anything-1
11918 :sources
11919 `(((name . "Emacs Commands history")
11920 (candidates . ,history)
11921 (filtered-candidate-transformer
11922 . (lambda (candidates sources)
11923 (loop for i in candidates
11924 do (set-text-properties 0 (length i) nil i)
11925 collect i)))
11926 (persistent-action . pers-help)
11927 (persistent-help . "Describe this command")
11928 (action . identity))
11929 ((name . "Emacs Commands")
11930 (init
11931 . (lambda ()
11932 (with-current-buffer (anything-candidate-buffer 'global)
11933 (goto-char (point-min))
11934 (loop
11935 for sym in (all-completions "" obarray 'commandp)
11936 do (insert (concat sym "\n"))))))
11937 (persistent-action . pers-help)
11938 (persistent-help . "Describe this command")
11939 (filtered-candidate-transformer . anything-M-x-transformer)
11940 (candidates-in-buffer)
11941 (action . identity)))
11942 :resume 'noresume
11943 :history 'anything-M-x-input-history
11944 :buffer "*anything M-x*")
11945 (keyboard-quit)))
11946 (sym-com (intern command)))
11947 (unless current-prefix-arg
11948 (setq current-prefix-arg anything-current-prefix-arg))
11949 ;; Avoid having `this-command' set to *exit-minibuffer.
11950 (setq this-command sym-com)
11951 (call-interactively sym-com)
11952 (setq extended-command-history
11953 (cons command (delete command history)))))))
11955 ;;;###autoload
11956 (defun anything-manage-advice ()
11957 "Preconfigured `anything' to disable/enable function advices."
11958 (interactive)
11959 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11961 ;;;###autoload
11962 (defun anything-bookmark-ext ()
11963 "Preconfigured `anything' for bookmark-extensions sources.
11964 Needs bookmark-ext.el:
11965 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11966 Contain also `anything-c-source-google-suggest'."
11967 (interactive)
11968 (anything-1
11969 :sources
11970 '(anything-c-source-bookmark-files&dirs
11971 anything-c-source-bookmark-w3m
11972 anything-c-source-google-suggest
11973 anything-c-source-bmkext-addressbook
11974 anything-c-source-bookmark-gnus
11975 anything-c-source-bookmark-info
11976 anything-c-source-bookmark-man
11977 anything-c-source-bookmark-images
11978 anything-c-source-bookmark-su-files&dirs
11979 anything-c-source-bookmark-ssh-files&dirs)
11980 :prompt "SearchBookmark: "
11981 :buffer "*anything bmkext*"))
11983 ;;;###autoload
11984 (defun anything-simple-call-tree ()
11985 "Preconfigured `anything' for simple-call-tree. List function relationships.
11987 Needs simple-call-tree.el.
11988 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11989 (interactive)
11990 (anything-other-buffer
11991 '(anything-c-source-simple-call-tree-functions-callers
11992 anything-c-source-simple-call-tree-callers-functions)
11993 "*anything simple-call-tree*"))
11995 ;;;###autoload
11996 (defun anything-mark-ring ()
11997 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11998 (interactive)
11999 (anything-1 :sources 'anything-c-source-mark-ring))
12001 ;;;###autoload
12002 (defun anything-global-mark-ring ()
12003 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12004 (interactive)
12005 (anything-1 :sources 'anything-c-source-global-mark-ring))
12007 ;;;###autoload
12008 (defun anything-all-mark-rings ()
12009 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12010 `anything-c-source-mark-ring'."
12011 (interactive)
12012 (anything-1 :sources '(anything-c-source-mark-ring
12013 anything-c-source-global-mark-ring)))
12015 ;;;###autoload
12016 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12017 "Preconfigured `anything' to edit or view EmacsWiki page.
12019 Needs yaoddmuse.el.
12021 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12022 (interactive)
12023 (anything-1 :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12025 ;;;###autoload
12026 (defun anything-yaoddmuse-emacswiki-post-library ()
12027 "Preconfigured `anything' to post library to EmacsWiki.
12029 Needs yaoddmuse.el.
12031 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12032 (interactive)
12033 (anything-1 :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12035 ;;;###autoload
12036 (defun anything-eval-expression (arg)
12037 "Preconfigured anything for `anything-c-source-evaluation-result'."
12038 (interactive "P")
12039 (anything-1 :sources 'anything-c-source-evaluation-result
12040 :input (when arg (thing-at-point 'sexp))
12041 :buffer "*anything eval*"
12042 :history 'anything-eval-expression-input-history
12043 :keymap anything-eval-expression-map))
12045 ;;;###autoload
12046 (defun anything-eval-expression-with-eldoc ()
12047 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12048 (interactive)
12049 (declare (special eldoc-idle-delay))
12050 (let ((timer (run-with-idle-timer eldoc-idle-delay
12051 'repeat 'anything-eldoc-show-in-eval))
12052 (minibuffer-completing-symbol t) ; Enable lisp completion.
12053 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12054 (unwind-protect
12055 (minibuffer-with-setup-hook
12056 'anything-eldoc-store-minibuffer
12057 (call-interactively 'anything-eval-expression))
12058 (and timer (cancel-timer timer))
12059 (setq anything-eldoc-active-minibuffers-list
12060 (cdr anything-eldoc-active-minibuffers-list)))))
12062 ;;;###autoload
12063 (defun anything-calcul-expression ()
12064 "Preconfigured anything for `anything-c-source-calculation-result'."
12065 (interactive)
12066 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12068 ;;;###autoload
12069 (defun anything-surfraw (pattern engine)
12070 "Preconfigured `anything' to search PATTERN with search ENGINE."
12071 (interactive (list (read-string "SearchFor: "
12072 nil 'anything-surfraw-input-history)
12073 (anything-comp-read
12074 "Engine: "
12075 (anything-c-build-elvi-list)
12076 :must-match t
12077 :name "Surfraw Search Engines"
12078 :history anything-surfraw-engines-history)))
12079 (let* ((engine-nodesc (car (split-string engine)))
12080 (url (with-temp-buffer
12081 (apply 'call-process "surfraw" nil t nil
12082 ;;JAVE
12083 (append (list engine-nodesc "-p") (split-string pattern)))
12084 (replace-regexp-in-string
12085 "\n" "" (buffer-string))))
12086 (browse-url-browser-function (or anything-surfraw-default-browser-function
12087 browse-url-browser-function)))
12088 (if (string= engine-nodesc "W")
12089 (anything-c-browse-url)
12090 (anything-c-browse-url url)
12091 (setq anything-surfraw-engines-history
12092 (cons engine (delete engine anything-surfraw-engines-history))))))
12094 ;;;###autoload
12095 (defun anything-call-source ()
12096 "Preconfigured `anything' to call anything source."
12097 (interactive)
12098 (anything-1 :sources 'anything-c-source-call-source
12099 :buffer anything-source-select-buffer))
12101 ;;;###autoload
12102 (defun anything-execute-anything-command ()
12103 "Preconfigured `anything' to execute preconfigured `anything'."
12104 (interactive)
12105 (anything-other-buffer 'anything-c-source-anything-commands
12106 "*anything commands*"))
12108 ;;;###autoload
12109 (defun anything-create (&optional string initial-input)
12110 "Preconfigured `anything' to do many create actions from STRING.
12111 See also `anything-create--actions'."
12112 (interactive)
12113 (setq string (or string (read-string "Create Anything: " initial-input)))
12114 (anything-1 :sources '(((name . "Anything Create")
12115 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12116 (candidates . anything-create--actions)
12117 (candidate-number-limit)
12118 (action . (lambda (func) (funcall func string)))))))
12120 ;;;###autoload
12121 (defun anything-top ()
12122 "Preconfigured `anything' for top command."
12123 (interactive)
12124 (let ((anything-samewindow t)
12125 (anything-enable-shortcuts)
12126 (anything-display-function 'anything-default-display-buffer)
12127 (anything-candidate-number-limit 9999))
12128 (save-window-excursion
12129 (delete-other-windows)
12130 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12132 ;;;###autoload
12133 (defun anything-select-xfont ()
12134 "Preconfigured `anything' to select Xfont."
12135 (interactive)
12136 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12138 ;;;###autoload
12139 (defun anything-world-time ()
12140 "Preconfigured `anything' to show world time."
12141 (interactive)
12142 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12144 ;;;###autoload
12145 (defun anything-apt (arg)
12146 "Preconfigured `anything' : frontend of APT package manager.
12147 With a prefix arg reload cache."
12148 (interactive "P")
12149 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12150 (when arg (anything-c-apt-refresh))
12151 (anything-1 :sources 'anything-c-source-apt
12152 :prompt "Search Package: "
12153 :input query
12154 :history 'anything-c-apt-input-history)))
12156 ;;;###autoload
12157 (defun anything-esh-pcomplete ()
12158 "Preconfigured anything to provide anything completion in eshell."
12159 (interactive)
12160 (let* ((anything-quit-if-no-candidate t)
12161 (anything-execute-action-at-once-if-one t)
12162 (target (thing-at-point 'symbol))
12163 (end (point))
12164 (beg (or (and target (- end (length target)))
12165 ;; Nothing at point.
12166 (progn (insert " ") (point)))))
12167 (setq anything-ec-target (or target " "))
12168 (with-anything-show-completion beg end
12169 (anything-1 :sources 'anything-c-source-esh
12170 :input (anything-ff-set-pattern ; Handle tramp filenames.
12171 (car (last (ignore-errors ; Needed in lisp symbols completion.
12172 (pcomplete-parse-arguments)))))))))
12174 ;;;###autoload
12175 (defun anything-eshell-history ()
12176 "Preconfigured anything for eshell history."
12177 (interactive)
12178 (let* ((end (point))
12179 (beg (save-excursion (eshell-bol) (point)))
12180 flag-empty)
12181 (when (eq beg end)
12182 (insert " ")
12183 (setq flag-empty t)
12184 (setq end (point)))
12185 (unwind-protect
12186 (with-anything-show-completion beg end
12187 (anything-1 :sources 'anything-c-source-eshell-history
12188 :buffer "*Eshell history*"))
12189 (when (and flag-empty
12190 (looking-back " "))
12191 (delete-char -1)))))
12193 ;;;###autoload
12194 (defun anything-c-run-external-command (program)
12195 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12196 If program is already running exit with error.
12197 You can set your own list of commands with
12198 `anything-c-external-commands-list'."
12199 (interactive (list
12200 (anything-comp-read
12201 "RunProgram: "
12202 (anything-c-external-commands-list-1 'sort)
12203 :must-match t
12204 :name "External Commands"
12205 :history anything-external-command-history)))
12206 (anything-run-or-raise program)
12207 (setq anything-external-command-history
12208 (cons program (delete program
12209 (loop for i in anything-external-command-history
12210 when (executable-find i) collect i)))))
12212 ;;;###autoload
12213 (defun anything-ratpoison-commands ()
12214 "Preconfigured `anything' to execute ratpoison commands."
12215 (interactive)
12216 (anything-other-buffer 'anything-c-source-ratpoison-commands
12217 "*anything ratpoison commands*"))
12219 ;;;###autoload
12220 (defun anything-ucs ()
12221 "Preconfigured anything for `ucs-names' math symbols."
12222 (interactive)
12223 (anything-1 :sources 'anything-c-source-ucs
12224 :keymap anything-c-ucs-map))
12226 ;;;###autoload
12227 (defun anything-c-apropos ()
12228 "Preconfigured anything to describe commands, functions, variables and faces."
12229 (interactive)
12230 (let ((default (thing-at-point 'symbol)))
12231 (anything-1 :sources
12232 `(((name . "Commands")
12233 (init . (lambda ()
12234 (anything-c-apropos-init 'commandp ,default)))
12235 (persistent-action . anything-lisp-completion-persistent-action)
12236 (persistent-help . "Show brief doc in mode-line")
12237 (candidates-in-buffer)
12238 (action . (lambda (candidate)
12239 (describe-function (intern candidate)))))
12240 ((name . "Functions")
12241 (init . (lambda ()
12242 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12243 (not (commandp x))))
12244 ,default)))
12245 (persistent-action . anything-lisp-completion-persistent-action)
12246 (persistent-help . "Show brief doc in mode-line")
12247 (candidates-in-buffer)
12248 (action . (lambda (candidate)
12249 (describe-function (intern candidate)))))
12250 ((name . "Variables")
12251 (init . (lambda ()
12252 (anything-c-apropos-init 'boundp ,default)))
12253 (persistent-action . anything-lisp-completion-persistent-action)
12254 (persistent-help . "Show brief doc in mode-line")
12255 (candidates-in-buffer)
12256 (action . (lambda (candidate)
12257 (describe-variable (intern candidate)))))
12258 ((name . "Faces")
12259 (init . (lambda ()
12260 (anything-c-apropos-init 'facep ,default)))
12261 (persistent-action . anything-lisp-completion-persistent-action)
12262 (persistent-help . "Show brief doc in mode-line")
12263 (candidates-in-buffer)
12264 (filtered-candidate-transformer . (lambda (candidates source)
12265 (loop for c in candidates
12266 collect (propertize c 'face (intern c)))))
12267 (action . (lambda (candidate)
12268 (describe-face (intern candidate)))))
12269 ((name . "Anything attributes")
12270 (candidates . (lambda ()
12271 (mapcar 'symbol-name anything-additional-attributes)))
12272 (action . (lambda (candidate)
12273 (with-output-to-temp-buffer "*Help*"
12274 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12277 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12280 (provide 'anything-config)
12282 ;;; Local Variables:
12283 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12284 ;;; End:
12286 ;; How to save (DO NOT REMOVE!!)
12287 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12288 ;;; anything-config.el ends here
12290 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12291 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12292 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12293 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12294 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12295 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12296 ;;; LocalWords: dotimes Thierry online vname
12297 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12298 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12299 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12300 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12301 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12302 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12303 ;;; LocalWords: startpos noselect dont desc