* anything.el Use anything keywords in some places.
[anything-config.git] / anything-config.el
blob5bf7472bf336305780030ac32055fd6be12c58a0
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-buffer
844 "*anything"
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 literally and *match-plugin is used
1066 if available."
1067 :group 'anything-config
1068 :type 'boolean)
1070 (defcustom anything-c-filelist-file-name nil
1071 "Filename of file list.
1072 Accept a list of string for multiple files.
1074 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1075 File list is created by make-filelist.rb script.
1077 Usage:
1078 ruby make-filelist.rb > /tmp/all.filelist
1080 Then
1081 ;; Assume that /tmp is ramdisk or tmpfs
1082 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1083 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1085 :type 'string
1086 :group 'anything-config)
1088 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1089 'anything-c-eldoc-show-in-mode-line
1090 "A function to display eldoc info.
1091 Should take one arg: the string to display."
1092 :group 'anything-config
1093 :type 'symbol)
1095 (defcustom anything-c-turn-on-show-completion t
1096 "Display candidate in buffer while moving selection when non--nil."
1097 :group 'anything-config
1098 :type 'boolean)
1100 (defcustom anything-lisp-completion-or-indent-delay 0.6
1101 "After this delay `anything-lisp-completion-counter' is reset to 0.
1102 This allow to indent again without completing lisp symbol after this delay.
1103 Default is 0.6 seconds."
1104 :group 'anything-config
1105 :type 'number)
1107 (defcustom anything-c-default-external-file-browser "nautilus"
1108 "Default external file browser for your system.
1109 Directories will be opened externally with it.
1110 Set to nil if you do not have external file browser
1111 or do not want to use it."
1112 :group 'anything-config
1113 :type 'string)
1115 (defcustom anything-c-use-adaptative-sorting nil
1116 "*Wheter to use or not adaptative sorting.
1117 Even if a source use it, it will have no effect when set to nil."
1118 :type 'boolean
1119 :group 'anything-config)
1121 (defcustom anything-ff-newfile-prompt-p t
1122 "Whether Prompt or not when creating new file.
1123 This set `ffap-newfile-prompt'."
1124 :type 'boolean
1125 :group 'anything-config)
1128 (defcustom anything-ff-avfs-directory nil
1129 "*The default avfs directory, usually '.avfs'.
1130 When this is set you will be able to expand archive filenames with `C-z'
1131 inside an avfs directory mounted with mountavfs.
1132 See <http://sourceforge.net/projects/avf/>."
1133 :type 'boolean
1134 :group 'anything-config)
1136 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1137 "*Minimal list of compressed files extension."
1138 :type 'list
1139 :group 'anything-config)
1141 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1142 "Default regexp to match locate database.
1143 If nil Search in all files."
1144 :type 'string
1145 :group 'anything-config)
1147 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1148 "Eldoc will show info in mode-line during this delay if user is idle."
1149 :type 'integer
1150 :group 'anything-config)
1152 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1153 "The file used to communicate with two emacs when copying files async."
1154 :type 'string
1155 :group 'anything-config)
1157 (defcustom anything-ff-printer-list nil
1158 "A list of available printers on your system.
1159 When non--nil let you choose a printer to print file.
1160 Otherwise when nil the variable `printer-name' will be used.
1161 On Unix based systems you can use `anything-ff-find-printers' to
1162 find a list of available printers."
1163 :type 'list
1164 :group 'anything-config)
1166 (defcustom anything-ff-transformer-show-only-basename nil
1167 "Show only basename of candidates in `anything-find-files'.
1168 This can be toggled at anytime from `anything-find-files' with \
1169 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1170 :type 'boolean
1171 :group 'anything-config)
1173 (defcustom anything-completing-read-handlers-alist
1174 '((describe-function . anything-completing-read-symbols)
1175 (describe-variable . anything-completing-read-symbols)
1176 (debug-on-entry . anything-completing-read-symbols)
1177 (find-function . anything-completing-read-symbols)
1178 (trace-function . anything-completing-read-symbols)
1179 (trace-function-background . anything-completing-read-symbols)
1180 (ffap-alternate-file . nil))
1181 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1182 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1183 where key and value are symbols.
1185 Each key is an Emacs command that use originaly `completing-read'.
1187 Each value maybe an anything function that take same arguments as
1188 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1189 anything source and BUFFER the name of the buffer we will use.
1190 This function prefix name must start by \"anything\".
1192 See `anything-completing-read-symbols' for example.
1194 If the value of an entry is nil completion will fall back to
1195 emacs vanilla behavior.
1196 e.g If you want to disable anything completion for `describe-function':
1197 \(describe-function . nil\).
1199 Ido is also supported, you can use `ido-completing-read' and
1200 `ido-read-file-name' as value of an entry or just 'ido.
1201 e.g ido completion for `find-file':
1202 \(find-file . ido\)
1203 same as
1204 \(find-file . ido-read-file-name\)
1205 Note that you don't need to enable `ido-mode' for this to work."
1206 :group 'anything-config
1207 :type '(alist :key-type symbol :value-type symbol))
1211 ;;; General internal variables
1213 ;; Some internals variable that need to be loaded
1214 ;; here to avoid compiler warnings.
1215 (defvar anything-c-external-commands-list nil
1216 "A list of all external commands the user can execute. If this
1217 variable is not set by the user, it will be calculated
1218 automatically.")
1220 (defvar anything-c-show-completion-overlay nil)
1222 (defvar anything-c-locate-command
1223 (case system-type
1224 ('gnu/linux "locate -i -r %s")
1225 ('berkeley-unix "locate -i %s")
1226 ('windows-nt "es -i -r %s")
1227 (t "locate %s"))
1228 "A list of arguments for locate program.
1229 The \"-r\" option must be the last option.")
1232 ;;; Faces
1235 (defface anything-buffer-saved-out
1236 '((t (:foreground "red")))
1237 "*Face used for buffer files modified outside of emacs."
1238 :group 'anything-config)
1240 (defface anything-buffer-not-saved
1241 '((t (:foreground "Indianred2")))
1242 "*Face used for buffer files not already saved on disk."
1243 :group 'anything-config)
1245 (defface anything-ff-prefix
1246 '((t (:background "yellow" :foreground "black")))
1247 "*Face used to prefix new file or url paths in `anything-find-files'."
1248 :group 'anything-config)
1250 (defface anything-ff-executable
1251 '((t (:foreground "green")))
1252 "*Face used for executable files in `anything-find-files'."
1253 :group 'anything-config)
1255 (defface anything-ff-directory
1256 '((t (:foreground "DarkRed" :background "LightGray")))
1257 "*Face used for directories in `anything-find-files'."
1258 :group 'anything-config)
1260 (defface anything-ff-symlink
1261 '((t (:foreground "DarkOrange")))
1262 "*Face used for symlinks in `anything-find-files'."
1263 :group 'anything-config)
1265 (defface anything-ff-invalid-symlink
1266 '((t (:foreground "black" :background "red")))
1267 "*Face used for invalid symlinks in `anything-find-files'."
1268 :group 'anything-config)
1270 (defface anything-ff-file
1271 '((t (:foreground "CadetBlue" :underline t)))
1272 "*Face used for file names in `anything-find-files'."
1273 :group 'anything-config)
1275 (defface anything-grep-match
1276 '((t (:inherit match)))
1277 "Face used to highlight grep matches."
1278 :group 'anything-config)
1280 (defface anything-grep-file
1281 '((t (:foreground "BlueViolet" :underline t)))
1282 "Face used to highlight grep results filenames."
1283 :group 'anything-config)
1285 (defface anything-grep-lineno
1286 '((t (:foreground "Darkorange1")))
1287 "Face used to highlight grep number lines."
1288 :group 'anything-config)
1290 (defface anything-grep-running
1291 '((t (:foreground "Red")))
1292 "Face used in mode line when grep is running."
1293 :group 'anything-config)
1295 (defface anything-grep-finish
1296 '((t (:foreground "Green")))
1297 "Face used in mode line when grep is finish."
1298 :group 'anything-config)
1300 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1301 "*Face used in anything-M-x to show keybinding."
1302 :group 'anything)
1304 (defface anything-bmkext-info
1305 '((t (:foreground "green")))
1306 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1307 :group 'anything)
1309 (defface anything-bmkext-w3m
1310 '((t (:foreground "yellow")))
1311 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1312 :group 'anything)
1314 (defface anything-bmkext-gnus
1315 '((t (:foreground "magenta")))
1316 "*Face used for Gnus bookmarks."
1317 :group 'anything)
1319 (defface anything-bmkext-man
1320 '((t (:foreground "Orange4")))
1321 "*Face used for Woman/man bookmarks."
1322 :group 'anything)
1324 (defface anything-bmkext-no--file
1325 '((t (:foreground "grey")))
1326 "*Face used for non--file bookmarks."
1327 :group 'anything)
1329 (defface anything-bmkext-file
1330 '((t (:foreground "Deepskyblue2")))
1331 "*Face used for non--file bookmarks."
1332 :group 'anything)
1334 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1335 "Face for su/sudo bookmarks."
1336 :group 'anything)
1338 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1339 "Face for w3m bookmarks" :group 'anything)
1341 (defface anything-emms-playlist
1342 '((t (:foreground "Springgreen4" :underline t)))
1343 "*Face used for tracks in current emms playlist."
1344 :group 'anything)
1346 (defface anything-apt-installed
1347 '((t (:foreground "green")))
1348 "*Face used for apt installed candidates."
1349 :group 'anything)
1351 (defface anything-gentoo-match-face '((t (:foreground "red")))
1352 "Face for anything-gentoo installed packages."
1353 :group 'traverse-faces)
1355 (defface anything-lisp-show-completion
1356 '((t (:background "DarkSlateGray")))
1357 "*Face used for showing candidates in `anything-lisp-completion'."
1358 :group 'anything-config)
1360 (defface anything-lisp-completion-info
1361 '((t (:foreground "red")))
1362 "*Face used for showing info in `anything-lisp-completion'."
1363 :group 'anything-config)
1365 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1366 "Face for source header in the anything buffer." :group 'anything)
1368 ;;;###autoload
1369 (defun anything-configuration ()
1370 "Customize `anything'."
1371 (interactive)
1372 (customize-group "anything-config"))
1376 ;;; Anything-command-map
1379 ;;;###autoload
1380 (defvar anything-command-map)
1381 (define-prefix-command 'anything-command-map)
1384 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1385 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1386 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1387 (define-key anything-command-map (kbd "l") 'anything-locate)
1388 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1389 (define-key anything-command-map (kbd "r") 'anything-regexp)
1390 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1391 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1392 (define-key anything-command-map (kbd "#") 'anything-emms)
1393 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1394 (define-key anything-command-map (kbd "t") 'anything-top)
1395 (define-key anything-command-map (kbd "i") 'anything-imenu)
1396 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1397 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1398 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1399 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1400 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1401 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1402 (define-key anything-command-map (kbd "f") 'anything-for-files)
1403 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1404 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1405 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1406 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1407 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1408 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1409 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1410 (define-key anything-command-map (kbd "c") 'anything-colors)
1411 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1412 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1413 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1414 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1415 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1416 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1417 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1418 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1419 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1420 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1422 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1423 ;; minibuffer-local-filename-must-match-map.
1424 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1425 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1426 (dolist (map (list minibuffer-local-filename-completion-map
1427 minibuffer-local-completion-map
1428 minibuffer-local-must-match-filename-map
1429 minibuffer-local-filename-must-match-map
1430 minibuffer-local-map
1431 minibuffer-local-isearch-map
1432 minibuffer-local-must-match-map
1433 minibuffer-local-ns-map))
1434 (define-key map "\C-r" 'anything-minibuffer-history))
1438 ;;; Menu
1441 (easy-menu-define nil global-map
1442 "`anything' menu"
1443 '("Anything"
1444 ["All anything commands" anything-execute-anything-command t]
1445 ["Find any Files/Buffers" anything-for-files t]
1446 ["Anything Everywhere" ac-mode t]
1447 "----"
1448 ("Files:"
1449 ["Find files" anything-find-files t]
1450 ["Recent Files" anything-recentf t]
1451 ["Locate" anything-locate t]
1452 ["Bookmarks" anything-c-pp-bookmarks t])
1453 ("Buffers:"
1454 ["Find buffers" anything-buffers-list t])
1455 ("Commands:"
1456 ["Emacs Commands" anything-M-x t]
1457 ["Externals Commands" anything-c-run-external-command t])
1458 ("Help:"
1459 ["Anything Apropos" anything-c-apropos t])
1460 ("Info:"
1461 ["Info at point" anything-info-at-point t]
1462 ["Emacs Manual index" anything-info-emacs t]
1463 ["Gnus Manual index" anything-info-gnus t])
1464 ("Org:"
1465 ["Org keywords" anything-org-keywords t]
1466 ["Org headlines" anything-org-headlines t])
1467 ("Tools:"
1468 ["Occur" anything-occur t]
1469 ["Grep" anything-do-grep t]
1470 ["Etags" anything-c-etags-select t]
1471 ["Lisp complete at point" anything-lisp-completion-at-point t]
1472 ["Browse Kill ring" anything-show-kill-ring t]
1473 ["Browse register" anything-register t]
1474 ["Browse code" anything-browse-code t]
1475 ["Mark Ring" anything-all-mark-rings t]
1476 ["Regexp handler" anything-regexp t]
1477 ["Colors & Faces" anything-colors t]
1478 ["Show xfonts" anything-select-xfont t]
1479 ["Ucs Symbols" anything-ucs t]
1480 ["Imenu" anything-imenu t]
1481 ["Google Suggest" anything-google-suggest t]
1482 ["Eval expression" anything-eval-expression-with-eldoc t]
1483 ["Calcul expression" anything-calcul-expression t]
1484 ["Man pages" anything-man-woman t]
1485 ["Top externals process" anything-top t]
1486 ["Emacs internals process" anything-list-emacs-process t])
1487 "----"
1488 ["Prefered Options" anything-configuration t]))
1490 ;;; Anything map add ons
1493 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1494 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1495 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1498 ;;; Specialized keymaps
1501 (defvar anything-c-buffer-map
1502 (let ((map (copy-keymap anything-map)))
1503 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1504 ;; No need to have separate command for grep and zgrep
1505 ;; as we don't use recursivity for buffers.
1506 ;; So use zgrep for both as it is capable to handle non--compressed files.
1507 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1508 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1509 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1510 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1511 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1512 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1513 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1514 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1515 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1516 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1517 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1518 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1519 (define-key map (kbd "M-a") 'anything-mark-all)
1520 (when (locate-library "elscreen")
1521 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1522 (delq nil map))
1523 "Keymap for buffer sources in anything.")
1525 (defvar anything-find-files-map
1526 (let ((map (copy-keymap anything-map)))
1527 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1528 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1529 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1530 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1531 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1532 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1533 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1534 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1535 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1536 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1537 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1538 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1539 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1540 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1541 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1542 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1543 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1544 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1545 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1546 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1547 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1548 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1549 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1550 (define-key map (kbd "C-c ?") 'anything-ff-help)
1551 (define-key map (kbd "C-}") 'anything-narrow-window)
1552 (define-key map (kbd "C-{") 'anything-enlarge-window)
1553 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1554 (define-key map (kbd "M-a") 'anything-mark-all)
1555 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1556 (define-key map (kbd "M-u") 'anything-unmark-all)
1557 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1558 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1559 ;; Next 2 have no effect if candidate is not an image file.
1560 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1561 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1562 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1563 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1565 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1566 (when anything-ff-lynx-style-map
1567 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1568 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1569 (delq nil map))
1570 "Keymap for `anything-find-files'.")
1572 (defvar anything-c-read-file-map
1573 (let ((map (copy-keymap anything-map)))
1574 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1575 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1576 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1577 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1578 (when anything-ff-lynx-style-map
1579 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1580 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1581 (define-key map (kbd "<M-left>") 'anything-previous-source)
1582 (define-key map (kbd "<M-right>") 'anything-next-source))
1583 (delq nil map))
1584 "Keymap for `anything-c-read-file-name'.")
1586 (defvar anything-generic-files-map
1587 (let ((map (copy-keymap anything-map)))
1588 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1589 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1590 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1591 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1592 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1593 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1594 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1595 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1596 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1597 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1598 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1599 map)
1600 "Generic Keymap for files.")
1602 (defvar anything-c-grep-map
1603 (let ((map (copy-keymap anything-map)))
1604 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1605 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1606 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1607 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1608 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1609 (when anything-c-grep-use-ioccur-style-keys
1610 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1611 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1612 (define-key map (kbd "C-c ?") 'anything-grep-help)
1613 (delq nil map))
1614 "Keymap used in Grep sources.")
1616 (defvar anything-c-pdfgrep-map
1617 (let ((map (copy-keymap anything-map)))
1618 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1619 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1620 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1621 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1622 map)
1623 "Keymap used in pdfgrep.")
1625 (defvar anything-c-etags-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-etags-help)
1631 map)
1632 "Keymap used in Etags.")
1634 (defvar anything-eval-expression-map
1635 (let ((map (copy-keymap anything-map)))
1636 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1637 (define-key map (kbd "<tab>") 'lisp-indent-line)
1638 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1639 (define-key map (kbd "C-p") 'previous-line)
1640 (define-key map (kbd "C-n") 'next-line)
1641 (define-key map (kbd "<up>") 'previous-line)
1642 (define-key map (kbd "<down>") 'next-line)
1643 (define-key map (kbd "<right>") 'forward-char)
1644 (define-key map (kbd "<left>") 'backward-char)
1645 map))
1647 (defvar anything-c-ucs-map
1648 (let ((map (copy-keymap anything-map)))
1649 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1650 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1651 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1652 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1653 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1654 map)
1655 "Keymap for `anything-ucs'.")
1659 ;;; Embeded documentation.
1662 (defun anything-c-list-preconfigured-anything ()
1663 "Collect preconfigured anything functions in this file."
1664 (loop with doc
1665 with sym
1666 for entry in (cdr (assoc
1667 (file-truename (locate-library "anything-config"))
1668 load-history))
1669 if (and (consp entry)
1670 (eq (car entry) 'defun)
1671 (string-match "^Preconfigured.+$"
1672 (setq doc (or (documentation (setq sym (cdr entry)))
1673 ""))))
1674 collect (cons sym (match-string 0 doc))))
1676 (defun anything-c-format-preconfigured-anything ()
1677 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1678 (anything-c-list-preconfigured-anything)))
1680 ;;; Global help message - Used by `anything-help'
1683 (setq anything-help-message
1684 (lambda ()
1685 (concat
1686 "\\<anything-map>"
1687 "`anything' is QuickSilver-like candidate-selection framework.
1689 Narrow the list by typing some pattern,
1690 Multiple patterns are allowed by splitting by space.
1691 Select with natural Emacs operations, choose with RET.
1693 If you have any problems, press C-c C-x C-b!!
1694 Feel free to send bug reports. I'll fix them.
1695 The steps are described in the beginning of anything.el file.
1697 == Basic Operations ==
1698 C-p, Up: Previous Line
1699 C-n, Down : Next Line
1700 M-v, PageUp : Previous Page
1701 C-v, PageDown : Next Page
1702 Enter : Execute first (default) action / Select
1703 M-< : First Line
1704 M-> : Last Line
1705 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1706 M-PageDown, C-M-v : Next Page (other-window)
1708 Tab, C-i : Show action list
1709 Left : Previous Source
1710 Right, C-o : Next Source
1711 C-k : Delete pattern
1712 C-z : Persistent Action (Execute action with anything session kept)
1713 C-c C-x C-b: Send a bug report
1715 == Shortcuts For 2nd/3rd Action ==
1716 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1717 \\[anything-select-3rd-action] : Execute 3rd Action
1719 == Visible Marks ==
1720 Visible marks store candidate. Some actions uses marked candidates.
1722 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1723 \\[anything-prev-visible-mark] : Previous Mark
1724 \\[anything-next-visible-mark] : Next Mark
1726 == Miscellaneous Commands ==
1727 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1728 \\[anything-quit-and-find-file] : Drop into `find-file'
1729 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1730 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1731 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1732 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1733 \\[anything-force-update] : Recalculate And Redisplay Candidates
1735 == Global Commands ==
1736 \\<global-map>\\[anything-resume] revives last `anything' session.
1737 It is very useful, so you should bind any key.
1739 Single source is executed by \\[anything-call-source].
1741 == Preconfigured `anything' ==
1742 Preconfigured `anything' is commands that uses `anything' interface.
1743 You can use them without configuration.
1746 (apply 'concat (anything-c-format-preconfigured-anything))
1748 Enjoy!")))
1750 ;;; `anything-buffer-list' help
1753 ;;;###autoload
1754 (defun anything-c-buffer-help ()
1755 "Help command for anything buffers."
1756 (interactive)
1757 (let ((anything-help-message "== Anything Buffer ==
1758 \nTips:
1759 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1760 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1761 \nSpecific commands for `anything-buffers-list':
1762 \\<anything-c-buffer-map>
1763 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1764 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1765 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1766 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1767 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1768 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1769 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1770 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1771 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1772 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1773 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1774 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1775 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1776 \\[anything-mark-all]\t\t->Mark all.
1777 \\[anything-c-buffer-help]\t\t->Display this help.
1778 \n== Anything Map ==
1779 \\{anything-map}
1781 (anything-help)))
1784 ;;; Find files help (`anything-find-files')
1787 ;;;###autoload
1788 (defun anything-ff-help ()
1789 "Help command for `anything-find-files'."
1790 (interactive)
1791 (let ((anything-help-message "== Anything Find Files ==
1792 \nTips:
1793 \n- Enter `~/' at end of pattern to quickly reach home directory.
1794 - Enter `/' at end of pattern to quickly reach root of your file system.
1795 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1796 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1797 - Use `C-u C-z' to watch an image.
1798 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1799 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1801 \nSpecific commands for `anything-find-files':
1802 \\<anything-find-files-map>
1803 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1804 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1805 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1806 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1807 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1808 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1809 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1810 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1811 \\[anything-ff-run-load-file]\t\t->Load File.
1812 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1813 \\[anything-ff-run-delete-file]\t\t->Delete File.
1814 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1815 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1816 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1817 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1818 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1819 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1820 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1821 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1822 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1823 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1824 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1825 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1826 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1827 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1828 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1829 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1830 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1831 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1832 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1833 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1834 \\[anything-narrow-window]\t\t->Narrow anything window.
1835 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1836 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1837 \\[anything-ff-help]\t\t->Display this help info.
1838 \n== Anything Map ==
1839 \\{anything-map}
1841 (anything-help)))
1843 ;;; Help for `anything-c-read-file-name'
1846 ;;;###autoload
1847 (defun anything-read-file-name-help ()
1848 (interactive)
1849 (let ((anything-help-message "== Anything read file name Map ==\
1850 \nSpecific commands for anything-c-read-file-name:
1851 \\<anything-c-read-file-map>
1852 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1853 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1854 \\[anything-next-source]\t\t->Goto next source.
1855 \\[anything-previous-source]\t->Goto previous source.
1856 \\[anything-read-file-name-help]\t\t->Display this help info.
1857 \n== Anything Map ==
1858 \\{anything-map}
1860 (anything-help)))
1862 ;;; Generic file help - Used by locate.
1865 ;;;###autoload
1866 (defun anything-generic-file-help ()
1867 (interactive)
1868 (let ((anything-help-message "== Anything Generic files Map ==\
1869 \nSpecific commands for anything locate and others files sources:
1870 \\<anything-generic-files-map>
1871 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1872 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1873 \\[anything-ff-run-delete-file]\t\t->Delete file.
1874 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1875 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1876 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1877 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1878 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1879 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1880 \nLocate tips:
1881 You can add after writing search pattern any of the locate command line options.
1882 e.g -b, -e, -n <number>...etc.
1883 See Man locate for more infos.
1884 \n== Anything Map ==
1885 \\{anything-map}"))
1886 (anything-help)))
1889 ;;; Grep help
1892 ;;;###autoload
1893 (defun anything-grep-help ()
1894 (interactive)
1895 (let ((anything-help-message "== Anything Grep Map ==\
1896 \nSpecific commands for Grep and Etags:
1897 \\<anything-c-grep-map>
1898 \\[anything-c-goto-next-file]\t->Next File.
1899 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1900 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1901 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1902 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1903 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1904 \\[anything-grep-help]\t\t->Show this help.
1905 \n== Anything Map ==
1906 \\{anything-map}"))
1907 (anything-help)))
1909 ;;; Pdf grep help
1912 ;;;###autoload
1913 (defun anything-pdfgrep-help ()
1914 (interactive)
1915 (let ((anything-help-message "== Anything PdfGrep Map ==\
1916 \nSpecific commands for Pdf Grep:
1917 \\<anything-c-pdfgrep-map>
1918 \\[anything-c-goto-next-file]\t->Next File.
1919 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1920 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1921 \\[anything-pdfgrep-help]\t\t->Show this help.
1922 \n== Anything Map ==
1923 \\{anything-map}"))
1924 (anything-help)))
1926 ;;; Etags help
1929 ;;;###autoload
1930 (defun anything-etags-help ()
1931 "The help function for etags."
1932 (interactive)
1933 (let ((anything-help-message "== Anything Etags Map ==\
1934 \nSpecific commands for Etags:
1935 \\<anything-c-etags-map>
1936 \\[anything-c-goto-next-file]\t->Next File.
1937 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1938 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1939 \\[anything-etags-help]\t\t->Show this help.
1940 \n== Anything Map ==
1941 \\{anything-map}"))
1942 (anything-help)))
1944 ;;; Ucs help
1947 (defun anything-c-ucs-help ()
1948 "Help command for `anything-ucs'."
1949 (interactive)
1950 (let ((anything-help-message "== Anything Ucs ==
1951 \nSpecific commands for `anything-ucs':
1952 \\<anything-c-ucs-map>
1953 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1954 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1955 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1956 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1957 \\[anything-c-ucs-help]\t\t->Show this help.
1959 \n== Anything Map ==
1960 \\{anything-map}
1962 (anything-help)))
1966 ;;; Mode line strings
1969 (defvar anything-buffer-mode-line-string
1970 '("Buffer(s)"
1971 "\\<anything-c-buffer-map>\
1972 \\[anything-c-buffer-help]:Help, \
1973 \\<anything-map>\
1974 \\[anything-select-action]:Acts,\
1975 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1976 \\[anything-select-3rd-action]:NthAct,\
1977 \\[anything-send-bug-report-from-anything]:BugReport."
1978 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1980 (defvar anything-ff-mode-line-string
1981 "\\<anything-find-files-map>\
1982 \\[anything-ff-help]:Help, \
1983 \\[anything-send-bug-report-from-anything]:BugReport, \
1984 \\<anything-map>\
1985 \\[anything-select-action]:Acts, \
1986 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1987 \\[anything-select-3rd-action]:NthAct"
1988 "String displayed in mode-line in `anything-c-source-find-files'")
1990 (defvar anything-read-file-name-mode-line-string
1991 "\\<anything-c-read-file-map>\
1992 \\[anything-read-file-name-help]:Help, \
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-generic-file-mode-line-string
2000 "\\<anything-generic-files-map>\
2001 \\[anything-generic-file-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 \\[anything-send-bug-report-from-anything]:BugReport."
2007 "String displayed in mode-line in Locate.")
2009 (defvar anything-grep-mode-line-string
2010 "\\<anything-c-grep-map>\
2011 \\[anything-grep-help]:Help,\
2012 \\<anything-map>\
2013 \\[anything-select-action]:Acts,\
2014 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2015 \\[anything-select-3rd-action]:NthAct,\
2016 \\[anything-send-bug-report-from-anything]:BugReport."
2017 "String displayed in mode-line in `anything-do-grep'.")
2019 (defvar anything-pdfgrep-mode-line-string
2020 "\\<anything-c-pdfgrep-map>\
2021 \\[anything-pdfgrep-help]:Help,\
2022 \\<anything-map>\
2023 \\[anything-select-action]:Acts,\
2024 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2025 \\[anything-select-3rd-action]:NthAct,\
2026 \\[anything-send-bug-report-from-anything]:BugReport."
2027 "String displayed in mode-line in `anything-do-pdfgrep'.")
2029 (defvar anything-etags-mode-line-string
2030 "\\<anything-c-etags-map>\
2031 \\[anything-etags-help]:Help,\
2032 \\<anything-map>\
2033 \\[anything-select-action]:Acts,\
2034 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2035 \\[anything-select-3rd-action]:NthAct,\
2036 \\[anything-send-bug-report-from-anything]:BugReport."
2037 "String displayed in mode-line in `anything-c-etags-select'.")
2040 (defvar anything-c-ucs-mode-line-string
2041 "\\<anything-c-ucs-map>\
2042 \\[anything-c-ucs-help]:Help, \
2043 \\<anything-map>\
2044 \\[anything-select-action]:Acts,\
2045 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2046 \\[anything-select-3rd-action]:NthAct."
2047 "String displayed in mode-line in `anything-ucs'.")
2051 ;;; Utilities Functions
2054 (defun anything-ff-find-printers ()
2055 "Return a list of available printers on Unix systems."
2056 (let ((printer-list (with-temp-buffer
2057 (call-process "lpstat" nil t nil "-a")
2058 (split-string (buffer-string) "\n"))))
2059 (loop for p in printer-list
2060 for printer = (car (split-string p))
2061 when printer
2062 collect printer)))
2064 ;; Shut up byte compiler in emacs24*.
2065 (defun anything-c-switch-to-buffer (buffer-or-name)
2066 "Same as `switch-to-buffer' whithout warnings at compile time."
2067 (with-no-warnings
2068 (switch-to-buffer buffer-or-name)))
2070 (defsubst* anything-c-position (item seq &key (test 'eq))
2071 "A simple and faster replacement of CL `position'."
2072 (loop for i in seq for index from 0
2073 when (funcall test i item) return index))
2075 (defun anything-c-get-pid-from-process-name (process-name)
2076 "Get pid from running process PROCESS-NAME."
2077 (loop with process-list = (list-system-processes)
2078 for pid in process-list
2079 for process = (assoc-default 'comm (process-attributes pid))
2080 when (and process (string-match process-name process))
2081 return pid))
2083 (defun* anything-current-buffer-narrowed-p (&optional
2084 (buffer anything-current-buffer))
2085 "Check if BUFFER is narrowed.
2086 Default is `anything-current-buffer'."
2087 (with-current-buffer buffer
2088 (let ((beg (point-min))
2089 (end (point-max))
2090 (total (buffer-size)))
2091 (or (/= beg 1) (/= end (1+ total))))))
2093 (defun anything-region-active-p ()
2094 (and transient-mark-mode mark-active (/= (mark) (point))))
2096 (defun anything-goto-line (lineno)
2097 "Goto LINENO opening only outline headline if needed."
2098 (goto-char (point-min)) (forward-line (1- lineno))
2099 (when (or (eq major-mode 'org-mode)
2100 (and (boundp 'outline-minor-mode)
2101 outline-minor-mode))
2102 (require 'org) ; On some old Emacs versions org may not be loaded.
2103 (org-reveal))
2104 (anything-match-line-color-current-line) (sit-for 0.3)
2105 (anything-match-line-cleanup))
2107 (defun anything-show-this-source-only ()
2108 "Show all candidates of this source."
2109 (interactive)
2110 (setq anything-candidate-number-limit nil)
2111 (anything-set-source-filter
2112 (list (assoc-default 'name (anything-get-current-source)))))
2114 ;;;###autoload
2115 (defun anything-test-sources ()
2116 "List all anything sources for test.
2117 The output is sexps which are evaluated by \\[eval-last-sexp]."
2118 (interactive)
2119 (with-output-to-temp-buffer "*Anything Test Sources*"
2120 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2121 (apropos-internal "^anything-c-source" #'boundp))
2122 (pop-to-buffer standard-output)))
2124 (defun anything-nest (&rest same-as-anything)
2125 "Nested `anything'. If you use `anything' within `anything', use it."
2126 (with-selected-window (anything-window)
2127 (let (anything-current-position
2128 anything-current-buffer
2129 (orig-anything-buffer anything-buffer)
2130 anything-pattern
2131 anything-buffer
2132 anything-sources
2133 anything-compiled-sources
2134 anything-buffer-chars-modified-tick
2135 (anything-samewindow t)
2136 (enable-recursive-minibuffers t))
2137 (unwind-protect
2138 (apply #'anything same-as-anything)
2139 (anything-initialize-overlays orig-anything-buffer)
2140 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2142 (defun anything-displaying-source-names ()
2143 "Display sources name."
2144 (with-current-buffer anything-buffer
2145 (goto-char (point-min))
2146 (loop with pos
2147 while (setq pos (next-single-property-change (point) 'anything-header))
2148 do (goto-char pos)
2149 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2150 do (forward-line 1))))
2152 ;; [Obsolete]
2153 (defun anything-select-source ()
2154 "[OBSOLETE] Select source."
2155 (interactive)
2156 (let ((default (assoc-default 'name (anything-get-current-source)))
2157 (source-names (anything-displaying-source-names))
2158 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2159 (anything-get-sources))))
2160 (setq anything-candidate-number-limit 9999)
2161 (anything-aif
2162 (let (anything-source-filter)
2163 (anything-nest '(((name . "Anything Source")
2164 (candidates . source-names)
2165 (action . identity))
2166 ((name . "Anything Source (ALL)")
2167 (candidates . all-source-names)
2168 (action . identity)))
2169 nil "Source: " nil
2170 default "*anything select source*"))
2171 (anything-set-source-filter (list it))
2172 (anything-set-source-filter nil))))
2174 (defun anything-c-match-on-file-name (candidate)
2175 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2176 (string-match anything-pattern (file-name-nondirectory candidate)))
2178 (defun anything-c-match-on-directory-name (candidate)
2179 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2180 (anything-aif (file-name-directory candidate)
2181 (string-match anything-pattern it)))
2183 (defun anything-c-match-on-basename (candidate)
2184 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2185 (string-match anything-pattern (anything-c-basename candidate)))
2187 (defun anything-c-string-match (candidate)
2188 "Return non-nil if `anything-pattern' match CANDIDATE.
2189 The match is done with `string-match'."
2190 (string-match anything-pattern candidate))
2192 (defun anything-c-skip-entries (list regexp)
2193 "Remove entries which matches REGEXP from LIST."
2194 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2195 list))
2197 (defun anything-c-shadow-entries (list regexp)
2198 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2199 (mapcar (lambda (file)
2200 ;; Add shadow face property to boring files.
2201 (let ((face (if (facep 'file-name-shadow)
2202 'file-name-shadow
2203 ;; fall back to default on XEmacs
2204 'default)))
2205 (if (string-match regexp file)
2206 (setq file (propertize file 'face face))))
2207 file)
2208 list))
2210 (defsubst anything-c-stringify (str-or-sym)
2211 "Get string of STR-OR-SYM."
2212 (if (stringp str-or-sym)
2213 str-or-sym
2214 (symbol-name str-or-sym)))
2216 (defsubst anything-c-symbolify (str-or-sym)
2217 "Get symbol of STR-OR-SYM."
2218 (if (symbolp str-or-sym)
2219 str-or-sym
2220 (intern str-or-sym)))
2222 (defun anything-c-describe-function (func)
2223 "FUNC is symbol or string."
2224 (describe-function (anything-c-symbolify func)))
2226 (defun anything-c-describe-variable (var)
2227 "VAR is symbol or string."
2228 (describe-variable (anything-c-symbolify var)))
2230 (defun anything-c-find-function (func)
2231 "FUNC is symbol or string."
2232 (find-function (anything-c-symbolify func)))
2234 (defun anything-c-find-variable (var)
2235 "VAR is symbol or string."
2236 (find-variable (anything-c-symbolify var)))
2238 (defun anything-c-kill-new (candidate &optional replace)
2239 "CANDIDATE is symbol or string.
2240 See `kill-new' for argument REPLACE."
2241 (kill-new (anything-c-stringify candidate) replace))
2243 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2244 "Remove duplicates elements in list SEQ.
2245 This is same as `remove-duplicates' but with memoisation.
2246 It is much faster, especially in large lists.
2247 A test function can be provided with TEST argument key.
2248 Default is `eq'."
2249 (let ((cont (make-hash-table :test test)))
2250 (loop for elm in seq
2251 unless (gethash elm cont)
2252 do (puthash elm elm cont)
2253 finally return
2254 (loop for i being the hash-values in cont collect i))))
2256 (defadvice eval-defun (after anything-source-hack activate)
2257 "Allow immediate execution of anything source when evaling it.
2258 See `anything-c-enable-eval-defun-hack'."
2259 (when anything-c-enable-eval-defun-hack
2260 (let ((varsym (save-excursion
2261 (beginning-of-defun)
2262 (forward-char 1)
2263 (when (memq (read (current-buffer)) '(defvar setq))
2264 (read (current-buffer))))))
2265 (when (string-match "^anything-c-source-" (symbol-name varsym))
2266 (anything varsym)))))
2267 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2270 ;; Move this function from anything.el and redefine here
2271 ;; to avoid an unneeded defadvice.
2272 (defun anything-quit-and-find-file ()
2273 "Drop into `anything-find-files' from `anything'.
2274 If current selection is a buffer or a file, `anything-find-files'
2275 from its directory."
2276 (interactive)
2277 (anything-run-after-quit
2278 (lambda (f)
2279 (if (file-exists-p f)
2280 (anything-find-files-1 (file-name-directory f)
2281 (if anything-ff-transformer-show-only-basename
2282 (anything-c-basename f) f))
2283 (anything-find-files-1 f)))
2284 (anything-aif (get-buffer (anything-get-selection))
2285 (or (buffer-file-name it)
2286 (car (rassoc it dired-buffers))
2287 (and (with-current-buffer it
2288 (eq major-mode 'org-agenda-mode))
2289 org-directory
2290 (expand-file-name org-directory))
2291 default-directory)
2292 (let ((sel (anything-get-selection)))
2293 (if (file-exists-p sel)
2294 (expand-file-name sel)
2295 default-directory)))))
2298 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2299 "Walk through DIRECTORY tree.
2300 PATH can be one of basename, relative, or full.
2301 DIRECTORIES when non--nil (default) return also directories names, otherwise
2302 skip directories names.
2303 MATCH match only filenames matching regexp MATCH."
2304 `(let (result
2305 (fn (case ,path
2306 (basename 'file-name-nondirectory)
2307 (relative 'file-relative-name)
2308 (full 'identity)
2309 (t 'file-name-nondirectory))))
2310 (labels ((ls-R (dir)
2311 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2312 for f in ls
2313 if (file-directory-p f)
2314 do (progn (when ,directories
2315 (push (funcall fn f) result))
2316 ;; Don't recurse in directory symlink.
2317 (unless (file-symlink-p f)
2318 (ls-R f)))
2319 else do
2320 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2321 (push (funcall fn f) result)))))
2322 (ls-R ,directory)
2323 (nreverse result))))
2325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2327 ;;; Anything regexp.
2330 (defun anything-c-query-replace-regexp (candidate)
2331 "Query replace regexp from `anything-regexp'.
2332 With a prefix arg replace only matches surrounded by word boundaries,
2333 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2334 (let ((regexp (funcall (anything-attr 'regexp))))
2335 (apply 'query-replace-regexp
2336 (anything-c-query-replace-args regexp))))
2338 (defun anything-c-kill-regexp-as-sexp (candidate)
2339 "Kill regexp in a format usable in lisp code."
2340 (anything-c-regexp-kill-new
2341 (prin1-to-string (funcall (anything-attr 'regexp)))))
2343 (defun anything-c-kill-regexp (candidate)
2344 "Kill regexp as it is in `anything-pattern'."
2345 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2347 (defun anything-c-query-replace-args (regexp)
2348 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2349 (let ((region-only (anything-region-active-p)))
2350 (list
2351 regexp
2352 (query-replace-read-to regexp
2353 (format "Query replace %sregexp %s"
2354 (if anything-current-prefix-arg "word " "")
2355 (if region-only "in region " ""))
2357 anything-current-prefix-arg
2358 (when region-only (region-beginning))
2359 (when region-only (region-end)))))
2361 (defvar anything-c-source-regexp
2362 '((name . "Regexp Builder")
2363 (init . (lambda ()
2364 (anything-candidate-buffer anything-current-buffer)))
2365 (candidates-in-buffer)
2366 (get-line . anything-c-regexp-get-line)
2367 (persistent-action . anything-c-regexp-persistent-action)
2368 (persistent-help . "Show this line")
2369 (multiline)
2370 (delayed)
2371 (requires-pattern . 2)
2372 (mode-line . "Press TAB to select action.")
2373 (regexp . (lambda () anything-input))
2374 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2375 ("Query Replace Regexp (C-u Not inside word.)"
2376 . anything-c-query-replace-regexp)
2377 ("Kill Regexp" . anything-c-kill-regexp)))))
2379 (defun anything-c-regexp-get-line (s e)
2380 (propertize
2381 (apply 'concat
2382 ;; Line contents
2383 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2384 ;; subexps
2385 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2386 collect (format "\n %s'%s'"
2387 (if (zerop i) "Group 0: " (format "Group %d: " i))
2388 (match-string i))))
2389 ;; match beginning
2390 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2391 ;; It is implementation problem of candidates-in-buffer.
2392 'anything-realvalue
2393 (1- s)))
2395 (defun anything-c-regexp-persistent-action (pt)
2396 (goto-char pt)
2397 (anything-persistent-highlight-point))
2399 (defun anything-c-regexp-kill-new (input)
2400 (kill-new input)
2401 (message "Killed: %s" input))
2405 ;;; Toggle all marks.
2408 ;;;###autoload
2409 (defun anything-mark-all ()
2410 "Mark all visible unmarked candidates in current source."
2411 (interactive)
2412 (with-anything-window
2413 (save-excursion
2414 (goto-char (anything-get-previous-header-pos))
2415 (anything-next-line)
2416 (let* ((next-head (anything-get-next-header-pos))
2417 (end (and next-head
2418 (save-excursion
2419 (goto-char next-head)
2420 (forward-line -1)
2421 (point))))
2422 (maxpoint (or end (point-max))))
2423 (while (< (point) maxpoint)
2424 (anything-mark-current-line)
2425 (let ((prefix (get-text-property (point-at-bol) 'display))
2426 (bn (anything-c-basename (anything-get-selection)))
2427 (src (assoc-default 'name (anything-get-current-source))))
2428 (when (and (not (anything-this-visible-mark))
2429 (not (or (string= prefix "[?]")
2430 (string= prefix "[@]"))))
2431 ;; Don't mark possibles directories ending with . or ..
2432 ;; and also autosave files/links.
2433 (unless
2434 (and (or (anything-file-completion-source-p)
2435 (equal src "Files from Current Directory"))
2436 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2437 (anything-make-visible-mark))))
2438 (forward-line 1) (end-of-line))))
2439 (anything-mark-current-line)
2440 (message "%s candidates marked" (length anything-marked-candidates))))
2442 ;;;###autoload
2443 (defun anything-unmark-all ()
2444 "Unmark all candidates in all sources of current anything session."
2445 (interactive)
2446 (with-anything-window
2447 (let ((len (length anything-marked-candidates)))
2448 (save-excursion
2449 (anything-clear-visible-mark))
2450 (setq anything-marked-candidates nil)
2451 (anything-mark-current-line)
2452 (message "%s candidates unmarked" len))))
2454 ;;;###autoload
2455 (defun anything-toggle-all-marks ()
2456 "Toggle all marks.
2457 Mark all visible candidates of current source or unmark all candidates
2458 visible or invisible in all sources of current anything session"
2459 (interactive)
2460 (let ((marked (anything-marked-candidates)))
2461 (if (and (>= (length marked) 1)
2462 (with-anything-window anything-visible-mark-overlays))
2463 (anything-unmark-all)
2464 (anything-mark-all))))
2468 ;;; Buffers
2471 (defun anything-c-buffer-list ()
2472 "Return the list of names of buffers with boring buffers filtered out.
2473 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2474 The first buffer in the list will be the last recently used
2475 buffer that is not the current buffer."
2476 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2477 (append (cdr buffers) (list (car buffers)))))
2479 (defvar anything-c-source-buffers
2480 '((name . "Buffers")
2481 (candidates . anything-c-buffer-list)
2482 (type . buffer)))
2483 ;; (anything 'anything-c-source-buffers)
2485 (defvar anything-c-source-buffer-not-found
2486 '((name . "Create buffer")
2487 (dummy)
2488 (filtered-candidate-transformer (lambda (cands source)
2489 (list anything-pattern)))
2490 (action . (lambda (candidate)
2491 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2492 ;; (anything 'anything-c-source-buffer-not-found)
2494 ;;; Buffers-list (was buffers+)
2497 (eval-when-compile (require 'dired))
2499 (defun anything-c-highlight-buffers (buffers)
2500 (loop for i in buffers
2501 for buf = (get-buffer i)
2502 for bfname = (buffer-file-name buf)
2503 collect
2504 (cond (;; A dired buffer.
2505 (rassoc buf dired-buffers)
2506 (propertize i 'face 'anything-ff-directory
2507 'help-echo (car (rassoc buf dired-buffers))))
2508 ;; A buffer file modified somewhere outside of emacs.
2509 ((and bfname (not (file-remote-p bfname))
2510 (file-exists-p bfname)
2511 (not (verify-visited-file-modtime buf)))
2512 (propertize i 'face 'anything-buffer-saved-out
2513 'help-echo bfname))
2514 ;; A new buffer file not already saved on disk.
2515 ((and bfname (not (file-remote-p bfname))
2516 (not (verify-visited-file-modtime buf)))
2517 (propertize i 'face 'anything-buffer-not-saved
2518 'help-echo bfname))
2519 ;; A Remote buffer file modified and not saved on disk.
2520 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2521 (let ((prefix (propertize
2522 " " 'display
2523 (propertize "@ " 'face 'anything-ff-prefix))))
2524 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2525 'help-echo bfname)) i)))
2526 ;; A buffer file modified and not saved on disk.
2527 ((and bfname (buffer-modified-p buf))
2528 (propertize i 'face 'anything-ff-symlink
2529 'help-echo bfname))
2530 ;; A remote buffer file not modified and saved on disk.
2531 ((and bfname (file-remote-p bfname))
2532 (let ((prefix (propertize
2533 " " 'display
2534 (propertize "@ " 'face 'anything-ff-prefix))))
2535 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2536 'help-echo bfname)) i)))
2537 ;; A buffer file not modified and saved on disk.
2538 (bfname
2539 (propertize i 'face 'font-lock-type-face
2540 'help-echo bfname))
2541 ;; Any non--file buffer.
2542 (t (propertize i 'face 'italic)))))
2545 (defvar anything-c-source-buffers-list
2546 '((name . "Buffers")
2547 (candidates . anything-c-buffer-list)
2548 (type . buffer)
2549 (match anything-c-buffer-match-major-mode)
2550 (diff-action . anything-buffer-toggle-diff)
2551 (revert-action . anything-buffer-revert-and-update)
2552 (save-action . anything-buffer-save-and-update)
2553 (candidate-transformer anything-c-skip-current-buffer
2554 anything-c-skip-boring-buffers
2555 anything-c-highlight-buffers)
2556 (persistent-action . anything-c-buffers-list-persistent-action)
2557 (volatile)
2558 (mode-line . anything-buffer-mode-line-string)
2559 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2560 ;; (anything 'anything-c-source-buffers-list)
2562 (defun anything-c-buffer-match-major-mode (candidate)
2563 "Match maybe buffer by major-mode.
2564 If you give a major-mode or partial major-mode,
2565 it will list all buffers of this major-mode and/or buffers with name
2566 matching this major-mode.
2567 If you add a space after major-mode and then a space,
2568 it will match all buffers of the major-mode
2569 before space matching pattern after space.
2570 If you give a pattern which doesn't match a major-mode, it will search buffer
2571 with name matching pattern."
2572 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2573 (buf (get-buffer cand)))
2574 (when buf
2575 (with-current-buffer buf
2576 (let ((mjm (symbol-name major-mode))
2577 (split (split-string anything-pattern)))
2578 (cond ((string-match "\\s-$" anything-pattern)
2579 (string-match (car split) mjm))
2580 ((string-match "\\s-" anything-pattern)
2581 (and (string-match (car split) mjm)
2582 (string-match (cadr split) cand)))
2583 (t (or (string-match anything-pattern mjm)
2584 (string-match anything-pattern cand)))))))))
2586 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2587 "Query replace in marked buffers.
2588 If REGEXP-FLAG is given use `query-replace-regexp'."
2589 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2590 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2591 (bufs (anything-marked-candidates)))
2592 (loop
2593 with replace = (query-replace-read-from prompt regexp-flag)
2594 with tostring = (unless (consp replace)
2595 (query-replace-read-to
2596 replace prompt regexp-flag))
2597 for buf in bufs
2599 (save-window-excursion
2600 (anything-c-switch-to-buffer buf)
2601 (save-excursion
2602 (let ((case-fold-search t))
2603 (goto-char (point-min))
2604 (if (consp replace)
2605 (apply fn (list (car replace) (cdr replace)))
2606 (apply fn (list replace tostring)))))))))
2608 (defun anything-c-buffer-query-replace-regexp (candidate)
2609 (anything-c-buffer-query-replace-1 'regexp))
2611 (defun anything-c-buffer-query-replace (candidate)
2612 (anything-c-buffer-query-replace-1))
2614 (defun anything-buffer-toggle-diff (candidate)
2615 "Toggle diff buffer CANDIDATE with it's file."
2616 (if (get-buffer-window "*Diff*")
2617 (kill-buffer "*Diff*")
2618 (diff-buffer-with-file (get-buffer candidate))))
2620 ;;;###autoload
2621 (defun anything-buffer-diff-persistent ()
2622 "Toggle diff buffer without quitting anything."
2623 (interactive)
2624 (anything-execute-persistent-action 'diff-action))
2626 (defun anything-buffer-revert-and-update (candidate)
2627 (let ((marked (anything-marked-candidates)))
2628 (loop for buf in marked do (anything-revert-buffer buf))
2629 (anything-force-update candidate)))
2631 ;;;###autoload
2632 (defun anything-buffer-revert-persistent ()
2633 "Revert buffer without quitting anything."
2634 (interactive)
2635 (anything-execute-persistent-action 'revert-action 'onewindow))
2637 (defun anything-buffer-save-and-update (candidate)
2638 (let ((marked (anything-marked-candidates))
2639 (enable-recursive-minibuffers t))
2640 (loop for buf in marked do
2641 (with-current-buffer (get-buffer buf)
2642 (save-buffer)))
2643 (anything-force-update candidate)))
2645 ;;;###autoload
2646 (defun anything-buffer-save-persistent ()
2647 "Save buffer without quitting anything."
2648 (interactive)
2649 (anything-execute-persistent-action 'save-action 'onewindow))
2651 ;;;###autoload
2652 (defun anything-buffer-run-kill-buffers ()
2653 "Run kill buffer action from `anything-c-source-buffers-list'."
2654 (interactive)
2655 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2657 ;;;###autoload
2658 (defun anything-buffer-run-grep ()
2659 "Run Grep action from `anything-c-source-buffers-list'."
2660 (interactive)
2661 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2663 ;;;###autoload
2664 (defun anything-buffer-run-zgrep ()
2665 "Run Grep action from `anything-c-source-buffers-list'."
2666 (interactive)
2667 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2669 ;;;###autoload
2670 (defun anything-buffer-run-query-replace-regexp ()
2671 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2672 (interactive)
2673 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2675 ;;;###autoload
2676 (defun anything-buffer-run-query-replace ()
2677 "Run Query replace action from `anything-c-source-buffers-list'."
2678 (interactive)
2679 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2681 ;;;###autoload
2682 (defun anything-buffer-switch-other-window ()
2683 "Run switch to other window action from `anything-c-source-buffers-list'."
2684 (interactive)
2685 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2687 ;;;###autoload
2688 (defun anything-buffer-switch-other-frame ()
2689 "Run switch to other frame action from `anything-c-source-buffers-list'."
2690 (interactive)
2691 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2693 ;;;###autoload
2694 (defun anything-buffer-switch-to-elscreen ()
2695 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2696 (interactive)
2697 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2699 ;;;###autoload
2700 (defun anything-buffer-run-ediff ()
2701 "Run ediff action from `anything-c-source-buffers-list'."
2702 (interactive)
2703 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2705 (defun anything-buffer-run-ediff-merge ()
2706 "Run ediff action from `anything-c-source-buffers-list'."
2707 (interactive)
2708 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2710 (defun anything-c-buffers-persistent-kill (buffer)
2711 "Persistent action to kill buffer."
2712 (with-current-buffer (get-buffer buffer)
2713 (if (and (buffer-modified-p)
2714 (buffer-file-name (current-buffer)))
2715 (progn
2716 (save-buffer)
2717 (kill-buffer buffer))
2718 (kill-buffer buffer)))
2719 (anything-delete-current-selection))
2721 (defun anything-c-buffers-list-persistent-action (candidate)
2722 (if current-prefix-arg
2723 (anything-c-buffers-persistent-kill candidate)
2724 (anything-c-switch-to-buffer candidate)))
2727 ;;;; <File>
2730 ;;; File name history
2731 (defvar anything-c-source-file-name-history
2732 '((name . "File Name History")
2733 (candidates . file-name-history)
2734 (match anything-c-match-on-basename)
2735 (type . file)))
2736 ;; (anything 'anything-c-source-file-name-history)
2738 ;;; Files in current dir
2741 (defvar anything-c-source-files-in-current-dir
2742 '((name . "Files from Current Directory")
2743 (candidates . (lambda ()
2744 (with-anything-current-buffer
2745 (directory-files (anything-c-current-directory)))))
2746 ;; volatile is not needed, I think.
2747 (type . file)))
2748 ;; (anything 'anything-c-source-files-in-current-dir)
2750 (defun anything-c-highlight-files (files)
2751 (loop for i in files
2752 if (file-directory-p i)
2753 collect (propertize (file-name-nondirectory i)
2754 'face 'anything-ff-directory
2755 'help-echo (expand-file-name i))
2756 else
2757 collect (propertize (file-name-nondirectory i)
2758 'face 'anything-ff-file
2759 'help-echo (expand-file-name i))))
2761 (defvar anything-c-source-files-in-current-dir+
2762 '((name . "Files from Current Directory")
2763 (candidates . (lambda ()
2764 (with-anything-current-buffer
2765 (directory-files (anything-c-current-directory) t))))
2766 (candidate-transformer anything-c-highlight-files)
2767 ;; volatile is not needed, I think.
2768 (type . file)))
2769 ;; (anything 'anything-c-source-files-in-current-dir+)
2773 ;;; Anything-find-files - The anything files browser.
2776 ;; Internal.
2777 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2778 "*The doc that is inserted in the Name header of a find-files or dired source.")
2779 (defvar anything-ff-auto-update-flag nil
2780 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2781 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2782 (defvar anything-ff-last-expanded nil
2783 "Store last expanded directory or file.")
2784 (defvar anything-ff-default-directory nil)
2785 (defvar anything-ff-history nil)
2786 (defvar anything-ff-cand-to-mark nil)
2789 (defvar anything-c-source-find-files
2790 `((name . "Find Files")
2791 (header-name . (lambda (name)
2792 (concat name anything-c-find-files-doc-header)))
2793 ;; It is needed for filenames with capital letters
2794 (disable-shortcuts)
2795 (init . (lambda ()
2796 (setq anything-ff-auto-update-flag
2797 anything-ff-auto-update-initial-value)))
2798 (candidates . anything-find-files-get-candidates)
2799 (filtered-candidate-transformer anything-c-find-files-transformer)
2800 (image-action1 . anything-ff-rotate-image-left)
2801 (image-action2 . anything-ff-rotate-image-right)
2802 (toggle-basename . anything-ff-toggle-basename)
2803 (properties-action . anything-ff-properties)
2804 (toggle-auto-update . anything-ff-toggle-auto-update)
2805 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2806 (persistent-action . anything-find-files-persistent-action)
2807 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2808 (mode-line . anything-ff-mode-line-string)
2809 (volatile)
2810 (candidate-number-limit . 9999)
2811 (action-transformer . anything-find-files-action-transformer)
2812 (action
2813 . ,(delq
2815 `(("Find File" . anything-c-find-file-or-marked)
2816 ("Find file in Dired" . anything-c-point-file-in-dired)
2817 ,(and (locate-library "elscreen")
2818 '("Find file in Elscreen" . anything-elscreen-find-file))
2819 ,(and (locate-library "popwin")
2820 '("Find file in popup window" . popwin:find-file))
2821 ("Checksum File" . anything-ff-checksum)
2822 ("Complete at point `M-tab'"
2823 . anything-c-insert-file-name-completion-at-point)
2824 ("Open file externally `C-c C-x, C-u to choose'"
2825 . anything-c-open-file-externally)
2826 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2827 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2828 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2829 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2830 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2831 . anything-find-files-eshell-command-on-file)
2832 ("Find file as root" . anything-find-file-as-root)
2833 ("Find file in hex dump" . hexl-find-file)
2834 ("Ediff File `C-='" . anything-find-files-ediff-files)
2835 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2836 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2837 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2838 ("Copy file(s) Async" . anything-ff-copy-async)
2839 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2840 ("Serial rename files" . anything-ff-serial-rename)
2841 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2842 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2843 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2844 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2845 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2846 ("Find file other window `C-o'" . find-file-other-window)
2847 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2848 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2849 ("Print File `C-c p'" . anything-ff-print)
2850 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2851 ;; (anything 'anything-c-source-find-files)
2853 (defun anything-find-files-set-prompt-for-action (action files)
2854 "Set prompt for action ACTION for FILES."
2855 (let ((len (length files)))
2856 (format "%s *%s File(s)\n%s to: "
2857 action len
2858 (mapconcat (lambda (f)
2859 (format "- %s\n" f)) files ""))))
2861 (defun anything-dwim-target-directory ()
2862 "Return value of `default-directory' of buffer in other window.
2863 If there is only one window return the value ot `default-directory'
2864 for current buffer."
2865 (with-anything-current-buffer
2866 (let ((num-windows (length (window-list))))
2867 (if (> num-windows 1)
2868 (save-window-excursion
2869 (other-window 1)
2870 default-directory)
2871 (car anything-ff-history)))))
2873 (defun anything-find-files-do-action (action)
2874 "Generic function for creating action from `anything-c-source-find-files'.
2875 ACTION must be an action supported by `anything-dired-action'."
2876 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2877 (anything-marked-candidates)))
2878 (cand (anything-get-selection)) ; Target
2879 (prompt (anything-find-files-set-prompt-for-action
2880 (capitalize (symbol-name action)) ifiles))
2881 (parg anything-current-prefix-arg)
2882 (dest (anything-c-read-file-name
2883 prompt
2884 :preselect (if anything-ff-transformer-show-only-basename
2885 (anything-c-basename cand) cand)
2886 :initial-input (anything-dwim-target-directory)
2887 :history (anything-find-files-history :comp-read nil))))
2888 (anything-dired-action
2889 dest :files ifiles :action action :follow parg)))
2891 (defun anything-find-files-copy (candidate)
2892 "Copy files from `anything-find-files'."
2893 (anything-find-files-do-action 'copy))
2895 (defun anything-find-files-rename (candidate)
2896 "Rename files from `anything-find-files'."
2897 (anything-find-files-do-action 'rename))
2899 (defun anything-find-files-symlink (candidate)
2900 "Symlink files from `anything-find-files'."
2901 (anything-find-files-do-action 'symlink))
2903 (defun anything-find-files-relsymlink (candidate)
2904 "Relsymlink files from `anything-find-files'."
2905 (anything-find-files-do-action 'relsymlink))
2907 (defun anything-find-files-hardlink (candidate)
2908 "Hardlink files from `anything-find-files'."
2909 (anything-find-files-do-action 'hardlink))
2911 (defun anything-find-files-byte-compile (candidate)
2912 "Byte compile elisp files from `anything-find-files'."
2913 (let ((files (anything-marked-candidates))
2914 (parg anything-current-prefix-arg))
2915 (loop for fname in files
2916 do (byte-compile-file fname parg))))
2918 (defun anything-find-files-load-files (candidate)
2919 "Load elisp files from `anything-find-files'."
2920 (let ((files (anything-marked-candidates)))
2921 (loop for fname in files
2922 do (load fname))))
2924 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2925 "Generic function to ediff/merge files in `anything-find-files'."
2926 (let ((bname (anything-c-basename candidate))
2927 (prompt (if merge "Ediff Merge `%s' With File: "
2928 "Ediff `%s' With File: "))
2929 (fun (if merge 'ediff-merge-files 'ediff-files)))
2930 (funcall fun
2931 candidate
2932 (condition-case quit
2933 (anything-c-read-file-name
2934 (format prompt bname))
2935 (quit ;; Hit C-g ask user to fallback to locate.
2936 (if (y-or-n-p "Search file for ediff with locate? ")
2937 (anything-c-locate-read-file-name
2938 (format prompt bname)
2939 ;; Check if -b option is available.
2940 (if (and (eq system-type 'windows-nt)
2941 (string-match "^es" anything-c-locate-command))
2942 bname
2943 (concat bname " -b")))
2944 (error "Error: Ediff Operation aborted")))))))
2946 (defun anything-find-files-ediff-files (candidate)
2947 (anything-find-files-ediff-files-1 candidate))
2949 (defun anything-find-files-ediff-merge-files (candidate)
2950 (anything-find-files-ediff-files-1 candidate 'merge))
2952 (defun anything-find-files-grep (candidate)
2953 "Default action to grep files from `anything-find-files'."
2954 (anything-do-grep-1 (anything-marked-candidates)
2955 anything-current-prefix-arg))
2957 (defun anything-ff-zgrep (candidate)
2958 "Default action to zgrep files from `anything-find-files'."
2959 (let ((prefarg anything-current-prefix-arg)
2960 (ls (anything-marked-candidates)))
2961 (anything-ff-zgrep-1 ls prefarg)))
2963 (defun anything-ff-pdfgrep (candidate)
2964 "Default action to pdfgrep files from `anything-find-files'."
2965 (let ((cands (loop for file in (anything-marked-candidates)
2966 if (or (string= (file-name-extension file) "pdf")
2967 (string= (file-name-extension file) "PDF"))
2968 collect file))
2969 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2970 (when cands
2971 (anything-do-pdfgrep-1 cands))))
2973 (defun anything-ff-etags-select (candidate)
2974 "Default action to jump to etags from `anything-find-files'."
2975 (when (get-buffer anything-action-buffer)
2976 (kill-buffer anything-action-buffer))
2977 (let ((default-directory anything-ff-default-directory))
2978 (anything-c-etags-select anything-current-prefix-arg)))
2980 (defun anything-find-files-switch-to-hist (candidate)
2981 "Switch to anything-find-files history."
2982 (anything-find-files t))
2984 ;;; Asynchronous copy of files.
2987 (defun anything-c-copy-files-async-1 (flist dest)
2988 "Copy a list of Files FLIST to DEST asynchronously.
2989 It use another emacs process to do the job.
2990 Communication with background emacs is done with temp file
2991 `anything-c-copy-files-async-log-file'."
2992 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2993 "-Q" "--batch" "--eval"
2994 (format "(progn
2995 (require 'dired) (require 'cl)
2996 (let ((dired-recursive-copies 'always)
2997 failures success
2998 (ovw-count 0)
2999 (cpf-count 0))
3000 (dolist (f '%S)
3001 (condition-case err
3002 (let ((file-exists (file-exists-p
3003 (expand-file-name
3004 (file-name-nondirectory (directory-file-name f))
3005 (file-name-directory
3006 (file-name-as-directory \"%s\"))))))
3007 (dired-copy-file f \"%s\" t)
3008 (if file-exists
3009 (progn (push (cons \"Overwriting\" f) success)
3010 (incf ovw-count))
3011 (push (cons \"Copying\" f) success)
3012 (incf cpf-count)))
3013 (file-error
3014 (push (dired-make-relative
3015 (expand-file-name
3016 (file-name-nondirectory (directory-file-name f))
3017 (file-name-directory \"%s\")))
3018 failures))))
3019 (with-current-buffer (find-file-noselect \"%s\")
3020 (erase-buffer)
3021 (when failures
3022 (dolist (fail (reverse failures))
3023 (insert (concat \"Failed to copy \" fail \"\n\"))))
3024 (when success
3025 (loop for (a . s) in (reverse success) do
3026 (insert (concat a \" \" s \" to %s done\n\"))))
3027 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3028 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3029 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3030 (save-buffer))))"
3031 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3033 (defun anything-c-copy-async-with-log (flist dest)
3034 "Copy file list FLIST to DEST showing log.
3035 Log is send to `anything-c-copy-files-async-log-file'.
3036 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3037 (declare (special auto-revert-interval))
3038 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3039 (set (make-local-variable 'auto-revert-interval) 1)
3040 (erase-buffer)
3041 (insert "Wait copying files...\n")
3042 (sit-for 0.5) (save-buffer)
3043 (goto-char (point-max))
3044 (auto-revert-mode 1)
3045 (anything-c-copy-files-async-1 flist dest))
3047 (defun anything-ff-copy-async (candidate)
3048 "Anything find files action to copy files async.
3049 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3050 (let* ((flist (anything-marked-candidates))
3051 (dest (anything-c-read-file-name
3052 (anything-find-files-set-prompt-for-action
3053 "Copy Async" flist)
3054 :preselect candidate
3055 :initial-input (car anything-ff-history)
3056 :history (anything-find-files-history :comp-read nil))))
3057 (anything-c-copy-async-with-log flist dest)))
3059 (defvar eshell-command-aliases-list nil)
3060 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3061 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3063 Basename of CANDIDATE can be a wild-card.
3064 If MAP is given run `eshell-command' on all marked files at once,
3065 Otherwise, run `eshell-command' on each marked files.
3067 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3068 `eshell-command-aliases-list' will not be loaded first time you use this."
3069 (when (or eshell-command-aliases-list
3070 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3071 (and eshell-command-aliases-list (eshell-read-aliases-list))
3072 (let* ((cand-list (anything-marked-candidates))
3073 (default-directory (or anything-ff-default-directory
3074 ;; If candidate is an url *-ff-default-directory is nil
3075 ;; so keep value of default-directory.
3076 default-directory))
3077 (command (anything-comp-read
3078 "Command: "
3079 (loop for (a . c) in eshell-command-aliases-list
3080 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3081 collect (propertize a 'help-echo (car c)) into ls
3082 finally return (sort ls 'string<))))
3083 (com-value (car (assoc-default command eshell-command-aliases-list))))
3084 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3085 (> (length cand-list) 1))
3086 ;; Run eshell-command with ALL marked files as arguments.
3087 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3088 (eshell-command (format "%s %s" command mapfiles)))
3089 ;; Run eshell-command on EACH marked files.
3090 (loop
3091 for i in cand-list
3092 for bn = (anything-c-basename i)
3093 for files = (if (and bn (string-match "^\*" bn))
3094 ;; Assume if fname is a wildcard
3095 ;; cand-list have a length of 1.
3096 (mapconcat
3097 'shell-quote-argument
3098 (file-expand-wildcards i t) " ")
3099 (format "'%s'" i))
3100 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3101 ;; This allow to enter other args AFTER filename
3102 ;; i.e <command %s some_more_args>
3103 (format command files)
3104 (format "%s %s" command files))
3105 do (eshell-command com))))))
3107 (defun anything-find-files-eshell-command-on-file (candidate)
3108 "Run `eshell-command' on CANDIDATE or marked candidates.
3109 See `anything-find-files-eshell-command-on-file-1' for more info."
3110 (anything-find-files-eshell-command-on-file-1
3111 candidate anything-current-prefix-arg))
3113 (defun anything-ff-switch-to-eshell (candidate)
3114 "Switch to eshell and cd to `anything-ff-default-directory'."
3115 (flet ((cd-eshell ()
3116 (goto-char (point-max))
3117 (insert
3118 (format "cd '%s'" anything-ff-default-directory))
3119 (eshell-send-input)))
3120 (if (get-buffer "*eshell*")
3121 (progn
3122 (anything-c-switch-to-buffer "*eshell*")
3123 (cd-eshell))
3124 (call-interactively 'eshell)
3125 (cd-eshell))))
3127 (defun anything-ff-serial-rename-action (method)
3128 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3129 See `anything-ff-serial-rename-1'."
3130 (let* ((cands (anything-marked-candidates))
3131 (name (read-string "NewName: "))
3132 (start (read-number "StartAtNumber: "))
3133 (extension (read-string "Extension: " (file-name-extension (car cands))))
3134 (dir (expand-file-name
3135 (anything-c-read-file-name
3136 "Serial Rename to directory: " :initial-input
3137 (expand-file-name anything-ff-default-directory)))))
3138 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3139 (length cands) dir name))
3140 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3141 (anything-find-files-1 dir))))
3143 (defun anything-ff-member-directory-p (file directory)
3144 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3145 (cur-dir (expand-file-name (file-name-as-directory directory))))
3146 (string= dir-file cur-dir)))
3148 (defun* anything-ff-serial-rename-1
3149 (directory collection new-name start-at-num extension &key (method 'rename))
3150 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3151 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3152 EXTENSION is the file extension to use, in empty prompt,
3153 reuse the original extension of file.
3154 METHOD can be one of rename, copy or symlink.
3155 Files will be renamed if they are files of current directory, otherwise they
3156 will be treated with METHOD.
3157 Default METHOD is rename."
3158 ;; Maybe remove directories selected by error in collection.
3159 (setq collection (remove-if 'file-directory-p collection))
3160 (flet ((symlink-file (file dest)
3161 (let ((flist (list file)))
3162 (anything-dired-action
3163 dest :action 'symlink :files flist))))
3165 (let* ((tmp-dir (file-name-as-directory
3166 (concat (file-name-as-directory directory)
3167 (symbol-name (gensym "tmp")))))
3168 (fn (case method
3169 (copy 'copy-file)
3170 (symlink 'symlink-file)
3171 (rename 'rename-file)
3172 (t (error "Error: Unknow method %s" method)))))
3173 (make-directory tmp-dir)
3174 (loop for i in collection
3175 for count from start-at-num
3176 for fnum = (if (< count 10) "0%s" "%s")
3177 for nname = (concat tmp-dir new-name (format fnum count)
3178 (if (not (string= extension ""))
3179 (format ".%s" (replace-regexp-in-string
3180 "[.]" "" extension))
3181 (file-name-extension i 'dot)))
3182 do (if (anything-ff-member-directory-p i directory)
3183 (rename-file i nname)
3184 (funcall fn i nname)))
3185 (loop with dirlist = (directory-files
3186 tmp-dir t directory-files-no-dot-files-regexp)
3187 for f in dirlist do
3188 (if (file-symlink-p f)
3189 (symlink-file (file-truename f)
3190 (concat (file-name-as-directory directory)
3191 (anything-c-basename f)))
3192 (rename-file f directory)))
3193 (delete-directory tmp-dir t))))
3195 (defun anything-ff-serial-rename (candidate)
3196 "Serial rename all marked files to `anything-ff-default-directory'.
3197 Rename only file of current directory, and symlink files coming from
3198 other directories.
3199 See `anything-ff-serial-rename-1'."
3200 (anything-ff-serial-rename-action 'rename))
3202 (defun anything-ff-serial-rename-by-symlink (candidate)
3203 "Serial rename all marked files to `anything-ff-default-directory'.
3204 Rename only file of current directory, and symlink files coming from
3205 other directories.
3206 See `anything-ff-serial-rename-1'."
3207 (anything-ff-serial-rename-action 'symlink))
3209 (defun anything-ff-serial-rename-by-copying (candidate)
3210 "Serial rename all marked files to `anything-ff-default-directory'.
3211 Rename only file of current directory, and copy files coming from
3212 other directories.
3213 See `anything-ff-serial-rename-1'."
3214 (anything-ff-serial-rename-action 'copy))
3216 (defun anything-c-quit-and-execute-action (action)
3217 "Quit current anything session and execute ACTION."
3218 (setq anything-saved-action action)
3219 (anything-exit-minibuffer))
3221 (defun anything-ff-toggle-auto-update (candidate)
3222 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3223 (message "[Auto expansion %s]"
3224 (if anything-ff-auto-update-flag "enabled" "disabled")))
3226 ;;;###autoload
3227 (defun anything-ff-run-toggle-auto-update ()
3228 (interactive)
3229 (anything-execute-persistent-action 'toggle-auto-update))
3231 ;;;###autoload
3232 (defun anything-ff-run-switch-to-history ()
3233 "Run Switch to history action from `anything-c-source-find-files'."
3234 (interactive)
3235 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3237 ;;;###autoload
3238 (defun anything-ff-run-grep ()
3239 "Run Grep action from `anything-c-source-find-files'."
3240 (interactive)
3241 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3243 ;;;###autoload
3244 (defun anything-ff-run-pdfgrep ()
3245 "Run Pdfgrep action from `anything-c-source-find-files'."
3246 (interactive)
3247 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3249 ;;;###autoload
3250 (defun anything-ff-run-zgrep ()
3251 "Run Grep action from `anything-c-source-find-files'."
3252 (interactive)
3253 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3255 ;;;###autoload
3256 (defun anything-ff-run-copy-file ()
3257 "Run Copy file action from `anything-c-source-find-files'."
3258 (interactive)
3259 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3261 ;;;###autoload
3262 (defun anything-ff-run-rename-file ()
3263 "Run Rename file action from `anything-c-source-find-files'."
3264 (interactive)
3265 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3267 ;;;###autoload
3268 (defun anything-ff-run-byte-compile-file ()
3269 "Run Byte compile file action from `anything-c-source-find-files'."
3270 (interactive)
3271 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3273 ;;;###autoload
3274 (defun anything-ff-run-load-file ()
3275 "Run Load file action from `anything-c-source-find-files'."
3276 (interactive)
3277 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3279 ;;;###autoload
3280 (defun anything-ff-run-eshell-command-on-file ()
3281 "Run eshell command on file action from `anything-c-source-find-files'."
3282 (interactive)
3283 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3285 ;;;###autoload
3286 (defun anything-ff-run-ediff-file ()
3287 "Run Ediff file action from `anything-c-source-find-files'."
3288 (interactive)
3289 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3291 ;;;###autoload
3292 (defun anything-ff-run-ediff-merge-file ()
3293 "Run Ediff merge file action from `anything-c-source-find-files'."
3294 (interactive)
3295 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3297 ;;;###autoload
3298 (defun anything-ff-run-symlink-file ()
3299 "Run Symlink file action from `anything-c-source-find-files'."
3300 (interactive)
3301 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3303 ;;;###autoload
3304 (defun anything-ff-run-delete-file ()
3305 "Run Delete file action from `anything-c-source-find-files'."
3306 (interactive)
3307 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3309 ;;;###autoload
3310 (defun anything-ff-run-complete-fn-at-point ()
3311 "Run complete file name action from `anything-c-source-find-files'."
3312 (interactive)
3313 (anything-c-quit-and-execute-action
3314 'anything-c-insert-file-name-completion-at-point))
3316 ;;;###autoload
3317 (defun anything-ff-run-switch-to-eshell ()
3318 "Run switch to eshell action from `anything-c-source-find-files'."
3319 (interactive)
3320 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3322 ;;;###autoload
3323 (defun anything-ff-run-switch-other-window ()
3324 "Run switch to other window action from `anything-c-source-find-files'."
3325 (interactive)
3326 (anything-c-quit-and-execute-action 'find-file-other-window))
3328 ;;;###autoload
3329 (defun anything-ff-run-switch-other-frame ()
3330 "Run switch to other frame action from `anything-c-source-find-files'."
3331 (interactive)
3332 (anything-c-quit-and-execute-action 'find-file-other-frame))
3334 ;;;###autoload
3335 (defun anything-ff-run-open-file-externally ()
3336 "Run open file externally command action from `anything-c-source-find-files'."
3337 (interactive)
3338 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3340 (defun anything-ff-locate (candidate)
3341 "Locate action function for `anything-find-files'."
3342 (let ((input (concat (anything-c-basename
3343 (expand-file-name
3344 candidate
3345 anything-ff-default-directory))
3346 ;; The locate '-b' option doesn't exists
3347 ;; in everything.
3348 (unless (and (eq system-type 'windows-nt)
3349 (string-match "^es" anything-c-locate-command))
3350 " -b")))
3351 (anything-mp-highlight-delay 0.7))
3352 (anything-locate-1 anything-current-prefix-arg input)))
3354 ;;;###autoload
3355 (defun anything-ff-run-locate ()
3356 "Run locate action from `anything-c-source-find-files'."
3357 (interactive)
3358 (anything-c-quit-and-execute-action 'anything-ff-locate))
3360 ;;;###autoload
3361 (defun anything-ff-run-gnus-attach-files ()
3362 "Run gnus attach files command action from `anything-c-source-find-files'."
3363 (interactive)
3364 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3366 ;;;###autoload
3367 (defun anything-ff-run-etags ()
3368 "Run Etags command action from `anything-c-source-find-files'."
3369 (interactive)
3370 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3373 (defun anything-ff-print (candidate)
3374 "Print marked files.
3375 You have to set in order
3376 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3378 e.g:
3379 \(setq lpr-command \"gtklp\"\)
3380 \(setq lpr-switches '(\"-P\")\)
3381 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3383 Same as `dired-do-print' but for anything."
3384 (let* ((file-list (anything-marked-candidates))
3385 (len (length file-list))
3386 (printer-name (if anything-ff-printer-list
3387 (anything-comp-read
3388 "Printer: " anything-ff-printer-list)
3389 printer-name))
3390 (command (read-string
3391 (format "Print *%s File(s):\n%s with: "
3393 (mapconcat
3394 (lambda (f) (format "- %s\n" f))
3395 file-list ""))
3396 (when (and lpr-command
3397 (or lpr-switches
3398 printer-name))
3399 (mapconcat 'identity
3400 (cons lpr-command
3401 (append (if (stringp lpr-switches)
3402 (list lpr-switches)
3403 lpr-switches)
3404 (list printer-name)))
3405 " "))))
3406 (file-args (mapconcat #'(lambda (x)
3407 (format "'%s'" x))
3408 file-list " "))
3409 (cmd-line (concat command " " file-args)))
3410 (if command
3411 (start-process-shell-command "anything-print" nil cmd-line)
3412 (error "Error: Please verify your printer settings in Emacs."))))
3414 ;;;###autoload
3415 (defun anything-ff-run-print-file ()
3416 "Run Print file action from `anything-c-source-find-files'."
3417 (interactive)
3418 (anything-c-quit-and-execute-action 'anything-ff-print))
3420 (defun anything-ff-checksum (file)
3421 "Calculate the checksum of FILE.
3422 Provide completion on different algorithms to use on Emacs24.
3423 On Emacs23 only 'sha1' is available.
3424 The checksum is copied to kill-ring."
3425 (let ((algo-list (and (fboundp 'secure-hash)
3426 '(md5 sha1 sha224 sha256 sha384 sha512))))
3427 (kill-new
3428 (if algo-list
3429 (secure-hash (intern
3430 (anything-comp-read
3431 "Algorithm: " algo-list))
3432 file)
3433 (sha1 (with-temp-buffer
3434 (insert-file-contents file)
3435 (buffer-string)))))
3436 (message "Checksum copied to kill-ring.")))
3438 (defun anything-ff-toggle-basename (candidate)
3439 (setq anything-ff-transformer-show-only-basename
3440 (not anything-ff-transformer-show-only-basename))
3441 (let ((target (if anything-ff-transformer-show-only-basename
3442 (anything-c-basename candidate) candidate)))
3443 (anything-force-update target)))
3445 (defun anything-ff-run-toggle-basename ()
3446 (interactive)
3447 (anything-execute-persistent-action 'toggle-basename))
3449 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3450 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3451 If LEVEL is positive reduce from end else from beginning.
3452 If UNIX-CLOSE is non--nil close filename with /.
3453 If EXPAND is non--nil expand-file-name."
3454 (let* ((exp-fname (expand-file-name fname))
3455 (fname-list (split-string (if (or (string= fname "~/") expand)
3456 exp-fname fname) "/" t))
3457 (len (length fname-list))
3458 (pop-list (if (< level 0)
3459 (subseq fname-list (* level -1))
3460 (subseq fname-list 0 (- len level))))
3461 (result (mapconcat 'identity pop-list "/"))
3462 (empty (string= result "")))
3463 (when unix-close (setq result (concat result "/")))
3464 (if (string-match "^~" result)
3465 (if (string= result "~/") "~/" result)
3466 (if (< level 0)
3467 (if empty "../" (concat "../" result))
3468 (cond ((eq system-type 'windows-nt)
3469 (if empty "c:/" result))
3470 (empty "/")
3472 (concat "/" result)))))))
3474 ;; Internal
3475 (defvar anything-file-completion-sources
3476 '("Find Files" "find-file" "Copy Files"
3477 "dired-do-copy" "dired-do-rename"
3478 "dired-do-symlink" "dired-do-hardlink"
3479 "write-file" "insert-file" "dired"
3480 "find-alternate-file" "find-alternate-file-other-window"
3481 "find-file-read-only" "list-directory"
3482 "Read File Name History" "mml-attach-file"
3483 "Rename Files" "Symlink Files"
3484 "Hardlink Files" "Write File"
3485 "Insert File" "Read File Name")
3486 "Sources that use the *find-files mechanism can be added here.
3487 You should not modify this yourself and know what you do if you do so.")
3489 (defun anything-file-completion-source-p ()
3490 "Test if current source is a dired or find-files source."
3491 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3492 (loop for i in anything-file-completion-sources
3493 thereis (string= cur-source i))))
3495 (defun anything-find-files-down-one-level (arg)
3496 "Go down one level like unix command `cd ..'.
3497 If prefix numeric arg is given go ARG level down."
3498 (interactive "p")
3499 (when (and (anything-file-completion-source-p)
3500 (not (anything-ff-invalid-tramp-name-p)))
3501 (with-anything-window
3502 (setq anything-follow-mode nil))
3503 ;; When going to precedent level we want to be at the line
3504 ;; corresponding to actual directory, so store this info
3505 ;; in `anything-ff-last-expanded'.
3506 (if (and (not (file-directory-p anything-pattern))
3507 (file-exists-p anything-pattern))
3508 (setq anything-ff-last-expanded anything-pattern)
3509 (setq anything-ff-last-expanded anything-ff-default-directory))
3510 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3511 :unix-close t :expand t)))
3512 (anything-set-pattern new-pattern))))
3514 (defun anything-ff-retrieve-last-expanded ()
3515 "Move overlay to last visited directory `anything-ff-last-expanded'.
3516 This happen after using `anything-find-files-down-one-level',
3517 or hitting C-z on \"..\"."
3518 (when (and anything-ff-last-expanded
3519 (anything-file-completion-source-p))
3520 (let ((dirname (if anything-ff-transformer-show-only-basename
3521 (anything-c-basename
3522 (directory-file-name anything-ff-last-expanded))
3523 (directory-file-name anything-ff-last-expanded))))
3524 (with-anything-window
3525 (when (or (re-search-forward (concat dirname "$") nil t)
3526 (re-search-forward
3527 (concat anything-ff-last-expanded "$") nil t))
3528 (forward-line 0)
3529 (anything-mark-current-line)))
3530 (setq anything-ff-last-expanded nil))))
3531 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3533 ;; Auto-update - anything-find-files auto expansion of directories.
3535 (defun anything-ff-update-when-only-one-matched ()
3536 "Expand to directory when sole completion.
3537 When only one candidate is remaining and it is a directory,
3538 expand to this directory."
3539 (when (and anything-ff-auto-update-flag
3540 (anything-file-completion-source-p)
3541 (not (anything-ff-invalid-tramp-name-p)))
3542 (let* ((history-p (string= (assoc-default
3543 'name (anything-get-current-source))
3544 "Read File Name History"))
3545 (pat (if (string-match tramp-file-name-regexp
3546 anything-pattern)
3547 (anything-create-tramp-name anything-pattern)
3548 anything-pattern))
3549 (completed-p (string= (file-name-as-directory pat)
3550 anything-ff-default-directory)))
3551 (when (and (or
3552 ;; Only one candidate remaining
3553 ;; and at least 2 char in basename.
3554 (and (<= (anything-approximate-candidate-number) 2)
3555 (>= (length (anything-c-basename anything-pattern)) 2))
3556 ;; Already completed.
3557 completed-p)
3558 (not history-p)) ; Don't try to auto complete in history.
3559 (with-anything-window
3560 (let ((cur-cand (prog2
3561 (unless completed-p
3562 ;; Only one non--existing candidate
3563 ;; and one directory candidate, move to it.
3564 (anything-next-line))
3565 (anything-get-selection))))
3566 (when (file-directory-p cur-cand)
3567 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3568 ;; Maybe we are here because completed-p is true
3569 ;; but check this again to be sure. (Windows fix)
3570 (<= (anything-approximate-candidate-number) 2)) ; [2]
3571 ;; If after going to next line the candidate
3572 ;; is not one of "." or ".." [1]
3573 ;; and only one candidate is remaining [2],
3574 ;; assume candidate is a new directory to expand, and do it.
3575 (anything-set-pattern (file-name-as-directory cur-cand))
3576 ;; The candidate is one of "." or ".."
3577 ;; that mean we have entered the last letter of the directory name
3578 ;; in prompt, so expansion is already done, just add the "/" at end
3579 ;; of name unless anything-pattern ends with "."
3580 ;; (i.e we are writing something starting with ".")
3581 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3582 (anything-set-pattern
3583 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3584 (expand-file-name (file-name-as-directory anything-pattern)))))
3585 (anything-check-minibuffer-input-1))))))))
3586 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3588 ;; Allow expanding to home directory or root
3589 ;; when entering respectively "~/" or "//" at end of pattern.
3590 ;; e.g /home/thierry/labo/anything-config-qp/~/
3591 ;; will expand to "~/"
3592 ;; and /home/thierry/labo/anything-config-qp//
3593 ;; will expand to "/"
3594 (defun anything-ff-auto-expand-to-home-or-root ()
3595 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3596 This happen only in function using sources that are
3597 `anything-file-completion-source-p' compliant."
3598 (when (and (anything-file-completion-source-p)
3599 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3600 anything-pattern))
3601 (let ((match (match-string 1 anything-pattern)))
3602 (cond ((string= match "//")
3603 (if (eq system-type 'windows-nt)
3604 (setq anything-pattern "c:/")
3605 (setq anything-pattern "/")))
3606 ((string= match "/~/")
3607 (if (eq system-type 'windows-nt)
3608 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3609 (setq anything-pattern "~/")))
3610 ((string= match "/./")
3611 (setq anything-pattern
3612 (with-anything-current-buffer
3613 (expand-file-name default-directory))))))
3614 (setq anything-ff-default-directory anything-pattern)
3615 ;; For some reasons, i must use here with-current-buffer => mini buffer
3616 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3617 (with-current-buffer (window-buffer (minibuffer-window))
3618 (delete-minibuffer-contents)
3619 (insert anything-pattern))))
3621 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3623 (defun anything-c-point-file-in-dired (file)
3624 "Put point on filename FILE in dired buffer."
3625 (dired (file-name-directory file))
3626 (dired-goto-file file))
3628 (defun anything-create-tramp-name (fname)
3629 "Build filename for `anything-pattern' like /su:: or /sudo::."
3630 (apply #'tramp-make-tramp-file-name
3631 (loop with v = (tramp-dissect-file-name fname)
3632 for i across v collect i)))
3634 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3635 "Get a list of hosts for tramp method found in `anything-pattern'.
3636 Argument PATTERN default to `anything-pattern', it is here only for debugging
3637 purpose."
3638 (when (string-match tramp-file-name-regexp pattern)
3639 (let ((method (match-string 1 pattern))
3640 (tn (match-string 0 pattern))
3641 (all-methods (mapcar 'car tramp-methods)))
3642 (remove-duplicates
3643 (loop for (f . h) in (tramp-get-completion-function method)
3644 append (loop for e in (funcall f (car h))
3645 for host = (and (consp e) (cadr e))
3646 when (and host (not (member host all-methods)))
3647 collect (concat tn host)))
3648 :test 'equal))))
3650 (defun anything-ff-before-action-hook-fn ()
3651 "Exit anything when user try to execute action on an invalid tramp fname."
3652 (let ((cand (anything-get-selection)))
3653 (when (and (anything-file-completion-source-p)
3654 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3655 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3656 (error "Error: Unknow file or directory `%s'" cand))))
3657 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3659 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3660 "Return non--nil when PATTERN is an invalid tramp filename."
3661 (string= (anything-ff-set-pattern pattern)
3662 "Invalid tramp file name"))
3664 (defun anything-ff-set-pattern (pattern)
3665 "Handle tramp filenames in `anything-pattern'."
3666 (let ((methods (mapcar 'car tramp-methods))
3667 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3668 cur-method tramp-name)
3669 (cond ((string= pattern "") "")
3670 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3671 (with-anything-current-buffer
3672 (expand-file-name default-directory)))
3673 ((string-match ".*\\(~//\\|//\\)$" pattern)
3674 (if (eq system-type 'windows-nt) "c:/" "/"))
3675 ((string-match "^~\\|.*/~/$" pattern)
3676 (let* ((home (expand-file-name (getenv "HOME"))))
3677 (replace-match home nil t pattern)))
3678 ;; Match "/method:maybe_hostname:"
3679 ((and (string-match reg pattern)
3680 (setq cur-method (match-string 1 pattern))
3681 (member cur-method methods))
3682 (setq tramp-name (anything-create-tramp-name
3683 (match-string 0 pattern)))
3684 (replace-match tramp-name nil t pattern))
3685 ;; Match "/hostname:"
3686 ((and (string-match tramp-file-name-regexp pattern)
3687 (setq cur-method (match-string 1 pattern))
3688 (and cur-method (not (member cur-method methods))))
3689 (setq tramp-name (anything-create-tramp-name
3690 (match-string 0 pattern)))
3691 (replace-match tramp-name nil t pattern))
3692 ;; Match "/method:" in this case don't try to connect.
3693 ((and (not (string-match reg pattern))
3694 (string-match tramp-file-name-regexp pattern)
3695 (member (match-string 1 pattern) methods))
3696 "Invalid tramp file name") ; Write in anything-buffer.
3697 ;; PATTERN is a directory, end it with "/".
3698 ;; This will make PATTERN not ending yet with "/"
3699 ;; candidate for `anything-ff-default-directory',
3700 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3701 ;; when descending level.
3702 ((file-directory-p pattern)
3703 (file-name-as-directory pattern))
3704 ;; Return PATTERN unchanged.
3705 (t pattern))))
3707 (defun anything-find-files-get-candidates ()
3708 "Create candidate list for `anything-c-source-find-files'."
3709 (let* ((path (anything-ff-set-pattern anything-pattern))
3710 (path-name-dir (if (file-directory-p path)
3711 (file-name-as-directory path)
3712 (file-name-directory path)))
3713 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3714 (set-text-properties 0 (length path) nil path)
3715 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3716 ;; like that the actual value (e.g /ssh:) is passed to
3717 ;; `anything-ff-tramp-hostnames'.
3718 (unless (string= path "Invalid tramp file name")
3719 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3720 (setq anything-ff-default-directory
3721 (if (string= anything-pattern "")
3722 (if (eq system-type 'windows-nt) "c:/" "/")
3723 (unless (string-match ffap-url-regexp path)
3724 ;; If path is an url *default-directory have to be nil.
3725 path-name-dir)))
3726 (cond ((string= path "Invalid tramp file name")
3727 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3728 (prog2
3729 ;; `anything-pattern' have not been modified yet.
3730 ;; Set it here to the value of `path' that should be now
3731 ;; "Invalid tramp file name" and set the candidates list
3732 ;; to ("Invalid tramp file name") to make `anything-pattern'
3733 ;; match single candidate "Invalid tramp file name".
3734 (setq anything-pattern path)
3735 ;; "Invalid tramp file name" is now printed
3736 ;; in `anything-buffer'.
3737 (list path))))
3738 ((or (file-regular-p path)
3739 (and (not (file-exists-p path)) (string-match "/$" path))
3740 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3741 (list path))
3742 ((string= path "") (directory-files "/" t))
3743 ((and (file-directory-p path) (not (file-readable-p path)))
3744 (list (format "Opening directory: access denied, `%s'" path)))
3745 ((file-directory-p path) (directory-files path t))
3747 (append (list path) (directory-files path-name-dir t))))))
3749 (defun anything-ff-transform-fname-for-completion (fname)
3750 "Return FNAME with it's basename modified as a regexp.
3751 e.g foo => f.*o.*o .
3752 If basename contain one or more space or FNAME is a valid directory name
3753 return FNAME unchanged."
3754 (let ((bn (anything-c-basename fname)))
3755 (if (or (not anything-ff-smart-completion)
3756 (string-match "\\s-" bn)
3757 (string-match "/$" fname) ; Allow mkdir.
3758 (file-directory-p fname))
3759 fname ; Fall back to match-plugin.
3760 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3761 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3762 (concat (file-name-directory fname) bn))))
3764 (defun anything-ff-save-history ()
3765 "Store the last value of `anything-ff-default-directory' \
3766 in `anything-ff-history'."
3767 (when (and anything-ff-default-directory
3768 (anything-file-completion-source-p))
3769 (push anything-ff-default-directory anything-ff-history)))
3770 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3772 (defun anything-ff-valid-symlink-p (file)
3773 (file-exists-p (file-truename file)))
3775 (defun anything-ff-properties (candidate)
3776 "Show file properties of CANDIDATE in a tooltip or message."
3777 (let ((type (anything-ff-attributes candidate :type t))
3778 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3779 (if (window-system)
3780 (tooltip-show
3781 (concat
3782 (anything-c-basename candidate) ": \n"
3783 "Type: " type "\n"
3784 (when (string= type "symlink")
3785 (format "True name: '%s'\n"
3786 (cond ((string-match "^\.#" (anything-c-basename candidate))
3787 "Autosave symlink")
3788 ((anything-ff-valid-symlink-p candidate)
3789 (file-truename candidate))
3790 (t "Invalid Symlink"))))
3791 dired-line))
3792 (message dired-line) (sit-for 5))))
3794 ;;;###autoload
3795 (defun anything-ff-properties-persistent ()
3796 "Show properties without quitting anything."
3797 (interactive)
3798 (anything-execute-persistent-action 'properties-action))
3800 (defun anything-ff-kill-buffer-fname (candidate)
3801 (let* ((buf (get-file-buffer candidate))
3802 (buf-name (buffer-name buf)))
3803 (if buf
3804 (progn
3805 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3806 (message "No buffer to kill"))))
3808 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3809 "Find file CANDIDATE or kill it's buffer if it is visible.
3810 Never kill `anything-current-buffer'.
3811 Never kill buffer modified.
3812 This is called normally on third hit of \
3813 \\<anything-map>\\[anything-execute-persistent-action]
3814 in `anything-find-files-persistent-action'."
3815 (let* ((buf (get-file-buffer candidate))
3816 (buf-name (buffer-name buf)))
3817 (if (and buf (get-buffer-window buf)
3818 (not (eq buf (get-buffer anything-current-buffer)))
3819 (not (buffer-modified-p buf)))
3820 (progn
3821 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3822 (find-file candidate))))
3824 ;;;###autoload
3825 (defun anything-ff-run-kill-buffer-persistent ()
3826 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3827 (interactive)
3828 (anything-execute-persistent-action 'kill-buffer-fname))
3830 (defun anything-ff-human-size (size)
3831 "Return a string showing SIZE of a file in human readable form.
3832 SIZE can be an integer or a float depending it's value.
3833 `file-attributes' will take care of that to avoid overflow error.
3834 KBSIZE if a floating point number, default value is 1024.0."
3835 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3836 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3837 (K (cons "K" (/ size anything-ff-default-kbsize)))
3838 (B (cons "B" size)))
3839 (loop with result = B
3840 for (a . b) in
3841 (loop for (x . y) in (list M G K B)
3842 unless (< y 1) collect (cons x y))
3843 when (< b (cdr result)) do (setq result (cons a b))
3844 finally return (if (string= (car result) "B")
3845 (format "%s" size)
3846 (format "%.1f%s" (cdr result) (car result))))))
3848 (defun* anything-ff-attributes
3849 (file &key type links uid gid access-time modif-time
3850 status size mode gid-change inode device-num dired human-size)
3851 "Easy interface for `file-attributes'."
3852 (let ((all (destructuring-bind
3853 (type links uid gid access-time modif-time
3854 status size mode gid-change inode device-num)
3855 (file-attributes file 'string)
3856 (list :type type
3857 :links links
3858 :uid uid
3859 :gid gid
3860 :access-time access-time
3861 :modif-time modif-time
3862 :status status
3863 :size size
3864 :mode mode
3865 :gid-change gid-change
3866 :inode inode
3867 :device-num device-num))))
3868 (cond (type
3869 (let ((result (getf all :type)))
3870 (cond ((stringp result)
3871 "symlink")
3872 (result "directory")
3873 (t "file"))))
3874 (links (getf all :links))
3875 (uid (getf all :uid))
3876 (gid (getf all :gid))
3877 (access-time
3878 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3879 (modif-time
3880 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3881 (status
3882 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3883 (size (if human-size (anything-ff-human-size (getf all :size))
3884 (getf all :size)))
3885 (mode (getf all :mode))
3886 (gid-change (getf all :gid-change))
3887 (inode (getf all :inode))
3888 (device-num (getf all :device-num))
3889 (dired
3890 (concat
3891 (getf all :mode) " "
3892 (number-to-string (getf all :links)) " "
3893 (getf all :uid) ":"
3894 (getf all :gid) " "
3895 (if human-size (anything-ff-human-size (getf all :size))
3896 (int-to-string (getf all :size))) " "
3897 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3898 (t all))))
3900 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3901 "Return filename FNAME maybe prefixed with [?] or [@].
3902 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3903 existing filename or valid symlink and there is no need to test it.
3904 NEW-FILE when non--nil mean FNAME is a non existing file and
3905 return FNAME prefixed with [?]."
3906 (let* ((prefix-new (propertize
3907 " " 'display
3908 (propertize "[?]" 'face 'anything-ff-prefix)))
3909 (prefix-url (propertize
3910 " " 'display
3911 (propertize "[@]" 'face 'anything-ff-prefix))))
3912 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3913 ((string-match ffap-url-regexp fname)
3914 (concat prefix-url " " fname))
3915 ((or new-file (not (file-exists-p fname)))
3916 (concat prefix-new " " fname)))))
3918 (defun anything-c-find-files-transformer (files sources)
3919 "Transformer for `anything-c-source-find-files'.
3920 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3921 is non--nil."
3922 (if (and (string-match tramp-file-name-regexp anything-pattern)
3923 anything-ff-tramp-not-fancy)
3924 (if anything-ff-transformer-show-only-basename
3925 (loop for i in files collect
3926 (if (string-match "[.]\\{1,2\\}$" i)
3927 i (cons (anything-c-basename i) i)))
3928 files)
3929 (anything-ff-highlight-files files sources)))
3931 (defun anything-ff-highlight-files (files sources)
3932 "Candidate transformer for `anything-c-source-find-files' without icons."
3933 (loop for i in files
3934 for disp = (if (and anything-ff-transformer-show-only-basename
3935 (not (string-match "[.]\\{1,2\\}$" i))
3936 (not (string-match ffap-url-regexp i)))
3937 (anything-c-basename i) i)
3938 collect
3939 (cond ((and (stringp (car (file-attributes i)))
3940 (not (anything-ff-valid-symlink-p i))
3941 (not (string-match "^\.#" (anything-c-basename i))))
3942 (cons (anything-ff-prefix-filename
3943 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3945 ((stringp (car (file-attributes i)))
3946 (cons (anything-ff-prefix-filename
3947 (propertize disp 'face 'anything-ff-symlink) t)
3949 ((eq t (car (file-attributes i)))
3950 (cons (anything-ff-prefix-filename
3951 (propertize disp 'face 'anything-ff-directory) t)
3953 ((file-executable-p i)
3954 (cons (anything-ff-prefix-filename
3955 (propertize disp 'face 'anything-ff-executable) t)
3957 ((file-exists-p i)
3958 (cons (anything-ff-prefix-filename
3959 (propertize disp 'face 'anything-ff-file) t)
3962 (cons (anything-ff-prefix-filename
3963 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3964 i)))))
3966 (defun anything-find-files-action-transformer (actions candidate)
3967 "Action transformer for `anything-c-source-find-files'."
3968 (cond ((with-anything-current-buffer
3969 (eq major-mode 'message-mode))
3970 (append (subseq actions 0 4)
3971 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3972 (subseq actions 4)))
3973 ((string-match (image-file-name-regexp) candidate)
3974 (append (subseq actions 0 4)
3975 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3976 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3977 (subseq actions 4)))
3978 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3979 (car it) candidate))
3980 (append (subseq actions 0 4)
3981 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3982 . anything-find-files-byte-compile)
3983 ("Load File(s) `M-L'" . anything-find-files-load-files))
3984 (subseq actions 4)))
3985 ((and (string-match "\.html?$" candidate)
3986 (file-exists-p candidate))
3987 (append (subseq actions 0 4)
3988 '(("Browse url file" . browse-url-of-file))
3989 (subseq actions 5)))
3990 ((or (string= (file-name-extension candidate) "pdf")
3991 (string= (file-name-extension candidate) "PDF"))
3992 (append (subseq actions 0 4)
3993 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3994 (subseq actions 5)))
3995 (t actions)))
3997 (defun anything-ff-gnus-attach-files (candidate)
3998 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3999 (let ((flist (anything-marked-candidates)))
4000 (gnus-dired-attach flist)))
4002 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4003 "Rotate current image at NUM-ARG degrees.
4004 This is a destructive operation on FILE made by external tool mogrify."
4005 (declare (special image-dired-display-image-buffer))
4006 (setq file (file-truename file)) ; For symlinked images.
4007 ;; When FILE is not an image-file, do nothing.
4008 (when (string-match (image-file-name-regexp) file)
4009 (if (executable-find "mogrify")
4010 (progn
4011 (shell-command (format "mogrify -rotate %s %s"
4012 (or num-arg 90)
4013 (shell-quote-argument file)))
4014 (when (buffer-live-p image-dired-display-image-buffer)
4015 (kill-buffer image-dired-display-image-buffer))
4016 (image-dired-display-image file)
4017 (message nil)
4018 (display-buffer (get-buffer image-dired-display-image-buffer)))
4019 (error "mogrify not found"))))
4021 (defun anything-ff-rotate-image-left (candidate)
4022 "Rotate image file CANDIDATE left.
4023 This affect directly file CANDIDATE."
4024 (anything-ff-rotate-current-image-1 candidate -90))
4026 (defun anything-ff-rotate-image-right (candidate)
4027 "Rotate image file CANDIDATE right.
4028 This affect directly file CANDIDATE."
4029 (anything-ff-rotate-current-image-1 candidate))
4031 (defun anything-ff-rotate-left-persistent ()
4032 "Rotate image left without quitting anything."
4033 (interactive)
4034 (anything-execute-persistent-action 'image-action1))
4036 (defun anything-ff-rotate-right-persistent ()
4037 "Rotate image right without quitting anything."
4038 (interactive)
4039 (anything-execute-persistent-action 'image-action2))
4041 (defun anything-ff-exif-data (candidate)
4042 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4043 (if (and anything-ff-exif-data-program
4044 (executable-find anything-ff-exif-data-program))
4045 (shell-command-to-string (format "%s %s %s"
4046 anything-ff-exif-data-program
4047 anything-ff-exif-data-program-args
4048 candidate))
4049 (format "No program %s found to extract exif"
4050 anything-ff-exif-data-program)))
4052 (defun anything-find-files-persistent-action (candidate)
4053 "Open subtree CANDIDATE without quitting anything.
4054 If CANDIDATE is not a directory expand CANDIDATE filename.
4055 If CANDIDATE is alone, open file CANDIDATE filename.
4056 That's mean:
4057 First hit on C-z expand CANDIDATE second hit open file.
4058 If a prefix arg is given or `anything-follow-mode' is on open file."
4059 (let ((follow (buffer-local-value
4060 'anything-follow-mode
4061 (get-buffer-create anything-buffer)))
4062 (new-pattern (anything-get-selection))
4063 (num-lines-buf (with-current-buffer anything-buffer
4064 (count-lines (point-min) (point-max)))))
4065 (flet ((insert-in-minibuffer (fname)
4066 (with-selected-window (minibuffer-window)
4067 (unless follow
4068 (delete-minibuffer-contents)
4069 (set-text-properties 0 (length fname) nil fname)
4070 (insert fname)))))
4071 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4072 "Invalid tramp file name")
4073 (string-match tramp-file-name-regexp candidate))
4074 ;; First hit insert hostname and
4075 ;; second hit insert ":" and expand.
4076 (if (string= candidate anything-pattern)
4077 (insert-in-minibuffer (concat candidate ":"))
4078 (insert-in-minibuffer candidate)))
4079 (;; A symlink directory, expand it's truename.
4080 (and (file-directory-p candidate) (file-symlink-p candidate))
4081 (insert-in-minibuffer (file-name-as-directory
4082 (file-truename
4083 (expand-file-name candidate)))))
4084 ;; A directory, open it.
4085 ((file-directory-p candidate)
4086 (when (string= (anything-c-basename candidate) "..")
4087 (setq anything-ff-last-expanded anything-ff-default-directory))
4088 (insert-in-minibuffer (file-name-as-directory
4089 (expand-file-name candidate))))
4090 ;; A symlink file, expand to it's true name. (first hit)
4091 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4092 (insert-in-minibuffer (file-truename candidate)))
4093 ;; A regular file, expand it, (first hit)
4094 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4095 (insert-in-minibuffer new-pattern))
4096 ;; An image file and it is the second hit on C-z,
4097 ;; show the file in `image-dired'.
4098 ((string-match (image-file-name-regexp) candidate)
4099 (when (buffer-live-p image-dired-display-image-buffer)
4100 (kill-buffer image-dired-display-image-buffer))
4101 (image-dired-display-image candidate)
4102 (message nil)
4103 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4104 (with-current-buffer image-dired-display-image-buffer
4105 (let ((exif-data (anything-ff-exif-data candidate)))
4106 (image-dired-update-property 'help-echo exif-data))))
4107 ;; Allow browsing archive on avfs fs.
4108 ;; Assume volume is already mounted with mountavfs.
4109 ((and anything-ff-avfs-directory
4110 (string-match
4111 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4112 (file-name-directory candidate))
4113 (anything-ff-file-compressed-p candidate))
4114 (insert-in-minibuffer (concat candidate "#")))
4115 ;; On second hit we open file.
4116 ;; On Third hit we kill it's buffer maybe.
4118 (anything-ff-kill-or-find-buffer-fname candidate))))))
4120 (defun anything-ff-file-compressed-p (candidate)
4121 "Whether CANDIDATE is a compressed file or not."
4122 (member (file-name-extension candidate)
4123 anything-ff-file-compressed-list))
4125 (defun anything-c-insert-file-name-completion-at-point (candidate)
4126 "Insert file name completion at point."
4127 (with-anything-current-buffer
4128 (if buffer-read-only
4129 (error "Error: Buffer `%s' is read-only" (buffer-name))
4130 (let* ((end (point))
4131 (guess (substring-no-properties (thing-at-point 'filename)))
4132 (beg (- (point) (length guess)))
4133 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4134 (string-match-p "^[^\~]" guess))))
4135 (set-text-properties 0 (length candidate) nil candidate)
4136 (if (and guess (not (string= guess ""))
4137 (string-match-p "^~\\|/.*" guess))
4138 (progn
4139 (delete-region beg end)
4140 (insert (if full-path-p
4141 (expand-file-name candidate)
4142 (abbreviate-file-name candidate))))
4143 (error "Aborting completion: No valid file name at point"))))))
4145 (defun* anything-find-files-history (&key (comp-read t))
4146 "The `anything-find-files' history.
4147 Show the first `anything-ff-history-max-length' elements of
4148 `anything-ff-history' in an `anything-comp-read'."
4149 (let ((history (when anything-ff-history
4150 (anything-fast-remove-dups anything-ff-history
4151 :test 'equal))))
4152 (when history
4153 (setq anything-ff-history
4154 (if (>= (length history) anything-ff-history-max-length)
4155 (subseq history 0 anything-ff-history-max-length)
4156 history))
4157 (if comp-read
4158 (anything-comp-read
4159 "Switch to Directory: "
4160 anything-ff-history
4161 :name "Anything Find Files History"
4162 :must-match t)
4163 anything-ff-history))))
4165 (defun anything-find-files-1 (fname &optional preselect)
4166 "Find FNAME with `anything' completion.
4167 Like `find-file' but with `anything' support.
4168 Use it for non--interactive calls of `anything-find-files'."
4169 (when (get-buffer anything-action-buffer)
4170 (kill-buffer anything-action-buffer))
4171 (let ((anything-mp-highlight-delay nil)
4172 ;; Be sure we don't erase the precedent minibuffer if some.
4173 (anything-ff-auto-update-initial-value
4174 (not (minibuffer-window-active-p (minibuffer-window))))
4175 anything-samewindow)
4176 (anything :sources 'anything-c-source-find-files
4177 :input fname
4178 :preselect preselect
4179 :keymap anything-find-files-map
4180 :prompt "Find Files or Url: "
4181 :buffer "*Anything Find Files*")))
4184 (defun anything-find-files-initial-input (&optional input)
4185 "Return INPUT if present, otherwise try to guess it."
4186 (or (and input (expand-file-name input))
4187 (anything-find-files-input
4188 (ffap-guesser)
4189 (thing-at-point 'filename))))
4191 (defun anything-find-files-input (fap tap)
4192 "Default input of `anything-find-files'."
4193 (let* ((def-dir (anything-c-current-directory))
4194 (lib (anything-find-library-at-point))
4195 (url (anything-ff-find-url-at-point))
4196 (file-p (and fap (not (string= fap ""))
4197 (file-exists-p fap)
4198 tap (not (string= tap ""))
4199 (file-exists-p
4200 (file-name-directory (expand-file-name tap def-dir))))))
4201 (cond (lib) ; e.g we are inside a require sexp.
4202 (url) ; String at point is an hyperlink.
4203 (file-p (expand-file-name tap def-dir))
4204 (t (and (not (string= fap "")) fap)))))
4206 (defun anything-c-current-directory ()
4207 "Return current-directory name at point.
4208 Useful in dired buffers when there is inserted subdirs."
4209 (if (eq major-mode 'dired-mode)
4210 (dired-current-directory)
4211 default-directory))
4213 (defun anything-ff-find-url-at-point ()
4214 "Try to find link to an url in text-property at point."
4215 (let* ((he (get-text-property (point) 'help-echo))
4216 (ov (overlays-at (point)))
4217 (ov-he (and ov (overlay-get
4218 (car (overlays-at (point))) 'help-echo)))
4219 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4220 (nt-prop (get-text-property (point) 'nt-link)))
4221 ;; Org link.
4222 (when (and (stringp he) (string-match "^LINK: " he))
4223 (setq he (replace-match "" t t he)))
4224 (loop for i in (list he ov-he w3m-l nt-prop)
4225 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4227 (defun anything-find-library-at-point ()
4228 "Try to find library path at point.
4229 Find inside `require' and `declare-function' sexp."
4230 (require 'find-func)
4231 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4232 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4233 (sexp (and beg-sexp end-sexp
4234 (buffer-substring-no-properties
4235 (1+ beg-sexp) (1- end-sexp)))))
4236 (ignore-errors
4237 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4238 (find-library-name
4239 (replace-regexp-in-string
4240 "'\\|\)\\|\(" ""
4241 ;; If require use third arg, ignore it,
4242 ;; always use library path found in `load-path'.
4243 (second (split-string (match-string 0 sexp))))))
4244 ((and sexp (string-match-p "^declare-function" sexp))
4245 (find-library-name
4246 (replace-regexp-in-string
4247 "\"\\|ext:" ""
4248 (third (split-string sexp)))))
4249 (t nil)))))
4251 ;;; Anything completion for `write-file'.==> C-x C-w
4252 (defvar anything-c-source-write-file
4253 `((name . "Write File")
4254 (header-name . (lambda (name)
4255 (concat name anything-c-find-files-doc-header)))
4256 ;; It is needed for filenames with capital letters
4257 (disable-shortcuts)
4258 (candidates . anything-find-files-get-candidates)
4259 (filtered-candidate-transformer anything-c-find-files-transformer)
4260 (persistent-action . anything-find-files-persistent-action)
4261 (persistent-help . "Expand Candidate")
4262 (volatile)
4263 (action .
4264 (("Write File" . (lambda (candidate)
4265 (write-file candidate 'confirm)))))))
4267 ;;; Anything completion for `insert-file'.==> C-x i
4268 (defvar anything-c-source-insert-file
4269 `((name . "Insert 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 (("Insert File" . (lambda (candidate)
4281 (when (y-or-n-p (format "Really insert %s in %s "
4282 candidate anything-current-buffer))
4283 (insert-file-contents candidate))))))))
4285 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4286 (defvar anything-c-source-copy-files
4287 `((name . "Copy Files")
4288 (header-name . (lambda (name)
4289 (concat name anything-c-find-files-doc-header)))
4290 ;; It is needed for filenames with capital letters
4291 (disable-shortcuts)
4292 (candidates . anything-find-files-get-candidates)
4293 (filtered-candidate-transformer anything-c-find-files-transformer)
4294 (persistent-action . anything-find-files-persistent-action)
4295 (persistent-help . "Expand Candidate")
4296 (volatile)
4297 (action .
4298 (("Copy File"
4299 . (lambda (candidate)
4300 (anything-dired-action candidate :action 'copy)))
4301 ("Copy and Follow"
4302 . (lambda (candidate)
4303 (anything-dired-action candidate :action 'copy :follow t)))))))
4306 (defvar anything-c-source-rename-files
4307 `((name . "Rename Files")
4308 (header-name . (lambda (name)
4309 (concat name anything-c-find-files-doc-header)))
4310 ;; It is needed for filenames with capital letters
4311 (disable-shortcuts)
4312 (candidates . anything-find-files-get-candidates)
4313 (filtered-candidate-transformer anything-c-find-files-transformer)
4314 (persistent-action . anything-find-files-persistent-action)
4315 (persistent-help . "Expand Candidate")
4316 (volatile)
4317 (action .
4318 (("Rename File"
4319 . (lambda (candidate)
4320 (anything-dired-action candidate :action 'rename)))
4321 ("Rename and Follow"
4322 . (lambda (candidate)
4323 (anything-dired-action candidate :action 'rename :follow t)))))))
4325 (defvar anything-c-source-symlink-files
4326 `((name . "Symlink Files")
4327 (header-name . (lambda (name)
4328 (concat name anything-c-find-files-doc-header)))
4329 ;; It is needed for filenames with capital letters
4330 (disable-shortcuts)
4331 (candidates . anything-find-files-get-candidates)
4332 (filtered-candidate-transformer anything-c-find-files-transformer)
4333 (persistent-action . anything-find-files-persistent-action)
4334 (persistent-help . "Expand Candidate")
4335 (volatile)
4336 (action
4337 . (("Symlink File"
4338 . (lambda (candidate)
4339 (anything-dired-action candidate :action 'symlink)))
4340 ("RelSymlink File"
4341 . (lambda (candidate)
4342 (anything-dired-action candidate :action 'relsymlink)))))))
4345 (defvar anything-c-source-hardlink-files
4346 `((name . "Hardlink Files")
4347 (header-name . (lambda (name)
4348 (concat name anything-c-find-files-doc-header)))
4349 ;; It is needed for filenames with capital letters
4350 (disable-shortcuts)
4351 (candidates . anything-find-files-get-candidates)
4352 (filtered-candidate-transformer anything-c-find-files-transformer)
4353 (persistent-action . anything-find-files-persistent-action)
4354 (persistent-help . "Expand Candidate")
4355 (volatile)
4356 (action
4357 . (("Hardlink File"
4358 . (lambda (candidate)
4359 (anything-dired-action candidate :action 'hardlink)))))))
4361 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4362 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4363 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4364 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4365 (let ((fn (case action
4366 ('copy 'dired-copy-file)
4367 ('rename 'dired-rename-file)
4368 ('symlink 'make-symbolic-link)
4369 ('relsymlink 'dired-make-relative-symlink)
4370 ('hardlink 'dired-hardlink)))
4371 (marker (case action
4372 ((copy rename) dired-keep-marker-copy)
4373 ('symlink dired-keep-marker-symlink)
4374 ('relsymlink dired-keep-marker-relsymlink)
4375 ('hardlink dired-keep-marker-hardlink)))
4376 (dirflag (and (= (length files) 1)
4377 (file-directory-p (car files))
4378 (not (file-directory-p candidate)))))
4379 (dired-create-files
4380 fn (symbol-name action) files
4381 ;; CANDIDATE is the destination.
4382 (if (file-directory-p candidate)
4383 ;; When CANDIDATE is a directory, build file-name in this directory.
4384 ;; Else we use CANDIDATE.
4385 #'(lambda (from)
4386 (expand-file-name (file-name-nondirectory from) candidate))
4387 #'(lambda (from) candidate))
4388 marker)
4389 (when (and follow (not (get-buffer dired-log-buffer)))
4390 (let ((target (directory-file-name candidate)))
4391 (unwind-protect
4392 (progn
4393 (setq anything-ff-cand-to-mark
4394 (anything-get-dest-fnames-from-list files candidate dirflag))
4395 (if (and dirflag (eq action 'rename))
4396 (anything-find-files-1 (file-name-directory target)
4397 (if anything-ff-transformer-show-only-basename
4398 (anything-c-basename target) target))
4399 (anything-find-files-1 (expand-file-name candidate))))
4400 (setq anything-ff-cand-to-mark nil))))))
4403 (defun anything-c-basename (fname)
4404 "Resolve basename of file or directory named FNAME."
4405 (file-name-nondirectory (directory-file-name fname)))
4407 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4408 "Transform filenames of FLIST to abs of DEST-CAND.
4409 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4410 members of FLIST."
4411 ;; At this point files have been renamed/copied at destination.
4412 ;; That's mean DEST-CAND exists.
4413 (loop
4414 with dest = (expand-file-name dest-cand)
4415 for src in flist
4416 for basename-src = (anything-c-basename src)
4417 for fname = (cond (rename-dir-flag (directory-file-name dest))
4418 ((file-directory-p dest)
4419 (concat (file-name-as-directory dest) basename-src))
4420 (t dest))
4421 when (file-exists-p fname)
4422 collect fname into tmp-list
4423 finally return (sort tmp-list 'string<)))
4425 (defun anything-ff-maybe-mark-candidates ()
4426 "Mark all candidates of list `anything-ff-cand-to-mark'."
4427 (when (and (string= (assoc-default 'name (anything-get-current-source))
4428 (assoc-default 'name anything-c-source-find-files))
4429 anything-ff-cand-to-mark)
4430 (with-anything-window
4431 (while anything-ff-cand-to-mark
4432 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4433 (progn
4434 (anything-make-visible-mark)
4435 (anything-next-line)
4436 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4437 (anything-next-line)))
4438 (unless (anything-this-visible-mark)
4439 (anything-prev-visible-mark)))))
4441 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4443 (defun* anything-dired-do-action-on-file (&key action)
4444 (let* ((files (dired-get-marked-files))
4445 (len (length files))
4446 (fname (if (> len 1)
4447 (format "* %d Files" len)
4448 (car files)))
4449 (source (case action
4450 ('copy 'anything-c-source-copy-files)
4451 ('rename 'anything-c-source-rename-files)
4452 ('symlink 'anything-c-source-symlink-files)
4453 ('hardlink 'anything-c-source-hardlink-files)))
4454 (prompt-fm (case action
4455 ('copy "Copy %s to: ")
4456 ('rename "Rename %s to: ")
4457 ('symlink "Symlink %s to: ")
4458 ('hardlink "Hardlink %s to: ")))
4459 (buffer (case action
4460 ('copy "*Anything Copy Files*")
4461 ('rename "*Anything Rename Files*")
4462 ('symlink "*Anything Symlink Files*")
4463 ('hardlink "*Anything Hardlink Files*")))
4464 (anything-mp-highlight-delay nil))
4465 (anything :sources source
4466 :input (or (dired-dwim-target-directory)
4467 (expand-file-name (anything-c-current-directory)))
4468 :preselect (dired-get-filename)
4469 :prompt (format prompt-fm fname)
4470 :keymap anything-c-read-file-map
4471 :buffer buffer)))
4473 ;;;###autoload
4474 (define-minor-mode anything-dired-mode ()
4475 "Enable anything completion in Dired functions.
4476 Bindings affected are C, R, S, H.
4477 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4478 :group 'anything-config
4479 :global t
4480 (if anything-dired-mode
4481 (progn
4482 (substitute-key-definition
4483 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4484 (substitute-key-definition
4485 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4486 (substitute-key-definition
4487 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4488 (substitute-key-definition
4489 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4490 (substitute-key-definition
4491 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4492 (substitute-key-definition
4493 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4494 (substitute-key-definition
4495 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4496 (substitute-key-definition
4497 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4499 (defalias 'anything-dired-bindings 'anything-dired-mode)
4501 (defun* anything-c-read-file-name (prompt
4502 &key
4503 (name "Read File Name")
4504 (initial-input (expand-file-name default-directory))
4505 (buffer "*Anything Completions*")
4506 test
4507 (preselect nil)
4508 (history nil)
4509 (marked-candidates nil)
4510 (alistp t)
4511 (persistent-action 'anything-find-files-persistent-action)
4512 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4513 "Anything `read-file-name' emulation.
4514 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4515 (when (get-buffer anything-action-buffer)
4516 (kill-buffer anything-action-buffer))
4517 (let ((anything-mp-highlight-delay nil)
4518 ;; Be sure we don't erase the underlying minibuffer if some.
4519 (anything-ff-auto-update-initial-value
4520 (not (minibuffer-window-active-p (minibuffer-window))))
4521 anything-same-window)
4522 (flet ((action-fn (candidate)
4523 (if marked-candidates
4524 (anything-marked-candidates)
4525 (identity candidate))))
4526 (or (anything
4527 :sources
4528 `(((name . ,(format "%s History" name))
4529 (header-name . (lambda (name)
4530 (concat name anything-c-find-files-doc-header)))
4531 (disable-shortcuts)
4532 (mode-line . anything-read-file-name-mode-line-string)
4533 (candidates . (lambda ()
4534 (anything-comp-read-get-candidates history nil nil alistp)))
4535 (persistent-action . ,persistent-action)
4536 (persistent-help . ,persistent-help)
4537 (action . ,'action-fn))
4538 ((name . ,name)
4539 (header-name . (lambda (name)
4540 (concat name anything-c-find-files-doc-header)))
4541 ;; It is needed for filenames with capital letters
4542 (disable-shortcuts)
4543 (mode-line . anything-read-file-name-mode-line-string)
4544 (candidates . (lambda ()
4545 (let ((seq (anything-find-files-get-candidates)))
4546 (if test
4547 (loop for fname in seq
4548 when (funcall test fname) collect fname)
4549 seq))))
4550 (filtered-candidate-transformer anything-c-find-files-transformer)
4551 (persistent-action . ,persistent-action)
4552 (candidate-number-limit . 9999)
4553 (toggle-auto-update . anything-ff-toggle-auto-update)
4554 (persistent-help . ,persistent-help)
4555 (volatile)
4556 (action . ,'action-fn)))
4557 :input initial-input
4558 :prompt prompt
4559 :keymap anything-c-read-file-map
4560 :resume 'noresume
4561 :buffer buffer
4562 :preselect preselect)
4563 (keyboard-quit)))))
4566 ;;; File Cache
4567 (defvar anything-c-file-cache-initialized-p nil)
4569 (defvar anything-c-file-cache-files nil)
4571 (defvar anything-c-source-file-cache
4572 '((name . "File Cache")
4573 (init
4574 . (lambda ()
4575 (require 'filecache nil t)
4576 (unless anything-c-file-cache-initialized-p
4577 (setq anything-c-file-cache-files
4578 (loop for item in file-cache-alist append
4579 (destructuring-bind (base &rest dirs) item
4580 (loop for dir in dirs collect
4581 (concat dir base)))))
4582 (defadvice file-cache-add-file (after file-cache-list activate)
4583 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4584 (setq anything-c-file-cache-initialized-p t))))
4585 (candidates . anything-c-file-cache-files)
4586 (match anything-c-match-on-basename)
4587 (type . file)))
4588 ;; (anything 'anything-c-source-file-cache)
4591 ;;; Locate
4594 ;; NOTE for WINDOZE users:
4595 ;; You have to install Everything with his command line interface here:
4596 ;; http://www.voidtools.com/download.php
4598 (defun anything-locate-1 (&optional localdb init)
4599 "Generic function to run Locate.
4600 if LOCALDB is non--nil search and use a local locate db file.
4601 INIT is a string to use as initial input in prompt.
4602 See `anything-locate-with-db' and `anything-locate'."
4603 (anything-locate-with-db
4604 (and localdb
4605 (anything-c-read-file-name
4606 "LocateDBFiles: "
4607 :marked-candidates t
4608 :preselect anything-locate-db-file-regexp
4609 :test #'(lambda (x)
4610 (if anything-locate-db-file-regexp
4611 ;; Select only locate db files and directories
4612 ;; to allow navigation.
4613 (or (string-match
4614 anything-locate-db-file-regexp x)
4615 (file-directory-p x))
4616 x))))
4617 init))
4618 ;; (anything-locate-1 t)
4620 (defun anything-locate-with-db (&optional db initial-input)
4621 "Run locate -d DB.
4622 If DB is not given or nil use locate without -d option.
4623 Argument DB can be given as a string or list of db files.
4624 Argument INITIAL-INPUT is a string to use as initial-input.
4625 See also `anything-locate'."
4626 (when (and db (stringp db)) (setq db (list db)))
4627 (let ((anything-c-locate-command
4628 (if db
4629 (replace-regexp-in-string
4630 "locate"
4631 (format "locate -d %s"
4632 (mapconcat 'identity
4633 ;; Remove eventually
4634 ;; marked directories by error.
4635 (loop for i in db
4636 unless (file-directory-p i)
4637 collect i) ":"))
4638 anything-c-locate-command)
4639 anything-c-locate-command)))
4640 (anything :sources 'anything-c-source-locate
4641 :buffer "*anything locate*"
4642 :input initial-input
4643 :keymap anything-generic-files-map)))
4644 ;; (anything-locate-with-db "~/locate.db")
4646 (defun anything-c-locate-init ()
4647 "Initialize async locate process for `anything-c-source-locate'."
4648 (setq mode-line-format
4649 '(" " mode-line-buffer-identification " "
4650 (line-number-mode "%l") " "
4651 (:eval (propertize "(Locate Process Running) "
4652 'face '((:foreground "red"))))))
4653 (prog1
4654 (start-process-shell-command "locate-process" nil
4655 (format anything-c-locate-command
4656 anything-pattern))
4657 (set-process-sentinel (get-process "locate-process")
4658 #'(lambda (process event)
4659 (when (string= event "finished\n")
4660 (with-anything-window
4661 (force-mode-line-update nil)
4662 (anything-update-move-first-line)))))))
4664 (defvar anything-c-source-locate
4665 '((name . "Locate")
4666 (candidates . anything-c-locate-init)
4667 (type . file)
4668 (properties-action . anything-ff-properties)
4669 (requires-pattern . 3)
4670 (candidate-number-limit . 9999)
4671 (mode-line . anything-generic-file-mode-line-string)
4672 (delayed))
4673 "Find files matching the current input pattern with locate.")
4674 ;; (anything 'anything-c-source-locate)
4676 (defun anything-c-locate-read-file-name (prompt &optional init)
4677 "Search a file with locate and return it's filename.
4678 Use argument PROMPT and INIT for `anything' arguments
4679 prompt and input."
4680 (anything :sources
4681 '((name . "Locate")
4682 (candidates . anything-c-locate-init)
4683 (action . identity)
4684 (properties-action . anything-ff-properties)
4685 (requires-pattern . 3)
4686 (candidate-number-limit . 9999)
4687 (mode-line . anything-generic-file-mode-line-string)
4688 (delayed))
4689 :prompt prompt
4690 :input init
4691 :buffer "*anything locate rfn*"))
4695 ;;; Anything Incremental Grep.
4698 ;; Allow to grep incrementally with anything interface.
4699 ;; It allow also to Grep files recursively without using 'find' shell command.
4700 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4701 (defvar anything-c-grep-default-command
4702 "grep -d skip %e -niH -e %p %f"
4703 "Default grep format command for `anything-do-grep-1'.
4704 Where:
4705 '%e' format spec is for --exclude or --include grep options.
4706 '%p' format spec is for pattern.
4707 '%f' format spec is for filenames.")
4709 (defvar anything-c-grep-default-recurse-command
4710 "grep -d recurse %e -niH -e %p %f"
4711 "Default recursive grep format command for `anything-do-grep-1'.
4712 See `anything-c-grep-default-command' for format specs.")
4714 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4716 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4718 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4720 (defvar anything-c-grep-debug-command-line nil
4721 "Turn on anything grep command-line debugging when non--nil.")
4723 (defvar anything-c-zgrep-recurse-flag nil)
4725 (defvar anything-c-grep-history nil)
4727 (defvar anything-c-grep-max-length-history 100
4728 "*Max number of elements to save in `anything-c-grep-history'.")
4730 (defun anything-c-grep-prepare-candidates (candidates)
4731 "Prepare filenames and directories CANDIDATES for grep command line."
4732 ;; If one or more candidate is a directory, search in all files
4733 ;; of this candidate (e.g /home/user/directory/*).
4734 ;; If r option is enabled search also in subdidrectories.
4735 ;; We need here to expand wildcards to support crap windows filenames
4736 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4737 (if anything-c-zgrep-recurse-flag
4738 (mapconcat 'shell-quote-argument candidates " ")
4739 (loop for i in candidates append
4740 (cond ( ;; Candidate is a directory and we use recursion.
4741 (and (file-directory-p i)
4742 (anything-c-grep-recurse-p))
4743 (list (expand-file-name i)))
4744 ;; Candidate is a directory, search in all files.
4745 ((file-directory-p i)
4746 (file-expand-wildcards
4747 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4748 ;; Candidate is a file or wildcard and we use recursion, use the
4749 ;; current directory instead of candidate.
4750 ((and (or (file-exists-p i) (string-match "\*" i))
4751 (anything-c-grep-recurse-p))
4752 (list (expand-file-name
4753 (directory-file-name ; Needed for windoze.
4754 (file-name-directory (directory-file-name i))))))
4755 ;; Candidate use wildcard.
4756 ((string-match "^\*" (anything-c-basename i))
4757 (file-expand-wildcards i t))
4758 ;; Else should be one or more file.
4759 (t (list i))) into all-files
4760 finally return
4761 (mapconcat 'shell-quote-argument all-files " "))))
4763 (defun anything-c-grep-recurse-p ()
4764 "Check if `anything-do-grep-1' have switched to recursive."
4765 (let ((args (replace-regexp-in-string
4766 "grep" "" anything-c-grep-default-command)))
4767 (string-match-p "r\\|recurse" args)))
4769 (defun anything-c-grep-init (only-files &optional include zgrep)
4770 "Start an asynchronous grep process in ONLY-FILES list."
4771 (let* ((fnargs (anything-c-grep-prepare-candidates
4772 (if (file-remote-p anything-ff-default-directory)
4773 (mapcar #'(lambda (x)
4774 (file-remote-p x 'localname))
4775 only-files)
4776 only-files)))
4777 (ignored-files (mapconcat
4778 #'(lambda (x)
4779 (concat "--exclude=" (shell-quote-argument x)))
4780 grep-find-ignored-files " "))
4781 (ignored-dirs (mapconcat
4782 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4783 #'(lambda (x)
4784 (concat "--exclude-dir=" (shell-quote-argument x)))
4785 grep-find-ignored-directories " "))
4786 (exclude (if (anything-c-grep-recurse-p)
4787 (concat (or include ignored-files) " " ignored-dirs)
4788 ignored-files))
4789 (cmd-line (format-spec
4790 anything-c-grep-default-command
4791 (delq nil
4792 (list (unless zgrep (cons ?e exclude))
4793 (cons ?p (shell-quote-argument anything-pattern))
4794 (cons ?f fnargs))))))
4795 (when anything-c-grep-debug-command-line
4796 (with-current-buffer (get-buffer-create "*any grep debug*")
4797 (goto-char (point-max))
4798 (insert (concat ">>> " cmd-line "\n\n"))))
4799 (setq mode-line-format
4800 '(" " mode-line-buffer-identification " "
4801 (line-number-mode "%l") " "
4802 (:eval (when (get-process "grep-process")
4803 (propertize "[Grep Process Running] "
4804 'face 'anything-grep-running)))))
4805 (force-mode-line-update nil)
4806 (prog1
4807 (let ((default-directory anything-ff-default-directory))
4808 (start-file-process-shell-command "grep-process" nil cmd-line))
4809 (message nil)
4810 (set-process-sentinel
4811 (get-process "grep-process")
4812 #'(lambda (process event)
4813 (when (string= event "finished\n")
4814 (with-anything-window
4815 (anything-update-move-first-line)
4816 (setq mode-line-format
4817 '(" " mode-line-buffer-identification " "
4818 (line-number-mode "%l") " "
4819 (:eval (propertize
4820 (format "[Grep Process Finished - (%s results)] "
4821 (let ((nlines (1- (count-lines
4822 (point-min)
4823 (point-max)))))
4824 (if (> nlines 0) nlines 0)))
4825 'face 'anything-grep-finish))))
4826 (force-mode-line-update nil))))))))
4828 (defun anything-c-grep-action (candidate &optional where mark)
4829 "Define a default action for `anything-do-grep' on CANDIDATE.
4830 WHERE can be one of other-window, elscreen, other-frame."
4831 (let* ((split (anything-c-grep-split-line candidate))
4832 (lineno (string-to-number (nth 1 split)))
4833 (loc-fname (car split))
4834 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4835 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4836 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4837 (fname (if tramp-host
4838 (concat tramp-prefix loc-fname) loc-fname)))
4839 (case where
4840 (other-window (find-file-other-window fname))
4841 (elscreen (anything-elscreen-find-file fname))
4842 (other-frame (find-file-other-frame fname))
4843 (t (find-file fname)))
4844 (anything-goto-line lineno)
4845 (when mark
4846 (set-marker (mark-marker) (point))
4847 (push-mark (point) 'nomsg))
4848 ;; Save history
4849 (unless (or anything-in-persistent-action
4850 (string= anything-pattern ""))
4851 (setq anything-c-grep-history
4852 (cons anything-pattern
4853 (delete anything-pattern anything-c-grep-history)))
4854 (when (> (length anything-c-grep-history)
4855 anything-c-grep-max-length-history)
4856 (setq anything-c-grep-history
4857 (delete (car (last anything-c-grep-history))
4858 anything-c-grep-history))))))
4860 (defun anything-c-grep-other-window (candidate)
4861 "Jump to result in other window from anything grep."
4862 (anything-c-grep-action candidate 'other-window))
4864 (defun anything-c-grep-other-frame (candidate)
4865 "Jump to result in other frame from anything grep."
4866 (anything-c-grep-action candidate 'other-frame))
4868 (defun anything-c-grep-jump-elscreen (candidate)
4869 "Jump to result in elscreen from anything grep."
4870 (anything-c-grep-action candidate 'elscreen))
4872 (defun anything-c-grep-save-results (candidate)
4873 "Save anything grep result in a `grep-mode' buffer."
4874 (let ((buf "*grep*")
4875 new-buf)
4876 (when (get-buffer buf)
4877 (setq new-buf (read-string "GrepBufferName: " buf))
4878 (loop for b in (anything-c-buffer-list)
4879 when (and (string= new-buf b)
4880 (not (y-or-n-p
4881 (format "Buffer `%s' already exists overwrite? "
4882 new-buf))))
4883 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4884 (setq buf new-buf))
4885 (with-current-buffer (get-buffer-create buf)
4886 (let ((inhibit-read-only t))
4887 (erase-buffer)
4888 (insert "-*- mode: grep -*-\n\n"
4889 (format "Grep Results for `%s':\n\n" anything-pattern))
4890 (save-excursion
4891 (insert (with-current-buffer anything-buffer
4892 (forward-line 1)
4893 (buffer-substring (point) (point-max))))
4894 (grep-mode))))
4895 (message "Anything Grep Results saved in `%s' buffer" buf)))
4897 (defun anything-c-grep-persistent-action (candidate)
4898 "Persistent action for `anything-do-grep'.
4899 With a prefix arg record CANDIDATE in `mark-ring'."
4900 (if current-prefix-arg
4901 (anything-c-grep-action candidate nil 'mark)
4902 (anything-c-grep-action candidate))
4903 (anything-match-line-color-current-line))
4905 (defun anything-c-grep-guess-extensions (files)
4906 "Try to guess file extensions in FILES list when using grep recurse.
4907 These extensions will be added to command line with --include arg of grep."
4908 (loop
4909 with glob-list = nil
4910 with lst = (if (file-directory-p (car files))
4911 (directory-files
4912 (car files) nil
4913 directory-files-no-dot-files-regexp)
4914 files)
4915 for i in lst
4916 for ext = (file-name-extension i t)
4917 for glob = (and ext (not (string= ext ""))
4918 (concat "*" ext))
4919 unless (or (not glob)
4920 (member glob glob-list)
4921 (member glob grep-find-ignored-files))
4922 collect glob into glob-list
4923 finally return glob-list))
4925 (defun anything-do-grep-1 (only &optional recurse zgrep)
4926 "Launch grep with a list of ONLY files.
4927 When RECURSE is given use -r option of grep and prompt user
4928 to set the --include args of grep.
4929 You can give more than one arg separated by space.
4930 e.g *.el *.py *.tex.
4931 If it's empty --exclude `grep-find-ignored-files' is used instead."
4932 (let* ((anything-compile-source-functions
4933 ;; rule out anything-match-plugin because the input is one regexp.
4934 (delq 'anything-compile-source--match-plugin
4935 (copy-sequence anything-compile-source-functions)))
4936 (exts (anything-c-grep-guess-extensions only))
4937 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4938 (include-files (and recurse (not zgrep)
4939 (read-string "OnlyExt(*.[ext]): "
4940 globs)))
4941 ;; Set `minibuffer-history' AFTER includes-files
4942 ;; to avoid storing wild-cards here.
4943 (minibuffer-history anything-c-grep-history)
4944 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4945 (recurse anything-c-grep-default-recurse-command)
4946 (zgrep anything-c-default-zgrep-command)
4947 (t anything-c-grep-default-command)))
4948 ;; Disable match-plugin and use here own highlighting.
4949 (anything-mp-highlight-delay nil))
4950 (when include-files
4951 (setq include-files
4952 (and (not (string= include-files ""))
4953 (mapconcat #'(lambda (x)
4954 (concat "--include=" (shell-quote-argument x)))
4955 (split-string include-files) " "))))
4956 ;; When called as action from an other source e.g *-find-files
4957 ;; we have to kill action buffer.
4958 (when (get-buffer anything-action-buffer)
4959 (kill-buffer anything-action-buffer))
4960 ;; `anything-find-files' haven't already started,
4961 ;; give a default value to `anything-ff-default-directory'.
4962 (setq anything-ff-default-directory (or anything-ff-default-directory
4963 default-directory))
4964 (anything
4965 :sources
4966 `(((name . "Grep (C-c ? Help)")
4967 (candidates
4968 . (lambda ()
4969 (funcall anything-c-grep-default-function only include-files zgrep)))
4970 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4971 (candidate-number-limit . 9999)
4972 (mode-line . anything-grep-mode-line-string)
4973 (jump-persistent . anything-c-grep-persistent-action)
4974 (action . ,(delq
4976 `(("Find File" . anything-c-grep-action)
4977 ("Find file other frame" . anything-c-grep-other-frame)
4978 ,(and (locate-library "elscreen")
4979 '("Find file in Elscreen"
4980 . anything-c-grep-jump-elscreen))
4981 ("Save results in grep buffer" . anything-c-grep-save-results)
4982 ("Find file other window" . anything-c-grep-other-window))))
4983 (persistent-action . anything-c-grep-persistent-action)
4984 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4985 (requires-pattern . 3)
4986 (delayed)))
4987 :keymap anything-c-grep-map
4988 :buffer "*anything grep*")))
4990 (defun anything-ff-zgrep-1 (flist recursive)
4991 (unwind-protect
4992 (let* ((def-dir (or anything-ff-default-directory
4993 default-directory))
4994 (only (if recursive
4995 (or (gethash def-dir anything-c-rzgrep-cache)
4996 (puthash
4997 def-dir
4998 (anything-c-walk-directory
4999 def-dir
5000 :directories nil
5001 :path 'full
5002 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5003 anything-c-rzgrep-cache))
5004 flist)))
5005 (when recursive (setq anything-c-zgrep-recurse-flag t))
5006 (anything-do-grep-1 only recursive 'zgrep))
5007 (setq anything-c-zgrep-recurse-flag nil)))
5009 (defun anything-c-grep-split-line (line)
5010 "Split a grep output line."
5011 (let (beg fname lineno str)
5012 ;; Don't print until grep line is valid.
5013 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5014 (with-temp-buffer
5015 (insert line)
5016 (goto-char (point-min))
5017 (setq beg (point))
5018 (forward-char 2)
5019 (re-search-forward ":" nil t)
5020 (setq fname (buffer-substring-no-properties beg (1- (point))))
5021 (setq beg (point))
5022 (re-search-forward ":" nil t)
5023 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5024 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5025 (list fname lineno str))))
5027 (defun anything-c-grep-cand-transformer (candidates sources)
5028 "Filtered candidate transformer function for `anything-do-grep'."
5029 (loop for i in candidates
5030 for split = (and i (anything-c-grep-split-line i))
5031 for fname = (car split)
5032 for lineno = (nth 1 split)
5033 for str = (nth 2 split)
5034 when (and fname lineno str)
5035 collect
5036 (cons (concat (propertize (file-name-nondirectory fname)
5037 'face 'anything-grep-file
5038 'help-echo fname) ":"
5039 (propertize lineno 'face 'anything-grep-lineno) ":"
5040 (anything-c-grep-highlight-match str))
5041 i)))
5043 (defun anything-c-grep-highlight-match (str)
5044 "Highlight in string STR all occurences matching `anything-pattern'."
5045 (condition-case nil
5046 (with-temp-buffer
5047 (insert str)
5048 (goto-char (point-min))
5049 (while (and (re-search-forward anything-pattern nil t)
5050 (> (- (match-end 0) (match-beginning 0)) 0))
5051 (add-text-properties
5052 (match-beginning 0) (match-end 0)
5053 '(face anything-grep-match)))
5054 (buffer-string))
5055 (error nil)))
5057 ;; Go to next or precedent file (common to etags and grep).
5058 (defun anything-c-goto-next-or-prec-file (n)
5059 "Go to next or precedent candidate file in anything grep/etags buffers.
5060 If N is positive go forward otherwise go backward."
5061 (with-anything-window
5062 (let* ((current-line-list (split-string
5063 (buffer-substring
5064 (point-at-bol)
5065 (point-at-eol)) ":"))
5066 (current-fname (nth 0 current-line-list))
5067 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5068 (catch 'break
5069 (while (not (funcall fn-b-o-f))
5070 (forward-line n) ; Go forward or backward depending of n value.
5071 (unless (search-forward current-fname (point-at-eol) t)
5072 (anything-mark-current-line)
5073 (throw 'break nil))))
5074 (cond ((and (eq n 1) (eobp))
5075 (re-search-backward ".")
5076 (forward-line 0)
5077 (anything-mark-current-line))
5078 ((and (< n 1) (bobp))
5079 (forward-line 1)
5080 (anything-mark-current-line))))))
5082 ;;;###autoload
5083 (defun anything-c-goto-precedent-file ()
5084 "Go to precedent file in anything grep/etags buffers."
5085 (interactive)
5086 (anything-c-goto-next-or-prec-file -1))
5088 ;;;###autoload
5089 (defun anything-c-goto-next-file ()
5090 "Go to precedent file in anything grep/etags buffers."
5091 (interactive)
5092 (anything-c-goto-next-or-prec-file 1))
5094 ;;;###autoload
5095 (defun anything-c-grep-run-persistent-action ()
5096 "Run grep persistent action from `anything-do-grep-1'."
5097 (interactive)
5098 (anything-execute-persistent-action 'jump-persistent))
5100 ;;;###autoload
5101 (defun anything-c-grep-run-default-action ()
5102 "Run grep default action from `anything-do-grep-1'."
5103 (interactive)
5104 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5106 ;;;###autoload
5107 (defun anything-c-grep-run-other-window-action ()
5108 "Run grep goto other window action from `anything-do-grep-1'."
5109 (interactive)
5110 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5112 ;;;###autoload
5113 (defun anything-c-grep-run-save-buffer ()
5114 "Run grep save results action from `anything-do-grep-1'."
5115 (interactive)
5116 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5118 ;; Grep buffers
5119 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5120 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5121 If one of selected buffers is not a file--buffer,
5122 it is ignored and grep will run on all others file--buffers.
5123 If only one candidate is selected and it is not a file--buffer,
5124 switch to this buffer and run `anything-occur'.
5125 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5126 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5127 (cands (if prefarg
5128 (buffer-list)
5129 (anything-marked-candidates)))
5130 (win-conf (current-window-configuration))
5131 ;; Non--fname buffers are ignored.
5132 (bufs (loop for buf in cands
5133 for fname = (buffer-file-name (get-buffer buf))
5134 when fname
5135 collect (expand-file-name fname))))
5136 (if bufs
5137 (if zgrep
5138 (anything-do-grep-1 bufs nil 'zgrep)
5139 (anything-do-grep-1 bufs))
5140 ;; bufs is empty, thats mean we have only CANDIDATE
5141 ;; and it is not a buffer-filename, fallback to occur.
5142 (anything-c-switch-to-buffer candidate)
5143 (when (get-buffer anything-action-buffer)
5144 (kill-buffer anything-action-buffer))
5145 (anything-occur)
5146 (when (eq anything-exit-status 1)
5147 (set-window-configuration win-conf)))))
5149 (defun anything-c-grep-buffers (candidate)
5150 "Action to grep buffers."
5151 (anything-c-grep-buffers-1 candidate))
5153 (defun anything-c-zgrep-buffers (candidate)
5154 "Action to zgrep buffers."
5155 (anything-c-grep-buffers-1 candidate 'zgrep))
5158 ;;; Anything interface for pdfgrep
5159 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5160 ;; and a pdf-reader (e.g xpdf) are needed.
5162 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5163 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5164 (defvar anything-c-pdfgrep-debug-command-line nil)
5166 (defun anything-c-pdfgrep-init (only-files)
5167 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5168 (let* ((fnargs (anything-c-grep-prepare-candidates
5169 (if (file-remote-p anything-ff-default-directory)
5170 (mapcar #'(lambda (x)
5171 (file-remote-p x 'localname))
5172 only-files)
5173 only-files)))
5174 (cmd-line (format anything-c-pdfgrep-default-command
5175 anything-pattern
5176 fnargs)))
5177 (when anything-c-pdfgrep-debug-command-line
5178 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5179 (goto-char (point-max))
5180 (insert (concat ">>> " cmd-line "\n\n"))))
5181 (setq mode-line-format
5182 '(" " mode-line-buffer-identification " "
5183 (line-number-mode "%l") " "
5184 (:eval (propertize "(Pdfgrep Process Running) "
5185 'face '((:foreground "red"))))))
5186 (prog1
5187 (let ((default-directory anything-ff-default-directory))
5188 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5189 (message nil)
5190 (set-process-sentinel
5191 (get-process "pdfgrep-process")
5192 #'(lambda (process event)
5193 (when (string= event "finished\n")
5194 (with-anything-window
5195 (anything-update-move-first-line))
5196 (force-mode-line-update nil)))))))
5199 (defun anything-do-pdfgrep-1 (only)
5200 "Launch pdfgrep with a list of ONLY files."
5201 (unless (executable-find "pdfgrep")
5202 (error "Error: No such program `pdfgrep'."))
5203 (let* ((anything-compile-source-functions
5204 ;; rule out anything-match-plugin because the input is one regexp.
5205 (delq 'anything-compile-source--match-plugin
5206 (copy-sequence anything-compile-source-functions)))
5207 ;; Disable match-plugin and use here own highlighting.
5208 (anything-mp-highlight-delay nil))
5209 ;; When called as action from an other source e.g *-find-files
5210 ;; we have to kill action buffer.
5211 (when (get-buffer anything-action-buffer)
5212 (kill-buffer anything-action-buffer))
5213 ;; If `anything-find-files' haven't already started,
5214 ;; give a default value to `anything-ff-default-directory'.
5215 (setq anything-ff-default-directory (or anything-ff-default-directory
5216 default-directory))
5217 (anything
5218 :sources
5219 `(((name . "PdfGrep")
5220 (candidates
5221 . (lambda ()
5222 (funcall anything-c-pdfgrep-default-function only)))
5223 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5224 (candidate-number-limit . 9999)
5225 (mode-line . anything-pdfgrep-mode-line-string)
5226 (action . anything-c-pdfgrep-action)
5227 (persistent-help . "Jump to PDF Page")
5228 (requires-pattern . 3)
5229 (delayed)))
5230 :keymap anything-c-pdfgrep-map
5231 :buffer "*anything grep*")))
5234 (defun anything-c-pdfgrep-action (candidate)
5235 (let* ((split (anything-c-grep-split-line candidate))
5236 (pageno (nth 1 split))
5237 (fname (car split)))
5238 (start-file-process-shell-command
5239 "pdf-reader" nil
5240 (format-spec anything-c-pdfgrep-default-read-command
5241 (list (cons ?f fname) (cons ?p pageno))))))
5243 (defun anything-do-pdfgrep ()
5244 (interactive)
5245 (let ((only (anything-c-read-file-name
5246 "Search in file(s): "
5247 :marked-candidates t
5248 :test #'(lambda (file)
5249 (or (string= (file-name-extension file) "pdf")
5250 (string= (file-name-extension file) "PDF")
5251 (file-directory-p file)))
5252 :preselect (or (dired-get-filename nil t)
5253 (buffer-file-name (current-buffer)))))
5254 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5255 (anything-do-pdfgrep-1 only)))
5258 ;; Yank text at point.
5261 ;; Internal
5262 (defvar anything-yank-point nil)
5264 ;;;###autoload
5265 (defun anything-yank-text-at-point ()
5266 "Yank text at point in minibuffer."
5267 (interactive)
5268 (let (input)
5269 (flet ((insert-in-minibuffer (word)
5270 (with-selected-window (minibuffer-window)
5271 (let ((str anything-pattern))
5272 (delete-minibuffer-contents)
5273 (set-text-properties 0 (length word) nil word)
5274 (insert (concat str word))))))
5275 (with-anything-current-buffer
5276 ;; Start to initial point if C-w have never been hit.
5277 (unless anything-yank-point (setq anything-yank-point (point)))
5278 (and anything-yank-point (goto-char anything-yank-point))
5279 (forward-word 1)
5280 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5281 (setq anything-yank-point (point))) ; End of last forward-word
5282 (insert-in-minibuffer input))))
5284 (defun anything-reset-yank-point ()
5285 (setq anything-yank-point nil))
5287 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5288 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5291 ;;; Recentf files
5294 (defvar anything-c-source-recentf
5295 '((name . "Recentf")
5296 (init . (lambda ()
5297 (require 'recentf)
5298 (or recentf-mode (recentf-mode 1))))
5299 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5300 (candidates . recentf-list)
5301 (match anything-c-match-on-basename)
5302 (type . file))
5303 "See (info \"(emacs)File Conveniences\").
5304 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5305 ;; (anything 'anything-c-source-recentf)
5307 ;;; ffap
5308 (eval-when-compile (require 'ffap))
5309 (defvar anything-c-source-ffap-guesser
5310 '((name . "File at point")
5311 (init . (lambda () (require 'ffap)))
5312 (candidates . (lambda ()
5313 (anything-aif
5314 (with-anything-current-buffer
5315 (ffap-guesser))
5316 (list it))))
5317 (type . file)))
5318 ;; (anything 'anything-c-source-ffap-guesser)
5320 ;;; ffap with line number
5321 (defun anything-c-ffap-file-line-at-point ()
5322 "Get (FILENAME . LINENO) at point."
5323 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5324 (save-excursion
5325 (beginning-of-line)
5326 (when (and (search-forward it nil t)
5327 (looking-at ":\\([0-9]+\\)"))
5328 (cons it (string-to-number (match-string 1)))))))
5330 (defvar anything-c-ffap-line-location nil
5331 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5332 It is cleared after jumping line.")
5334 (defun anything-c-ffap-line-candidates ()
5335 (with-anything-current-buffer
5336 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5337 (when anything-c-ffap-line-location
5338 (destructuring-bind (file . line) anything-c-ffap-line-location
5339 (list (cons (format "%s (line %d)" file line) file)))))
5341 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5342 (defun anything-c-ffap-line-goto-line ()
5343 (when (car anything-c-ffap-line-location)
5344 (unwind-protect
5345 (ignore-errors
5346 (with-selected-window
5347 (get-buffer-window
5348 (get-file-buffer (car anything-c-ffap-line-location)))
5349 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5350 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5351 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5353 (defvar anything-c-source-ffap-line
5354 '((name . "File/Lineno at point")
5355 (init . (lambda () (require 'ffap)))
5356 (candidates . anything-c-ffap-line-candidates)
5357 (type . file)))
5358 ;; (anything 'anything-c-source-ffap-line)
5360 ;;; list of files gleaned from every dired buffer
5361 (defun anything-c-files-in-all-dired-candidates ()
5362 (save-excursion
5363 (mapcan
5364 (lambda (dir)
5365 (cond ((listp dir) ;filelist
5366 dir)
5367 ((equal "" (file-name-nondirectory dir)) ;dir
5368 (directory-files dir t))
5369 (t ;wildcard
5370 (file-expand-wildcards dir t))))
5371 (delq nil
5372 (mapcar (lambda (buf)
5373 (set-buffer buf)
5374 (when (eq major-mode 'dired-mode)
5375 (if (consp dired-directory)
5376 (cdr dired-directory) ;filelist
5377 dired-directory))) ;dir or wildcard
5378 (buffer-list))))))
5379 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5381 (defvar anything-c-source-files-in-all-dired
5382 '((name . "Files in all dired buffer.")
5383 (candidates . anything-c-files-in-all-dired-candidates)
5384 (type . file)))
5385 ;; (anything 'anything-c-source-files-in-all-dired)
5387 (defvar anything-c-source-filelist
5388 '((name . "FileList")
5389 (grep-candidates . anything-c-filelist-file-name)
5390 (candidate-number-limit . 200)
5391 (requires-pattern . 4)
5392 (type . file))
5393 "Source to find files instantly.
5394 See `anything-c-filelist-file-name' docstring for usage.")
5397 ;;;; <info>
5398 ;;; Info pages
5399 (defvar anything-c-info-pages nil
5400 "All info pages on system.
5401 Will be calculated the first time you invoke anything with this
5402 source.")
5404 (defun anything-c-info-pages-init ()
5405 "Collect candidates for initial Info node Top."
5406 (if anything-c-info-pages
5407 anything-c-info-pages
5408 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5409 topics)
5410 (require 'info)
5411 (with-temp-buffer
5412 (Info-find-node "dir" "top")
5413 (goto-char (point-min))
5414 (while (re-search-forward info-topic-regexp nil t)
5415 (push (match-string-no-properties 1) topics))
5416 (kill-buffer))
5417 (setq anything-c-info-pages topics))))
5419 (defvar anything-c-source-info-pages
5420 `((name . "Info Pages")
5421 (init . anything-c-info-pages-init)
5422 (candidates . anything-c-info-pages)
5423 (action . (("Show with Info" .(lambda (node-str)
5424 (info (replace-regexp-in-string
5425 "^[^:]+: " "" node-str))))))
5426 (requires-pattern . 2)))
5427 ;; (anything 'anything-c-source-info-pages)
5430 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5431 (defun anything-c-describe-attributes (anything-attribute)
5432 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5433 Same as `anything-describe-anything-attribute' but with anything completion."
5434 (interactive (list (intern
5435 (anything-comp-read
5436 "Describe anything attribute: "
5437 (mapcar 'symbol-name anything-additional-attributes)
5438 :must-match t
5439 :persistent-action
5440 #'(lambda (candidate)
5441 (with-output-to-temp-buffer "*Help*"
5442 (princ (get (intern candidate) 'anything-attrdoc))))))))
5443 (with-output-to-temp-buffer "*Help*"
5444 (princ (get anything-attribute 'anything-attrdoc))))
5447 ;;; Use info-index plug-in.
5450 ;; Note that `name' attribute is not needed since
5451 ;; `anything-c-insert-summary' have been removed.
5452 ;; Info Elisp
5453 (defvar anything-c-source-info-elisp
5454 '((name . "Info index: elisp")
5455 (info-index . "elisp")))
5456 ;; (anything 'anything-c-source-info-elisp)
5458 ;; Info-Common-Lisp
5459 (defvar anything-c-source-info-cl
5460 '((name . "Info index: cl")
5461 (info-index . "cl")))
5462 ;; (anything 'anything-c-source-info-cl)
5464 ;; Info Index org
5465 (defvar anything-c-source-info-org
5466 '((name . "Info index: org")
5467 (info-index . "org")))
5468 ;; (anything 'anything-c-source-info-org)
5470 ;; Info Index gnus
5471 (defvar anything-c-source-info-gnus
5472 '((name . "Info index: Gnus")
5473 (info-index . "gnus")))
5475 ;; Info Index ratpoison
5476 (defvar anything-c-source-info-ratpoison
5477 '((name . "Info index: ratpoison")
5478 (info-index . "ratpoison")))
5479 ;; (anything 'anything-c-source-info-ratpoison)
5481 ;; Info Index zsh
5482 (defvar anything-c-source-info-zsh
5483 '((name . "Info index: zsh")
5484 (info-index . "zsh")))
5485 ;; (anything 'anything-c-source-info-zsh)
5487 ;; Info Index bash
5488 (defvar anything-c-source-info-bash
5489 '((name . "Info index: bash")
5490 (info-index . "bash")))
5491 ;; (anything 'anything-c-source-info-bash)
5493 ;; Info Index coreutils
5494 (defvar anything-c-source-info-coreutils
5495 '((name . "Info index: coreutils")
5496 (info-index . "coreutils")))
5497 ;; (anything 'anything-c-source-info-coreutils)
5499 ;; Info Index fileutils
5500 (defvar anything-c-source-info-fileutils
5501 '((name . "Info index: fileutils")
5502 (info-index . "fileutils")))
5503 ;; (anything 'anything-c-source-info-fileutils)
5505 ;; Info Index find
5506 (defvar anything-c-source-info-find
5507 '((name . "Info index: find")
5508 (info-index . "find")))
5509 ;; (anything 'anything-c-source-info-find)
5511 ;; Info Index sh-utils
5512 (defvar anything-c-source-info-sh-utils
5513 '((name . "Info index: sh-utils")
5514 (info-index . "sh-utils")))
5515 ;; (anything 'anything-c-source-info-sh-utils)
5517 ;; Info Index textutils
5518 (defvar anything-c-source-info-textutils
5519 '((name . "Info index: textutils")
5520 (info-index . "textutils")))
5521 ;; (anything 'anything-c-source-info-textutils)
5523 ;; Info Index libc
5524 (defvar anything-c-source-info-libc
5525 '((name . "Info index: libc")
5526 (info-index . "libc")))
5527 ;; (anything 'anything-c-source-info-libc)
5529 ;; Info Index make
5530 (defvar anything-c-source-info-make
5531 '((name . "Info index: make")
5532 (info-index . "make")))
5533 ;; (anything 'anything-c-source-info-make)
5535 ;; Info Index automake
5536 (defvar anything-c-source-info-automake
5537 '((name . "Info index: automake")
5538 (info-index . "automake")))
5539 ;; (anything 'anything-c-source-info-automake)
5541 ;; Info Index autoconf
5542 (defvar anything-c-source-info-autoconf
5543 '((name . "Info index: autoconf")
5544 (info-index . "autoconf")))
5545 ;; (anything 'anything-c-source-info-autoconf)
5547 ;; Info Index emacs-lisp-intro
5548 (defvar anything-c-source-info-emacs-lisp-intro
5549 '((name . "Info index: emacs-lisp-intro")
5550 (info-index . "emacs-lisp-intro")))
5551 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5553 ;; Info Index emacs
5554 (defvar anything-c-source-info-emacs
5555 '((name . "Info index: emacs")
5556 (info-index . "emacs")))
5557 ;; (anything 'anything-c-source-info-emacs)
5559 ;; Info Index elib
5560 (defvar anything-c-source-info-elib
5561 '((name . "Info index: elib")
5562 (info-index . "elib")))
5563 ;; (anything 'anything-c-source-info-elib)
5565 ;; Info Index eieio
5566 (defvar anything-c-source-info-eieio
5567 '((name . "Info index: eieio")
5568 (info-index . "eieio")))
5569 ;; (anything 'anything-c-source-info-eieio)
5571 ;; Info Index gauche-refe
5572 (defvar anything-c-source-info-gauche-refe
5573 '((name . "Info index: gauche")
5574 (info-index . "gauche-refe")))
5575 ;; (anything 'anything-c-source-info-gauche-refe)
5577 ;; Info Index guile
5578 (defvar anything-c-source-info-guile
5579 '((name . "Info index: guile")
5580 (info-index . "guile")))
5581 ;; (anything 'anything-c-source-info-guile)
5583 ;; Info Index guile-tut
5584 (defvar anything-c-source-info-guile-tut
5585 '((name . "Info index: guile-tut")
5586 (info-index . "guile-tut")))
5587 ;; (anything 'anything-c-source-info-guile-tut)
5589 ;; Info Index goops
5590 (defvar anything-c-source-info-goops
5591 '((name . "Info index: goops")
5592 (info-index . "goops")))
5593 ;; (anything 'anything-c-source-info-goops)
5595 ;; Info Index screen
5596 (defvar anything-c-source-info-screen
5597 '((name . "Info index: screen")
5598 (info-index . "screen")
5599 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5600 ;; (anything 'anything-c-source-info-screen)
5602 ;; Info Index latex
5603 (defvar anything-c-source-info-latex
5604 '((name . "Info index: latex")
5605 (info-index . "latex")))
5606 ;; (anything 'anything-c-source-info-latex)
5608 ;; Info Index gawk
5609 (defvar anything-c-source-info-gawk
5610 '((name . "Info index: gawk")
5611 (info-index . "gawk")))
5612 ;; (anything 'anything-c-source-info-gawk)
5614 ;; Info Index sed
5615 (defvar anything-c-source-info-sed
5616 '((name . "Info index: sed")
5617 (info-index . "sed")))
5618 ;; (anything 'anything-c-source-info-sed)
5620 ;; Info Index m4
5621 (defvar anything-c-source-info-m4
5622 '((name . "Info index: m4")
5623 (info-index . "m4")))
5624 ;; (anything 'anything-c-source-info-m4)
5626 ;; Info Index wget
5627 (defvar anything-c-source-info-wget
5628 '((name . "Info index: wget")
5629 (info-index . "wget")))
5630 ;; (anything 'anything-c-source-info-wget)
5632 ;; Info Index binutils
5633 (defvar anything-c-source-info-binutils
5634 '((name . "Info index: binutils")
5635 (info-index . "binutils")))
5636 ;; (anything 'anything-c-source-info-binutils)
5638 ;; Info Index as
5639 (defvar anything-c-source-info-as
5640 '((name . "Info index: as")
5641 (info-index . "as")))
5642 ;; (anything 'anything-c-source-info-as)
5644 ;; Info Index bfd
5645 (defvar anything-c-source-info-bfd
5646 '((name . "Info index: bfd")
5647 (info-index . "bfd")))
5648 ;; (anything 'anything-c-source-info-bfd)
5650 ;; Info Index gprof
5651 (defvar anything-c-source-info-gprof
5652 '((name . "Info index: gprof")
5653 (info-index . "gprof")))
5654 ;; (anything 'anything-c-source-info-gprof)
5656 ;; Info Index ld
5657 (defvar anything-c-source-info-ld
5658 '((name . "Info index: ld")
5659 (info-index . "ld")))
5660 ;; (anything 'anything-c-source-info-ld)
5662 ;; Info Index diff
5663 (defvar anything-c-source-info-diff
5664 '((name . "Info index: diff")
5665 (info-index . "diff")))
5666 ;; (anything 'anything-c-source-info-diff)
5668 ;; Info Index flex
5669 (defvar anything-c-source-info-flex
5670 '((name . "Info index: flex")
5671 (info-index . "flex")))
5672 ;; (anything 'anything-c-source-info-flex)
5674 ;; Info Index grep
5675 (defvar anything-c-source-info-grep
5676 '((name . "Info index: grep")
5677 (info-index . "grep")))
5678 ;; (anything 'anything-c-source-info-grep)
5680 ;; Info Index gzip
5681 (defvar anything-c-source-info-gzip
5682 '((name . "Info index: gzip")
5683 (info-index . "gzip")))
5684 ;; (anything 'anything-c-source-info-gzip)
5686 ;; Info Index libtool
5687 (defvar anything-c-source-info-libtool
5688 '((name . "Info index: libtool")
5689 (info-index . "libtool")))
5690 ;; (anything 'anything-c-source-info-libtool)
5692 ;; Info Index texinfo
5693 (defvar anything-c-source-info-texinfo
5694 '((name . "Info index: texinfo")
5695 (info-index . "texinfo")))
5696 ;; (anything 'anything-c-source-info-texinfo)
5698 ;; Info Index info
5699 (defvar anything-c-source-info-info
5700 '((name . "Info index: info")
5701 (info-index . "info")))
5702 ;; (anything 'anything-c-source-info-info)
5704 ;; Info Index gdb
5705 (defvar anything-c-source-info-gdb
5706 '((name . "Info index: gdb")
5707 (info-index . "gdb")))
5708 ;; (anything 'anything-c-source-info-gdb)
5710 ;; Info Index stabs
5711 (defvar anything-c-source-info-stabs
5712 '((name . "Info index: stabs")
5713 (info-index . "stabs")))
5714 ;; (anything 'anything-c-source-info-stabs)
5716 ;; Info Index cvsbook
5717 (defvar anything-c-source-info-cvsbook
5718 '((name . "Info index: cvsbook")
5719 (info-index . "cvsbook")))
5720 ;; (anything 'anything-c-source-info-cvsbook)
5722 ;; Info Index cvs
5723 (defvar anything-c-source-info-cvs
5724 '((name . "Info index: cvs")
5725 (info-index . "cvs")))
5726 ;; (anything 'anything-c-source-info-cvs)
5728 ;; Info Index bison
5729 (defvar anything-c-source-info-bison
5730 '((name . "Info index: bison")
5731 (info-index . "bison")))
5732 ;; (anything 'anything-c-source-info-bison)
5734 ;; Info Index id-utils
5735 (defvar anything-c-source-info-id-utils
5736 '((name . "Info index: id-utils")
5737 (info-index . "id-utils")))
5738 ;; (anything 'anything-c-source-info-id-utils)
5740 ;; Info Index global
5741 (defvar anything-c-source-info-global
5742 '((name . "Info index: global")
5743 (info-index . "global")))
5744 ;; (anything 'anything-c-source-info-global)
5747 ;;; Man and woman UI
5750 (defvar anything-c-man-pages nil
5751 "All man pages on system.
5752 Will be calculated the first time you invoke anything with this
5753 source.")
5755 (defun anything-c-man-default-action (candidate)
5756 "Default action for jumping to a woman or man page from anything."
5757 (let ((wfiles (woman-file-name-all-completions candidate)))
5758 (condition-case err
5759 (if (> (length wfiles) 1)
5760 (woman-find-file
5761 (anything-comp-read
5762 "ManFile: " wfiles :must-match t))
5763 (woman candidate))
5764 ;; If woman is unable to format correctly
5765 ;; use man instead.
5766 (error (kill-buffer) ; Kill woman buffer.
5767 (let ((Man-notify-method 'meek))
5768 (Man-getpage-in-background candidate))))))
5770 (defvar anything-c-source-man-pages
5771 `((name . "Manual Pages")
5772 (candidates . (lambda ()
5773 (if anything-c-man-pages
5774 anything-c-man-pages
5775 ;; XEmacs doesn't have a woman :)
5776 (setq anything-c-man-pages
5777 (ignore-errors
5778 (require 'woman)
5779 (woman-file-name "")
5780 (sort (mapcar 'car woman-topic-all-completions)
5781 'string-lessp))))))
5782 (action ("Show with Woman" . anything-c-man-default-action))
5783 ;; Woman does not work OS X
5784 ;; http://xahlee.org/emacs/modernization_man_page.html
5785 (action-transformer . (lambda (actions candidate)
5786 (if (eq system-type 'darwin)
5787 '(("Show with Man" . man))
5788 actions)))
5789 (requires-pattern . 2)))
5790 ;; (anything 'anything-c-source-man-pages)
5793 ;;;; <Command>
5794 ;;; Anything M-x - Enhanced M-x UI
5797 ;; Another replacement of `M-x' that act exactly like the
5798 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5799 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5800 ;; anything invocation.
5801 ;; Documentation of commands available without quitting,
5802 ;; Show keybindings of commands.
5803 ;; Show history.
5804 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5805 "Return alist of MODE-MAP."
5806 (loop for key being the key-seqs of mode-map using (key-bindings com)
5807 for str-key = (key-description key)
5808 for ismenu = (string-match "<menu-bar>" str-key)
5809 unless ismenu collect (cons str-key com)))
5811 (defun anything-get-mode-map-from-mode (mode)
5812 "Guess the mode-map name according to MODE.
5813 Some modes don't use conventional mode-map name
5814 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5815 Return nil if no mode-map found."
5816 (loop
5817 ;; Start with a conventional mode-map name.
5818 with mode-map = (intern-soft (format "%s-map" mode))
5819 with mode-string = (symbol-name mode)
5820 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5821 while (not mode-map)
5822 for count downfrom (length mode-name)
5823 ;; Return when no result after parsing entire string.
5824 when (eq count 0) return nil
5825 for sub-name = (substring mode-name 0 count)
5826 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5827 finally return mode-map))
5829 (defun anything-M-x-current-mode-map-alist ()
5830 "Return mode-map alist of current `major-mode'."
5831 (let ((map (anything-get-mode-map-from-mode major-mode)))
5832 (when (and map (boundp map))
5833 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5836 (defun anything-M-x-transformer (candidates sources)
5837 "filtered-candidate-transformer to show bindings in emacs commands.
5838 Show global bindings and local bindings according to current `major-mode'."
5839 (with-anything-current-buffer
5840 (loop
5841 with local-map = (anything-M-x-current-mode-map-alist)
5842 for cand in candidates
5843 for local-key = (car (rassq cand local-map))
5844 for key = (substitute-command-keys (format "\\[%s]" cand))
5845 collect
5846 (cons (cond ((and (string-match "^M-x" key) local-key)
5847 (format "%s (%s)"
5848 cand (propertize
5849 local-key
5850 'face 'anything-M-x-key-face)))
5851 ((string-match "^M-x" key) cand)
5852 (t (format "%s (%s)"
5853 cand (propertize
5855 'face 'anything-M-x-key-face))))
5856 cand) into ls
5857 finally return
5858 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5861 ;;; Complex command history
5864 (defvar anything-c-source-complex-command-history
5865 '((name . "Complex Command History")
5866 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5867 (type . sexp)))
5868 ;; (anything 'anything-c-source-complex-command-history)
5870 ;;; M-x history (not related to `anything-M-x')
5873 (defvar anything-c-source-extended-command-history
5874 '((name . "Emacs Commands History")
5875 (candidates . extended-command-history)
5876 (type . command)))
5877 ;; (anything 'anything-c-source-extended-command-history)
5879 ;;; Emacs commands (Basic source for emacs commands)
5882 (defvar anything-c-source-emacs-commands
5883 '((name . "Emacs Commands")
5884 (candidates . (lambda ()
5885 (let (commands)
5886 (mapatoms (lambda (a)
5887 (if (commandp a)
5888 (push (symbol-name a)
5889 commands))))
5890 (sort commands 'string-lessp))))
5891 (type . command)
5892 (requires-pattern . 2))
5893 "Source for completing and invoking Emacs commands.
5894 A command is a function with interactive spec that can
5895 be invoked with `M-x'.
5897 To get non-interactive functions listed, use
5898 `anything-c-source-emacs-functions'.")
5899 ;; (anything 'anything-c-source-emacs-commands)
5902 ;;;; <Function>
5903 ;;; Emacs functions
5906 (defvar anything-c-source-emacs-functions
5907 '((name . "Emacs Functions")
5908 (candidates . (lambda ()
5909 (let (commands)
5910 (mapatoms (lambda (a)
5911 (if (functionp a)
5912 (push (symbol-name a) commands))))
5913 (sort commands 'string-lessp))))
5914 (type . function)
5915 (requires-pattern . 2))
5916 "Source for completing Emacs functions.")
5917 ;; (anything 'anything-c-source-emacs-functions)
5919 ;;; With abbrev expansion
5920 ;;; Similar to my exec-abbrev-cmd.el
5921 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5922 (defvar anything-c-function-abbrev-regexp nil
5923 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5924 Regexp built from the current `anything-pattern' interpreting it
5925 as abbreviation.
5926 Only for internal use.")
5928 (defun anything-c-match-function-by-abbrev (candidate)
5929 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5931 Abbreviations are made by taking the first character from each
5932 word in the function's name, e.g. \"bb\" is an abbrev for
5933 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5934 (string-match anything-c-function-abbrev-regexp candidate))
5936 (defvar anything-c-source-emacs-functions-with-abbrevs
5937 (append anything-c-source-emacs-functions
5938 '((match anything-c-match-function-by-abbrev
5939 anything-c-string-match))
5940 '((init
5941 . (lambda ()
5942 (defadvice anything-update
5943 (before anything-c-update-function-abbrev-regexp activate)
5944 (let ((char-list (append anything-pattern nil))
5945 (str "^"))
5946 (dolist (c char-list)
5947 (setq str (concat str (list c) "[^-]*-")))
5948 (setq str (concat (substring str 0 (1- (length str))) "$"))
5949 (setq anything-c-function-abbrev-regexp str))))))))
5950 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5952 (defvar anything-c-source-advice
5953 '((name . "Function Advice")
5954 (candidates . anything-c-advice-candidates)
5955 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5956 ;; (real-to-display . anything-c-advice-real-to-display)
5957 (persistent-action . anything-c-advice-persistent-action)
5958 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5959 ;; (anything 'anything-c-source-advice)
5960 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5961 ;; (testadvice)
5963 (defun anything-c-advice-candidates ()
5964 (require 'advice)
5965 (loop for (fname) in ad-advised-functions
5966 for function = (intern fname)
5967 append
5968 (loop for class in ad-advice-classes append
5969 (loop for advice in (ad-get-advice-info-field function class)
5970 for enabled = (ad-advice-enabled advice)
5971 collect
5972 (cons (format
5973 "%s %s %s"
5974 (if enabled "Enabled " "Disabled")
5975 (propertize fname 'face 'font-lock-function-name-face)
5976 (ad-make-single-advice-docstring advice class nil))
5977 (list function class advice))))))
5979 (defun anything-c-advice-persistent-action (func-class-advice)
5980 (if current-prefix-arg
5981 (anything-c-advice-toggle func-class-advice)
5982 (describe-function (car func-class-advice))))
5984 (defun anything-c-advice-toggle (func-class-advice)
5985 (destructuring-bind (function class advice) func-class-advice
5986 (cond ((ad-advice-enabled advice)
5987 (ad-advice-set-enabled advice nil)
5988 (message "Disabled"))
5989 (t ;disabled
5990 (ad-advice-set-enabled advice t)
5991 (message "Enabled")))
5992 (ad-activate function)
5993 (and anything-in-persistent-action
5994 (anything-c-advice-update-current-display-string))))
5996 (defun anything-c-advice-update-current-display-string ()
5997 (anything-edit-current-selection
5998 (let ((newword (cond ((looking-at "Disabled") "Enabled")
5999 ((looking-at "Enabled") "Disabled")))
6000 realvalue)
6001 (when newword
6002 (delete-region (point) (progn (forward-word 1) (point)))
6003 (insert newword)))))
6006 ;;;; <Variable>
6007 ;;; Emacs variables
6010 (defvar anything-c-source-emacs-variables
6011 '((name . "Emacs Variables")
6012 (candidates . (lambda ()
6013 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6014 (type . variable)
6015 (requires-pattern . 2))
6016 "Source for completing Emacs variables.")
6017 ;; (anything 'anything-c-source-emacs-variables)
6020 ;;; LaCarte
6021 (defvar anything-c-source-lacarte
6022 '((name . "Lacarte")
6023 (init . (lambda () (require 'lacarte )))
6024 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6025 (candidate-number-limit . 9999)
6026 (action . anything-c-call-interactively))
6027 "Needs lacarte.el.
6029 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6030 ;; (anything 'anything-c-source-lacarte)
6033 ;;; Bookmarks
6036 ;; Bind some faces for bookmarks.
6037 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6038 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6039 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6041 (eval-when-compile (require 'bookmark))
6042 (defvar anything-c-source-bookmarks
6043 '((name . "Bookmarks")
6044 (init . (lambda ()
6045 (require 'bookmark)))
6046 (candidates . bookmark-all-names)
6047 (type . bookmark))
6048 "See (info \"(emacs)Bookmarks\").")
6049 ;; (anything 'anything-c-source-bookmarks)
6051 ;;; bookmark-set
6052 (defvar anything-c-source-bookmark-set
6053 '((name . "Set Bookmark")
6054 (dummy)
6055 (action . bookmark-set))
6056 "See (info \"(emacs)Bookmarks\").")
6057 ;; (anything 'anything-c-source-bookmark-set)
6059 ;;; Visible Bookmarks
6060 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6063 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6064 (defvar anything-c-source-bm
6065 '((name . "Visible Bookmarks")
6066 (init . anything-c-bm-init)
6067 (candidates-in-buffer)
6068 (type . line))
6069 "Needs bm.el.
6071 http://www.nongnu.org/bm/")
6073 (defun anything-c-bm-init ()
6074 "Init function for `anything-c-source-bm'."
6075 (when (require 'bm nil t)
6076 (with-no-warnings
6077 (let ((bookmarks (bm-lists))
6078 (buf (anything-candidate-buffer 'global)))
6079 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6080 '< :key 'overlay-start))
6081 (let ((start (overlay-start bm))
6082 (end (overlay-end bm))
6083 (annotation (or (overlay-get bm 'annotation) "")))
6084 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6085 (let ((str (format "%5d: [%s]: %s\n"
6086 (line-number-at-pos start)
6087 annotation
6088 (buffer-substring start (1- end)))))
6089 (with-current-buffer buf (insert str))))))))))
6091 ;;; Special bookmarks
6092 (defvar anything-c-source-bookmarks-ssh
6093 '((name . "Bookmarks-ssh")
6094 (init . (lambda ()
6095 (require 'bookmark)))
6096 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6097 (type . bookmark))
6098 "See (info \"(emacs)Bookmarks\").")
6099 ;; (anything 'anything-c-source-bookmarks-ssh)
6101 (defvar anything-c-source-bookmarks-su
6102 '((name . "Bookmarks-root")
6103 (init . (lambda ()
6104 (require 'bookmark)))
6105 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6106 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6108 (type . bookmark))
6109 "See (info \"(emacs)Bookmarks\").")
6110 ;; (anything 'anything-c-source-bookmarks-su)
6112 (defvar anything-c-source-bookmarks-local
6113 '((name . "Bookmarks-Local")
6114 (init . (lambda ()
6115 (require 'bookmark)))
6116 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6117 (filtered-candidate-transformer
6118 anything-c-adaptive-sort
6119 anything-c-highlight-bookmark)
6120 (type . bookmark))
6121 "See (info \"(emacs)Bookmarks\").")
6122 ;; (anything 'anything-c-source-bookmarks-local)
6124 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6125 (let* ((lis-all (bookmark-all-names))
6126 (lis-loc (cond (local (loop for i in lis-all
6127 unless (string-match "^(ssh)\\|^(su)" i)
6128 collect i))
6129 (su (loop for i in lis-all
6130 when (string-match "^(su)" i)
6131 collect i))
6132 (sudo (loop for i in lis-all
6133 when (string-match "^(sudo)" i)
6134 collect i))
6135 (ssh (loop for i in lis-all
6136 when (string-match "^(ssh)" i)
6137 collect i)))))
6138 (sort lis-loc 'string-lessp)))
6140 (defun anything-c-bookmark-root-logged-p ()
6141 (catch 'break
6142 (dolist (i (mapcar #'buffer-name (buffer-list)))
6143 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6144 (throw 'break t)))))
6146 (defun anything-c-highlight-bookmark-su (files source)
6147 (if (anything-c-bookmark-root-logged-p)
6148 (anything-c-highlight-bookmark files source)
6149 (anything-c-highlight-not-logged files source)))
6151 (defun anything-c-highlight-not-logged (files source)
6152 (loop for i in files
6153 collect (propertize i 'face anything-c-bookmarks-face3)))
6155 (defun anything-c-highlight-bookmark (bookmarks source)
6156 "Used as `candidate-transformer' to colorize bookmarks.
6157 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6158 (loop for i in bookmarks
6159 for isfile = (bookmark-get-filename i)
6160 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6161 (bmkext-get-buffer-name i))
6162 for handlerp = (and (fboundp 'bookmark-get-handler)
6163 (bookmark-get-handler i))
6164 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6165 (bmkext-w3m-bookmark-p i))
6166 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6167 (bmkext-gnus-bookmark-p i))
6168 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6169 (bmkext-man-bookmark-p i))
6170 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6171 (bmkext-woman-bookmark-p i))
6172 for handlerp = (bookmark-get-handler i)
6173 for isannotation = (bookmark-get-annotation i)
6174 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6175 for isinfo = (eq handlerp 'Info-bookmark-jump)
6176 ;; Add a * if bookmark have annotation
6177 if (and isannotation (not (string-equal isannotation "")))
6178 do (setq i (concat "*" i))
6179 collect (cond (;; info buffers
6180 isinfo
6181 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6182 (;; w3m buffers
6183 isw3m
6184 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6185 (;; gnus buffers
6186 isgnus
6187 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6188 (;; Man Woman
6189 (or iswoman isman)
6190 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6191 (;; Addressbook
6192 isabook
6193 (propertize i 'face '((:foreground "Tomato"))))
6194 (;; directories
6195 (and isfile (file-directory-p isfile))
6196 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6197 (;; regular files
6199 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6203 ;;; Sources to filter bookmark-extensions bookmarks.
6206 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6207 ;; If you want to enable google-maps in addressbook you will need
6208 ;; Julien Danjou google-maps-el package available here:
6209 ;; http://julien.danjou.info/google-maps-el.html
6211 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6212 "Return a filtered `bookmark-alist' sorted alphabetically."
6213 (loop
6214 with alist = (if args
6215 (apply #'(lambda (x) (funcall fn x)) args)
6216 (funcall fn))
6217 for i in alist
6218 for b = (car i)
6219 collect b into sa
6220 finally return (sort sa 'string-lessp)))
6222 ;;; Addressbook.
6225 (defvar anything-c-source-bmkext-addressbook
6226 '((name . "Bookmark Addressbook")
6227 (init . (lambda ()
6228 (require 'bookmark-extensions)
6229 (bookmark-maybe-load-default-file)))
6230 (candidates . anything-c-bmkext-addressbook-setup-alist)
6231 (persistent-action
6232 . (lambda (candidate)
6233 (let ((bmk (anything-bookmark-get-bookmark-from-name
6234 candidate)))
6235 (bookmark--jump-via bmk 'pop-to-buffer))))
6236 (persistent-help . "Show contact - Prefix with C-u to append")
6237 (filtered-candidate-transformer
6238 anything-c-adaptive-sort
6239 anything-c-highlight-bookmark)
6240 (action . (("Show Contact(s)"
6241 . (lambda (candidate)
6242 (let* ((contacts (anything-marked-candidates))
6243 (current-prefix-arg (or anything-current-prefix-arg
6244 (> (length contacts) 1))))
6245 (bookmark-jump
6246 (anything-bookmark-get-bookmark-from-name (car contacts)))
6247 (anything-aif (cdr contacts)
6248 (loop for bmk in it do
6249 (bookmark-jump
6250 (anything-bookmark-get-bookmark-from-name bmk)))))))
6251 ("Send Mail"
6252 . (lambda (candidate)
6253 (let* ((contacts (anything-marked-candidates))
6254 (bmk (anything-bookmark-get-bookmark-from-name
6255 (car contacts)))
6256 (append (message-buffers)))
6257 (if append
6258 (addressbook-set-mail-buffer1 bmk 'append)
6259 (addressbook-set-mail-buffer1 bmk))
6260 (setq contacts (cdr contacts))
6261 (when contacts
6262 (loop for bmk in contacts do
6263 (addressbook-set-mail-buffer1 bmk 'append))))))
6264 ("Edit Bookmark"
6265 . (lambda (candidate)
6266 (let ((bmk (anything-bookmark-get-bookmark-from-name
6267 candidate)))
6268 (addressbook-bookmark-edit
6269 (assoc bmk bookmark-alist)))))
6270 ("Insert Email at point"
6271 . (lambda (candidate)
6272 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6273 candidate))
6274 (mlist (split-string
6275 (assoc-default
6276 'email (assoc bmk bookmark-alist))
6277 ", ")))
6278 (insert
6279 (if (> (length mlist) 1)
6280 (anything-comp-read
6281 "Insert Mail Address: " mlist :must-match t)
6282 (car mlist))))))
6283 ("Show annotation"
6284 . (lambda (candidate)
6285 (let ((bmk (anything-bookmark-get-bookmark-from-name
6286 candidate)))
6287 (bookmark-show-annotation bmk))))
6288 ("Edit annotation"
6289 . (lambda (candidate)
6290 (let ((bmk (anything-bookmark-get-bookmark-from-name
6291 candidate)))
6292 (bookmark-edit-annotation bmk))))
6293 ("Show Google map"
6294 . (lambda (candidate)
6295 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6296 candidate))
6297 (full-bmk (assoc bmk bookmark-alist)))
6298 (addressbook-google-map full-bmk))))))))
6301 (defun anything-c-bmkext-addressbook-setup-alist ()
6302 "Specialized filter function for bookmarks w3m."
6303 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6305 ;; W3m bookmarks from bookmark-extensions.
6306 (defvar anything-c-source-bookmark-w3m
6307 '((name . "Bookmark W3m")
6308 (init . (lambda ()
6309 (require 'bookmark-extensions)
6310 (bookmark-maybe-load-default-file)))
6311 (candidates . anything-c-bookmark-w3m-setup-alist)
6312 (filtered-candidate-transformer
6313 anything-c-adaptive-sort
6314 anything-c-highlight-bookmark)
6315 (type . bookmark)))
6316 ;; (anything 'anything-c-source-bookmark-w3m)
6318 (defun anything-c-bookmark-w3m-setup-alist ()
6319 "Specialized filter function for bookmarks w3m."
6320 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6322 ;; Images
6323 (defvar anything-c-source-bookmark-images
6324 '((name . "Bookmark Images")
6325 (init . (lambda ()
6326 (require 'bookmark-extensions)
6327 (bookmark-maybe-load-default-file)))
6328 (candidates . anything-c-bookmark-images-setup-alist)
6329 (filtered-candidate-transformer
6330 anything-c-adaptive-sort
6331 anything-c-highlight-bookmark)
6332 (type . bookmark)))
6333 ;; (anything 'anything-c-source-bookmark-images)
6335 (defun anything-c-bookmark-images-setup-alist ()
6336 "Specialized filter function for images bookmarks."
6337 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6339 ;; Woman Man
6340 (defvar anything-c-source-bookmark-man
6341 '((name . "Bookmark Woman&Man")
6342 (init . (lambda ()
6343 (require 'bookmark-extensions)
6344 (bookmark-maybe-load-default-file)))
6345 (candidates . anything-c-bookmark-man-setup-alist)
6346 (filtered-candidate-transformer
6347 anything-c-adaptive-sort
6348 anything-c-highlight-bookmark)
6349 (type . bookmark)))
6350 ;; (anything 'anything-c-source-bookmark-man)
6352 (defun anything-c-bookmark-man-setup-alist ()
6353 "Specialized filter function for bookmarks w3m."
6354 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6355 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6357 ;; Gnus
6358 (defvar anything-c-source-bookmark-gnus
6359 '((name . "Bookmark Gnus")
6360 (init . (lambda ()
6361 (require 'bookmark-extensions)
6362 (bookmark-maybe-load-default-file)))
6363 (candidates . anything-c-bookmark-gnus-setup-alist)
6364 (filtered-candidate-transformer
6365 anything-c-adaptive-sort
6366 anything-c-highlight-bookmark)
6367 (type . bookmark)))
6368 ;; (anything 'anything-c-source-bookmark-gnus)
6370 (defun anything-c-bookmark-gnus-setup-alist ()
6371 "Specialized filter function for bookmarks gnus."
6372 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6374 ;; Info
6375 (defvar anything-c-source-bookmark-info
6376 '((name . "Bookmark Info")
6377 (init . (lambda ()
6378 (require 'bookmark-extensions)
6379 (bookmark-maybe-load-default-file)))
6380 (candidates . anything-c-bookmark-info-setup-alist)
6381 (filtered-candidate-transformer
6382 anything-c-adaptive-sort
6383 anything-c-highlight-bookmark)
6384 (type . bookmark)))
6385 ;; (anything 'anything-c-source-bookmark-info)
6387 (defun anything-c-bookmark-info-setup-alist ()
6388 "Specialized filter function for bookmarks info."
6389 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6391 ;; Local Files&directories
6392 (defvar anything-c-source-bookmark-files&dirs
6393 '((name . "Bookmark Files&Directories")
6394 (init . (lambda ()
6395 (require 'bookmark-extensions)
6396 (bookmark-maybe-load-default-file)))
6397 (candidates . anything-c-bookmark-local-files-setup-alist)
6398 (filtered-candidate-transformer
6399 anything-c-adaptive-sort
6400 anything-c-highlight-bookmark)
6401 (type . bookmark)))
6402 ;; (anything 'anything-c-source-bookmark-files&dirs)
6404 (defun anything-c-bookmark-local-files-setup-alist ()
6405 "Specialized filter function for bookmarks locals files."
6406 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6408 ;; Su Files&directories
6409 (defvar anything-c-source-bookmark-su-files&dirs
6410 '((name . "Bookmark Root-Files&Directories")
6411 (init . (lambda ()
6412 (require 'bookmark-extensions)
6413 (bookmark-maybe-load-default-file)))
6414 (candidates . anything-c-bookmark-su-files-setup-alist)
6415 (filtered-candidate-transformer
6416 anything-c-adaptive-sort
6417 anything-c-highlight-bookmark-su)
6418 (type . bookmark)))
6419 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6421 (defun anything-c-bookmark-su-files-setup-alist ()
6422 "Specialized filter function for bookmarks su/sudo files."
6423 (declare (special bmkext-su-or-sudo-regexp))
6424 (loop
6425 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6426 for i in l
6427 for isfile = (bookmark-get-filename i)
6428 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6429 (save-match-data
6430 (string-match tramp-file-name-regexp isfile)))
6431 for issu = (and istramp
6432 (string-match bmkext-su-or-sudo-regexp isfile))
6433 if issu
6434 collect i))
6436 ;; Ssh Files&directories
6437 (defvar anything-c-source-bookmark-ssh-files&dirs
6438 '((name . "Bookmark Ssh-Files&Directories")
6439 (init . (lambda ()
6440 (require 'bookmark-extensions)
6441 (bookmark-maybe-load-default-file)))
6442 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6443 (filtered-candidate-transformer . anything-c-adaptive-sort)
6444 (type . bookmark)))
6445 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6447 (defun anything-c-bookmark-ssh-files-setup-alist ()
6448 "Specialized filter function for bookmarks ssh files."
6449 (loop
6450 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6451 for i in l
6452 for isfile = (bookmark-get-filename i)
6453 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6454 (save-match-data
6455 (string-match tramp-file-name-regexp isfile)))
6456 for isssh = (and istramp
6457 (string-match "/ssh:" isfile))
6458 if isssh
6459 collect i))
6463 ;;; Firefox bookmarks
6466 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6467 ;; (only for firefox versions >=3)
6468 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6469 ;; to true:
6470 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6471 ;; You should have now:
6472 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6474 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6475 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6477 (defun anything-get-firefox-user-init-dir ()
6478 "Guess the default Firefox user directory name."
6479 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6480 (moz-user-dir
6481 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6482 (goto-char (point-min))
6483 (prog1
6484 (when (search-forward "Path=" nil t)
6485 (buffer-substring-no-properties (point) (point-at-eol)))
6486 (kill-buffer)))))
6487 (file-name-as-directory (concat moz-dir moz-user-dir))))
6489 (defun anything-guess-firefox-bookmark-file ()
6490 "Return the path of the Firefox bookmarks file."
6491 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6493 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6494 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6495 (let (bookmarks-alist url title)
6496 (with-temp-buffer
6497 (insert-file-contents file)
6498 (goto-char (point-min))
6499 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6500 (forward-line 0)
6501 (when (re-search-forward url-regexp nil t)
6502 (setq url (match-string 0)))
6503 (when (re-search-forward bmk-regexp nil t)
6504 (setq title (match-string 1)))
6505 (push (cons title url) bookmarks-alist)
6506 (forward-line)))
6507 (nreverse bookmarks-alist)))
6509 (defvar anything-c-firefox-bookmarks-alist nil)
6510 (defvar anything-c-source-firefox-bookmarks
6511 '((name . "Firefox Bookmarks")
6512 (init . (lambda ()
6513 (setq anything-c-firefox-bookmarks-alist
6514 (anything-html-bookmarks-to-alist
6515 (anything-guess-firefox-bookmark-file)
6516 anything-firefox-bookmark-url-regexp
6517 anything-firefox-bookmarks-regexp))))
6518 (candidates . (lambda ()
6519 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6520 (filtered-candidate-transformer
6521 anything-c-adaptive-sort
6522 anything-c-highlight-firefox-bookmarks)
6523 (action . (("Browse Url Firefox"
6524 . (lambda (candidate)
6525 (browse-url-firefox
6526 (anything-c-firefox-bookmarks-get-value candidate))))
6527 ("Browse Url w3m"
6528 . (lambda (candidate)
6529 (w3m-browse-url
6530 (anything-c-firefox-bookmarks-get-value candidate))))
6531 ("Copy Url"
6532 . (lambda (elm)
6533 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6535 ;; (anything 'anything-c-source-firefox-bookmarks)
6537 (defun anything-c-firefox-bookmarks-get-value (elm)
6538 (assoc-default elm anything-c-firefox-bookmarks-alist))
6540 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6541 (loop for i in bookmarks
6542 collect (propertize
6543 i 'face '((:foreground "YellowGreen"))
6544 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6548 ;;; W3m bookmark - anything interface.
6551 ;; Some users have the emacs-w3m library in load-path
6552 ;; without having the w3m executable :-;
6553 ;; So check if w3m program is present before trying to load
6554 ;; emacs-w3m.
6555 (eval-when-compile
6556 (when (executable-find "w3m")
6557 (require 'w3m-bookmark nil t)))
6559 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6560 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6561 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6562 (defvar anything-c-w3m-bookmarks-alist nil)
6563 (defvar anything-c-source-w3m-bookmarks
6564 '((name . "W3m Bookmarks")
6565 (init . (lambda ()
6566 (setq anything-c-w3m-bookmarks-alist
6567 (anything-html-bookmarks-to-alist
6568 w3m-bookmark-file
6569 anything-w3m-bookmark-url-regexp
6570 anything-w3m-bookmarks-regexp))))
6571 (candidates . (lambda ()
6572 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6573 (filtered-candidate-transformer
6574 anything-c-adaptive-sort
6575 anything-c-highlight-w3m-bookmarks)
6576 (action . (("Browse Url"
6577 . (lambda (candidate)
6578 (anything-c-w3m-browse-bookmark candidate)))
6579 ("Copy Url"
6580 . (lambda (elm)
6581 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6582 ("Browse Url Firefox"
6583 . (lambda (candidate)
6584 (anything-c-w3m-browse-bookmark candidate t)))
6585 ("Delete Bookmark"
6586 . (lambda (candidate)
6587 (anything-c-w3m-delete-bookmark candidate)))
6588 ("Rename Bookmark"
6589 . (lambda (candidate)
6590 (anything-c-w3m-rename-bookmark candidate)))))
6591 (persistent-action . (lambda (candidate)
6592 (if current-prefix-arg
6593 (anything-c-w3m-browse-bookmark candidate t)
6594 (anything-c-w3m-browse-bookmark candidate nil t))))
6595 (persistent-help . "Open URL with emacs-w3m in new tab / \
6596 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6597 "Needs w3m and emacs-w3m.
6599 http://w3m.sourceforge.net/
6600 http://emacs-w3m.namazu.org/")
6602 ;; (anything 'anything-c-source-w3m-bookmarks)
6604 (defun anything-c-w3m-bookmarks-get-value (elm)
6605 (replace-regexp-in-string
6606 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6608 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6609 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6610 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6611 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6613 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6614 (loop for i in bookmarks
6615 collect (propertize
6616 i 'face 'anything-w3m-bookmarks-face
6617 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6620 (defun anything-c-w3m-delete-bookmark (elm)
6621 "Delete w3m bookmark from `w3m-bookmark-file'."
6622 (with-current-buffer
6623 (find-file-literally w3m-bookmark-file)
6624 (goto-char (point-min))
6625 (when (re-search-forward elm nil t)
6626 (beginning-of-line)
6627 (delete-region (point)
6628 (line-end-position))
6629 (delete-blank-lines))
6630 (save-buffer)
6631 (kill-buffer)))
6633 (defun anything-c-w3m-rename-bookmark (elm)
6634 "Rename w3m bookmark in `w3m-bookmark-file'."
6635 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6636 (new-title (read-string "NewTitle: " old-title)))
6637 (with-current-buffer
6638 (find-file-literally w3m-bookmark-file)
6639 (goto-char (point-min))
6640 (when (re-search-forward (concat elm "<") nil t)
6641 (goto-char (1- (point)))
6642 (delete-char (- (length old-title)))
6643 (insert new-title))
6644 (save-buffer)
6645 (kill-buffer))))
6648 ;;;; <Library>
6649 ;;; Elisp library scan
6652 (defvar anything-c-source-elisp-library-scan
6653 '((name . "Elisp libraries (Scan)")
6654 (init . (anything-c-elisp-library-scan-init))
6655 (candidates-in-buffer)
6656 (action ("Find library"
6657 . (lambda (candidate) (find-file (find-library-name candidate))))
6658 ("Find library other window"
6659 . (lambda (candidate)
6660 (find-file-other-window (find-library-name candidate))))
6661 ("Load library"
6662 . (lambda (candidate) (load-library candidate))))))
6663 ;; (anything 'anything-c-source-elisp-library-scan)
6665 (defun anything-c-elisp-library-scan-init ()
6666 "Init anything buffer status."
6667 (let ((anything-buffer (anything-candidate-buffer 'global))
6668 (library-list (anything-c-elisp-library-scan-list)))
6669 (with-current-buffer anything-buffer
6670 (dolist (library library-list)
6671 (insert (format "%s\n" library))))))
6673 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6674 "Do completion for file names passed to `locate-file'.
6675 DIRS is directory to search path.
6676 STRING is string to match."
6677 ;; Use `load-path' as path when ignore `dirs'.
6678 (or dirs (setq dirs load-path))
6679 ;; Init with blank when ignore `string'.
6680 (or string (setq string ""))
6681 ;; Get library list.
6682 (let ((string-dir (file-name-directory string))
6683 ;; File regexp that suffix match `load-file-rep-suffixes'.
6684 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6685 name
6686 names)
6687 (dolist (dir dirs)
6688 (unless dir
6689 (setq dir default-directory))
6690 (if string-dir
6691 (setq dir (expand-file-name string-dir dir)))
6692 (when (file-directory-p dir)
6693 (dolist (file (file-name-all-completions
6694 (file-name-nondirectory string) dir))
6695 ;; Suffixes match `load-file-rep-suffixes'.
6696 (setq name (if string-dir (concat string-dir file) file))
6697 (if (string-match match-regexp name)
6698 (add-to-list 'names name)))))
6699 names))
6702 ;;;; <Programming>
6706 ;;; Imenu
6709 (defvar anything-c-imenu-delimiter " / ")
6711 (defvar anything-c-imenu-index-filter nil)
6712 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6714 (defvar anything-c-cached-imenu-alist nil)
6715 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6717 (defvar anything-c-cached-imenu-candidates nil)
6718 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6720 (defvar anything-c-cached-imenu-tick nil)
6721 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6723 (eval-when-compile (require 'imenu))
6724 (setq imenu-auto-rescan t)
6726 (defun anything-imenu-create-candidates (entry)
6727 "Create candidates with ENTRY."
6728 (if (listp (cdr entry))
6729 (mapcan
6730 (lambda (sub)
6731 (if (consp (cdr sub))
6732 (mapcar
6733 (lambda (subentry)
6734 (concat (car entry) anything-c-imenu-delimiter subentry))
6735 (anything-imenu-create-candidates sub))
6736 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6737 (cdr entry))
6738 (list entry)))
6740 (defvar anything-c-source-imenu
6741 '((name . "Imenu")
6742 (init . (lambda () (require 'imenu)))
6743 (candidates . anything-c-imenu-candidates)
6744 (persistent-action . (lambda (elm)
6745 (anything-c-imenu-default-action elm)
6746 (unless (fboundp 'semantic-imenu-tag-overlay)
6747 (anything-match-line-color-current-line))))
6748 (persistent-help . "Show this entry")
6749 (action . anything-c-imenu-default-action))
6750 "See (info \"(emacs)Imenu\")")
6752 ;; (anything 'anything-c-source-imenu)
6754 (defun anything-c-imenu-candidates ()
6755 (with-anything-current-buffer
6756 (let ((tick (buffer-modified-tick)))
6757 (if (eq anything-c-cached-imenu-tick tick)
6758 anything-c-cached-imenu-candidates
6759 (setq imenu--index-alist nil)
6760 (setq anything-c-cached-imenu-tick tick
6761 anything-c-cached-imenu-candidates
6762 (ignore-errors
6763 (mapcan
6764 'anything-imenu-create-candidates
6765 (setq anything-c-cached-imenu-alist
6766 (let ((index (imenu--make-index-alist)))
6767 (if anything-c-imenu-index-filter
6768 (funcall anything-c-imenu-index-filter index)
6769 index))))))
6770 (setq anything-c-cached-imenu-candidates
6771 (mapcar #'(lambda (x)
6772 (if (stringp x)
6774 (car x)))
6775 anything-c-cached-imenu-candidates))))))
6777 (setq imenu-default-goto-function 'imenu-default-goto-function)
6778 (defun anything-c-imenu-default-action (elm)
6779 "The default action for `anything-c-source-imenu'."
6780 (let ((path (split-string elm anything-c-imenu-delimiter))
6781 (alist anything-c-cached-imenu-alist))
6782 (dolist (elm path)
6783 (setq alist (assoc elm alist)))
6784 (imenu alist)))
6788 ;;; Ctags
6791 (defvar anything-c-ctags-modes
6792 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6793 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6794 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6796 (defun anything-c-source-ctags-init ()
6797 (when (and buffer-file-name
6798 (memq major-mode anything-c-ctags-modes)
6799 (anything-current-buffer-is-modified))
6800 (with-current-buffer (anything-candidate-buffer 'local)
6801 (call-process-shell-command
6802 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6803 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6804 anything-buffer-file-name)
6805 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6806 nil (current-buffer))
6807 (goto-char (point-min))
6808 (forward-line 2)
6809 (delete-region (point-min) (point))
6810 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6811 for lineno-start = (point)
6812 for lineno = (buffer-substring
6813 lineno-start
6814 (1- (search-forward "," (point-at-eol) t)))
6816 (beginning-of-line)
6817 (insert (format "%5s:" lineno))
6818 (search-forward "\177" (point-at-eol) t)
6819 (delete-region (1- (point)) (point-at-eol))
6820 (forward-line 1)))))
6822 (defvar anything-c-source-ctags
6823 '((name . "Exuberant ctags")
6824 (init . anything-c-source-ctags-init)
6825 (candidates-in-buffer)
6826 (adjust)
6827 (type . line))
6828 "Needs Exuberant Ctags.
6830 http://ctags.sourceforge.net/")
6831 ;; (anything 'anything-c-source-ctags)
6834 ;;; Etags
6837 ;; anything-etags.el is deprecated, if this file is found,
6838 ;; warn user at compile time.
6839 (eval-when-compile
6840 (when (locate-library "anything-etags.el")
6841 (display-warning
6842 '(anything-config)
6843 "You are using obsolete library `anything-etags.el' and should remove it."
6844 :warning)))
6846 (defvar anything-c-etags-tag-file-dir nil
6847 "Etags file directory.")
6848 (defvar anything-c-etags-mtime-alist nil
6849 "Store the last modification time of etags files here.")
6850 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6851 "Cache content of etags files used here for faster access.")
6853 (defun anything-c-etags-get-tag-file (&optional directory)
6854 "Return the path of etags file if found."
6855 ;; Get tag file from `default-directory' or upper directory.
6856 (let ((current-dir (anything-c-etags-find-tag-file-directory
6857 (or directory default-directory))))
6858 ;; Return nil if not find tag file.
6859 (when current-dir
6860 ;; Set tag file directory.
6861 (setq anything-c-etags-tag-file-dir current-dir)
6862 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6864 (defun anything-c-etags-find-tag-file-directory (current-dir)
6865 "Try to find the directory containing tag file.
6866 If not found in CURRENT-DIR search in upper directory."
6867 (flet ((file-exists? (dir)
6868 (let ((tag-path (expand-file-name
6869 anything-c-etags-tag-file-name dir)))
6870 (and (stringp tag-path)
6871 (file-exists-p tag-path)
6872 (file-readable-p tag-path)))))
6873 (loop with count = 0
6874 until (file-exists? current-dir)
6875 ;; Return nil if outside the value of
6876 ;; `anything-c-etags-tag-file-search-limit'.
6877 if (= count anything-c-etags-tag-file-search-limit)
6878 do (return nil)
6879 ;; Or search upper directories.
6880 else
6881 do (incf count)
6882 (setq current-dir (expand-file-name (concat current-dir "../")))
6883 finally return current-dir)))
6885 (defun anything-c-source-etags-header-name (x)
6886 "Create header name for this anything etags session."
6887 (concat "Etags in "
6888 (with-anything-current-buffer
6889 (anything-c-etags-get-tag-file))))
6891 (defmacro anything-c-etags-create-buffer (file)
6892 "Create the `anything-buffer' based on contents of etags tag FILE."
6893 `(let* ((tag-fname ,file)
6895 (split (with-current-buffer (find-file-noselect tag-fname)
6896 (prog1
6897 (split-string (buffer-string) "\n" 'omit-nulls)
6898 (setq max (line-number-at-pos (point-max)))
6899 (kill-buffer))))
6900 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6901 (loop
6902 with fname
6903 with cand
6904 for i in split for count from 0
6905 for elm = (unless (string-match "^\x0c" i)
6906 (anything-aif (string-match "\177" i)
6907 (substring i 0 it)
6909 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6910 (setq fname (match-string 1 elm)))
6911 (elm (setq cand (concat fname ": " elm)))
6912 (t (setq cand nil)))
6913 when cand do (progn
6914 (insert (concat cand "\n"))
6915 (progress-reporter-update progress-reporter count)))))
6917 (defun anything-c-etags-init ()
6918 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6919 If no entry in cache, create one."
6920 (let ((tagfile (anything-c-etags-get-tag-file)))
6921 (when tagfile
6922 (with-current-buffer (anything-candidate-buffer 'global)
6923 (anything-aif (gethash tagfile anything-c-etags-cache)
6924 ;; An entry is present in cache, insert it.
6925 (insert it)
6926 ;; No entry, create a new buffer using content of tag file (slower).
6927 (anything-c-etags-create-buffer tagfile)
6928 ;; Store content of buffer in cache.
6929 (puthash tagfile (buffer-string) anything-c-etags-cache)
6930 ;; Store or set the last modification of tag file.
6931 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6932 ;; If an entry exists modify it.
6933 (setcdr it (anything-c-etags-mtime tagfile))
6934 ;; No entry create a new one.
6935 (add-to-list 'anything-c-etags-mtime-alist
6936 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6938 (defvar anything-c-source-etags-select
6939 '((name . "Etags")
6940 (header-name . anything-c-source-etags-header-name)
6941 (init . anything-c-etags-init)
6942 (candidates-in-buffer)
6943 (search . (anything-c-etags-search-fn))
6944 (mode-line . anything-etags-mode-line-string)
6945 (action . anything-c-etags-default-action)
6946 (persistent-action . (lambda (candidate)
6947 (anything-c-etags-default-action candidate)
6948 (anything-match-line-color-current-line))))
6949 "Anything source for Etags.")
6951 (defun anything-c-etags-search-fn (pattern bound noerror)
6952 "Search function for `anything-c-source-etags-select'."
6953 (re-search-forward
6954 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6955 bound noerror))
6957 (defun anything-c-etags-default-action (candidate)
6958 "Anything default action to jump to an etags entry."
6959 (let* ((split (split-string candidate ": "))
6960 (fname (expand-file-name
6961 (car split) anything-c-etags-tag-file-dir))
6962 (elm (cadr split)))
6963 (find-file fname)
6964 (goto-char (point-min))
6965 (search-forward elm nil t)
6966 (goto-char (match-beginning 0))))
6968 (defun anything-c-etags-mtime (file)
6969 "Last modification time of etags tag FILE."
6970 (cadr (nth 5 (file-attributes file))))
6972 (defun anything-c-etags-file-modified-p (file)
6973 "Check if tag FILE have been modified in this session.
6974 If FILE is nil return nil."
6975 (let ((last-modif (and file
6976 (assoc-default file anything-c-etags-mtime-alist))))
6977 (and last-modif
6978 (/= last-modif (anything-c-etags-mtime file)))))
6982 ;;; Semantic
6985 (defvar anything-semantic-candidates nil)
6987 (defun anything-semantic-construct-candidates (tags depth)
6988 (when (require 'semantic nil t)
6989 (apply
6990 'append
6991 (mapcar
6992 (lambda (tag)
6993 (if (listp tag)
6994 (let ((type (semantic-tag-type tag))
6995 (class (semantic-tag-class tag)))
6996 (if (or (and (stringp type)
6997 (or (string= type "class")
6998 (string= type "namespace")))
6999 (eq class 'function)
7000 (eq class 'variable))
7001 (cons (cons (concat (make-string (* depth 2) ?\s)
7002 (semantic-format-tag-summarize tag nil t))
7003 tag)
7004 (anything-semantic-construct-candidates
7005 (semantic-tag-components tag) (1+ depth)))))))
7006 tags))))
7008 (defun anything-semantic-default-action (candidate)
7009 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7010 (semantic-go-to-tag tag)))
7012 (defvar anything-c-source-semantic
7013 '((name . "Semantic Tags")
7014 (init . (lambda ()
7015 (setq anything-semantic-candidates
7016 (ignore-errors (anything-semantic-construct-candidates
7017 (semantic-fetch-tags) 0)))))
7018 (candidates . (lambda ()
7019 (if anything-semantic-candidates
7020 (mapcar 'car anything-semantic-candidates))))
7021 (persistent-action . (lambda (elm)
7022 (anything-semantic-default-action elm)
7023 (anything-match-line-color-current-line)))
7024 (persistent-help . "Show this entry")
7025 (action . anything-semantic-default-action)
7026 "Needs semantic in CEDET.
7028 http://cedet.sourceforge.net/semantic.shtml
7029 http://cedet.sourceforge.net/"))
7031 ;; (anything 'anything-c-source-semantic)
7034 ;;; Anything interface of `simple-call-tree.el'.
7036 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7038 ;; Function is called by
7039 (defvar anything-c-source-simple-call-tree-functions-callers
7040 '((name . "Function is called by")
7041 (init . anything-c-simple-call-tree-functions-callers-init)
7042 (multiline)
7043 (candidates . anything-c-simple-call-tree-candidates)
7044 (persistent-action . anything-c-simple-call-tree-persistent-action)
7045 (persistent-help . "Show function definitions by rotation")
7046 (action ("Find definition selected by persistent-action" .
7047 anything-c-simple-call-tree-find-definition)))
7048 "Needs simple-call-tree.el.
7049 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7051 (defvar anything-c-simple-call-tree-tick nil)
7052 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7053 (defun anything-c-simple-call-tree-analyze-maybe ()
7054 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7055 (simple-call-tree-analyze)
7056 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7058 (defun anything-c-simple-call-tree-init-base (function message)
7059 (require 'simple-call-tree)
7060 (with-no-warnings
7061 (when (anything-current-buffer-is-modified)
7062 (anything-c-simple-call-tree-analyze-maybe)
7063 (let ((list (funcall function simple-call-tree-alist)))
7064 (with-current-buffer (anything-candidate-buffer 'local)
7065 (dolist (entry list)
7066 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7067 (insert (car entry) message
7068 (if (string= funcs " ")
7069 " no functions."
7070 funcs)
7071 "\n\n"))))))))
7073 (defun anything-c-simple-call-tree-functions-callers-init ()
7074 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7075 " is called by\n"))
7077 (defun anything-c-simple-call-tree-candidates ()
7078 (with-current-buffer (anything-candidate-buffer)
7079 (split-string (buffer-string) "\n\n")))
7081 (defvar anything-c-simple-call-tree-related-functions nil)
7082 (defvar anything-c-simple-call-tree-function-index 0)
7083 (defun anything-c-simple-call-tree-persistent-action (candidate)
7084 (unless (eq last-command 'anything-execute-persistent-action)
7085 (setq anything-c-simple-call-tree-related-functions
7086 (delete "no functions."
7087 (split-string
7088 (replace-regexp-in-string " \\| is called by\\| calls "
7089 "" candidate)
7090 "\n")))
7091 (setq anything-c-simple-call-tree-function-index -1))
7092 (incf anything-c-simple-call-tree-function-index)
7093 (anything-c-simple-call-tree-find-definition candidate))
7095 (defun anything-c-simple-call-tree-find-definition (candidate)
7096 (find-function
7097 (intern
7098 (nth (mod anything-c-simple-call-tree-function-index
7099 (length anything-c-simple-call-tree-related-functions))
7100 anything-c-simple-call-tree-related-functions))))
7102 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7104 ;;; Function calls
7105 (defvar anything-c-source-simple-call-tree-callers-functions
7106 '((name . "Function calls")
7107 (init . anything-c-simple-call-tree-callers-functions-init)
7108 (multiline)
7109 (candidates . anything-c-simple-call-tree-candidates)
7110 (persistent-action . anything-c-simple-call-tree-persistent-action)
7111 (persistent-help . "Show function definitions by rotation")
7112 (action ("Find definition selected by persistent-action" .
7113 anything-c-simple-call-tree-find-definition)))
7114 "Needs simple-call-tree.el.
7115 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7117 (defun anything-c-simple-call-tree-callers-functions-init ()
7118 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7120 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7124 ;;; Anything UI of auto-document.el
7126 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7128 ;; Commands/Options with doc
7129 (defvar anything-c-auto-document-data nil)
7130 (make-variable-buffer-local 'anything-c-auto-document-data)
7131 (defvar anything-c-source-commands-and-options-in-file
7132 '((name . "Commands/Options in file")
7133 (header-name
7134 . (lambda (x) (format "Commands/Options in %s"
7135 (buffer-local-value 'buffer-file-name
7136 anything-current-buffer))))
7137 (candidates . anything-command-and-options-candidates)
7138 (multiline)
7139 (action . imenu))
7140 "List Commands and Options with doc. It needs auto-document.el .
7142 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7144 (eval-when-compile (require 'auto-document nil t))
7145 (defun anything-command-and-options-candidates ()
7146 (with-anything-current-buffer
7147 (when (and (require 'auto-document nil t)
7148 (eq major-mode 'emacs-lisp-mode)
7149 (or (anything-current-buffer-is-modified)
7150 (not anything-c-auto-document-data)))
7151 (or imenu--index-alist (imenu--make-index-alist t))
7152 (setq anything-c-auto-document-data
7153 (destructuring-bind (commands options)
7154 (adoc-construct anything-current-buffer)
7155 (append
7156 (loop for (command . doc) in commands
7157 for cmdname = (symbol-name command)
7158 collect
7159 (cons
7160 (format "Command: %s\n %s"
7161 (propertize cmdname 'face font-lock-function-name-face)
7162 (adoc-first-line doc))
7163 (assoc cmdname imenu--index-alist)))
7164 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7165 for (option doc default) in options
7166 for optname = (symbol-name option)
7167 collect
7168 (cons
7169 (format "Option: %s\n %s\n default = %s"
7170 (propertize optname 'face font-lock-variable-name-face)
7171 (adoc-first-line doc)
7172 (adoc-prin1-to-string default))
7173 (assoc optname
7174 var-alist)))))))
7175 anything-c-auto-document-data))
7177 ;; (anything 'anything-c-source-commands-and-options-in-file)
7180 ;;;; <Color and Face>
7183 ;;; Customize Face
7186 (defvar anything-c-source-customize-face
7187 '((name . "Customize Face")
7188 (init . (lambda ()
7189 (unless (anything-candidate-buffer)
7190 (save-window-excursion (list-faces-display))
7191 (anything-candidate-buffer (get-buffer "*Faces*")))))
7192 (candidates-in-buffer)
7193 (get-line . buffer-substring)
7194 (action . (lambda (line)
7195 (customize-face (intern (car (split-string line))))))
7196 (requires-pattern . 3))
7197 "See (info \"(emacs)Faces\")")
7198 ;; (anything 'anything-c-source-customize-face)
7200 ;;; Colors browser
7203 (defvar anything-c-source-colors
7204 '((name . "Colors")
7205 (init . (lambda () (unless (anything-candidate-buffer)
7206 (save-window-excursion (list-colors-display))
7207 (anything-candidate-buffer (get-buffer "*Colors*")))))
7208 (candidates-in-buffer)
7209 (get-line . buffer-substring)
7210 (action
7211 ("Copy Name" . (lambda (candidate)
7212 (kill-new (anything-c-colors-get-name candidate))))
7213 ("Copy RGB" . (lambda (candidate)
7214 (kill-new (anything-c-colors-get-rgb candidate))))
7215 ("Insert Name" . (lambda (candidate)
7216 (with-anything-current-buffer
7217 (insert (anything-c-colors-get-name candidate)))))
7218 ("Insert RGB" . (lambda (candidate)
7219 (with-anything-current-buffer
7220 (insert (anything-c-colors-get-rgb candidate))))))))
7221 ;; (anything 'anything-c-source-colors)
7223 (defun anything-c-colors-get-name (candidate)
7224 "Get color name."
7225 (replace-regexp-in-string
7226 " " ""
7227 (with-temp-buffer
7228 (insert (capitalize candidate))
7229 (goto-char (point-min))
7230 (search-forward-regexp "\\s-\\{2,\\}")
7231 (delete-region (point) (point-max))
7232 (buffer-string))))
7234 (defun anything-c-colors-get-rgb (candidate)
7235 "Get color RGB."
7236 (replace-regexp-in-string
7237 " " ""
7238 (with-temp-buffer
7239 (insert (capitalize candidate))
7240 (goto-char (point-max))
7241 (search-backward-regexp "\\s-\\{2,\\}")
7242 (delete-region (point) (point-min))
7243 (buffer-string))))
7246 ;;;; <Search Engine>
7247 ;;; Tracker desktop search
7248 (defvar anything-c-source-tracker-search
7249 '((name . "Tracker Search")
7250 (candidates . (lambda ()
7251 (start-process "tracker-search-process" nil
7252 "tracker-search"
7253 anything-pattern)))
7254 (type . file)
7255 (requires-pattern . 3)
7256 (delayed))
7257 "Source for retrieving files matching the current input pattern
7258 with the tracker desktop search.")
7259 ;; (anything 'anything-c-source-tracker-search)
7261 ;;; Spotlight (MacOS X desktop search)
7262 (defvar anything-c-source-mac-spotlight
7263 '((name . "mdfind")
7264 (candidates
7265 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7266 (type . file)
7267 (requires-pattern . 3)
7268 (delayed))
7269 "Source for retrieving files via Spotlight's command line
7270 utility mdfind.")
7271 ;; (anything 'anything-c-source-mac-spotlight)
7273 ;;; Picklist
7274 (defvar anything-c-source-picklist
7275 '((name . "Picklist")
7276 (candidates . (lambda () (mapcar 'car picklist-list)))
7277 (type . file)))
7278 ;; (anything 'anything-c-source-picklist)
7282 ;;; Kill ring
7285 (defvar anything-c-source-kill-ring
7286 '((name . "Kill Ring")
7287 (init . (lambda () (anything-attrset 'last-command last-command)))
7288 (candidates . anything-c-kill-ring-candidates)
7289 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7290 (action . anything-c-kill-ring-action)
7291 (last-command)
7292 (migemo)
7293 (multiline))
7294 "Source for browse and insert contents of kill-ring.")
7296 (defun anything-c-kill-ring-candidates ()
7297 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7298 unless (or (< (length kill) anything-kill-ring-threshold)
7299 (string-match "^[\\s\\t]+$" kill))
7300 collect kill))
7302 (defun anything-c-kill-ring-transformer (candidates source)
7303 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7304 (loop for i in candidates
7305 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7306 if (and anything-c-kill-ring-max-lines-number
7307 (> nlines anything-c-kill-ring-max-lines-number))
7308 collect (cons
7309 (with-temp-buffer
7310 (insert i)
7311 (goto-char (point-min))
7312 (concat
7313 (buffer-substring
7314 (point-min)
7315 (save-excursion
7316 (forward-line anything-c-kill-ring-max-lines-number)
7317 (point)))
7318 "[...]")) i)
7319 else collect i))
7321 (defun anything-c-kill-ring-action (str)
7322 "Insert STR in `kill-ring' and set STR to the head.
7323 If this action is executed just after `yank',
7324 replace with STR as yanked string."
7325 (setq kill-ring (delete str kill-ring))
7326 (if (not (eq (anything-attr 'last-command) 'yank))
7327 (insert-for-yank str)
7328 ;; from `yank-pop'
7329 (let ((inhibit-read-only t)
7330 (before (< (point) (mark t))))
7331 (if before
7332 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7333 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7334 (setq yank-undo-function nil)
7335 (set-marker (mark-marker) (point) (current-buffer))
7336 (insert-for-yank str)
7337 ;; Set the window start back where it was in the yank command,
7338 ;; if possible.
7339 (set-window-start (selected-window) yank-window-start t)
7340 (if before
7341 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7342 ;; It is cleaner to avoid activation, even though the command
7343 ;; loop would deactivate the mark because we inserted text.
7344 (goto-char (prog1 (mark t)
7345 (set-marker (mark-marker) (point) (current-buffer)))))))
7346 (kill-new str))
7348 ;; (anything 'anything-c-source-kill-ring)
7351 ;;;; <Mark ring>
7352 ;; DO NOT include these sources in `anything-sources' use
7353 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7354 ;; `anything-all-mark-rings' instead.
7356 (defun anything-c-source-mark-ring-candidates ()
7357 (flet ((get-marks (pos)
7358 (save-excursion
7359 (goto-char pos)
7360 (beginning-of-line)
7361 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7362 (when (string= "" line)
7363 (setq line "<EMPTY LINE>"))
7364 (format "%7d: %s" (line-number-at-pos) line)))))
7365 (with-anything-current-buffer
7366 (loop
7367 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7368 with recip = nil
7369 for i in marks
7370 for m = (get-marks i)
7371 unless (member m recip)
7372 collect m into recip
7373 finally return recip))))
7375 (defvar anything-mark-ring-cache nil)
7376 (defvar anything-c-source-mark-ring
7377 '((name . "mark-ring")
7378 (init . (lambda ()
7379 (setq anything-mark-ring-cache
7380 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7381 (candidates . (lambda ()
7382 (anything-aif anything-mark-ring-cache
7383 it)))
7384 (action . (("Goto line"
7385 . (lambda (candidate)
7386 (anything-goto-line (string-to-number candidate))))))
7387 (persistent-action . (lambda (candidate)
7388 (anything-goto-line (string-to-number candidate))
7389 (anything-match-line-color-current-line)))
7390 (persistent-help . "Show this line")))
7392 ;; (anything 'anything-c-source-mark-ring)
7394 ;;; Global-mark-ring
7395 (defvar anything-c-source-global-mark-ring
7396 '((name . "global-mark-ring")
7397 (candidates . anything-c-source-global-mark-ring-candidates)
7398 (action . (("Goto line"
7399 . (lambda (candidate)
7400 (let ((items (split-string candidate ":")))
7401 (anything-c-switch-to-buffer (second items))
7402 (anything-goto-line (string-to-number (car items))))))))
7403 (persistent-action . (lambda (candidate)
7404 (let ((items (split-string candidate ":")))
7405 (anything-c-switch-to-buffer (second items))
7406 (anything-goto-line (string-to-number (car items)))
7407 (anything-match-line-color-current-line))))
7408 (persistent-help . "Show this line")))
7410 (defun anything-c-source-global-mark-ring-candidates ()
7411 (flet ((buf-fn (m)
7412 (with-current-buffer (marker-buffer m)
7413 (goto-char m)
7414 (beginning-of-line)
7415 (let (line)
7416 (if (string= "" line)
7417 (setq line "<EMPTY LINE>")
7418 (setq line (car (split-string (thing-at-point 'line)
7419 "[\n\r]"))))
7420 (format "%7d:%s: %s"
7421 (line-number-at-pos) (marker-buffer m) line)))))
7422 (loop
7423 with marks = global-mark-ring
7424 with recip = nil
7425 for i in marks
7426 for gm = (unless (or (string-match
7427 "^ " (format "%s" (marker-buffer i)))
7428 (null (marker-buffer i)))
7429 (buf-fn i))
7430 when (and gm (not (member gm recip)))
7431 collect gm into recip
7432 finally return recip)))
7434 ;; (anything 'anything-c-source-global-mark-ring)
7437 ;;;; <Register>
7438 ;;; Insert from register
7439 (defvar anything-c-source-register
7440 '((name . "Registers")
7441 (candidates . anything-c-register-candidates)
7442 (action-transformer . anything-c-register-action-transformer)
7443 (multiline)
7444 (action))
7445 "See (info \"(emacs)Registers\")")
7447 (defun anything-c-register-candidates ()
7448 "Collecting register contents and appropriate commands."
7449 (loop for (char . val) in register-alist
7450 for key = (single-key-description char)
7451 for string-actions =
7452 (cond
7453 ((numberp val)
7454 (list (int-to-string val)
7455 'insert-register
7456 'increment-register))
7457 ((markerp val)
7458 (let ((buf (marker-buffer val)))
7459 (if (null buf)
7460 (list "a marker in no buffer")
7461 (list (concat
7462 "a buffer position:"
7463 (buffer-name buf)
7464 ", position "
7465 (int-to-string (marker-position val)))
7466 'jump-to-register
7467 'insert-register))))
7468 ((and (consp val) (window-configuration-p (car val)))
7469 (list "window configuration."
7470 'jump-to-register))
7471 ((and (consp val) (frame-configuration-p (car val)))
7472 (list "frame configuration."
7473 'jump-to-register))
7474 ((and (consp val) (eq (car val) 'file))
7475 (list (concat "file:"
7476 (prin1-to-string (cdr val))
7477 ".")
7478 'jump-to-register))
7479 ((and (consp val) (eq (car val) 'file-query))
7480 (list (concat "file:a file-query reference: file "
7481 (car (cdr val))
7482 ", position "
7483 (int-to-string (car (cdr (cdr val))))
7484 ".")
7485 'jump-to-register))
7486 ((consp val)
7487 (let ((lines (format "%4d" (length val))))
7488 (list (format "%s: %s\n" lines
7489 (truncate-string-to-width
7490 (mapconcat 'identity (list (car val))
7491 ;; (mapconcat (lambda (y) y) val
7492 "^J") (- (window-width) 15)))
7493 'insert-register)))
7494 ((stringp val)
7495 (list ;; without properties
7496 (substring-no-properties val)
7497 'insert-register
7498 'append-to-register
7499 'prepend-to-register))
7501 "GARBAGE!"))
7502 collect (cons (format "register %3s: %s" key (car string-actions))
7503 (cons char (cdr string-actions)))))
7505 (defun anything-c-register-action-transformer (actions register-and-functions)
7506 "Decide actions by the contents of register."
7507 (loop with func-actions =
7508 '((insert-register
7509 "Insert Register" .
7510 (lambda (c) (insert-register (car c))))
7511 (jump-to-register
7512 "Jump to Register" .
7513 (lambda (c) (jump-to-register (car c))))
7514 (append-to-register
7515 "Append Region to Register" .
7516 (lambda (c) (append-to-register
7517 (car c) (region-beginning) (region-end))))
7518 (prepend-to-register
7519 "Prepend Region to Register" .
7520 (lambda (c) (prepend-to-register
7521 (car c) (region-beginning) (region-end))))
7522 (increment-register
7523 "Increment Prefix Arg to Register" .
7524 (lambda (c) (increment-register
7525 anything-current-prefix-arg (car c)))))
7526 for func in (cdr register-and-functions)
7527 for cell = (assq func func-actions)
7528 when cell
7529 collect (cdr cell)))
7531 ;; (anything 'anything-c-source-register)
7534 ;;; Latex completion
7535 (defun anything-c-latex-math-candidates ()
7536 "Collect candidates for latex math completion."
7537 (declare (special LaTeX-math-menu))
7538 (loop for i in (cddr LaTeX-math-menu)
7539 for elm = (loop for s in i when (vectorp s)
7540 collect (cons (aref s 0) (aref s 1)))
7541 append elm))
7543 (defvar anything-c-source-latex-math
7544 '((name . "Latex Math Menu")
7545 (init . (lambda ()
7546 (with-anything-current-buffer
7547 (LaTeX-math-mode 1))))
7548 (candidate-number-limit . 9999)
7549 (candidates . anything-c-latex-math-candidates)
7550 (action . (lambda (candidate)
7551 (call-interactively candidate)))))
7554 ;;;; <Headline Extraction>
7555 (defvar anything-c-source-fixme
7556 '((name . "TODO/FIXME/DRY comments")
7557 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7558 (adjust)
7559 (recenter))
7560 "Show TODO/FIXME/DRY comments in current file.")
7561 ;; (anything 'anything-c-source-fixme)
7563 (defvar anything-c-source-rd-headline
7564 '((name . "RD HeadLine")
7565 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7566 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7567 (migemo)
7568 (subexp . 1))
7569 "Show RD headlines.
7571 RD is Ruby's POD.
7572 http://en.wikipedia.org/wiki/Ruby_Document_format")
7573 ;; (anything 'anything-c-source-rd-headline)
7575 (defvar anything-c-source-oddmuse-headline
7576 '((name . "Oddmuse HeadLine")
7577 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7578 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7579 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7580 (migemo)
7581 (subexp . 1))
7582 "Show Oddmuse headlines, such as EmacsWiki.")
7583 ;; (anything 'anything-c-source-oddmuse-headline)
7585 (defvar anything-c-source-emacs-source-defun
7586 '((name . "Emacs Source DEFUN")
7587 (headline . "DEFUN\\|DEFVAR")
7588 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7589 (or buffer-file-name ""))))
7590 "Show DEFUN/DEFVAR in Emacs C source file.")
7591 ;; (anything 'anything-c-source-emacs-source-defun)
7593 (defvar anything-c-source-emacs-lisp-expectations
7594 '((name . "Emacs Lisp Expectations")
7595 (headline . "(desc[ ]\\|(expectations")
7596 (condition . (eq major-mode 'emacs-lisp-mode)))
7597 "Show descriptions (desc) in Emacs Lisp Expectations.
7599 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7600 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7602 (defvar anything-c-source-emacs-lisp-toplevels
7603 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7604 (headline . "^(\\|(@\\*\\|^;;;;")
7605 (get-line . buffer-substring)
7606 (condition . (eq major-mode 'emacs-lisp-mode))
7607 (adjust))
7608 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7609 linkd.el is optional because linkd stars are extracted by regexp.
7610 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7611 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7614 ;;; Anything yaoddmuse
7616 ;; Be sure to have yaoddmuse.el installed
7617 ;; install-elisp may be required if you want to install elisp file from here.
7618 (defvar anything-yaoddmuse-use-cache-file nil)
7619 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7620 (defvar anything-c-yaoddmuse-ew-cache nil)
7622 (defun anything-yaoddmuse-get-candidates ()
7623 (declare (special yaoddmuse-pages-hash))
7624 (if anything-yaoddmuse-use-cache-file
7625 (ignore-errors
7626 (unless anything-c-yaoddmuse-ew-cache
7627 (load anything-c-yaoddmuse-cache-file)
7628 (setq anything-c-yaoddmuse-ew-cache
7629 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7630 anything-c-yaoddmuse-ew-cache)
7631 (yaoddmuse-update-pagename t)
7632 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7634 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7635 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7636 (candidates . anything-yaoddmuse-get-candidates)
7637 (action . (("Edit page" . (lambda (candidate)
7638 (yaoddmuse-edit "EmacsWiki" candidate)))
7639 ("Browse page"
7640 . (lambda (candidate)
7641 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7642 ("Browse page other window"
7643 . (lambda (candidate)
7644 (if (one-window-p)
7645 (split-window-vertically))
7646 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7647 ("Browse diff"
7648 . (lambda (candidate)
7649 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7650 ("Copy URL"
7651 . (lambda (candidate)
7652 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7653 (message "Have copy page %s's URL to yank." candidate)))
7654 ("Create page"
7655 . (lambda (candidate)
7656 (yaoddmuse-edit "EmacsWiki" anything-input)))
7657 ("Update cache"
7658 . (lambda (candidate)
7659 (if anything-yaoddmuse-use-cache-file
7660 (progn
7661 (anything-yaoddmuse-cache-pages t)
7662 (setq anything-c-yaoddmuse-ew-cache
7663 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7664 (yaoddmuse-update-pagename))))))
7665 (action-transformer anything-c-yaoddmuse-action-transformer))
7666 "Needs yaoddmuse.el.
7668 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7670 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7672 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7673 '((name . "Yaoddmuse Post library (EmacsWiki)")
7674 (init . (anything-yaoddmuse-init))
7675 (candidates-in-buffer)
7676 (action . (("Post library and Browse"
7677 . (lambda (candidate)
7678 (yaoddmuse-post-file
7679 (find-library-name candidate)
7680 "EmacsWiki"
7681 (file-name-nondirectory (find-library-name candidate))
7682 nil t)))
7683 ("Post library"
7684 . (lambda (candidate)
7685 (yaoddmuse-post-file
7686 (find-library-name candidate)
7687 "EmacsWiki"
7688 (file-name-nondirectory
7689 (find-library-name candidate))))))))
7690 "Needs yaoddmuse.el.
7692 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7694 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7696 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7697 "Allow the use of `install-elisp' only on elisp files."
7698 (if (string-match "\.el$" candidate)
7699 (append actions '(("Install Elisp"
7700 . (lambda (elm)
7701 (install-elisp-from-emacswiki elm)))))
7702 actions))
7704 ;;;###autoload
7705 (defun anything-yaoddmuse-cache-pages (&optional load)
7706 "Fetch the list of files on emacswiki and create cache file.
7707 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7708 (interactive)
7709 (declare (special yaoddmuse-pages-hash))
7710 (yaoddmuse-update-pagename)
7711 (save-excursion
7712 (find-file anything-c-yaoddmuse-cache-file)
7713 (erase-buffer)
7714 (insert "(puthash \"EmacsWiki\" '(")
7715 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7717 (insert (concat "(\"" (car i) "\") ")))
7718 (insert ") yaoddmuse-pages-hash)\n")
7719 (save-buffer)
7720 (kill-buffer (current-buffer))
7721 (when (or current-prefix-arg
7722 load)
7723 (load anything-c-yaoddmuse-cache-file))))
7725 (defun anything-yaoddmuse-init ()
7726 "Init anything buffer status."
7727 (let ((anything-buffer (anything-candidate-buffer 'global))
7728 (library-list (yaoddmuse-get-library-list)))
7729 (with-current-buffer anything-buffer
7730 ;; Insert library name.
7731 (dolist (library library-list)
7732 (insert (format "%s\n" library)))
7733 ;; Sort lines.
7734 (sort-lines nil (point-min) (point-max)))))
7737 ;;; Eev anchors
7738 (defvar anything-c-source-eev-anchor
7739 '((name . "Anchors")
7740 (candidates
7741 . (lambda ()
7742 (ignore-errors
7743 (with-anything-current-buffer
7744 (loop initially (goto-char (point-min))
7745 while (re-search-forward
7746 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7747 for anchor = (match-string-no-properties 1)
7748 collect (cons (format "%5d:%s"
7749 (line-number-at-pos (match-beginning 0))
7750 (format ee-anchor-format anchor))
7751 anchor))))))
7752 (persistent-action . (lambda (item)
7753 (ee-to item)
7754 (anything-match-line-color-current-line)))
7755 (persistent-help . "Show this entry")
7756 (action . (("Goto link" . ee-to)))))
7757 ;; (anything 'anything-c-source-eev-anchor)
7760 ;;; Org headlines
7763 (defvar anything-c-source-org-headline
7764 `((name . "Org HeadLine")
7765 (headline
7766 ,@(mapcar
7767 (lambda (num)
7768 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7769 num))
7770 (number-sequence 1 8)))
7771 (condition . (eq major-mode 'org-mode))
7772 (migemo)
7773 (subexp . 1)
7774 (persistent-action . (lambda (elm)
7775 (anything-c-action-line-goto elm)
7776 (org-cycle)))
7777 (action-transformer
7778 . (lambda (actions candidate)
7779 '(("Go to Line" . anything-c-action-line-goto)
7780 ("Refile to this Headline" . anything-c-org-headline-refile)
7781 ("Insert Link to This Headline"
7782 . anything-c-org-headline-insert-link-to-headline)))))
7783 "Show Org headlines.
7784 org-mode is very very much extended text-mode/outline-mode.
7786 See (find-library \"org.el\")
7787 See http://orgmode.org for the latest version.")
7788 ;; (anything 'anything-c-source-org-headline)
7790 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7791 (insert
7792 (save-excursion
7793 (anything-goto-line (car lineno-and-content))
7794 (and (looking-at org-complex-heading-regexp)
7795 (org-make-link-string (concat "*" (match-string 4)))))))
7797 (defun anything-c-org-headline-refile (lineno-and-content)
7798 "Refile current org entry to LINENO-AND-CONTENT."
7799 (with-anything-current-buffer
7800 (org-cut-subtree)
7801 (anything-goto-line (car lineno-and-content))
7802 (org-end-of-subtree t t)
7803 (let ((org-yank-adjusted-subtrees t))
7804 (org-yank))))
7807 ;;; Org keywords
7810 (defvar anything-c-source-org-keywords
7811 '((name . "Org Keywords")
7812 (init . anything-c-org-keywords-init)
7813 (candidates . anything-c-org-keywords-candidates)
7814 (action . anything-c-org-keywords-insert)
7815 (persistent-action . anything-c-org-keywords-show-help)
7816 (persistent-help . "Show an example and info page to describe this keyword.")
7817 (keywords-examples)
7818 (keywords)))
7819 ;; (anything 'anything-c-source-org-keywords)
7821 (defvar anything-c-org-keywords-info-location
7822 '(("#+TITLE:" . "(org)Export options")
7823 ("#+AUTHOR:" . "(org)Export options")
7824 ("#+DATE:" . "(org)Export options")
7825 ("#+EMAIL:" . "(org)Export options")
7826 ("#+DESCRIPTION:" . "(org)Export options")
7827 ("#+KEYWORDS:" . "(org)Export options")
7828 ("#+LANGUAGE:" . "(org)Export options")
7829 ("#+TEXT:" . "(org)Export options")
7830 ("#+TEXT:" . "(org)Export options")
7831 ("#+OPTIONS:" . "(org)Export options")
7832 ("#+BIND:" . "(org)Export options")
7833 ("#+LINK_UP:" . "(org)Export options")
7834 ("#+LINK_HOME:" . "(org)Export options")
7835 ("#+LATEX_HEADER:" . "(org)Export options")
7836 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7837 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7838 ("#+INFOJS_OPT" . "(org)Javascript support")
7839 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7840 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7841 ("#+ORGTBL" . "(org)Radio tables")
7842 ("#+HTML:" . "(org)Quoting HTML tags")
7843 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7844 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7845 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7846 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7847 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7848 ("#+BEGIN_SRC" . "(org)Literal examples")
7849 ("#+CAPTION" . "(org)Tables in HTML export")
7850 ("#+LABEL" . "(org)Tables in LaTeX export")
7851 ("#+ATTR_HTML" . "(org)Links")
7852 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7854 (defun anything-c-org-keywords-init ()
7855 (unless (anything-attr 'keywords-examples)
7856 (require 'org)
7857 (anything-attrset 'keywords-examples
7858 (append
7859 (mapcar
7860 (lambda (x)
7861 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7862 (cons (match-string 2 x) (match-string 1 x)))
7863 (org-split-string (org-get-current-options) "\n"))
7864 (mapcar 'list org-additional-option-like-keywords)))
7865 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7867 (defun anything-c-org-keywords-candidates ()
7868 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7869 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7870 (anything-attr 'keywords)))
7872 (defun anything-c-org-keywords-insert (keyword)
7873 (cond ((and (string-match "BEGIN" keyword)
7874 (anything-region-active-p))
7875 (let ((beg (region-beginning))
7876 (end (region-end)))
7877 (goto-char end)
7878 (insert "\n#+" (replace-regexp-in-string
7879 "BEGIN" "END" keyword) "\n")
7880 (goto-char beg)
7881 (insert "#+" keyword " ")
7882 (save-excursion (insert "\n"))))
7883 ((string-match "BEGIN" keyword)
7884 (insert "#+" keyword " ")
7885 (save-excursion
7886 (insert "\n#+" (replace-regexp-in-string
7887 "BEGIN" "END" keyword) "\n")))
7888 (t (insert "#+" keyword " "))))
7890 (defun anything-c-org-keywords-show-help (keyword)
7891 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7892 "(org)In-buffer settings"))
7893 (search-forward (concat "#+" keyword) nil t)
7894 (anything-persistent-highlight-point)
7895 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7899 ;;; bbdb
7902 (defvar bbdb-records)
7903 (defvar bbdb-buffer-name)
7905 (defun anything-c-bbdb-candidates ()
7906 "Return a list of all names in the bbdb database. The format
7907 is \"Firstname Lastname\"."
7908 (mapcar (lambda (bbdb-record)
7909 (replace-regexp-in-string
7910 "\\s-+$" ""
7911 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7912 (bbdb-records)))
7914 (defun anything-c-bbdb-create-contact (actions candidate)
7915 "Action transformer that returns only an entry to add the
7916 current `anything-pattern' as new contact. All other actions are
7917 removed."
7918 (if (string= candidate "*Add to contacts*")
7919 '(("Add to contacts" . (lambda (actions)
7920 (bbdb-create-internal
7921 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7922 (read-from-minibuffer "Company: ")
7923 (read-from-minibuffer "Email: ")
7926 (read-from-minibuffer "Note: ")))))
7927 actions))
7929 (defun anything-c-bbdb-get-record (candidate)
7930 "Return record that match CANDIDATE."
7931 (bbdb candidate nil)
7932 (set-buffer "*BBDB*")
7933 (bbdb-current-record))
7935 (defvar anything-c-bbdb-name nil
7936 "Only for internal use.")
7938 (defvar anything-c-source-bbdb
7939 '((name . "BBDB")
7940 (candidates . anything-c-bbdb-candidates)
7941 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7942 ("View person's data" . anything-c-bbdb-view-person-action))
7943 (filtered-candidate-transformer . (lambda (candidates source)
7944 (setq anything-c-bbdb-name anything-pattern)
7945 (if (not candidates)
7946 (list "*Add to contacts*")
7947 candidates)))
7948 (action-transformer . (lambda (actions candidate)
7949 (anything-c-bbdb-create-contact actions candidate))))
7950 "Needs BBDB.
7952 http://bbdb.sourceforge.net/")
7953 ;; (anything 'anything-c-source-bbdb)
7955 (defun anything-c-bbdb-view-person-action (candidate)
7956 "View BBDB data of single CANDIDATE or marked candidates."
7957 (anything-aif (anything-marked-candidates)
7958 (let ((bbdb-append-records (length it)))
7959 (dolist (i it)
7960 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7961 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7963 (defun anything-c-bbdb-collect-mail-addresses ()
7964 "Return a list of all mail addresses of records in bbdb buffer."
7965 (with-current-buffer bbdb-buffer-name
7966 (loop for i in bbdb-records
7967 if (bbdb-record-net (car i))
7968 collect (bbdb-dwim-net-address (car i)))))
7970 (defun anything-c-bbdb-compose-mail (candidate)
7971 "Compose a mail with all records of bbdb buffer."
7972 (anything-c-bbdb-view-person-action candidate)
7973 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7974 (address-str (mapconcat 'identity address-list ",\n ")))
7975 (compose-mail address-str)))
7978 ;;; Evaluation Result
7981 ;; Internal
7982 (defvar anything-eldoc-active-minibuffers-list nil)
7984 (defvar anything-c-source-evaluation-result
7985 '((name . "Evaluation Result")
7986 (disable-shortcuts)
7987 (dummy)
7988 (multiline)
7989 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7990 (filtered-candidate-transformer . (lambda (candidates source)
7991 (list
7992 (condition-case nil
7993 (with-anything-current-buffer
7994 (pp-to-string
7995 (eval (read anything-pattern))))
7996 (error "Error")))))
7997 (action . (("Copy result to kill-ring" . (lambda (candidate)
7998 (with-current-buffer anything-buffer
7999 (let ((end (save-excursion
8000 (goto-char (point-max))
8001 (search-backward "\n")
8002 (point))))
8003 (kill-region (point) end)))))
8004 ("copy sexp to kill-ring" . (lambda (candidate)
8005 (kill-new anything-input)))))))
8006 ;; (anything 'anything-c-source-evaluation-result)
8008 (defun anything-eval-new-line-and-indent ()
8009 (interactive)
8010 (newline) (lisp-indent-line))
8012 (defun anything-eldoc-store-minibuffer ()
8013 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8014 (with-selected-window (minibuffer-window)
8015 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8017 (defun anything-eldoc-show-in-eval ()
8018 "Return eldoc in mode-line for current minibuffer input."
8019 (let ((buf (with-selected-window (minibuffer-window)
8020 (buffer-name))))
8021 (when (member buf anything-eldoc-active-minibuffers-list)
8022 (let* ((str-all (with-current-buffer buf
8023 (minibuffer-completion-contents)))
8024 (sym (when str-all
8025 (with-temp-buffer
8026 (insert str-all)
8027 (goto-char (point-max))
8028 (unless (looking-back ")\\|\"") (forward-char -1))
8029 (eldoc-current-symbol))))
8030 (info-fn (eldoc-fnsym-in-current-sexp))
8031 (doc (or (eldoc-get-var-docstring sym)
8032 (eldoc-get-fnsym-args-string
8033 (car info-fn) (cadr info-fn)))))
8034 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8036 (defun anything-c-eldoc-show-in-mode-line (str)
8037 "Show string STR in mode-line."
8038 (save-window-excursion
8039 (with-current-buffer anything-buffer
8040 (let ((mode-line-format (concat " " str)))
8041 (force-mode-line-update)
8042 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8043 (force-mode-line-update))))
8045 ;;; Calculation Result
8048 (defvar anything-c-source-calculation-result
8049 '((name . "Calculation Result")
8050 (dummy)
8051 (filtered-candidate-transformer . (lambda (candidates source)
8052 (list
8053 (condition-case nil
8054 (calc-eval anything-pattern)
8055 (error "error")))))
8056 (action ("Copy result to kill-ring" . kill-new))))
8057 ;; (anything 'anything-c-source-calculation-result)
8060 ;;; Google Suggestions
8063 ;; Internal
8064 (defvar anything-ggs-max-length-real-flag 0)
8065 (defvar anything-ggs-max-length-num-flag 0)
8067 (defun anything-c-google-suggest-fetch (input)
8068 "Fetch suggestions for INPUT from XML buffer.
8069 Return an alist with elements like (data . number_results)."
8070 (setq anything-ggs-max-length-real-flag 0
8071 anything-ggs-max-length-num-flag 0)
8072 (let ((request (concat anything-c-google-suggest-url
8073 (url-hexify-string input))))
8074 (flet ((fetch ()
8075 (loop
8076 with result-alist = (xml-get-children
8077 (car (xml-parse-region
8078 (point-min) (point-max)))
8079 'CompleteSuggestion)
8080 for i in result-alist
8081 for data = (cdr (caadr (assoc 'suggestion i)))
8082 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8083 for lqueries = (length (anything-c-ggs-set-number-result
8084 nqueries))
8085 for ldata = (length data)
8087 (progn
8088 (when (> ldata anything-ggs-max-length-real-flag)
8089 (setq anything-ggs-max-length-real-flag ldata))
8090 (when (> lqueries anything-ggs-max-length-num-flag)
8091 (setq anything-ggs-max-length-num-flag lqueries)))
8092 collect (cons data nqueries) into cont
8093 finally return cont)))
8094 (if anything-google-suggest-use-curl-p
8095 (with-temp-buffer
8096 (call-process "curl" nil t nil request)
8097 (fetch))
8098 (with-current-buffer
8099 (url-retrieve-synchronously request)
8100 (fetch))))))
8102 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8103 "Set candidates with result and number of google results found."
8104 (let ((suggestions
8105 (loop with suggested-results = (anything-c-google-suggest-fetch
8106 (or (and request-prefix
8107 (concat request-prefix " " anything-pattern))
8108 anything-pattern))
8109 for (real . numresult) in suggested-results
8110 ;; Prepare number of results with ","
8111 for fnumresult = (anything-c-ggs-set-number-result numresult)
8112 ;; Calculate number of spaces to add before fnumresult
8113 ;; if it is smaller than longest result
8114 ;; `anything-ggs-max-length-num-flag'.
8115 ;; e.g 1,234,567
8116 ;; 345,678
8117 ;; To be sure it is aligned properly.
8118 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8119 (- anything-ggs-max-length-num-flag (length fnumresult))
8121 ;; Add now the spaces before fnumresult.
8122 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8123 for interval = (- anything-ggs-max-length-real-flag (length real))
8124 for spaces = (make-string (+ 2 interval) ? )
8125 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8126 collect (cons display real))))
8127 (if (loop for (disp . dat) in suggestions
8128 thereis (equal dat anything-pattern))
8129 suggestions
8130 ;; if there is no suggestion exactly matching the input then
8131 ;; prepend a Search on Google item to the list
8132 (append
8133 suggestions
8134 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8135 anything-input))))))
8137 (defun anything-c-ggs-set-number-result (num)
8138 (if num
8139 (progn
8140 (and (numberp num) (setq num (number-to-string num)))
8141 (loop for i in (reverse (split-string num "" t))
8142 for count from 1
8143 append (list i) into C
8144 when (= count 3)
8145 append (list ",") into C
8146 and do (setq count 0)
8147 finally return
8148 (replace-regexp-in-string
8149 "^," "" (mapconcat 'identity (reverse C) ""))))
8150 "?"))
8152 (defvar anything-c-google-suggest-default-browser-function nil
8153 "*The browse url function you prefer to use with google suggest.
8154 When nil, use the first browser function available
8155 See `anything-browse-url-default-browser-alist'.")
8157 (defun anything-c-google-suggest-action (candidate)
8158 "Default action to jump to a google suggested candidate."
8159 (let ((arg (concat anything-c-google-suggest-search-url
8160 (url-hexify-string candidate))))
8161 (anything-aif anything-c-google-suggest-default-browser-function
8162 (funcall it arg)
8163 (anything-c-browse-url arg))))
8165 (defvar anything-c-google-suggest-default-function
8166 'anything-c-google-suggest-set-candidates
8167 "Default function to use in anything google suggest.")
8169 (defvar anything-c-source-google-suggest
8170 '((name . "Google Suggest")
8171 (candidates . (lambda ()
8172 (funcall anything-c-google-suggest-default-function)))
8173 (action . (("Google Search" . anything-c-google-suggest-action)))
8174 (volatile)
8175 (requires-pattern . 3)
8176 (delayed)))
8178 (defun anything-c-google-suggest-emacs-lisp ()
8179 "Try to emacs lisp complete with google suggestions."
8180 (anything-c-google-suggest-set-candidates "emacs lisp"))
8182 ;; (anything 'anything-c-source-google-suggest)
8184 ;;; Yahoo suggestions
8187 (defun anything-c-yahoo-suggest-fetch (input)
8188 "Fetch Yahoo suggestions for INPUT from XML buffer.
8189 Return an alist with elements like (data . number_results)."
8190 (let ((request (concat anything-c-yahoo-suggest-url
8191 (url-hexify-string input))))
8192 (flet ((fetch ()
8193 (loop
8194 with result-alist = (xml-get-children
8195 (car (xml-parse-region (point-min) (point-max)))
8196 'Result)
8197 for i in result-alist
8198 collect (caddr i))))
8199 (with-current-buffer
8200 (url-retrieve-synchronously request)
8201 (fetch)))))
8203 (defun anything-c-yahoo-suggest-set-candidates ()
8204 "Set candidates with Yahoo results found."
8205 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8206 (or suggestions
8207 (append
8208 suggestions
8209 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8210 anything-input))))))
8212 (defun anything-c-yahoo-suggest-action (candidate)
8213 "Default action to jump to a Yahoo suggested candidate."
8214 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8215 (url-hexify-string candidate))))
8217 (defvar anything-c-source-yahoo-suggest
8218 '((name . "Yahoo Suggest")
8219 (candidates . anything-c-yahoo-suggest-set-candidates)
8220 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8221 (volatile)
8222 (requires-pattern . 3)
8223 (delayed)))
8225 ;; (anything 'anything-c-source-yahoo-suggest)
8228 ;;; Web browser functions.
8231 (require 'browse-url)
8232 ;; If default setting of `w3m-command' is not
8233 ;; what you want you and you modify it, you will have to reeval
8234 ;; also `anything-browse-url-default-browser-alist'.
8235 (defvar w3m-command "/usr/bin/w3m")
8236 (defvar anything-c-home-url "http://www.google.fr"
8237 "*Default url to use as home url.")
8239 (defvar ac-browse-url-chromium-program "chromium-browser")
8240 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8241 (defvar anything-browse-url-default-browser-alist
8242 `((,w3m-command . w3m-browse-url)
8243 (,browse-url-firefox-program . browse-url-firefox)
8244 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8245 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8246 (,browse-url-kde-program . browse-url-kde)
8247 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8248 (,browse-url-mozilla-program . browse-url-mozilla)
8249 (,browse-url-galeon-program . browse-url-galeon)
8250 (,browse-url-netscape-program . browse-url-netscape)
8251 (,browse-url-mosaic-program . browse-url-mosaic)
8252 (,browse-url-xterm-program . browse-url-text-xterm))
8253 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8255 (defun* anything-c-generic-browser (url name &rest args)
8256 "Browse URL with NAME browser."
8257 (let ((proc (concat name " " url)))
8258 (message "Starting %s..." name)
8259 (apply 'start-process proc nil name
8260 (append args (list url)))
8261 (set-process-sentinel
8262 (get-process proc)
8263 #'(lambda (process event)
8264 (when (string= event "finished\n")
8265 (message "%s process %s" process event))))))
8267 (defun ac-browse-url-chromium (url)
8268 "Browse URL with google chrome browser."
8269 (interactive "sURL: ")
8270 (anything-c-generic-browser
8271 url ac-browse-url-chromium-program))
8273 (defun ac-browse-url-uzbl (url &optional ignore)
8274 "Browse URL with uzbl browser."
8275 (interactive "sURL: ")
8276 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8278 (defun anything-browse-url-default-browser (url &rest args)
8279 "Find the first available browser and ask it to load URL."
8280 (let ((default-browser-fn
8281 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8282 thereis (and exe (executable-find exe) fn))))
8283 (if default-browser-fn
8284 (apply default-browser-fn url args)
8285 (error "No usable browser found"))))
8287 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8288 "Default command to browse URL."
8289 (if browse-url-browser-function
8290 (browse-url url)
8291 (anything-browse-url-default-browser url)))
8294 ;;; Surfraw
8296 ;; Need external program surfraw.
8297 ;; <http://surfraw.alioth.debian.org/>
8299 (defvar anything-surfraw-default-browser-function nil
8300 "*The browse url function you prefer to use with surfraw.
8301 When nil, fallback to `browse-url-browser-function'.")
8303 ;; Internal
8304 (defvar anything-surfraw-engines-history nil)
8306 (defun anything-c-build-elvi-list ()
8307 "Return list of all engines and descriptions handled by surfraw."
8308 (cdr
8309 (with-temp-buffer
8310 (call-process "surfraw" nil t nil
8311 "-elvi")
8312 (split-string (buffer-string) "\n"))))
8315 ;;; Emms
8318 (defun anything-emms-stream-edit-bookmark (elm)
8319 "Change the information of current emms-stream bookmark from anything."
8320 (declare (special emms-stream-list))
8321 (let* ((cur-buf anything-current-buffer)
8322 (bookmark (assoc elm emms-stream-list))
8323 (name (read-from-minibuffer "Description: "
8324 (nth 0 bookmark)))
8325 (url (read-from-minibuffer "URL: "
8326 (nth 1 bookmark)))
8327 (fd (read-from-minibuffer "Feed Descriptor: "
8328 (int-to-string (nth 2 bookmark))))
8329 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8330 (format "%s" (car (last bookmark))))))
8331 (save-excursion
8332 (emms-streams)
8333 (when (re-search-forward (concat "^" name) nil t)
8334 (beginning-of-line)
8335 (emms-stream-delete-bookmark)
8336 (emms-stream-add-bookmark name url (string-to-number fd) type)
8337 (emms-stream-save-bookmarks-file)
8338 (emms-stream-quit)
8339 (anything-c-switch-to-buffer cur-buf)))))
8341 (defun anything-emms-stream-delete-bookmark (elm)
8342 "Delete an emms-stream bookmark from anything."
8343 (let* ((cur-buf anything-current-buffer)
8344 (bookmark (assoc elm emms-stream-list))
8345 (name (nth 0 bookmark)))
8346 (save-excursion
8347 (emms-streams)
8348 (when (re-search-forward (concat "^" name) nil t)
8349 (beginning-of-line)
8350 (emms-stream-delete-bookmark)
8351 (emms-stream-save-bookmarks-file)
8352 (emms-stream-quit)
8353 (anything-c-switch-to-buffer cur-buf)))))
8355 (defvar anything-c-source-emms-streams
8356 '((name . "Emms Streams")
8357 (init . (lambda ()
8358 (emms-stream-init)))
8359 (candidates . (lambda ()
8360 (declare (special emms-stream-list))
8361 (mapcar 'car emms-stream-list)))
8362 (action . (("Play" . (lambda (elm)
8363 (declare (special emms-stream-list))
8364 (let* ((stream (assoc elm emms-stream-list))
8365 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8366 (url (second stream)))
8367 (funcall fn url))))
8368 ("Delete" . anything-emms-stream-delete-bookmark)
8369 ("Edit" . anything-emms-stream-edit-bookmark)))
8370 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8371 ;; (anything 'anything-c-source-emms-streams)
8373 ;; Don't forget to set `emms-source-file-default-directory'
8374 (defvar anything-c-source-emms-dired
8375 '((name . "Music Directory")
8376 (candidates . (lambda ()
8377 (cddr (directory-files emms-source-file-default-directory))))
8378 (action .
8379 (("Play Directory" . (lambda (item)
8380 (emms-play-directory
8381 (expand-file-name
8382 item
8383 emms-source-file-default-directory))))
8384 ("Open dired in file's directory" . (lambda (item)
8385 (anything-c-open-dired
8386 (expand-file-name
8387 item
8388 emms-source-file-default-directory))))))
8389 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8390 ;; (anything 'anything-c-source-emms-dired)
8393 (defun anything-c-emms-files-modifier (candidates source)
8394 (let ((current-playlist (with-current-emms-playlist
8395 (loop
8396 with cur-list = (emms-playlist-tracks-in-region
8397 (point-min) (point-max))
8398 for i in cur-list
8399 collect (assoc-default 'name i)))))
8400 (loop for i in candidates
8401 if (member (cdr i) current-playlist)
8402 collect (cons (propertize (car i)
8403 'face 'anything-emms-playlist)
8404 (cdr i)) into lis
8405 else collect i into lis
8406 finally return lis)))
8408 (defun anything-c-emms-play-current-playlist ()
8409 "Play current playlist."
8410 (with-current-emms-playlist
8411 (emms-playlist-first)
8412 (emms-playlist-mode-play-smart)))
8414 (defvar anything-c-source-emms-files
8415 '((name . "Emms files")
8416 (candidates . (lambda ()
8417 (loop for v being the hash-values in emms-cache-db
8418 for name = (assoc-default 'name v)
8419 for artist = (or (assoc-default 'info-artist v) "unknown")
8420 for genre = (or (assoc-default 'info-genre v) "unknown")
8421 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8422 for song = (or (assoc-default 'info-title v) "unknown")
8423 for info = (concat artist " - " genre " - " tracknum ": " song)
8424 unless (string-match "^http:" name) collect (cons info name))))
8425 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8426 (action . (("Play file" . emms-play-file)
8427 ("Add to Playlist and play (C-u clear current)"
8428 . (lambda (candidate)
8429 (when anything-current-prefix-arg
8430 (emms-playlist-current-clear))
8431 (emms-playlist-new)
8432 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8433 (unless emms-player-playing-p
8434 (anything-c-emms-play-current-playlist))))))))
8436 ;; (anything 'anything-c-source-emms-files)
8439 ;;; Jabber Contacts (jabber.el)
8440 (defun anything-c-jabber-online-contacts ()
8441 "List online Jabber contacts."
8442 (with-no-warnings
8443 (let (jids)
8444 (dolist (item (jabber-concat-rosters) jids)
8445 (when (get item 'connected)
8446 (push (if (get item 'name)
8447 (cons (get item 'name) item)
8448 (cons (symbol-name item) item)) jids))))))
8450 (defvar anything-c-source-jabber-contacts
8451 '((name . "Jabber Contacts")
8452 (init . (lambda () (require 'jabber)))
8453 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8454 (action . (lambda (x)
8455 (jabber-chat-with
8456 (jabber-read-account)
8457 (symbol-name
8458 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8459 ;; (anything 'anything-c-source-jabber-contacts)
8463 ;;; Call source.
8464 (defvar anything-source-select-buffer "*anything source select*")
8465 (defvar anything-c-source-call-source
8466 `((name . "Call anything source")
8467 (candidate-number-limit)
8468 (candidates
8469 . (lambda ()
8470 (loop for vname in (all-completions "anything-c-source-" obarray)
8471 for var = (intern vname)
8472 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8473 if name collect
8474 (cons (format "%s `%s'"
8475 name (propertize vname 'face 'font-lock-variable-name-face))
8476 var))))
8477 (action
8478 . (("Invoke anything with selected source"
8480 (lambda (candidate)
8481 (setq anything-candidate-number-limit 9999)
8482 (anything candidate nil nil nil nil
8483 anything-source-select-buffer)))
8484 ("Describe variable" . describe-variable)
8485 ("Find variable" . find-variable)))
8486 (persistent-action . describe-variable)
8487 (persistent-help . "Show description of this source")))
8488 ;; (anything 'anything-c-source-call-source)
8490 (defun anything-call-source-from-anything ()
8491 "Call anything source within `anything' session."
8492 (interactive)
8493 (setq anything-input-idle-delay 0)
8494 (anything-set-sources '(anything-c-source-call-source)))
8496 ;;; Execute Preconfigured anything.
8497 (defvar anything-c-source-anything-commands
8498 '((name . "Preconfigured Anything")
8499 (candidates . anything-c-anything-commands-candidates)
8500 (type . command)
8501 (candidate-number-limit)))
8502 ;; (anything 'anything-c-source-anything-commands)
8504 (defun anything-c-anything-commands-candidates ()
8505 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8506 collect (cons (if (where-is-internal cmd nil t)
8507 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8508 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8509 cmd)))
8512 ;;; Occur
8515 (defun anything-c-occur-init ()
8516 "Create the initial anything occur buffer.
8517 If region is active use region as buffer contents
8518 instead of whole buffer."
8519 (with-current-buffer (anything-candidate-buffer 'global)
8520 (erase-buffer)
8521 (let ((buf-contents
8522 (with-anything-current-buffer
8523 (if (anything-region-active-p)
8524 (buffer-substring (region-beginning) (region-end))
8525 (buffer-substring (point-min) (point-max))))))
8526 (insert buf-contents))))
8528 (defun anything-c-occur-get-line (s e)
8529 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8531 (defun anything-c-occur-query-replace-regexp (candidate)
8532 "Query replace regexp starting from CANDIDATE.
8533 If region is active ignore CANDIDATE and replace only in region.
8534 With a prefix arg replace only matches surrounded by word boundaries,
8535 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8536 (let ((regexp anything-input))
8537 (unless (anything-region-active-p)
8538 (anything-c-action-line-goto candidate))
8539 (apply 'query-replace-regexp
8540 (anything-c-query-replace-args regexp))))
8542 (defvar anything-c-source-occur
8543 '((name . "Occur")
8544 (init . anything-c-occur-init)
8545 (candidates-in-buffer)
8546 (migemo)
8547 (get-line . anything-c-occur-get-line)
8548 (display-to-real . anything-c-display-to-real-line)
8549 (action . (("Go to Line" . anything-c-action-line-goto)
8550 ("Query replace regexp (C-u Not inside word.)"
8551 . anything-c-occur-query-replace-regexp)))
8552 (recenter)
8553 (requires-pattern . 1)
8554 (delayed)
8555 (volatile)))
8556 ;; (anything 'anything-c-source-occur)
8559 ;;; Anything browse code.
8560 (defun anything-c-browse-code-get-line (beg end)
8561 "Select line if it match the regexp corresponding to current `major-mode'.
8562 Line is parsed for BEG position to END position."
8563 (let ((str-line (buffer-substring beg end))
8564 (regexp (assoc-default major-mode
8565 anything-c-browse-code-regexp-alist))
8566 (num-line (if (string= anything-pattern "") beg (1- beg))))
8567 (when (and regexp (string-match regexp str-line))
8568 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8571 (defvar anything-c-source-browse-code
8572 '((name . "Browse code")
8573 (init . (lambda ()
8574 (anything-candidate-buffer anything-current-buffer)
8575 (with-anything-current-buffer
8576 (jit-lock-fontify-now))))
8577 (candidate-number-limit . 9999)
8578 (candidates-in-buffer)
8579 (get-line . anything-c-browse-code-get-line)
8580 (type . line)
8581 (recenter)))
8584 ;; Do many actions for input
8585 (defvar anything-c-source-create
8586 '((name . "Create")
8587 (dummy)
8588 (action)
8589 (action-transformer . anything-create--actions))
8590 "Do many create actions from `anything-pattern'.
8591 See also `anything-create--actions'.")
8592 ;; (anything 'anything-c-source-create)
8594 (defun anything-create-from-anything ()
8595 "Run `anything-create' from `anything' as a fallback."
8596 (interactive)
8597 (anything-run-after-quit 'anything-create nil anything-pattern))
8599 (defun anything-create--actions (&rest ignored)
8600 "Default actions for `anything-create' / `anything-c-source-create'."
8601 (remove-if-not
8602 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8603 (append anything-create--actions-private
8604 '(("find-file" . find-file)
8605 ("find-file other window" . find-file-other-window)
8606 ("New buffer" . anything-c-switch-to-buffer)
8607 ("New buffer other window" . switch-to-buffer-other-window)
8608 ("Bookmark Set" . bookmark-set)
8609 ("Set Register" .
8610 (lambda (x) (set-register (read-char "Register: ") x)))
8611 ("Insert Linkd star" . linkd-insert-star)
8612 ("Insert Linkd Tag" . linkd-insert-tag)
8613 ("Insert Linkd Link" . linkd-insert-link)
8614 ("Insert Linkd Lisp" . linkd-insert-lisp)
8615 ("Insert Linkd Wiki" . linkd-insert-wiki)
8616 ("Google Search" . google)))))
8619 ;; Minibuffer History
8622 (defvar anything-c-source-minibuffer-history
8623 '((name . "Minibuffer History")
8624 (header-name . (lambda (name)
8625 (format "%s (%s)" name minibuffer-history-variable)))
8626 (candidates
8627 . (lambda ()
8628 (let ((history (loop
8629 for i in (symbol-value minibuffer-history-variable)
8630 unless (string= "" i) collect i)))
8631 (if (consp (car history))
8632 (mapcar 'prin1-to-string history)
8633 history))))
8634 (migemo)
8635 (action . insert)))
8636 ;; (anything 'anything-c-source-minibuffer-history)
8639 ;;; Elscreen
8642 (defvar anything-c-source-elscreen
8643 '((name . "Elscreen")
8644 (candidates . (lambda ()
8645 (if (cdr (elscreen-get-screen-to-name-alist))
8646 (sort
8647 (loop for sname in (elscreen-get-screen-to-name-alist)
8648 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8649 finally (return lst))
8650 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8651 (action . (("Change Screen".
8652 (lambda (candidate)
8653 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8654 ("Kill Screen(s)".
8655 (lambda (candidate)
8656 (dolist (i (anything-marked-candidates))
8657 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8658 (elscreen-kill))))
8659 ("Only Screen".
8660 (lambda (candidate)
8661 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8662 (elscreen-kill-others)))))))
8663 ;; (anything 'anything-c-source-elscreen)
8666 ;;;; <System>
8668 ;;; Top (process)
8669 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8670 "Top command (batch mode). %s is replaced with `frame-width'.")
8671 (defvar anything-c-source-top
8672 '((name . "Top (Press C-c C-u to refresh)")
8673 (init . anything-c-top-init)
8674 (candidates-in-buffer)
8675 (display-to-real . anything-c-top-display-to-real)
8676 (update . anything-c-top-update)
8677 (persistent-action . anything-c-top-sh-persistent-action)
8678 (persistent-help . "SIGTERM")
8679 (action
8680 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8681 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8682 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8683 ;; (anything 'anything-c-source-top)
8685 (defun anything-c-top-sh (cmd)
8686 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8688 (defun anything-c-top-sh-persistent-action (pid)
8689 (delete-other-windows)
8690 (anything-c-top-sh (format "kill -TERM %s" pid))
8691 (anything-force-update))
8693 (defun anything-c-top-init ()
8694 (with-current-buffer (anything-candidate-buffer 'global)
8695 (call-process-shell-command
8696 (format anything-c-top-command
8697 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8698 nil (current-buffer))))
8700 (defun anything-c-top-display-to-real (line)
8701 (car (split-string line)))
8703 (defun anything-c-top-update ()
8704 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8705 (anything-c-top-init)))
8707 ;;; Timers
8708 (defvar anything-c-source-absolute-time-timers
8709 '((name . "Absolute Time Timers")
8710 (candidates . timer-list)
8711 (type . timer)))
8712 ;; (anything 'anything-c-source-absolute-time-timers)
8714 (defvar anything-c-source-idle-time-timers
8715 '((name . "Idle Time Timers")
8716 (candidates . timer-idle-list)
8717 (type . timer)))
8718 ;; (anything 'anything-c-source-idle-time-timers)
8720 (defun anything-c-timer-real-to-display (timer)
8721 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8722 (append timer nil) ;use `append' to convert vector->list
8723 (format "%s repeat=%5S %s(%s)"
8724 (let ((time (list t1 t2 t3)))
8725 (if idle-delay
8726 (format-time-string "idle-for=%5s" time)
8727 (format-time-string "%m/%d %T" time)))
8728 repeat-delay
8729 func
8730 (mapconcat 'prin1-to-string args " "))))
8732 ;;; X RandR resolution change
8733 ;;; FIXME I do not care multi-display.
8734 (defvar anything-c-xrandr-output "VGA")
8735 (defvar anything-c-xrandr-screen "0")
8736 (defvar anything-c-source-xrandr-change-resolution
8737 '((name . "Change Resolution")
8738 (candidates
8739 . (lambda ()
8740 (with-temp-buffer
8741 (call-process "xrandr" nil (current-buffer) nil
8742 "--screen" anything-c-xrandr-screen "-q")
8743 (goto-char 1)
8744 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8745 collect (match-string 1)))))
8746 (action
8747 ("Change Resolution" . (lambda (mode)
8748 (call-process "xrandr" nil nil nil
8749 "--screen" anything-c-xrandr-screen
8750 "--output" anything-c-xrandr-output
8751 "--mode" mode))))))
8752 ;; (anything 'anything-c-source-xrandr-change-resolution)
8754 ;;; Xfont selection
8757 (defun anything-c-persistent-xfont-action (elm)
8758 "Show current font temporarily"
8759 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8760 (default-font elm))
8761 (unwind-protect
8762 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8763 (set-frame-font current-font))))
8765 (defvar anything-c-xfonts-cache nil)
8766 (defvar anything-c-source-xfonts
8767 '((name . "X Fonts")
8768 (init . (lambda ()
8769 (unless anything-c-xfonts-cache
8770 (setq anything-c-xfonts-cache
8771 (x-list-fonts "*")))))
8772 (candidates . anything-c-xfonts-cache)
8773 (action . (("Copy to kill ring" . (lambda (elm)
8774 (kill-new elm)))
8775 ("Set Font" . (lambda (elm)
8776 (kill-new elm)
8777 (set-frame-font elm 'keep-size)
8778 (message "New font have been copied to kill ring")))))
8779 (persistent-action . anything-c-persistent-xfont-action)
8780 (persistent-help . "Switch to this font temporarily")))
8781 ;; (anything 'anything-c-source-xfonts)
8783 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8786 (defvar anything-c-ucs-max-len 0)
8787 (defun anything-c-calculate-ucs-max-len ()
8788 "Calculate the length of longest `ucs-names' candidate."
8789 (loop with count = 0
8790 for (n . v) in (ucs-names)
8791 for len = (length n)
8792 if (> len count)
8793 do (setq count len)
8794 finally return count))
8796 (defun anything-c-ucs-init ()
8797 "Initialize an anything buffer with ucs symbols.
8798 Only math* symbols are collected."
8799 (unless (> anything-c-ucs-max-len 0)
8800 (setq anything-c-ucs-max-len
8801 (anything-c-calculate-ucs-max-len)))
8802 (with-current-buffer (anything-candidate-buffer
8803 (get-buffer-create "*anything ucs*"))
8804 ;; `ucs-names' fn will not run again, data is cached in
8805 ;; var `ucs-names'.
8806 (loop for (n . v) in (ucs-names)
8807 for len = (length n)
8808 for diff = (+ (- anything-c-ucs-max-len len) 2)
8809 unless (string= "" n)
8810 do (progn (insert (concat
8811 n ":"
8812 (make-string
8813 diff ? )))
8814 (ucs-insert v)
8815 (insert "\n")))))
8817 (defun anything-c-ucs-forward-char (candidate)
8818 (with-anything-current-buffer
8819 (forward-char 1)))
8821 (defun anything-c-ucs-backward-char (candidate)
8822 (with-anything-current-buffer
8823 (forward-char -1)))
8825 (defun anything-c-ucs-delete-backward (candidate)
8826 (with-anything-current-buffer
8827 (delete-char -1)))
8829 (defun anything-c-ucs-insert-char (candidate)
8830 (with-anything-current-buffer
8831 (insert
8832 (replace-regexp-in-string
8833 " " ""
8834 (cadr (split-string candidate ":"))))))
8836 (defun anything-c-ucs-persistent-insert ()
8837 (interactive)
8838 (anything-execute-persistent-action 'action-insert))
8840 (defun anything-c-ucs-persistent-forward ()
8841 (interactive)
8842 (anything-execute-persistent-action 'action-forward))
8844 (defun anything-c-ucs-persistent-backward ()
8845 (interactive)
8846 (anything-execute-persistent-action 'action-back))
8848 (defun anything-c-ucs-persistent-delete ()
8849 (interactive)
8850 (anything-execute-persistent-action 'action-delete))
8852 (defvar anything-c-source-ucs
8853 '((name . "Ucs names")
8854 (init . anything-c-ucs-init)
8855 (candidate-number-limit . 9999)
8856 (candidates-in-buffer)
8857 (mode-line . anything-c-ucs-mode-line-string)
8858 (action-insert . anything-c-ucs-insert-char)
8859 (action-forward . anything-c-ucs-forward-char)
8860 (action-back . anything-c-ucs-backward-char)
8861 (action-delete . anything-c-ucs-delete-backward)
8862 (action . (("Insert" . anything-c-ucs-insert-char)
8863 ("Forward char" . anything-c-ucs-forward-char)
8864 ("Backward char" . anything-c-ucs-backward-char)
8865 ("Delete char backward" . anything-c-ucs-delete-backward))))
8866 "Source for collecting `ucs-names' math symbols.")
8869 ;;; Emacs process
8872 (defvar anything-c-source-emacs-process
8873 '((name . "Emacs Process")
8874 (candidates . (lambda () (mapcar #'process-name (process-list))))
8875 (persistent-action . (lambda (elm)
8876 (delete-process (get-process elm))
8877 (anything-delete-current-selection)))
8878 (persistent-help . "Kill Process")
8879 (action ("Kill Process" . (lambda (elm)
8880 (delete-process (get-process elm)))))))
8881 ;; (anything 'anything-c-source-emacs-process)
8883 ;;; World time
8886 (defvar anything-c-source-time-world
8887 '((name . "Time World List")
8888 (init . (lambda ()
8889 (let ((anything-buffer (anything-candidate-buffer 'global)))
8890 (with-current-buffer anything-buffer
8891 (display-time-world-display display-time-world-list)))))
8892 (candidates-in-buffer)))
8896 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8899 (defvar anything-c-source-apt
8900 '((name . "APT")
8901 (init . anything-c-apt-init)
8902 (candidates-in-buffer)
8903 (candidate-transformer anything-c-apt-candidate-transformer)
8904 (display-to-real . anything-c-apt-display-to-real)
8905 (requires-pattern . 2)
8906 (update . anything-c-apt-refresh)
8907 (action
8908 ("Show package description" . anything-c-apt-cache-show)
8909 ("Install package" . anything-c-apt-install)
8910 ("Remove package" . anything-c-apt-uninstall)
8911 ("Purge package" . anything-c-apt-purge))
8912 (persistent-action . anything-c-apt-persistent-action)
8913 (persistent-help . "Show package description")))
8914 ;; (anything 'anything-c-source-apt)
8916 (defvar anything-c-apt-query "emacs")
8917 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8918 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8919 (defvar anything-c-apt-installed-packages nil)
8920 (defvar anything-c-apt-all-packages nil)
8923 (defun anything-c-apt-refresh ()
8924 "Refresh installed candidates list."
8925 (setq anything-c-apt-installed-packages nil)
8926 (setq anything-c-apt-all-packages nil))
8928 (defun anything-c-apt-persistent-action (candidate)
8929 "Persistent action for APT source."
8930 (anything-c-apt-cache-show candidate))
8932 (defun anything-c-apt-candidate-transformer (candidates)
8933 "Show installed candidates in a different color."
8934 (loop
8935 with all
8936 for cand in candidates
8937 for name = (anything-c-apt-display-to-real cand)
8938 if (member name anything-c-apt-installed-packages)
8939 collect (propertize cand 'face 'anything-apt-installed) into all
8940 else collect cand into all finally return all))
8942 (defun anything-c-apt-init ()
8943 "Initialize list of debian packages."
8944 (let ((query ""))
8945 (unless (and anything-c-apt-installed-packages
8946 anything-c-apt-all-packages)
8947 (message "Loading package list...")
8948 (setq anything-c-apt-installed-packages
8949 (with-temp-buffer
8950 (call-process-shell-command "dpkg --get-selections"
8951 nil (current-buffer))
8952 (loop for i in (split-string (buffer-string) "\n" t)
8953 collect (car (split-string i)))))
8954 (setq anything-c-apt-all-packages
8955 (with-current-buffer
8956 (anything-candidate-buffer
8957 (get-buffer-create (format "*anything-apt*")))
8958 (erase-buffer)
8959 (call-process-shell-command
8960 (format anything-c-apt-search-command query)
8961 nil (current-buffer))))
8962 (message "Loading package list done")
8963 (sit-for 0.5))))
8965 (defun anything-c-apt-display-to-real (line)
8966 "Return only name of a debian package.
8967 LINE is displayed like:
8968 package name - description."
8969 (car (split-string line " - ")))
8971 (defun anything-c-shell-command-if-needed (command)
8972 "Run shell command COMMAND to describe package.
8973 If a buffer named COMMAND already exists, just switch to it."
8974 (let ((buf (get-buffer command)))
8975 (anything-c-switch-to-buffer (get-buffer-create command))
8976 (unless buf (insert (shell-command-to-string command)))))
8978 (defun anything-c-apt-cache-show (package)
8979 "Show information on apt package PACKAGE."
8980 (anything-c-shell-command-if-needed
8981 (format anything-c-apt-show-command package)))
8983 (defun anything-c-apt-install (package)
8984 "Run 'apt-get install' shell command on PACKAGE."
8985 (anything-c-apt-generic-action :action 'install))
8987 (defun anything-c-apt-uninstall (package)
8988 "Run 'apt-get remove' shell command on PACKAGE."
8989 (anything-c-apt-generic-action :action 'uninstall))
8991 (defun anything-c-apt-purge (package)
8992 "Run 'apt-get purge' shell command on PACKAGE."
8993 (anything-c-apt-generic-action :action 'purge))
8995 (defun* anything-c-apt-generic-action (&key action)
8996 "Run 'apt-get ACTION'.
8997 Support install, remove and purge actions."
8998 (ansi-term (getenv "SHELL") "anything apt")
8999 (term-line-mode)
9000 (let ((command (case action
9001 ('install "sudo apt-get install ")
9002 ('uninstall "sudo apt-get remove ")
9003 ('purge "sudo apt-get purge ")
9004 (t (error "Unknow action"))))
9005 (beg (point))
9007 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9008 (anything-marked-candidates) " ")))
9009 (goto-char (point-max))
9010 (insert (concat command cand-list))
9011 (setq end (point))
9012 (if (y-or-n-p (format "%s package" (symbol-name action)))
9013 (progn
9014 (setq anything-c-external-commands-list nil)
9015 (setq anything-c-apt-installed-packages nil)
9016 (term-char-mode) (term-send-input))
9017 (delete-region beg end) (term-send-eof) (kill-buffer))))
9019 ;; (anything-c-apt-install "jed")
9022 ;;; Anything UI for gentoo portage.
9025 (defvar anything-c-gentoo-use-flags nil)
9026 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9027 (defvar anything-c-cache-gentoo nil)
9028 (defvar anything-c-cache-world nil)
9029 (defvar anything-c-source-gentoo
9030 '((name . "Portage sources")
9031 (init . (lambda ()
9032 (get-buffer-create anything-c-gentoo-buffer)
9033 (unless anything-c-cache-gentoo
9034 (anything-c-gentoo-setup-cache))
9035 (unless anything-c-cache-world
9036 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9037 (anything-c-gentoo-init-list)))
9038 (candidates-in-buffer)
9039 (match . identity)
9040 (candidate-transformer anything-c-highlight-world)
9041 (action . (("Show package" . (lambda (elm)
9042 (anything-c-gentoo-eshell-action elm "eix")))
9043 ("Show history" . (lambda (elm)
9044 (if (member elm anything-c-cache-world)
9045 (anything-c-gentoo-eshell-action elm "genlop -qe")
9046 (message "No infos on packages not yet installed"))))
9047 ("Copy in kill-ring" . kill-new)
9048 ("insert at point" . insert)
9049 ("Browse HomePage" . (lambda (elm)
9050 (let ((urls (anything-c-gentoo-get-url elm)))
9051 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9052 ("Show extra infos" . (lambda (elm)
9053 (if (member elm anything-c-cache-world)
9054 (anything-c-gentoo-eshell-action elm "genlop -qi")
9055 (message "No infos on packages not yet installed"))))
9056 ("Show use flags" . (lambda (elm)
9057 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9058 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9059 (font-lock-mode 1)))
9060 ("Run emerge pretend" . (lambda (elm)
9061 (anything-c-gentoo-eshell-action elm "emerge -p")))
9062 ("Emerge" . (lambda (elm)
9063 (anything-gentoo-install elm :action 'install)))
9064 ("Unmerge" . (lambda (elm)
9065 (anything-gentoo-install elm :action 'uninstall)))
9066 ("Show dependencies" . (lambda (elm)
9067 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9068 ("Show related files" . (lambda (elm)
9069 (anything-c-gentoo-default-action elm "equery" "files")))
9070 ("Refresh" . (lambda (elm)
9071 (anything-c-gentoo-setup-cache)
9072 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9074 ;; (anything 'anything-c-source-gentoo)
9076 (defun* anything-gentoo-install (candidate &key action)
9077 (setq anything-c-external-commands-list nil)
9078 (ansi-term (getenv "SHELL") "Gentoo emerge")
9079 (term-line-mode)
9080 (let ((command (case action
9081 ('install "sudo emerge -av ")
9082 ('uninstall "sudo emerge -avC ")
9083 (t (error "Unknow action"))))
9084 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9085 (beg (point)) end)
9086 (goto-char (point-max))
9087 (insert (concat command elms))
9088 (setq end (point))
9089 (term-char-mode) (term-send-input)))
9091 (defun anything-c-gentoo-default-action (elm command &rest args)
9092 "Gentoo default action that use `anything-c-gentoo-buffer'."
9093 (if (member elm anything-c-cache-world)
9094 (progn
9095 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9096 (erase-buffer)
9097 (let ((com-list (append args (list elm))))
9098 (apply #'call-process command nil t nil
9099 com-list)))
9100 (message "No infos on packages not yet installed")))
9102 (defvar anything-c-source-use-flags
9103 '((name . "Use Flags")
9104 (init . (lambda ()
9105 (unless anything-c-gentoo-use-flags
9106 (anything-c-gentoo-setup-use-flags-cache))
9107 (anything-c-gentoo-get-use)))
9108 (candidates-in-buffer)
9109 (match . identity)
9110 (candidate-transformer anything-c-highlight-local-use)
9111 (action . (("Description"
9112 . (lambda (elm)
9113 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9114 (erase-buffer)
9115 (apply #'call-process "euse" nil t nil
9116 `("-i"
9117 ,elm))
9118 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9119 (font-lock-mode 1)))
9120 ("Enable"
9121 . (lambda (elm)
9122 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9123 ("Disable"
9124 . (lambda (elm)
9125 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9126 ("Remove"
9127 . (lambda (elm)
9128 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9129 ("Show which dep use this flag"
9130 . (lambda (elm)
9131 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9132 (erase-buffer)
9133 (apply #'call-process "equery" nil t nil
9134 `("-C"
9136 ,elm))))))))
9139 ;; (anything 'anything-c-source-use-flags)
9141 (defun anything-c-gentoo-init-list ()
9142 "Initialize buffer with all packages in Portage."
9143 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9144 (buf (anything-candidate-buffer 'portage-buf)))
9145 (with-current-buffer buf
9146 (dolist (i anything-c-cache-gentoo)
9147 (insert (concat i "\n"))))))
9149 (defun anything-c-gentoo-setup-cache ()
9150 "Set up `anything-c-cache-gentoo'"
9151 (setq anything-c-cache-gentoo
9152 (split-string (with-temp-buffer
9153 (call-process "eix" nil t nil
9154 "--only-names")
9155 (buffer-string)))))
9157 (defun anything-c-gentoo-eshell-action (elm command)
9158 (when (get-buffer "*EShell Command Output*")
9159 (kill-buffer "*EShell Command Output*"))
9160 (message "Wait searching...")
9161 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9162 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9163 (progn
9164 (save-window-excursion
9165 (pop-to-buffer "*scratch*")
9166 (eshell-command (format "%s %s" command elm)))
9167 (pop-to-buffer "*EShell Command Output*"))
9168 (eshell-command (format "%s %s" command elm)))))
9170 (defun anything-c-gentoo-get-use ()
9171 "Initialize buffer with all use flags."
9172 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9173 (buf (anything-candidate-buffer 'use-buf)))
9174 (with-current-buffer buf
9175 (dolist (i anything-c-gentoo-use-flags)
9176 (insert (concat i "\n"))))))
9179 (defun anything-c-gentoo-setup-use-flags-cache ()
9180 "Setup `anything-c-gentoo-use-flags'"
9181 (setq anything-c-gentoo-use-flags
9182 (split-string (with-temp-buffer
9183 (call-process "eix" nil t nil
9184 "--print-all-useflags")
9185 (buffer-string)))))
9187 (defun anything-c-gentoo-get-url (elm)
9188 "Return a list of urls from eix output."
9189 (loop
9190 with url-list = (split-string
9191 (with-temp-buffer
9192 (call-process "eix" nil t nil
9193 elm "--format" "<homepage>\n")
9194 (buffer-string)))
9195 with all
9196 for i in url-list
9197 when (and (string-match "^http://.*" i)
9198 (not (member i all)))
9199 collect i into all
9200 finally return all))
9202 (defun anything-c-gentoo-get-world ()
9203 "Return list of all installed package on your system."
9204 (split-string (with-temp-buffer
9205 (call-process "qlist" nil t nil
9206 "-I")
9207 (buffer-string))))
9209 (defun anything-c-gentoo-get-local-use ()
9210 (split-string (with-temp-buffer
9211 (call-process "portageq" nil t nil
9212 "envvar"
9213 "USE")
9214 (buffer-string))))
9217 (defun anything-c-highlight-world (eix)
9218 "Highlight all installed package."
9219 (loop for i in eix
9220 if (member i anything-c-cache-world)
9221 collect (propertize i 'face 'anything-gentoo-match-face)
9222 else
9223 collect i))
9225 (defun anything-c-highlight-local-use (use-flags)
9226 (let ((local-uses (anything-c-gentoo-get-local-use)))
9227 (loop for i in use-flags
9228 if (member i local-uses)
9229 collect (propertize i 'face 'anything-gentoo-match-face)
9230 else
9231 collect i)))
9235 ;;; Anything ratpoison UI
9238 (defvar anything-c-source-ratpoison-commands
9239 '((name . "Ratpoison Commands")
9240 (init . anything-c-ratpoison-commands-init)
9241 (candidates-in-buffer)
9242 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9243 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9244 (candidate-number-limit)))
9245 ;; (anything 'anything-c-source-ratpoison-commands)
9247 (defun anything-c-ratpoison-commands-init ()
9248 (unless (anything-candidate-buffer)
9249 (with-current-buffer (anything-candidate-buffer 'global)
9250 ;; with ratpoison prefix key
9251 (save-excursion
9252 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9253 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9254 (replace-match "<ratpoison> \\1: \\2"))
9255 (goto-char (point-max))
9256 ;; direct binding
9257 (save-excursion
9258 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9259 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9260 (replace-match "\\1: \\2")))))
9262 (defun anything-c-ratpoison-commands-display-to-real (display)
9263 (and (string-match ": " display)
9264 (substring display (match-end 0))))
9266 (defun anything-c-ratpoison-commands-execute (candidate)
9267 (call-process "ratpoison" nil nil nil "-ic" candidate))
9271 ;;; Anything `completing-read' replacement
9274 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9275 "Convert COLLECTION to list removing elements that don't match TEST.
9276 See `anything-comp-read' about supported COLLECTION arguments.
9278 SORT-FN is a predicate to sort COLLECTION.
9280 ALISTP when non--nil will not use `all-completions' to collect
9281 candidates because it doesn't handle alists correctly for anything.
9282 i.e In `all-completions' the keys \(cars of elements\)
9283 are the possible completions. In anything we want to use the cdr instead
9284 like \(display . real\).
9285 See docstring of `all-completions' for more info.
9287 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9288 (let ((cands
9289 (cond ((and (eq collection obarray) test)
9290 (all-completions "" collection test))
9291 ((and (vectorp collection) test)
9292 (loop for i across collection when (funcall test i) collect i))
9293 ((vectorp collection)
9294 (loop for i across collection collect i))
9295 ((and alistp test)
9296 (loop for i in collection when (funcall test i) collect i))
9297 ((and (symbolp collection) (boundp collection))
9298 (symbol-value collection))
9299 (alistp collection)
9300 ((and collection test)
9301 (all-completions "" collection test))
9302 (t (all-completions "" collection)))))
9303 (if sort-fn (sort cands sort-fn) cands)))
9305 (defun anything-cr-default-transformer (candidates source)
9306 "Default filter candidate function for `anything-comp-read'.
9307 Do nothing, just return candidate list unmodified."
9308 candidates)
9310 (defun* anything-comp-read (prompt collection
9311 &key
9312 test
9313 initial-input
9314 default
9315 preselect
9316 (buffer "*Anything Completions*")
9317 must-match
9318 (requires-pattern 0)
9319 (history nil)
9320 (persistent-action nil)
9321 (persistent-help "DoNothing")
9322 (name "Anything Completions")
9323 (volatile t)
9324 sort
9325 (fc-transformer 'anything-cr-default-transformer)
9326 (marked-candidates nil)
9327 (alistp t))
9328 "Anything `completing-read' emulation.
9329 PROMPT is the prompt name to use.
9330 COLLECTION can be a list, vector, obarray or hash-table.
9331 It can be also a function that receives three arguments:
9332 the values string, predicate and t. See `all-completions' for more details.
9334 Keys description:
9336 TEST: A predicate called with one arg i.e candidate.
9337 INITIAL-INPUT: Same as initial-input arg in `anything'.
9338 PRESELECT: See preselect arg of `anything'.
9339 DEFAULT: This option is used only for compatibility with regular
9340 Emacs `completing-read'.
9341 BUFFER: Name of anything-buffer.
9342 MUST-MATCH: Candidate selected must be one of COLLECTION.
9343 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9344 HISTORY: A list containing specific history, default is nil.
9345 When it is non--nil, all elements of HISTORY are displayed in
9346 a special source before COLLECTION.
9347 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9348 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9349 NAME: The name related to this local source.
9350 VOLATILE: Use volatile attribute \(enabled by default\).
9351 SORT: A predicate to give to `sort' e.g `string-lessp'.
9352 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9353 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9354 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9356 Any prefix args passed during `anything-comp-read' invocation will be recorded
9357 in `anything-current-prefix-arg', otherwise if prefix args where given before
9358 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9359 That's mean you can pass prefix args before or after calling a command
9360 that use `anything-comp-read' See `anything-M-x' for example."
9361 (when (get-buffer anything-action-buffer)
9362 (kill-buffer anything-action-buffer))
9363 (flet ((action-fn (candidate)
9364 (if marked-candidates
9365 (anything-marked-candidates)
9366 (identity candidate))))
9367 (let ((hist `((name . ,(format "%s History" name))
9368 (candidates
9369 . (lambda ()
9370 (let ((all (anything-comp-read-get-candidates
9371 history nil nil ,alistp)))
9372 (anything-fast-remove-dups
9373 (if (and default (not (string= default "")))
9374 (delq nil (cons default (delete default all)))
9375 all)
9376 :test 'equal))))
9377 (filtered-candidate-transformer
9378 . (lambda (candidates sources)
9379 (loop for i in candidates
9380 do (set-text-properties 0 (length i) nil i)
9381 collect i)))
9382 (persistent-action . ,persistent-action)
9383 (persistent-help . ,persistent-help)
9384 (action . ,'action-fn)))
9385 (src `((name . ,name)
9386 (candidates
9387 . (lambda ()
9388 (let ((cands (anything-comp-read-get-candidates
9389 collection test sort alistp)))
9390 (unless (or must-match (string= anything-pattern ""))
9391 (setq cands (append (list anything-pattern) cands)))
9392 (if (and default (not (string= default "")))
9393 (delq nil (cons default (delete default cands)))
9394 cands))))
9395 (filtered-candidate-transformer ,fc-transformer)
9396 (requires-pattern . ,requires-pattern)
9397 (persistent-action . ,persistent-action)
9398 (persistent-help . ,persistent-help)
9399 (action . ,'action-fn))))
9400 (when volatile (setq src (append src '((volatile)))))
9402 (anything
9403 :sources `(,hist ,src)
9404 :input initial-input
9405 :default default
9406 :preselect preselect
9407 :prompt prompt
9408 :resume 'noresume
9409 :history history
9410 :buffer buffer)
9411 (unless (or (eq anything-exit-status 1) must-match)
9412 default)
9413 (keyboard-quit)))))
9415 ;; Generic completing-read
9417 ;; Support also function as collection.
9418 ;; e.g M-x man is supported.
9419 ;; Support hash-table and vectors as collection.
9420 ;; NOTE:
9421 ;; Some crap emacs functions may not be supported
9422 ;; like ffap-alternate-file (bad use of completing-read)
9423 ;; and maybe others.
9424 ;; Provide a mode `anything-completion-mode' which turn on
9425 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9427 (defvar anything-completion-mode-string " AC")
9429 (defvar anything-completion-mode-quit-message
9430 "Anything completion disabled")
9432 (defvar anything-completion-mode-start-message
9433 "Anything completion enabled")
9435 ;;; Specialized handlers
9438 (defun anything-completing-read-symbols
9439 (prompt collection test require-match init
9440 hist default inherit-input-method name buffer)
9441 "Specialized function for fast symbols completion in `ac-mode'."
9443 (anything
9444 :sources `((name . ,name)
9445 (init . (lambda ()
9446 (with-current-buffer (anything-candidate-buffer 'global)
9447 (goto-char (point-min))
9448 (when (and default (stringp default)
9449 ;; Some defaults args result as
9450 ;; (symbol-name nil) == "nil".
9451 ;; e.g debug-on-entry.
9452 (not (string= default "nil")))
9453 (insert (concat default "\n")))
9454 (loop with all = (all-completions "" collection test)
9455 for sym in all
9456 unless (and default (eq sym default))
9457 do (insert (concat sym "\n"))))))
9458 (persistent-action . anything-lisp-completion-persistent-action)
9459 (persistent-help . "Show brief doc in mode-line")
9460 (candidates-in-buffer)
9461 (action . identity))
9462 :prompt prompt
9463 :buffer buffer
9464 :input init
9465 :history hist
9466 :resume 'noresume
9467 :default (or default ""))
9468 (keyboard-quit)))
9471 ;;; Generic completing read
9474 (defun anything-completing-read-default-1
9475 (prompt collection test require-match
9476 init hist default inherit-input-method
9477 name buffer)
9478 (anything-comp-read
9479 prompt collection
9480 :test test
9481 :fc-transformer #'(lambda (candidates source)
9482 ;; In regular `completing-read'
9483 ;; when a candidate is a cons cell
9484 ;; the car is used. Anything use
9485 ;; normally the cdr, so modify that
9486 ;; to fit `completing-read'.
9487 (loop for i in candidates
9488 for cand = (if (consp i) (car i) i)
9489 do (set-text-properties 0 (length cand) nil cand)
9490 collect cand))
9491 :history (or (car-safe hist) hist)
9492 :must-match require-match
9493 :alistp nil
9494 :name name
9495 :buffer buffer
9496 ;; If DEF is not provided, fallback to empty string
9497 ;; to avoid `thing-at-point' to be appended on top of list
9498 :default (or default "")
9499 :initial-input init))
9501 (defun* anything-completing-read-default
9502 (prompt collection &optional
9503 predicate require-match
9504 initial-input hist def
9505 inherit-input-method)
9506 "An anything replacement of `completing-read'.
9507 This function should be used only as a `completing-read-function'.
9509 Don't use it directly, use instead `anything-comp-read' in your programs \
9510 which is more powerful.
9512 See documentation of `completing-read' and `all-completions' for details."
9513 (declare (special anything-completion-mode))
9514 (let* ((current-command this-command)
9515 (str-command (symbol-name current-command))
9516 (buf-name (format "*ac-mode-%s*" str-command))
9517 (entry (assq current-command
9518 anything-completing-read-handlers-alist))
9519 (def-com (cdr-safe entry))
9520 (str-defcom (and def-com (symbol-name def-com)))
9521 (def-args (list prompt collection predicate require-match
9522 initial-input hist def inherit-input-method))
9523 ;; Append the two extra args needed to set the buffer and source name
9524 ;; in anything specialized functions.
9525 (any-args (append def-args (list str-command buf-name)))
9526 anything-completion-mode-start-message ; Be quiet
9527 anything-completion-mode-quit-message)
9528 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9529 (unless (or (not entry) def-com)
9530 ;; An entry in *read-handlers-alist exists but have
9531 ;; a nil value, so we exit from here, disable `ac-mode'
9532 ;; and run the command again with it original behavior.
9533 ;; `ac-mode' will be restored on exit.
9534 (return-from anything-completing-read-default
9535 (unwind-protect
9536 (progn
9537 (ac-mode -1)
9538 (call-interactively current-command))
9539 (ac-mode 1))))
9540 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9541 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9542 (when (or (eq def-com 'completing-read)
9543 ;; All specialized functions are prefixed by "anything"
9544 (and (stringp str-defcom)
9545 (not (string-match "^anything" str-defcom))))
9546 (ac-mode -1))
9547 (unwind-protect
9548 (cond (;; An anything specialized function exists, run it.
9549 (and def-com anything-completion-mode)
9550 (apply def-com any-args))
9551 (;; Try to handle `ido-completing-read' everywhere.
9552 (and def-com (eq def-com 'ido-completing-read))
9553 (setcar (memq collection def-args)
9554 (all-completions "" collection predicate))
9555 (apply def-com def-args))
9556 (;; User set explicitely `completing-read' or something similar
9557 ;; in *read-handlers-alist, use this with exactly the same
9558 ;; args as in `completing-read'.
9559 ;; If we are here `anything-completion-mode' is now disabled.
9560 def-com
9561 (apply def-com def-args))
9562 (t ; Fall back to classic `anything-comp-read'.
9563 (anything-completing-read-default-1
9564 prompt collection predicate require-match
9565 initial-input hist def inherit-input-method
9566 str-command buf-name)))
9567 (ac-mode 1)
9568 ;; When exiting minibuffer, `this-command' is set to
9569 ;; `anything-exit-minibuffer', which is unwanted when starting
9570 ;; on another `completing-read', so restore `this-command' to
9571 ;; initial value when exiting.
9572 (setq this-command current-command))))
9574 (defun* anything-generic-read-file-name
9575 (prompt &optional dir default-filename mustmatch initial predicate)
9576 "An anything replacement of `read-file-name'."
9577 (declare (special anything-completion-mode))
9578 (let* ((default (and default-filename
9579 (if (listp default-filename)
9580 (car default-filename)
9581 default-filename)))
9582 (init (or default initial dir default-directory))
9583 (ini-input (and init (expand-file-name init)))
9584 (current-command this-command)
9585 (str-command (symbol-name current-command))
9586 (buf-name (format "*ac-mode-%s*" str-command))
9587 (entry (assq current-command
9588 anything-completing-read-handlers-alist))
9589 (def-com (cdr-safe entry))
9590 (str-defcom (symbol-name def-com))
9591 (def-args (list prompt dir default-filename mustmatch initial predicate))
9592 ;; Append the two extra args needed to set the buffer and source name
9593 ;; in anything specialized functions.
9594 (any-args (append def-args (list str-command buf-name)))
9595 (ido-state ido-mode)
9596 anything-completion-mode-start-message ; Be quiet
9597 anything-completion-mode-quit-message ; Same here
9598 fname)
9599 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9600 (unless (or (not entry) def-com)
9601 (return-from anything-completing-read-default
9602 (unwind-protect
9603 (progn
9604 (ac-mode -1)
9605 (call-interactively current-command))
9606 (ac-mode 1))))
9607 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9608 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9609 (when (or (eq def-com 'read-file-name)
9610 (eq def-com 'ido-read-file-name)
9611 (and (stringp str-defcom)
9612 (not (string-match "^anything" str-defcom))))
9613 (ac-mode -1))
9614 (unwind-protect
9615 (setq fname
9616 (cond (;; A specialized function exists, run it
9617 ;; with the two extra args specific to anything..
9618 (and def-com anything-completion-mode
9619 (not (eq def-com 'ido-read-file-name)))
9620 (apply def-com any-args))
9621 (;; Def-com value is `ido-read-file-name'
9622 ;; run it with default args.
9623 (and def-com (eq def-com 'ido-read-file-name))
9624 (ido-mode 1)
9625 (apply def-com def-args))
9626 (;; Def-com value is `read-file-name'
9627 ;; run it with default args.
9628 def-com
9629 (apply def-com def-args))
9630 (t ; Fall back to classic `anything-c-read-file-name'.
9631 (anything-c-read-file-name
9632 prompt
9633 :name str-command
9634 :buffer buf-name
9635 :initial-input (expand-file-name init dir)
9636 :alistp nil
9637 :test predicate))))
9638 (ac-mode 1)
9639 (ido-mode (if ido-state 1 -1))
9640 ;; Same comment as in `anything-completing-read-default'.
9641 (setq this-command current-command))
9642 (if (and mustmatch (not (file-exists-p fname)))
9643 (if (y-or-n-p "File does not exists, create buffer?")
9644 fname (error "Abort file does not exists"))
9645 fname)))
9647 ;;;###autoload
9648 (define-minor-mode anything-completion-mode
9649 "Toggle generic anything completion.
9651 All functions in Emacs that use `completing-read'
9652 or `read-file-name' and friends will use anything interface
9653 when this mode is turned on.
9654 However you can modify this behavior for functions of your choice
9655 with `anything-completing-read-handlers-alist'.
9657 Called with a positive arg, turn on inconditionnaly, with a
9658 negative arg turn off.
9659 You can turn it on with `ac-mode'.
9661 Some crap emacs functions may not be supported,
9662 e.g `ffap-alternate-file' and maybe others
9663 You can add such functions to `anything-completing-read-handlers-alist'
9664 with a nil value.
9666 Note: This mode will work only partially on Emacs23."
9667 :group 'anything
9668 :global t
9669 :lighter anything-completion-mode-string
9670 (declare (special completing-read-function))
9671 (if anything-completion-mode
9672 (progn
9673 (setq completing-read-function 'anything-completing-read-default
9674 read-file-name-function 'anything-generic-read-file-name)
9675 (message anything-completion-mode-start-message))
9676 (setq completing-read-function (and (fboundp 'completing-read-default)
9677 'completing-read-default)
9678 read-file-name-function (and (fboundp 'read-file-name-default)
9679 'read-file-name-default))
9680 (message anything-completion-mode-quit-message)))
9682 (defalias 'ac-mode 'anything-completion-mode)
9686 ;;; Eshell completion.
9688 ;; Enable like this in .emacs:
9690 ;; (add-hook 'eshell-mode-hook
9691 ;; #'(lambda ()
9692 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9694 (defvar anything-c-source-esh
9695 '((name . "Eshell completions")
9696 (init . (lambda ()
9697 (setq pcomplete-current-completions nil
9698 pcomplete-last-completion-raw nil)
9699 ;; Eshell-command add this hook in all minibuffers
9700 ;; Remove it for the anything one. (Fixed in Emacs24)
9701 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9702 (candidates . anything-esh-get-candidates)
9703 (action . anything-ec-insert))
9704 "Anything source for Eshell completion.")
9706 ;; Internal.
9707 (defvar anything-ec-target "")
9708 (defun anything-ec-insert (candidate)
9709 "Insert CANDIDATE at point.
9710 This is the same as `ac-insert', just inlined here for compatibility."
9711 (let ((pt (point)))
9712 (when (and anything-ec-target
9713 (search-backward anything-ec-target nil t)
9714 (string= (buffer-substring (point) pt) anything-ec-target))
9715 (delete-region (point) pt)))
9716 (insert candidate))
9718 (defun anything-esh-get-candidates ()
9719 "Get candidates for eshell completion using `pcomplete'."
9720 (catch 'pcompleted
9721 (let* ((pcomplete-stub)
9722 pcomplete-seen pcomplete-norm-func
9723 pcomplete-args pcomplete-last pcomplete-index
9724 (pcomplete-autolist pcomplete-autolist)
9725 (pcomplete-suffix-list pcomplete-suffix-list))
9726 (with-anything-current-buffer
9727 (loop
9728 with table = (pcomplete-completions)
9729 with entry = (condition-case nil
9730 ;; For Emacs24
9731 (try-completion anything-pattern (pcomplete-entries))
9732 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9733 (error
9735 (let ((fc (car (last (pcomplete-parse-arguments)))))
9736 ;; Check if last arg require fname completion.
9737 (and (file-name-directory fc) fc))))
9738 for i in (if (listp table) table ; Emacs23 or commands.
9739 (all-completions pcomplete-stub table)) ; Emacs24
9740 for file-cand = (and entry
9741 (if (file-remote-p i) i
9742 (expand-file-name i (file-name-directory entry))))
9743 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9744 collect file-cand into ls
9745 else collect i into ls
9746 finally return
9747 (if (and entry (not (string= entry "")) (file-exists-p entry))
9748 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9750 ;;; Eshell history.
9753 (defvar anything-c-source-eshell-history
9754 '((name . "Eshell history")
9755 (init . (lambda ()
9756 (let (eshell-hist-ignoredups)
9757 ;; Dump the content's of hist file
9758 ;; to `eshell-history-ring'.
9759 (eshell-read-history eshell-history-file-name)
9760 ;; And now write the content's of ring to file.
9761 (eshell-write-history eshell-history-file-name t)
9762 (with-current-buffer (anything-candidate-buffer 'global)
9763 (insert-file-contents eshell-history-file-name)))
9764 ;; Same comment as in `anything-c-source-esh'
9765 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9766 (candidates-in-buffer)
9767 (filtered-candidate-transformer . (lambda (candidates sources)
9768 (reverse candidates)))
9769 (candidate-number-limit . 9999)
9770 (action . (lambda (candidate)
9771 (eshell-kill-input)
9772 (insert candidate))))
9773 "Anything source for Eshell history.")
9776 ;;; Show completion - an alternative of anything-show-completion.el.
9778 ;; Provide show completion with macro `with-anything-show-completion'.
9781 ;; Called each time cursor move in anything-buffer.
9782 (defun anything-c-show-completion ()
9783 (with-anything-current-buffer
9784 (overlay-put anything-c-show-completion-overlay
9785 'display (anything-get-selection))))
9787 (defun anything-c-show-completion-init-overlay (beg end)
9788 (and anything-c-turn-on-show-completion
9789 (setq anything-c-show-completion-overlay (make-overlay beg end))
9790 (overlay-put anything-c-show-completion-overlay
9791 'face 'anything-lisp-show-completion)))
9793 (defmacro with-anything-show-completion (beg end &rest body)
9794 "Show anything candidate in an overlay at point.
9795 BEG and END are the beginning and end position of the current completion
9796 in `anything-current-buffer'.
9797 BODY is an anything call where we want to enable show completion.
9798 If `anything-c-turn-on-show-completion' is nil just do nothing."
9799 (declare (indent 2) (debug t))
9800 `(let ((anything-move-selection-after-hook
9801 (and anything-c-turn-on-show-completion
9802 (append (list 'anything-c-show-completion)
9803 anything-move-selection-after-hook))))
9804 (unwind-protect
9805 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9806 ,@body)
9807 (and anything-c-turn-on-show-completion
9808 (delete-overlay anything-c-show-completion-overlay)))))
9811 ;;; Lisp symbol completion.
9814 ;;;###autoload
9815 (defun anything-lisp-completion-at-point ()
9816 "Anything lisp symbol completion at point."
9817 (interactive)
9818 (let* ((data (lisp-completion-at-point))
9819 (beg (car data))
9820 (end (point)) ; 'cadr data' is wrong when no space after point.
9821 (plist (nthcdr 3 data))
9822 (pred (plist-get plist :predicate))
9823 (lgst-len 0)
9824 (target (and beg end (buffer-substring-no-properties beg end)))
9825 (candidates (all-completions target (nth 2 data) pred))
9826 (anything-quit-if-no-candidate t)
9827 (anything-execute-action-at-once-if-one t)
9828 (anything-match-plugin-enabled
9829 (member 'anything-compile-source--match-plugin
9830 anything-compile-source-functions)))
9831 (if candidates
9832 (with-anything-show-completion beg end
9833 ;; Overlay is initialized now in anything-current-buffer.
9834 (anything
9835 :sources
9836 '((name . "Lisp completion")
9837 (init . (lambda ()
9838 (with-current-buffer (anything-candidate-buffer 'global)
9839 (loop for sym in candidates
9840 for len = (length sym)
9841 when (> len lgst-len) do (setq lgst-len len)
9842 do (insert (concat sym "\n"))))))
9843 (candidates-in-buffer)
9844 (persistent-action . anything-lisp-completion-persistent-action)
9845 (persistent-help . "Show brief doc in mode-line")
9846 (filtered-candidate-transformer anything-lisp-completion-transformer)
9847 (action . (lambda (candidate)
9848 (delete-region beg end)
9849 (insert candidate))))
9850 :input (if anything-match-plugin-enabled (concat target " ") target)))
9851 (message "[No Match]"))))
9853 (defun anything-lisp-completion-persistent-action (candidate)
9854 (let ((cursor-in-echo-area t)
9855 mode-line-in-non-selected-windows)
9856 (anything-c-eldoc-show-in-mode-line
9857 (propertize
9858 (anything-c-get-first-line-documentation
9859 (intern candidate))
9860 'face 'anything-lisp-completion-info))))
9862 (defun anything-lisp-completion-transformer (candidates source)
9863 "Anything candidates transformer for lisp completion."
9864 (declare (special lgst-len))
9865 (loop for c in candidates
9866 for sym = (intern c)
9867 for annot = (cond ((commandp sym) " (Com)")
9868 ((fboundp sym) " (Fun)")
9869 ((boundp sym) " (Var)")
9870 ((facep sym) " (Face)"))
9871 for spaces = (make-string (- lgst-len (length c)) ? )
9872 collect (cons (concat c spaces annot) c)))
9874 (defun anything-c-get-first-line-documentation (sym)
9875 "Return first line documentation of symbol SYM.
9876 If SYM is not documented, return \"Not documented\"."
9877 (let ((doc (cond ((fboundp sym)
9878 (documentation sym t))
9879 ((boundp sym)
9880 (documentation-property sym 'variable-documentation t))
9881 ((facep sym)
9882 (face-documentation sym))
9883 (t nil))))
9884 (if (and doc (not (string= doc ""))
9885 ;; `documentation' return "\n\n(args...)"
9886 ;; for CL-style functions.
9887 (not (string-match-p "^\n\n" doc)))
9888 (car (split-string doc "\n"))
9889 "Not documented")))
9891 ;;; File completion.
9893 ;; Complete file name at point.
9894 (defun anything-c-thing-before-point ()
9895 "Get symbol name before point.
9896 Borrowed from anything-complete.el, inlined here for compatibility."
9897 (save-excursion
9898 (let ((beg (point)))
9899 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9900 (when (re-search-backward
9901 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9902 (buffer-substring-no-properties beg (match-end 0))))))
9904 ;;;###autoload
9905 (defun anything-c-complete-file-name-at-point ()
9906 "Complete file name at point."
9907 (interactive)
9908 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9909 (end (point))
9910 (beg (- (point) (length init)))
9911 (anything-quit-if-no-candidate t)
9912 (anything-execute-action-at-once-if-one t)
9913 completion)
9914 (with-anything-show-completion beg end
9915 (setq completion (anything-c-read-file-name "FileName: "
9916 :initial-input init)))
9917 (anything-c-insert-file-name-completion-at-point completion)))
9919 ;; Internal
9920 (defvar anything-lisp-completion-counter 0)
9921 ;;;###autoload
9922 (defun anything-lisp-completion-at-point-or-indent (arg)
9923 "First call indent and second call complete lisp symbol.
9924 The second call should happen before `anything-lisp-completion-or-indent-delay',
9925 after this delay, next call will indent again.
9926 After completion, next call is always indent.
9927 See that like click and double mouse click.
9928 One hit indent, two quick hits maybe indent and complete."
9929 (interactive "P")
9930 ;; Be sure `indent-for-tab-command' will not try
9931 ;; to use `completion-at-point'.
9932 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9933 t tab-always-indent)))
9934 (incf anything-lisp-completion-counter)
9935 (unwind-protect
9936 (if (> anything-lisp-completion-counter 1)
9937 (anything-lisp-completion-or-file-name-at-point)
9938 (indent-for-tab-command arg))
9939 ;; After `anything-lisp-completion-or-indent-delay' seconds
9940 ;; reset to 0.
9941 (run-with-timer anything-lisp-completion-or-indent-delay nil
9942 #'(lambda ()
9943 (setq anything-lisp-completion-counter 0)))
9944 ;; Always reset to 0 at second hit.
9945 (when (eq anything-lisp-completion-counter 2)
9946 (setq anything-lisp-completion-counter 0)))))
9948 ;;;###autoload
9949 (defun anything-lisp-completion-or-file-name-at-point ()
9950 "Complete lisp symbol or filename at point.
9951 Filename completion happen if filename is started in
9952 or between double quotes."
9953 (interactive)
9954 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9955 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9956 (save-excursion (search-backward "\"" (point-at-bol) t)))
9957 (anything-c-complete-file-name-at-point)
9958 (anything-lisp-completion-at-point))))
9960 (defun anything-c-apropos-init (test default)
9961 "Init candidates buffer for `anything-c-apropos' sources."
9962 (with-current-buffer (anything-candidate-buffer 'global)
9963 (goto-char (point-min))
9964 (when (and default (stringp default)
9965 ;; Some defaults args result as
9966 ;; (symbol-name nil) == "nil".
9967 ;; e.g debug-on-entry.
9968 (not (string= default "nil"))
9969 (funcall test (intern default)))
9970 (insert (concat default "\n")))
9971 (loop with all = (all-completions "" obarray test)
9972 for sym in all
9973 unless (and default (eq sym default))
9974 do (insert (concat sym "\n")))))
9977 ;;; Run Externals commands within Emacs with anything completion
9980 (defvar anything-external-command-history nil)
9982 (defun anything-c-external-commands-list-1 (&optional sort)
9983 "Returns a list of all external commands the user can execute.
9984 If `anything-c-external-commands-list' is non-nil it will
9985 return its contents. Else it calculates all external commands
9986 and sets `anything-c-external-commands-list'."
9987 (if anything-c-external-commands-list
9988 anything-c-external-commands-list
9989 (setq anything-c-external-commands-list
9990 (loop
9991 with paths = (split-string (getenv "PATH") path-separator)
9992 with completions = ()
9993 for dir in paths
9994 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9995 for lsdir = (loop for i in (directory-files dir t)
9996 for bn = (file-name-nondirectory i)
9997 when (and (not (member bn completions))
9998 (not (file-directory-p i))
9999 (file-executable-p i))
10000 collect bn)
10001 append lsdir into completions
10002 finally return (if sort (sort completions 'string-lessp) completions)))))
10004 (defun anything-run-or-raise (exe &optional file)
10005 "Generic command that run asynchronously EXE.
10006 If EXE is already running just jump to his window if `anything-raise-command'
10007 is non--nil.
10008 When FILE argument is provided run EXE with FILE.
10009 In this case EXE must be provided as \"EXE %s\"."
10010 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10011 "%s" "" exe))))
10012 (proc (if file (concat real-com " " file) real-com)))
10013 (if (get-process proc)
10014 (if anything-raise-command
10015 (shell-command (format anything-raise-command real-com))
10016 (error "Error: %s is already running" real-com))
10017 (when (loop for i in anything-c-external-commands-list thereis real-com)
10018 (message "Starting %s..." real-com)
10019 (if file
10020 (start-process-shell-command
10021 proc nil (format exe (shell-quote-argument file)))
10022 (start-process-shell-command proc nil real-com))
10023 (set-process-sentinel
10024 (get-process proc)
10025 #'(lambda (process event)
10026 (when (and (string= event "finished\n")
10027 anything-raise-command
10028 (not (anything-c-get-pid-from-process-name real-com)))
10029 (shell-command (format anything-raise-command "emacs")))
10030 (message "%s process...Finished." process))))
10031 (setq anything-c-external-commands-list
10032 (cons real-com
10033 (delete real-com anything-c-external-commands-list))))))
10037 ;;; Generic action functions
10040 (defun anything-c-file-buffers (filename)
10041 "Returns a list of buffer names corresponding to FILENAME."
10042 (let ((name (expand-file-name filename))
10043 (buf-list ()))
10044 (dolist (buf (buffer-list) buf-list)
10045 (let ((bfn (buffer-file-name buf)))
10046 (when (and bfn (string= name bfn))
10047 (push (buffer-name buf) buf-list))))))
10049 (defun anything-revert-buffer (candidate)
10050 (with-current-buffer candidate
10051 (when (or (buffer-modified-p)
10052 (not (verify-visited-file-modtime
10053 (get-buffer candidate))))
10054 (revert-buffer t t))))
10056 (defun anything-revert-marked-buffers (ignore)
10057 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10059 (defun anything-kill-marked-buffers (ignore)
10060 (mapc 'kill-buffer (anything-marked-candidates)))
10062 (defun anything-c-delete-file (file)
10063 "Delete the given file after querying the user.
10064 Ask to kill buffers associated with that file, too."
10065 (let ((buffers (anything-c-file-buffers file)))
10066 (if (< emacs-major-version 24)
10067 ;; `dired-delete-file' in Emacs versions < 24
10068 ;; doesn't support delete-by-moving-to-trash
10069 ;; so use `delete-directory' and `delete-file'
10070 ;; that handle it.
10071 (cond ((and (not (file-symlink-p file))
10072 (file-directory-p file)
10073 (directory-files file t dired-re-no-dot))
10074 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10075 (delete-directory file 'recursive)))
10076 ((and (not (file-symlink-p file))
10077 (file-directory-p file))
10078 (delete-directory file))
10079 (t (delete-file file)))
10080 (dired-delete-file
10081 file 'dired-recursive-deletes delete-by-moving-to-trash))
10082 (when buffers
10083 (dolist (buf buffers)
10084 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10085 (kill-buffer buf))))))
10087 (defun anything-get-mailcap-for-file (filename)
10088 "Get the command to use for FILENAME from mailcap files.
10089 The command is like <command %s> and is meant to use with `format'."
10090 (mailcap-parse-mailcaps)
10091 (let* ((ext (file-name-extension filename))
10092 (mime (when ext (mailcap-extension-to-mime ext)))
10093 (result (when mime (mailcap-mime-info mime))))
10094 ;; If elisp file have no associations in .mailcap
10095 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10096 (when (stringp result) result)))
10098 (defun anything-get-default-program-for-file (filename)
10099 "Try to find a default program to open FILENAME.
10100 Try first in `anything-c-external-programs-associations' and then in mailcap file
10101 if nothing found return nil."
10102 (let* ((ext (file-name-extension filename))
10103 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10104 (cond ((and def-prog (not (string= def-prog "")))
10105 (concat def-prog " %s"))
10106 ((and anything-c-default-external-file-browser
10107 (file-directory-p filename))
10108 (concat anything-c-default-external-file-browser " %s"))
10109 (t (anything-get-mailcap-for-file filename)))))
10111 (defun anything-c-open-file-externally (file)
10112 "Open FILE with an external program.
10113 Try to guess which program to use with `anything-get-default-program-for-file'.
10114 If not found or a prefix arg is given query the user which tool to use."
10115 (let* ((fname (expand-file-name file))
10116 (collection (anything-c-external-commands-list-1 'sort))
10117 (def-prog (anything-get-default-program-for-file fname))
10118 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10119 ;; Prefix arg or no default program.
10120 (prog1
10121 (anything-comp-read
10122 "Program: " collection
10123 :must-match t
10124 :name "Open file Externally"
10125 :history anything-external-command-history)
10126 ;; Always prompt to set this program as default.
10127 (setq def-prog nil))
10128 ;; No prefix arg or default program exists.
10129 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10130 (program (concat real-prog-name " %s")))
10131 (unless (or def-prog ; Association exists, no need to record it.
10132 ;; Don't try to record non--filenames associations (e.g urls).
10133 (not (file-exists-p fname)))
10134 (when
10135 (y-or-n-p
10136 (format
10137 "Do you want to make `%s' the default program for this kind of files? "
10138 real-prog-name))
10139 (anything-aif (assoc (file-name-extension fname)
10140 anything-c-external-programs-associations)
10141 (setq anything-c-external-programs-associations
10142 (delete it anything-c-external-programs-associations)))
10143 (push (cons (file-name-extension fname)
10144 (read-string
10145 "Program (Add args maybe and confirm): " real-prog-name))
10146 anything-c-external-programs-associations)
10147 (customize-save-variable 'anything-c-external-programs-associations
10148 anything-c-external-programs-associations)))
10149 (anything-run-or-raise program file)
10150 (setq anything-external-command-history
10151 (cons real-prog-name
10152 (delete real-prog-name
10153 (loop for i in anything-external-command-history
10154 when (executable-find i) collect i))))))
10156 (defun anything-c-find-file-or-marked (candidate)
10157 "Open file CANDIDATE or open anything marked files in background."
10158 (let ((marked (anything-marked-candidates))
10159 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10160 (find-file-wildcards nil))
10161 (if (> (length marked) 1)
10162 ;; Open all marked files in background and display
10163 ;; the first one.
10164 (progn (mapc 'find-file-noselect (cdr marked))
10165 (find-file (car marked)))
10166 (if (and (not (file-exists-p candidate))
10167 (and ffap-url-regexp
10168 (not (string-match ffap-url-regexp candidate)))
10169 (string-match "/$" candidate))
10170 ;; A a non--existing filename ending with /
10171 ;; Create a directory and jump to it.
10172 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10173 (let ((dirfname (directory-file-name candidate)))
10174 (if (file-exists-p dirfname)
10175 (error "Mkdir: Unable to create directory `%s': file exists."
10176 (anything-c-basename dirfname))
10177 (make-directory candidate 'parent)))
10178 (anything-find-files-1 candidate))
10179 ;; A non--existing filename NOT ending with / or
10180 ;; an existing filename, create or jump to it.
10181 (find-file-at-point (car marked))))))
10183 (defun anything-delete-marked-files (ignore)
10184 (let* ((files (anything-marked-candidates))
10185 (len (length files)))
10186 (if (not (y-or-n-p
10187 (format "Delete *%s File(s):\n%s"
10189 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10190 (message "(No deletions performed)")
10191 (dolist (i files)
10192 (set-text-properties 0 (length i) nil i)
10193 (anything-c-delete-file i))
10194 (message "%s File(s) deleted" len))))
10196 (defun anything-ediff-marked-buffers (candidate &optional merge)
10197 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10198 With optional arg MERGE call `ediff-merge-buffers'."
10199 (let ((lg-lst (length (anything-marked-candidates)))
10200 buf1 buf2)
10201 (case lg-lst
10203 (error "Error:You have to mark at least 1 buffer"))
10205 (setq buf1 anything-current-buffer
10206 buf2 (first (anything-marked-candidates))))
10208 (setq buf1 (first (anything-marked-candidates))
10209 buf2 (second (anything-marked-candidates))))
10211 (error "Error:To much buffers marked!")))
10212 (if merge
10213 (ediff-merge-buffers buf1 buf2)
10214 (ediff-buffers buf1 buf2))))
10216 (defun anything-ediff-marked-buffers-merge (candidate)
10217 "Ediff merge `anything-current-buffer' with CANDIDATE.
10218 See `anything-ediff-marked-buffers'."
10219 (anything-ediff-marked-buffers candidate t))
10221 (defun anything-bookmark-get-bookmark-from-name (bmk)
10222 "Return bookmark name even if it is a bookmark with annotation.
10223 e.g prepended with *.
10224 Return nil if bmk is not a valid bookmark."
10225 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10226 (if (assoc bookmark bookmark-alist)
10227 bookmark
10228 (when (assoc bmk bookmark-alist)
10229 bmk))))
10231 (defun anything-delete-marked-bookmarks (ignore)
10232 "Delete this bookmark or all marked bookmarks."
10233 (dolist (i (anything-marked-candidates))
10234 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10235 'batch)))
10237 (defun anything-require-or-error (feature function)
10238 (or (require feature nil t)
10239 (error "Need %s to use `%s'." feature function)))
10241 (defun anything-find-buffer-on-elscreen (candidate)
10242 "Open buffer in new screen, if marked buffers open all in elscreens."
10243 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10244 (anything-aif (anything-marked-candidates)
10245 (dolist (i it)
10246 (let ((target-screen (elscreen-find-screen-by-buffer
10247 (get-buffer i) 'create)))
10248 (elscreen-goto target-screen)))
10249 (let ((target-screen (elscreen-find-screen-by-buffer
10250 (get-buffer candidate) 'create)))
10251 (elscreen-goto target-screen))))
10253 (defun anything-elscreen-find-file (file)
10254 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10255 (elscreen-find-file file))
10257 ;;;###autoload
10258 (defun w32-shell-execute-open-file (file)
10259 (interactive "fOpen file:")
10260 (with-no-warnings
10261 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10262 "/" "\\"
10263 (replace-regexp-in-string ; strip cygdrive paths
10264 "/cygdrive/\\(.\\)" "\\1:"
10265 file nil nil) nil t))))
10267 (defun anything-c-open-file-with-default-tool (file)
10268 "Open FILE with the default tool on this platform."
10269 (if (eq system-type 'windows-nt)
10270 (w32-shell-execute-open-file file)
10271 (start-process "anything-c-open-file-with-default-tool"
10273 (cond ((eq system-type 'gnu/linux)
10274 "xdg-open")
10275 ((or (eq system-type 'darwin) ;; Mac OS X
10276 (eq system-type 'macos)) ;; Mac OS 9
10277 "open"))
10278 file)))
10280 (defun anything-c-open-dired (file)
10281 "Opens a dired buffer in FILE's directory. If FILE is a
10282 directory, open this directory."
10283 (if (file-directory-p file)
10284 (dired file)
10285 (dired (file-name-directory file))
10286 (dired-goto-file file)))
10288 (defun anything-c-display-to-real-line (candidate)
10289 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10290 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10291 (error "Line number not found")))
10293 (defun anything-c-action-line-goto (lineno-and-content)
10294 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10295 (append lineno-and-content
10296 (list (if (and (anything-attr-defined 'target-file)
10297 (not anything-in-persistent-action))
10298 'find-file-other-window
10299 'find-file)))))
10301 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10302 (apply #'anything-goto-file-line
10303 (if (stringp file-line-content)
10304 ;; Case: filtered-candidate-transformer is skipped
10305 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10306 file-line-content)))
10308 (require 'compile)
10309 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10310 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10312 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10313 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10314 (let ((filename (match-string 1 candidate))
10315 (lineno (match-string 2 candidate))
10316 (content (match-string 3 candidate)))
10317 (cons (format "%s:%s\n %s"
10318 (propertize filename 'face compilation-info-face)
10319 (propertize lineno 'face compilation-line-face)
10320 content)
10321 (list (expand-file-name
10322 filename
10323 (or (anything-interpret-value (anything-attr 'default-directory))
10324 (and (anything-candidate-buffer)
10325 (buffer-local-value
10326 'default-directory (anything-candidate-buffer)))))
10327 (string-to-number lineno) content)))))
10329 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10330 (anything-aif (anything-attr 'before-jump-hook)
10331 (funcall it))
10332 (when file (funcall find-file-function file))
10333 (if (anything-attr-defined 'adjust)
10334 (anything-c-goto-line-with-adjustment lineno content)
10335 (anything-goto-line lineno))
10336 (unless (anything-attr-defined 'recenter)
10337 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10338 (anything-aif (anything-attr 'after-jump-hook)
10339 (funcall it))
10340 (when anything-in-persistent-action
10341 (anything-match-line-color-current-line)))
10343 (defun anything-find-file-as-root (candidate)
10344 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10346 (defun anything-find-many-files (ignore)
10347 (mapc 'find-file (anything-marked-candidates)))
10349 ;; borrowed from etags.el
10350 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10351 (defun anything-c-goto-line-with-adjustment (line line-content)
10352 (let ((startpos)
10353 offset found pat)
10354 ;; This constant is 1/2 the initial search window.
10355 ;; There is no sense in making it too small,
10356 ;; since just going around the loop once probably
10357 ;; costs about as much as searching 2000 chars.
10358 (setq offset 1000
10359 found nil
10360 pat (concat (if (eq selective-display t)
10361 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10362 (regexp-quote line-content)))
10363 ;; If no char pos was given, try the given line number.
10364 (setq startpos (progn (anything-goto-line line) (point)))
10365 (or startpos (setq startpos (point-min)))
10366 ;; First see if the tag is right at the specified location.
10367 (goto-char startpos)
10368 (setq found (looking-at pat))
10369 (while (and (not found)
10370 (progn
10371 (goto-char (- startpos offset))
10372 (not (bobp))))
10373 (setq found
10374 (re-search-forward pat (+ startpos offset) t)
10375 offset (* 3 offset))) ; expand search window
10376 (or found
10377 (re-search-forward pat nil t)
10378 (error "not found")))
10379 ;; Position point at the right place
10380 ;; if the search string matched an extra Ctrl-m at the beginning.
10381 (and (eq selective-display t)
10382 (looking-at "\^m")
10383 (forward-char 1))
10384 (beginning-of-line))
10386 (anything-document-attribute 'default-directory "type . file-line"
10387 "`default-directory' to interpret file.")
10388 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10389 "Function to call before jumping to the target location.")
10390 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10391 "Function to call after jumping to the target location.")
10392 (anything-document-attribute 'adjust "type . file-line"
10393 "Search around line matching line contents.")
10394 (anything-document-attribute 'recenter "type . file-line / line"
10395 "`recenter' after jumping.")
10396 (anything-document-attribute 'target-file "type . line"
10397 "Goto line of target-file.")
10399 ;;;###autoload
10400 (defun anything-c-call-interactively (cmd-or-name)
10401 "Execute CMD-OR-NAME as Emacs command.
10402 It is added to `extended-command-history'.
10403 `anything-current-prefix-arg' is used as the command's prefix argument."
10404 (setq extended-command-history
10405 (cons (anything-c-stringify cmd-or-name)
10406 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10407 (let ((current-prefix-arg anything-current-prefix-arg)
10408 (cmd (anything-c-symbolify cmd-or-name)))
10409 (if (stringp (symbol-function cmd))
10410 (execute-kbd-macro (symbol-function cmd))
10411 (setq this-command cmd)
10412 (call-interactively cmd))))
10414 ;;;###autoload
10415 (defun anything-c-set-variable (var)
10416 "Set value to VAR interactively."
10417 (interactive)
10418 (let ((sym (anything-c-symbolify var)))
10419 (set sym (eval-minibuffer (format "Set %s: " var)
10420 (prin1-to-string (symbol-value sym))))))
10421 ;; (setq hh 12)
10422 ;; (anything-c-set-variable 'hh)
10426 ;;; Persistent Action Helpers
10429 (defvar anything-match-line-overlay-face nil)
10430 (defvar anything-match-line-overlay nil)
10432 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10433 "Highlight and underline current position"
10434 (let ((args (list (or start (line-beginning-position))
10435 (or end (1+ (line-end-position)))
10436 buf)))
10437 (if (not anything-match-line-overlay)
10438 (setq anything-match-line-overlay (apply 'make-overlay args))
10439 (apply 'move-overlay anything-match-line-overlay args)))
10440 (overlay-put anything-match-line-overlay
10441 'face (or face anything-match-line-overlay-face))
10442 (when rec
10443 (goto-char start)
10444 (recenter)))
10446 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10449 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10451 (defun anything-match-line-cleanup ()
10452 (when anything-match-line-overlay
10453 (delete-overlay anything-match-line-overlay)
10454 (setq anything-match-line-overlay nil)))
10456 (defun anything-match-line-update ()
10457 (when anything-match-line-overlay
10458 (delete-overlay anything-match-line-overlay)
10459 (anything-match-line-color-current-line)))
10461 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10462 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10465 ;;; Actions Transformers
10468 ;;; Files
10469 (defun anything-c-transform-file-load-el (actions candidate)
10470 "Add action to load the file CANDIDATE if it is an emacs lisp
10471 file. Else return ACTIONS unmodified."
10472 (if (member (file-name-extension candidate) '("el" "elc"))
10473 (append actions '(("Load Emacs Lisp File" . load-file)))
10474 actions))
10476 (defun anything-c-transform-file-browse-url (actions candidate)
10477 "Add an action to browse the file CANDIDATE if it in a html
10478 file or URL. Else return ACTIONS unmodified."
10479 (let ((browse-action '("Browse with Browser" . browse-url)))
10480 (cond ((string-match "^http\\|^ftp" candidate)
10481 (cons browse-action actions))
10482 ((string-match "\\.html?$" candidate)
10483 (append actions (list browse-action)))
10484 (t actions))))
10486 ;;; Function
10487 (defun anything-c-transform-function-call-interactively (actions candidate)
10488 "Add an action to call the function CANDIDATE interactively if
10489 it is a command. Else return ACTIONS unmodified."
10490 (if (commandp (intern-soft candidate))
10491 (append actions '(("Call Interactively"
10493 anything-c-call-interactively)))
10494 actions))
10496 ;;;; S-Expressions
10497 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10498 "If CANDIDATE's `car' is a command, then add an action to
10499 evaluate it and put it onto the `command-history'."
10500 (if (commandp (car (read candidate)))
10501 ;; Make it first entry
10502 (cons '("Eval and put onto command-history" .
10503 (lambda (sexp)
10504 (let ((sym (read sexp)))
10505 (eval sym)
10506 (setq command-history
10507 (cons sym command-history)))))
10508 actions)
10509 actions))
10512 ;;; Candidate Transformers
10515 ;;; Buffers
10516 (defun anything-c-skip-boring-buffers (buffers)
10517 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10519 (defun anything-c-skip-current-buffer (buffers)
10520 (if anything-allow-skipping-current-buffer
10521 (remove (buffer-name anything-current-buffer) buffers)
10522 buffers))
10524 (defun anything-c-shadow-boring-buffers (buffers)
10525 "Buffers matching `anything-c-boring-buffer-regexp' will be
10526 displayed with the `file-name-shadow' face if available."
10527 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10529 (defvar anything-c-buffer-display-string-functions
10530 '(anything-c-buffer-display-string--compilation
10531 anything-c-buffer-display-string--shell
10532 anything-c-buffer-display-string--eshell)
10533 "Functions to setup display string for buffer.
10535 Function has one argument, buffer name.
10536 If it returns string, use it.
10537 If it returns nil, display buffer name.
10538 See `anything-c-buffer-display-string--compilation' for example.")
10540 (defun anything-c-transform-buffer-display-string (buffers)
10541 "Setup display string for buffer candidates
10542 using `anything-c-buffer-display-string-functions'."
10543 (loop for buf in buffers
10544 if (consp buf)
10545 collect buf
10546 else
10547 for disp = (progn (set-buffer buf)
10548 (run-hook-with-args-until-success
10549 'anything-c-buffer-display-string-functions buf))
10550 collect (if disp (cons disp buf) buf)))
10552 (defun anything-c-buffer-display-string--compilation (buf)
10553 (anything-aif (car compilation-arguments)
10554 (format "%s: %s [%s]" buf it default-directory)))
10556 (defun anything-c-buffer-display-string--eshell (buf)
10557 (declare (special eshell-history-ring))
10558 (when (eq major-mode 'eshell-mode)
10559 (format "%s: %s [%s]" buf
10560 (ignore-errors (ring-ref eshell-history-ring 0))
10561 default-directory)))
10563 (defun anything-c-buffer-display-string--shell (buf)
10564 (when (eq major-mode 'shell-mode)
10565 (format "%s: %s [%s]" buf
10566 (ignore-errors (ring-ref comint-input-ring 0))
10567 default-directory)))
10569 ;;; Files
10570 (defun anything-c-shadow-boring-files (files)
10571 "Files matching `anything-c-boring-file-regexp' will be
10572 displayed with the `file-name-shadow' face if available."
10573 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10575 (defun anything-c-skip-boring-files (files)
10576 "Files matching `anything-c-boring-file-regexp' will be skipped."
10577 (anything-c-skip-entries files anything-c-boring-file-regexp))
10578 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10580 (defun anything-c-skip-current-file (files)
10581 "Current file will be skipped."
10582 (remove (buffer-file-name anything-current-buffer) files))
10584 (defun anything-c-w32-pathname-transformer (args)
10585 "Change undesirable features of windows pathnames to ones more acceptable to
10586 other candidate transformers."
10587 (if (eq system-type 'windows-nt)
10588 (mapcar (lambda (x)
10589 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10590 (mapcar (lambda (y)
10591 (replace-regexp-in-string "\\\\" "/" y)) args))
10592 args))
10594 (defun anything-c-shorten-home-path (files)
10595 "Replaces /home/user with ~."
10596 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10597 (getenv "HOME"))))
10598 (mapcar (lambda (file)
10599 (if (and (stringp file) (string-match home file))
10600 (cons (replace-match "~" nil nil file) file)
10601 file))
10602 files)))
10604 ;;; Functions
10605 (defun anything-c-mark-interactive-functions (functions)
10606 "Mark interactive functions (commands) with (i) after the function name."
10607 (let (list)
10608 (loop for function in functions
10609 do (push (cons (concat function
10610 (when (commandp (intern-soft function)) " (i)"))
10611 function)
10612 list)
10613 finally (return (nreverse list)))))
10616 ;;; Adaptive Sorting of Candidates
10619 ;; Internal
10620 (defvar anything-c-adaptive-done nil
10621 "nil if history information is not yet stored for the current
10622 selection.")
10624 (defvar anything-c-adaptive-history nil
10625 "Contains the stored history information.
10626 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10628 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10629 "Reset `anything-c-adaptive-done' when anything is started."
10630 (when anything-c-use-adaptative-sorting
10631 (setq anything-c-adaptive-done nil)))
10633 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10634 "Store history information when action is executed on selected candidate."
10635 (when anything-c-use-adaptative-sorting
10636 (anything-c-adaptive-store-selection)))
10638 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10639 "Store history information when the user goes to the action buffer."
10640 (when anything-c-use-adaptative-sorting
10641 (anything-c-adaptive-store-selection)))
10643 (defun anything-c-source-use-adaptative-p (&optional source-name)
10644 "Return current source only if it use adaptative history, nil otherwise."
10645 (when anything-c-use-adaptative-sorting
10646 (let* ((source (or source-name (anything-get-current-source)))
10647 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10648 (assoc (assoc-default 'type source)
10649 anything-type-attributes))
10650 (assoc-default 'candidate-transformer
10651 (assoc (assoc-default 'type source)
10652 anything-type-attributes))
10653 (assoc-default 'filtered-candidate-transformer source)
10654 (assoc-default 'candidate-transformer source))))
10655 (if (listp adapt-source)
10656 (when (member 'anything-c-adaptive-sort adapt-source) source)
10657 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10659 (defun anything-c-adaptive-store-selection ()
10660 "Store history information for the selected candidate."
10661 (unless anything-c-adaptive-done
10662 (setq anything-c-adaptive-done t)
10663 (let ((source (anything-c-source-use-adaptative-p)))
10664 (when source
10665 (let* ((source-name (or (assoc-default 'type source)
10666 (assoc-default 'name source)))
10667 (source-info (or (assoc source-name anything-c-adaptive-history)
10668 (progn
10669 (push (list source-name) anything-c-adaptive-history)
10670 (car anything-c-adaptive-history))))
10671 (selection (anything-get-selection))
10672 (selection-info (progn
10673 (setcdr source-info
10674 (cons
10675 (let ((found (assoc selection (cdr source-info))))
10676 (if (not found)
10677 ;; new entry
10678 (list selection)
10680 ;; move entry to the beginning of the
10681 ;; list, so that it doesn't get
10682 ;; trimmed when the history is
10683 ;; truncated
10684 (setcdr source-info
10685 (delete found (cdr source-info)))
10686 found))
10687 (cdr source-info)))
10688 (cadr source-info)))
10689 (pattern-info (progn
10690 (setcdr selection-info
10691 (cons
10692 (let ((found (assoc anything-pattern (cdr selection-info))))
10693 (if (not found)
10694 ;; new entry
10695 (cons anything-pattern 0)
10697 ;; move entry to the beginning of the
10698 ;; list, so if two patterns used the
10699 ;; same number of times then the one
10700 ;; used last appears first in the list
10701 (setcdr selection-info
10702 (delete found (cdr selection-info)))
10703 found))
10704 (cdr selection-info)))
10705 (cadr selection-info))))
10707 ;; increase usage count
10708 (setcdr pattern-info (1+ (cdr pattern-info)))
10710 ;; truncate history if needed
10711 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10712 (setcdr selection-info
10713 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10715 (defun anything-c-adaptative-maybe-load-history ()
10716 (when (and anything-c-use-adaptative-sorting
10717 (file-readable-p anything-c-adaptive-history-file))
10718 (load-file anything-c-adaptive-history-file)))
10720 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10721 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10723 (defun anything-c-adaptive-save-history (&optional arg)
10724 "Save history information to file given by `anything-c-adaptive-history-file'."
10725 (interactive "p")
10726 (when anything-c-use-adaptative-sorting
10727 (with-temp-buffer
10728 (insert
10729 ";; -*- mode: emacs-lisp -*-\n"
10730 ";; History entries used for anything adaptive display.\n")
10731 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10732 (current-buffer))
10733 (insert ?\n)
10734 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10735 (unless arg 'quiet)))))
10737 (defun anything-c-adaptive-sort (candidates source)
10738 "Sort the CANDIDATES for SOURCE by usage frequency.
10739 This is a filtered candidate transformer you can use for the
10740 attribute `filtered-candidate-transformer' of a source in
10741 `anything-sources' or a type in `anything-type-attributes'."
10742 (let* ((source-name (or (assoc-default 'type source)
10743 (assoc-default 'name source)))
10744 (source-info (assoc source-name anything-c-adaptive-history)))
10745 (if source-info
10746 (let ((usage
10747 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10748 ;; pairs
10749 (mapcar (lambda (candidate-info)
10750 (let ((count 0))
10751 (dolist (pattern-info (cdr candidate-info))
10752 (if (not (equal (car pattern-info)
10753 anything-pattern))
10754 (incf count (cdr pattern-info))
10756 ;; if current pattern is equal to the previously
10757 ;; used one then this candidate has priority
10758 ;; (that's why its count is boosted by 10000) and
10759 ;; it only has to compete with other candidates
10760 ;; which were also selected with the same pattern
10761 (setq count (+ 10000 (cdr pattern-info)))
10762 (return)))
10763 (cons (car candidate-info) count)))
10764 (cdr source-info)))
10765 sorted)
10766 (if (and usage (consp usage))
10767 ;; sort the list in descending order, so candidates with highest
10768 ;; priorty come first
10769 (progn
10770 (setq usage (sort usage (lambda (first second)
10771 (> (cdr first) (cdr second)))))
10773 ;; put those candidates first which have the highest usage count
10774 (dolist (info usage)
10775 (when (member* (car info) candidates
10776 :test 'anything-c-adaptive-compare)
10777 (push (car info) sorted)
10778 (setq candidates (remove* (car info) candidates
10779 :test 'anything-c-adaptive-compare))))
10781 ;; and append the rest
10782 (append (reverse sorted) candidates nil))
10783 (message "Your `%s' is maybe corrupted or too old, \
10784 you should reinitialize it with `anything-c-reset-adaptative-history'"
10785 anything-c-adaptive-history-file)
10786 (sit-for 1)
10787 candidates))
10788 ;; if there is no information stored for this source then do nothing
10789 candidates)))
10791 ;;;###autoload
10792 (defun anything-c-reset-adaptative-history ()
10793 "Delete all `anything-c-adaptive-history' and his file.
10794 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10795 (interactive)
10796 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10797 (setq anything-c-adaptive-history nil)
10798 (delete-file anything-c-adaptive-history-file)))
10800 (defun anything-c-adaptive-compare (x y)
10801 "Compare candidates X and Y taking into account that the
10802 candidate can be in (DISPLAY . REAL) format."
10803 (equal (if (listp x)
10804 (cdr x)
10806 (if (listp y)
10807 (cdr y)
10808 y)))
10812 ;;; Outliner
10815 (defvar anything-outline-goto-near-line-flag t)
10816 (defvar anything-outline-using nil)
10817 (defun anything-after-update-hook--outline ()
10818 (if (and (eq anything-outline-using t)
10819 (eq anything-outline-goto-near-line-flag t))
10820 (anything-outline-goto-near-line)))
10821 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10823 (defun anything-outline-goto-near-line ()
10824 (with-anything-window
10825 ;; TODO need consideration whether to update position by every input.
10826 (when t ; (equal anything-pattern "")
10827 (anything-goto-line 2)
10828 (let ((lineno (with-anything-current-buffer
10829 (line-number-at-pos (car anything-current-position)))))
10830 (block exit
10831 (while (<= (progn (skip-chars-forward " ")
10832 (or (number-at-point) lineno))
10833 lineno)
10834 (forward-line 1)
10835 (when (eobp)
10836 (forward-line -1)
10837 (return-from exit))))
10838 (forward-line -1)
10839 (and (bobp) (forward-line 1))
10840 (and (anything-pos-header-line-p) (forward-line -2))
10841 (anything-mark-current-line)))))
10845 ;;; Plug-in
10848 ;; Plug-in: info-index
10849 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10850 (let (result)
10851 (unless (anything-candidate-buffer)
10852 (save-window-excursion
10853 (info file)
10854 (let (Info-history
10855 (tobuf (anything-candidate-buffer 'global))
10856 (infobuf (current-buffer))
10857 s e)
10858 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10859 (Info-goto-node node)
10860 (goto-char (point-min))
10861 (while (search-forward "\n* " nil t)
10862 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10863 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10864 (setq s (point-at-bol)
10865 e (point-at-eol))
10866 (with-current-buffer tobuf
10867 (insert-buffer-substring infobuf s e)
10868 (insert "\n"))))))))))
10870 (defun anything-c-info-goto (node-line)
10871 (Info-goto-node (car node-line))
10872 (anything-goto-line (cdr node-line)))
10874 (defun anything-c-info-display-to-real (line)
10875 (and (string-match
10876 ;; This regexp is stolen from Info-apropos-matches
10877 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10878 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10879 (string-to-number (or (match-string 3 line) "1")))))
10881 (defun anything-c-make-info-source (source file)
10882 `(,@source
10883 (name . ,(concat "Info Index: " file))
10884 (info-file . ,file)
10885 (init . anything-c-info-init)
10886 (display-to-real . anything-c-info-display-to-real)
10887 (get-line . buffer-substring)
10888 (candidates-in-buffer)
10889 (action ("Goto node" . anything-c-info-goto))))
10891 (defun anything-compile-source--info-index (source)
10892 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10893 (anything-c-make-info-source source it)
10894 source))
10895 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10897 (anything-document-attribute 'info-index "info-index plugin"
10898 "Create a source of info index very easily.
10900 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10902 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10903 "Index nodes of info file.
10905 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10906 Some info files are missing index specification.
10908 ex. See `anything-c-source-info-screen'.")
10910 ;; Plug-in: candidates-file
10911 (defun anything-compile-source--candidates-file (source)
10912 (if (assoc-default 'candidates-file source)
10913 `((init anything-p-candidats-file-init
10914 ,@(let ((orig-init (assoc-default 'init source)))
10915 (cond ((null orig-init) nil)
10916 ((functionp orig-init) (list orig-init))
10917 (t orig-init))))
10918 (candidates-in-buffer)
10919 ,@source)
10920 source))
10921 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10923 (defun anything-p-candidats-file-init ()
10924 (destructuring-bind (file &optional updating)
10925 (anything-mklist (anything-attr 'candidates-file))
10926 (setq file (anything-interpret-value file))
10927 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10928 (when updating
10929 (buffer-disable-undo)
10930 (font-lock-mode -1)
10931 (auto-revert-mode 1)))))
10933 (anything-document-attribute 'candidates-file "candidates-file plugin"
10934 "Use a file as the candidates buffer.
10936 1st argument is a filename, string or function name or variable name.
10937 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10939 ;; Plug-in: headline
10940 (defun anything-compile-source--anything-headline (source)
10941 (if (assoc-default 'headline source)
10942 (append '((init . anything-headline-init)
10943 (get-line . buffer-substring)
10944 (type . line))
10945 source
10946 '((candidates-in-buffer)
10947 (persistent-help . "Show this line")))
10948 source))
10949 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10951 (defun anything-headline-init ()
10952 (when (and (anything-current-buffer-is-modified)
10953 (with-anything-current-buffer
10954 (eval (or (anything-attr 'condition) t))))
10955 (anything-headline-make-candidate-buffer
10956 (anything-interpret-value (anything-attr 'headline))
10957 (anything-interpret-value (anything-attr 'subexp)))))
10959 (anything-document-attribute 'headline "Headline plug-in"
10960 "Regexp string for anything-headline to scan.")
10961 (anything-document-attribute 'condition "Headline plug-in"
10962 "A sexp representing the condition to use anything-headline.")
10963 (anything-document-attribute 'subexp "Headline plug-in"
10964 "Display (match-string-no-properties subexp).")
10966 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10967 ;; of regexps.
10969 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10970 ;; 2. Sort this list by start-of-match.
10971 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10973 ;; It's quite brilliantly written.
10977 (defun anything-headline-get-candidates (regexp subexp)
10978 (with-anything-current-buffer
10979 (save-excursion
10980 (goto-char (point-min))
10981 (if (functionp regexp) (setq regexp (funcall regexp)))
10982 (let (hierarchy curhead)
10983 (flet ((matched ()
10984 (if (numberp subexp)
10985 (cons (match-string-no-properties subexp) (match-beginning subexp))
10986 (cons (buffer-substring (point-at-bol) (point-at-eol))
10987 (point-at-bol))))
10988 (hierarchies (headlines)
10989 (1+ (loop for (_ . hierarchy) in headlines
10990 maximize hierarchy)))
10991 (vector-0-n (v n)
10992 (loop for i from 0 to hierarchy
10993 collecting (aref curhead i)))
10994 (arrange (headlines)
10995 (unless (null headlines) ; FIX headlines empty bug!
10996 (loop with curhead = (make-vector (hierarchies headlines) "")
10997 for ((str . pt) . hierarchy) in headlines
10998 do (aset curhead hierarchy str)
10999 collecting
11000 (cons
11001 (format "H%d:%s" (1+ hierarchy)
11002 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11003 pt)))))
11004 (if (listp regexp)
11005 (arrange
11006 (sort
11007 (loop for re in regexp
11008 for hierarchy from 0
11009 do (goto-char (point-min))
11010 appending
11011 (loop
11012 while (re-search-forward re nil t)
11013 collect (cons (matched) hierarchy)))
11014 (lambda (a b) (> (cdar b) (cdar a)))))
11015 (loop while (re-search-forward regexp nil t)
11016 collect (matched))))))))
11019 (defun anything-headline-make-candidate-buffer (regexp subexp)
11020 (with-current-buffer (anything-candidate-buffer 'local)
11021 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11022 do (insert
11023 (format "%5d:%s\n"
11024 (with-anything-current-buffer
11025 (line-number-at-pos pos))
11026 content)))))
11028 (defun anything-headline-goto-position (pos recenter)
11029 (goto-char pos)
11030 (unless recenter
11031 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11034 ;; Plug-in: persistent-help
11035 (defun anything-compile-source--persistent-help (source)
11036 (append source '((header-line . anything-persistent-help-string))))
11037 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11039 (defun anything-persistent-help-string ()
11040 (substitute-command-keys
11041 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11042 (or (anything-interpret-value (anything-attr 'persistent-help))
11043 (anything-aif (or (assoc-default 'persistent-action
11044 (anything-get-current-source))
11045 (assoc-default 'action
11046 (anything-get-current-source)))
11047 (cond ((symbolp it) (symbol-name it))
11048 ((listp it) (or (ignore-errors (caar it)) ""))))
11050 " (keeping session)")))
11052 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11053 "A string to explain persistent-action of this source.
11054 It also accepts a function or a variable name.")
11056 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11058 ;; Plug-in: Type customize
11059 (defun anything-c-uniq-list (lst)
11060 "Like `remove-duplicates' in CL.
11061 But cut deeper duplicates and test by `equal'. "
11062 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11063 (defvar anything-additional-type-attributes nil)
11064 (defun anything-c-arrange-type-attribute (type spec)
11065 "Override type attributes by `define-anything-type-attribute'.
11067 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11069 Example: Set `play-sound-file' as default action
11070 (anything-c-arrange-type-attribute 'file
11071 '((action (\"Play sound\" . play-sound-file)
11072 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11075 (add-to-list 'anything-additional-type-attributes
11076 (cons type
11077 (loop with typeattr = (assoc-default type anything-type-attributes)
11078 for (attr . value) in spec
11079 if (listp value)
11080 collect (cons attr
11081 (anything-c-uniq-list
11082 (loop for v in value
11083 if (eq v 'REST)
11084 append (assoc-default attr typeattr)
11085 else
11086 collect v)))
11087 else
11088 collect (cons attr value)))))
11089 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11091 (defun anything-compile-source--type-customize (source)
11092 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11093 (append it source)
11094 source))
11095 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11097 ;; Plug-in: default-action
11098 (defun anything-compile-source--default-action (source)
11099 (anything-aif (assoc-default 'default-action source)
11100 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11101 source)
11102 source))
11103 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11104 (anything-document-attribute 'default-action "default-action plug-in"
11105 "Default action.")
11108 ;;; Toggle anything-match-plugin
11111 (defvar anything-mp-initial-highlight-delay nil)
11113 ;;;###autoload
11114 (defun anything-c-toggle-match-plugin ()
11115 "Toggle anything-match-plugin."
11116 (interactive)
11117 (let ((anything-match-plugin-enabled
11118 (member 'anything-compile-source--match-plugin
11119 anything-compile-source-functions)))
11120 (flet ((disable-match-plugin ()
11121 (setq anything-compile-source-functions
11122 (delq 'anything-compile-source--match-plugin
11123 anything-compile-source-functions))
11124 (setq anything-mp-initial-highlight-delay
11125 anything-mp-highlight-delay)
11126 (setq anything-mp-highlight-delay nil))
11127 (enable-match-plugin ()
11128 (require 'anything-match-plugin)
11129 (unless anything-mp-initial-highlight-delay
11130 (setq anything-mp-initial-highlight-delay
11131 anything-mp-highlight-delay))
11132 (setq anything-compile-source-functions
11133 (cons 'anything-compile-source--match-plugin
11134 anything-compile-source-functions))
11135 (unless anything-mp-highlight-delay
11136 (setq anything-mp-highlight-delay
11137 anything-mp-initial-highlight-delay))))
11138 (if anything-match-plugin-enabled
11139 (when (y-or-n-p "Really disable match-plugin? ")
11140 (disable-match-plugin)
11141 (message "Anything-match-plugin disabled"))
11142 (when (y-or-n-p "Really enable match-plugin? ")
11143 (enable-match-plugin)
11144 (message "Anything-match-plugin enabled"))))))
11148 ;;; Type Attributes
11151 (define-anything-type-attribute 'buffer
11152 `((action
11153 ("Switch to buffer" . anything-c-switch-to-buffer)
11154 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11155 ("Switch to buffer other window" . switch-to-buffer-other-window)
11156 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11157 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11158 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11159 ("Query replace" . anything-c-buffer-query-replace)
11160 ("View buffer" . view-buffer)
11161 ("Display buffer" . display-buffer)
11162 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11163 ("Revert buffer(s)" . anything-revert-marked-buffers)
11164 ("Insert buffer" . insert-buffer)
11165 ("Kill buffer(s)" . anything-kill-marked-buffers)
11166 ("Diff with file" . diff-buffer-with-file)
11167 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11168 ("Ediff Merge marked buffers" . (lambda (candidate)
11169 (anything-ediff-marked-buffers candidate t))))
11170 (persistent-help . "Show this buffer")
11171 (candidate-transformer anything-c-skip-current-buffer
11172 anything-c-skip-boring-buffers
11173 anything-c-transform-buffer-display-string))
11174 "Buffer or buffer name.")
11176 (define-anything-type-attribute 'file
11177 `((action
11178 ("Find file" . anything-find-many-files)
11179 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11180 ("Find file as root" . anything-find-file-as-root)
11181 ("Find file other window" . find-file-other-window)
11182 ("Find file other frame" . find-file-other-frame)
11183 ("Open dired in file's directory" . anything-c-open-dired)
11184 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11185 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11186 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11187 ("Checksum File" . anything-ff-checksum)
11188 ("Ediff File" . anything-find-files-ediff-files)
11189 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11190 ("View file" . view-file)
11191 ("Insert file" . insert-file)
11192 ("Delete file(s)" . anything-delete-marked-files)
11193 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11194 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11195 ("Find file in hex dump" . hexl-find-file))
11196 (persistent-help . "Show this file")
11197 (action-transformer anything-c-transform-file-load-el
11198 anything-c-transform-file-browse-url)
11199 (candidate-transformer anything-c-w32-pathname-transformer
11200 anything-c-skip-current-file
11201 anything-c-skip-boring-files
11202 anything-c-shorten-home-path))
11203 "File name.")
11205 (let ((actions '(("Describe command" . describe-function)
11206 ("Add command to kill ring" . anything-c-kill-new)
11207 ("Go to command's definition" . find-function)
11208 ("Debug on entry" . debug-on-entry)
11209 ("Cancel debug on entry" . cancel-debug-on-entry)
11210 ("Trace function" . trace-function)
11211 ("Trace function (background)" . trace-function-background)
11212 ("Untrace function" . untrace-function))))
11213 (define-anything-type-attribute 'command
11214 `((action ("Call interactively" . anything-c-call-interactively)
11215 ,@actions)
11216 ;; Sort commands according to their usage count.
11217 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11218 (coerce . anything-c-symbolify)
11219 (persistent-action . describe-function))
11220 "Command. (string or symbol)")
11222 (define-anything-type-attribute 'function
11223 `((action . ,actions)
11224 (action-transformer anything-c-transform-function-call-interactively)
11225 (candidate-transformer anything-c-mark-interactive-functions)
11226 (coerce . anything-c-symbolify))
11227 "Function. (string or symbol)"))
11229 (define-anything-type-attribute 'variable
11230 '((action ("Describe variable" . describe-variable)
11231 ("Add variable to kill ring" . anything-c-kill-new)
11232 ("Go to variable's definition" . find-variable)
11233 ("Set variable" . anything-c-set-variable))
11234 (coerce . anything-c-symbolify))
11235 "Variable.")
11237 (define-anything-type-attribute 'sexp
11238 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11239 ("Add s-expression to kill ring" . kill-new))
11240 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11241 "String representing S-Expressions.")
11243 (define-anything-type-attribute 'bookmark
11244 `((coerce . anything-bookmark-get-bookmark-from-name)
11245 (action
11246 ("Jump to bookmark" . (lambda (bookmark)
11247 (let ((current-prefix-arg anything-current-prefix-arg))
11248 (bookmark-jump bookmark))
11249 (anything-update)))
11250 ("Jump to BM other window" . (lambda (bookmark)
11251 (bookmark-jump-other-window bookmark)
11252 (anything-update)))
11253 ("Bookmark edit annotation" . bookmark-edit-annotation)
11254 ("Bookmark show annotation" . bookmark-show-annotation)
11255 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11256 ,@(and (locate-library "bookmark-extensions")
11257 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11258 ("Rename bookmark" . bookmark-rename)
11259 ("Relocate bookmark" . bookmark-relocate)))
11260 "Bookmark name.")
11262 (define-anything-type-attribute 'line
11263 '((display-to-real . anything-c-display-to-real-line)
11264 (action ("Go to Line" . anything-c-action-line-goto)))
11265 "LINENO:CONTENT string, eg. \" 16:foo\".
11267 Optional `target-file' attribute is a name of target file.
11269 Optional `before-jump-hook' attribute is a function with no
11270 arguments which is called before jumping to position.
11272 Optional `after-jump-hook' attribute is a function with no
11273 arguments which is called after jumping to position.
11275 If `adjust' attribute is specified, searches the line whose
11276 content is CONTENT near the LINENO.
11278 If `recenter' attribute is specified, the line is displayed at
11279 the center of window, otherwise at the top of window.
11282 (define-anything-type-attribute 'file-line
11283 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11284 (multiline)
11285 (action ("Go to" . anything-c-action-file-line-goto)))
11286 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11288 Optional `default-directory' attribute is a default-directory
11289 FILENAME is interpreted.
11291 Optional `before-jump-hook' attribute is a function with no
11292 arguments which is called before jumping to position.
11294 Optional `after-jump-hook' attribute is a function with no
11295 arguments which is called after jumping to position.
11297 If `adjust' attribute is specified, searches the line whose
11298 content is CONTENT near the LINENO.
11300 If `recenter' attribute is specified, the line is displayed at
11301 the center of window, otherwise at the top of window.
11304 (define-anything-type-attribute 'timer
11305 '((real-to-display . anything-c-timer-real-to-display)
11306 (action ("Cancel Timer" . cancel-timer)
11307 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11308 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11309 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11310 (persistent-help . "Describe Function"))
11311 "Timer.")
11314 ;;; Default `anything-sources'
11315 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11316 ;; tend to invoke M-x anything directly. So I offer default setting.
11317 (setq anything-sources
11318 '(anything-c-source-buffers-list
11319 anything-c-source-recentf
11320 anything-c-source-files-in-current-dir+))
11323 ;;; Preconfigured Anything
11326 ;;;###autoload
11327 (defun anything-mini ()
11328 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11329 (interactive)
11330 (anything-other-buffer '(anything-c-source-buffers-list
11331 anything-c-source-recentf
11332 anything-c-source-buffer-not-found)
11333 "*anything mini*"))
11334 ;;;###autoload
11335 (defun anything-for-files ()
11336 "Preconfigured `anything' for opening files.
11337 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11338 (interactive)
11339 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11341 ;;;###autoload
11342 (defun anything-recentf ()
11343 "Preconfigured `anything' for `recentf'."
11344 (interactive)
11345 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11347 ;;;###autoload
11348 (defun anything-info-at-point (arg)
11349 "Preconfigured `anything' for searching info at point.
11350 With a prefix-arg insert symbol at point."
11351 (interactive "P")
11352 (let ((anything-c-google-suggest-default-function
11353 'anything-c-google-suggest-emacs-lisp))
11354 (anything :sources '(anything-c-source-info-elisp
11355 anything-c-source-info-cl
11356 anything-c-source-info-pages
11357 anything-c-source-google-suggest)
11358 :input (and arg (thing-at-point 'symbol))
11359 :buffer "*anything info*")))
11361 ;;;###autoload
11362 (defun anything-info-emacs ()
11363 "Preconfigured anything for Emacs manual index."
11364 (interactive)
11365 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11367 ;;;###autoload
11368 (defun anything-show-kill-ring ()
11369 "Preconfigured `anything' for `kill-ring'.
11370 It is drop-in replacement of `yank-pop'.
11371 You may bind this command to M-y.
11372 First call open the kill-ring browser, next calls move to next line."
11373 (interactive)
11374 (let ((buf "*anything kill-ring*"))
11375 (if (get-buffer-window buf)
11376 (with-anything-window
11377 (if (eq (overlay-end anything-selection-overlay) (point-max))
11378 (anything-beginning-of-buffer)
11379 (anything-next-line)))
11380 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11382 ;;;###autoload
11383 (defun anything-minibuffer-history ()
11384 "Preconfigured `anything' for `minibuffer-history'."
11385 (interactive)
11386 (let ((enable-recursive-minibuffers t))
11387 (anything-other-buffer 'anything-c-source-minibuffer-history
11388 "*anything minibuffer-history*")))
11390 ;;;###autoload
11391 (defun anything-gentoo ()
11392 "Preconfigured `anything' for gentoo linux."
11393 (interactive)
11394 (anything-other-buffer '(anything-c-source-gentoo
11395 anything-c-source-use-flags)
11396 "*anything gentoo*"))
11398 ;;;###autoload
11399 (defun anything-imenu ()
11400 "Preconfigured `anything' for `imenu'."
11401 (interactive)
11402 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11404 ;;;###autoload
11405 (defun anything-google-suggest ()
11406 "Preconfigured `anything' for google search with google suggest."
11407 (interactive)
11408 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11410 ;;;###autoload
11411 (defun anything-yahoo-suggest ()
11412 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11413 (interactive)
11414 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11416 ;;; Converted from anything-show-*-only
11417 ;;;###autoload
11418 (defun anything-for-buffers ()
11419 "Preconfigured `anything' for buffer."
11420 (interactive)
11421 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11423 ;;;###autoload
11424 (defun anything-buffers-list ()
11425 "Enhanced preconfigured `anything' for buffer."
11426 (interactive)
11427 (anything :sources '(anything-c-source-buffers-list
11428 anything-c-source-buffer-not-found)
11429 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11431 ;;;###autoload
11432 (defun anything-bbdb ()
11433 "Preconfigured `anything' for BBDB.
11435 Needs BBDB.
11437 http://bbdb.sourceforge.net/"
11438 (interactive)
11439 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11441 ;;;###autoload
11442 (defun anything-locate (arg)
11443 "Preconfigured `anything' for Locate.
11444 Note: you can add locate options after entering pattern.
11445 See 'man locate' for valid options.
11447 You can specify a specific database with prefix argument ARG \(C-u\).
11448 Many databases can be used: navigate and mark them.
11449 See also `anything-locate-with-db'.
11451 To create a user specific db, use
11452 \"updatedb -l 0 -o db_path -U directory\".
11453 Where db_path is a filename matched by
11454 `anything-locate-db-file-regexp'."
11455 (interactive "P")
11456 (anything-locate-1 arg))
11458 ;;;###autoload
11459 (defun anything-w3m-bookmarks ()
11460 "Preconfigured `anything' for w3m bookmark.
11462 Needs w3m and emacs-w3m.
11464 http://w3m.sourceforge.net/
11465 http://emacs-w3m.namazu.org/"
11466 (interactive)
11467 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11468 "*anything w3m bookmarks*"))
11470 ;;;###autoload
11471 (defun anything-firefox-bookmarks ()
11472 "Preconfigured `anything' for firefox bookmark.
11473 You will have to enable html bookmarks in firefox:
11474 open about:config in firefox and double click on this line to enable value \
11475 to true:
11477 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11479 You should have now:
11481 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11483 After closing firefox, you will be able to browse you bookmarks.
11485 (interactive)
11486 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11487 "*Anything Firefox*"))
11489 ;;;###autoload
11490 (defun anything-colors ()
11491 "Preconfigured `anything' for color."
11492 (interactive)
11493 (anything-other-buffer
11494 '(anything-c-source-colors anything-c-source-customize-face)
11495 "*anything colors*"))
11497 ;;;###autoload
11498 (defun anything-bookmarks ()
11499 "Preconfigured `anything' for bookmarks."
11500 (interactive)
11501 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11503 ;;;###autoload
11504 (defun anything-c-pp-bookmarks ()
11505 "Preconfigured `anything' for bookmarks (pretty-printed)."
11506 (interactive)
11507 (anything-other-buffer '(anything-c-source-bookmarks-local
11508 anything-c-source-bookmarks-su
11509 anything-c-source-bookmarks-ssh)
11510 "*anything pp bookmarks*"))
11512 ;;;###autoload
11513 (defun anything-c-insert-latex-math ()
11514 "Preconfigured anything for latex math symbols completion."
11515 (interactive)
11516 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11518 ;;;###autoload
11519 (defun anything-register ()
11520 "Preconfigured `anything' for Emacs registers."
11521 (interactive)
11522 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11524 ;;;###autoload
11525 (defun anything-man-woman ()
11526 "Preconfigured `anything' for Man and Woman pages."
11527 (interactive)
11528 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11530 ;;;###autoload
11531 (defun anything-org-keywords ()
11532 "Preconfigured `anything' for org keywords."
11533 (interactive)
11534 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11536 ;;;###autoload
11537 (defun anything-emms ()
11538 "Preconfigured `anything' for emms sources."
11539 (interactive)
11540 (anything '(anything-c-source-emms-streams
11541 anything-c-source-emms-files
11542 anything-c-source-emms-dired)
11543 nil nil nil nil
11544 "*Anything Emms*"))
11546 ;;;###autoload
11547 (defun anything-eev-anchors ()
11548 "Preconfigured `anything' for eev anchors."
11549 (interactive)
11550 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11552 ;;;###autoload
11553 (defun anything-bm-list ()
11554 "Preconfigured `anything' for visible bookmarks.
11556 Needs bm.el
11558 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11559 (interactive)
11560 (let ((anything-outline-using t))
11561 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11563 ;;;###autoload
11564 (defun anything-timers ()
11565 "Preconfigured `anything' for timers."
11566 (interactive)
11567 (anything-other-buffer '(anything-c-source-absolute-time-timers
11568 anything-c-source-idle-time-timers)
11569 "*anything timers*"))
11571 ;;;###autoload
11572 (defun anything-list-emacs-process ()
11573 "Preconfigured `anything' for emacs process."
11574 (interactive)
11575 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11577 ;;;###autoload
11578 (defun anything-occur ()
11579 "Preconfigured Anything for Occur source.
11580 If region is active, search only in region,
11581 otherwise search in whole buffer."
11582 (interactive)
11583 (let ((anything-compile-source-functions
11584 ;; rule out anything-match-plugin because the input is one regexp.
11585 (delq 'anything-compile-source--match-plugin
11586 (copy-sequence anything-compile-source-functions))))
11587 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11589 ;;;###autoload
11590 (defun anything-browse-code ()
11591 "Preconfigured anything to browse code."
11592 (interactive)
11593 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11595 ;;;###autoload
11596 (defun anything-org-headlines ()
11597 "Preconfigured anything to show org headlines."
11598 (interactive)
11599 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11601 ;;;###autoload
11602 (defun anything-info-gnus ()
11603 "Preconfigured anything to browse Gnus Manual."
11604 (interactive)
11605 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11607 ;;;###autoload
11608 (defun anything-regexp ()
11609 "Preconfigured anything to build regexps and run query-replace-regexp \
11610 against."
11611 (interactive)
11612 (save-restriction
11613 (let ((anything-compile-source-functions
11614 ;; rule out anything-match-plugin because the input is one regexp.
11615 (delq 'anything-compile-source--match-plugin
11616 (copy-sequence anything-compile-source-functions))))
11617 (when (and (anything-region-active-p)
11618 ;; Don't narrow to region if buffer is already narrowed.
11619 (not (anything-current-buffer-narrowed-p)))
11620 (narrow-to-region (region-beginning) (region-end)))
11621 (anything :sources
11622 anything-c-source-regexp
11623 :buffer "*anything regexp*"
11624 :prompt "Regexp: "))))
11626 (defun anything-c-copy-files-async ()
11627 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11628 (interactive)
11629 (let* ((flist (anything-c-read-file-name
11630 "Copy File async: "
11631 :marked-candidates t))
11632 (dest (anything-c-read-file-name
11633 "Copy File async To: "
11634 :preselect (car flist)
11635 :initial-input (car anything-ff-history)
11636 :history (anything-find-files-history :comp-read nil))))
11637 (anything-c-copy-async-with-log flist dest)))
11639 ;;;###autoload
11640 (defun anything-find-files (arg)
11641 "Preconfigured `anything' for anything implementation of `find-file'.
11642 Called with a prefix arg show history if some.
11643 Don't call it from programs, use `anything-find-files-1' instead.
11644 This is the starting point for nearly all actions you can do on files."
11645 (interactive "P")
11646 (let ((any-input (if (and arg anything-ff-history)
11647 (anything-find-files-history)
11648 (anything-find-files-initial-input)))
11649 (presel (buffer-file-name (current-buffer))))
11650 (when (and (eq major-mode 'org-agenda-mode)
11651 org-directory
11652 (not any-input))
11653 (setq any-input (expand-file-name org-directory)))
11654 (set-text-properties 0 (length any-input) nil any-input)
11655 (if any-input
11656 (anything-find-files-1 any-input)
11657 (setq any-input (expand-file-name (anything-c-current-directory)))
11658 (anything-find-files-1
11659 any-input (if anything-ff-transformer-show-only-basename
11660 (and presel (anything-c-basename presel))
11661 presel)))))
11663 ;;;###autoload
11664 (defun anything-write-file ()
11665 "Preconfigured `anything' providing completion for `write-file'."
11666 (interactive)
11667 (let ((anything-mp-highlight-delay nil))
11668 (anything :sources 'anything-c-source-write-file
11669 :input (expand-file-name default-directory)
11670 :prompt "Write buffer to file: "
11671 :buffer "*Anything write file*")))
11673 ;;;###autoload
11674 (defun anything-insert-file ()
11675 "Preconfigured `anything' providing completion for `insert-file'."
11676 (interactive)
11677 (let ((anything-mp-highlight-delay nil))
11678 (anything :sources 'anything-c-source-insert-file
11679 :input (expand-file-name default-directory)
11680 :prompt "Insert file: "
11681 :buffer "*Anything insert file*")))
11683 ;;;###autoload
11684 (defun anything-dired-rename-file ()
11685 "Preconfigured `anything' to rename files from dired."
11686 (interactive)
11687 (anything-dired-do-action-on-file :action 'rename))
11689 ;;;###autoload
11690 (defun anything-dired-copy-file ()
11691 "Preconfigured `anything' to copy files from dired."
11692 (interactive)
11693 (anything-dired-do-action-on-file :action 'copy))
11695 ;;;###autoload
11696 (defun anything-dired-symlink-file ()
11697 "Preconfigured `anything' to symlink files from dired."
11698 (interactive)
11699 (anything-dired-do-action-on-file :action 'symlink))
11701 ;;;###autoload
11702 (defun anything-dired-hardlink-file ()
11703 "Preconfigured `anything' to hardlink files from dired."
11704 (interactive)
11705 (anything-dired-do-action-on-file :action 'hardlink))
11707 ;;;###autoload
11708 (defun anything-do-grep ()
11709 "Preconfigured anything for grep.
11710 Contrarily to Emacs `grep' no default directory is given, but
11711 the full path of candidates in ONLY.
11712 That allow to grep different files not only in `default-directory' but anywhere
11713 by marking them (C-<SPACE>). If one or more directory is selected
11714 grep will search in all files of these directories.
11715 You can use also wildcard in the base name of candidate.
11716 If a prefix arg is given use the -r option of grep.
11717 The prefix arg can be passed before or after start.
11718 See also `anything-do-grep-1'."
11719 (interactive)
11720 (let ((only (anything-c-read-file-name
11721 "Search in file(s): "
11722 :marked-candidates t
11723 :preselect (or (dired-get-filename nil t)
11724 (buffer-file-name (current-buffer)))))
11725 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11726 (anything-do-grep-1 only prefarg)))
11728 ;;;###autoload
11729 (defun anything-do-zgrep (candidate)
11730 "Preconfigured anything for zgrep."
11731 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11732 (ls (anything-c-read-file-name
11733 "Search in file(s): "
11734 :marked-candidates t
11735 :preselect (or (dired-get-filename nil t)
11736 (buffer-file-name (current-buffer))))))
11737 (anything-ff-zgrep-1 ls prefarg)))
11739 (defun anything-c-etags-select (arg)
11740 "Preconfigured anything for etags.
11741 Called with one prefix arg use symbol at point as initial input.
11742 Called with two prefix arg reinitialize cache.
11743 If tag file have been modified reinitialize cache."
11744 (interactive "P")
11745 (let ((tag (anything-c-etags-get-tag-file))
11746 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11747 (anything-quit-if-no-candidate t)
11748 (anything-execute-action-at-once-if-one t)
11749 (anything-compile-source-functions
11750 (if anything-c-etags-use-regexp-search
11751 ;; rule out anything-match-plugin because the input is one regexp.
11752 (delq 'anything-compile-source--match-plugin
11753 (copy-sequence anything-compile-source-functions))
11754 anything-compile-source-functions)))
11755 (when (or (equal arg '(16))
11756 (and anything-c-etags-mtime-alist
11757 (anything-c-etags-file-modified-p tag)))
11758 (remhash tag anything-c-etags-cache))
11759 (if (and tag (file-exists-p tag))
11760 (anything :sources 'anything-c-source-etags-select
11761 :keymap anything-c-etags-map
11762 :input init
11763 :buffer "*anything etags*")
11764 (message "Error: No tag file found, please create one with etags shell command."))))
11766 ;;;###autoload
11767 (defun anything-filelist ()
11768 "Preconfigured `anything' to open files instantly.
11770 See `anything-c-filelist-file-name' docstring for usage."
11771 (interactive)
11772 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11774 ;;;###autoload
11775 (defun anything-filelist+ ()
11776 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11778 This is a replacement for `anything-for-files'.
11779 See `anything-c-filelist-file-name' docstring for usage."
11780 (interactive)
11781 (anything-other-buffer
11782 '(anything-c-source-ffap-line
11783 anything-c-source-ffap-guesser
11784 anything-c-source-buffers-list
11785 anything-c-source-recentf
11786 anything-c-source-bookmarks
11787 anything-c-source-file-cache
11788 anything-c-source-filelist)
11789 "*anything file list*"))
11791 ;;;###autoload
11792 (defun anything-M-x ()
11793 "Preconfigured `anything' for Emacs commands.
11794 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11795 (interactive)
11796 (let* (in-help
11797 help-cand
11798 special-display-buffer-names
11799 special-display-regexps
11800 anything-persistent-action-use-special-display
11801 (history (loop with hist
11802 for i in extended-command-history
11803 for com = (intern i)
11804 when (fboundp com)
11805 collect i into hist finally return hist)))
11806 (flet ((pers-help (candidate)
11807 (let ((hbuf (get-buffer (help-buffer))))
11808 (if (and in-help (string= candidate help-cand))
11809 (progn
11810 ;; When M-x is started from a help buffer,
11811 ;; Don't kill it as it is anything-current-buffer.
11812 (unless (equal hbuf anything-current-buffer)
11813 (kill-buffer hbuf))
11814 (setq in-help nil))
11815 ;; Be sure anything-current-buffer
11816 ;; have not a dedicated window.
11817 (set-window-dedicated-p
11818 (get-buffer-window anything-current-buffer) nil)
11819 (describe-function (intern candidate))
11820 (message nil) ; Erase the new stupid message Type "q"[...]
11821 (setq in-help t))
11822 (setq help-cand candidate))))
11823 (let* ((command
11825 (anything
11826 :sources
11827 '(((name . "Emacs Commands history")
11828 (candidates . history)
11829 (filtered-candidate-transformer
11830 . (lambda (candidates sources)
11831 (loop for i in candidates
11832 do (set-text-properties 0 (length i) nil i)
11833 collect i)))
11834 (persistent-action . pers-help)
11835 (persistent-help . "Describe this command")
11836 (action . identity))
11837 ((name . "Emacs Commands")
11838 (init
11839 . (lambda ()
11840 (with-current-buffer (anything-candidate-buffer 'global)
11841 (goto-char (point-min))
11842 (loop
11843 for sym in (all-completions "" obarray 'commandp)
11844 do (insert (concat sym "\n"))))))
11845 (persistent-action . pers-help)
11846 (persistent-help . "Describe this command")
11847 (filtered-candidate-transformer . anything-M-x-transformer)
11848 (candidates-in-buffer)
11849 (action . identity)))
11850 :buffer "*anything M-x*")
11851 (keyboard-quit)))
11852 (sym-com (intern command)))
11853 (unless current-prefix-arg
11854 (setq current-prefix-arg anything-current-prefix-arg))
11855 ;; Avoid having `this-command' set to *exit-minibuffer.
11856 (setq this-command sym-com)
11857 (call-interactively sym-com)
11858 (setq extended-command-history
11859 (cons command (delete command history)))))))
11861 ;;;###autoload
11862 (defun anything-manage-advice ()
11863 "Preconfigured `anything' to disable/enable function advices."
11864 (interactive)
11865 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11867 ;;;###autoload
11868 (defun anything-bookmark-ext ()
11869 "Preconfigured `anything' for bookmark-extensions sources.
11870 Needs bookmark-ext.el:
11871 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11872 Contain also `anything-c-source-google-suggest'."
11873 (interactive)
11874 (anything
11875 :sources
11876 '(anything-c-source-bookmark-files&dirs
11877 anything-c-source-bookmark-w3m
11878 anything-c-source-google-suggest
11879 anything-c-source-bmkext-addressbook
11880 anything-c-source-bookmark-gnus
11881 anything-c-source-bookmark-info
11882 anything-c-source-bookmark-man
11883 anything-c-source-bookmark-images
11884 anything-c-source-bookmark-su-files&dirs
11885 anything-c-source-bookmark-ssh-files&dirs)
11886 :prompt "SearchBookmark: "
11887 :buffer "*anything bmkext*"))
11889 ;;;###autoload
11890 (defun anything-simple-call-tree ()
11891 "Preconfigured `anything' for simple-call-tree. List function relationships.
11893 Needs simple-call-tree.el.
11894 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11895 (interactive)
11896 (anything-other-buffer
11897 '(anything-c-source-simple-call-tree-functions-callers
11898 anything-c-source-simple-call-tree-callers-functions)
11899 "*anything simple-call-tree*"))
11901 ;;;###autoload
11902 (defun anything-mark-ring ()
11903 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11904 (interactive)
11905 (anything 'anything-c-source-mark-ring))
11907 ;;;###autoload
11908 (defun anything-global-mark-ring ()
11909 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11910 (interactive)
11911 (anything 'anything-c-source-global-mark-ring))
11913 ;;;###autoload
11914 (defun anything-all-mark-rings ()
11915 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11916 `anything-c-source-mark-ring'."
11917 (interactive)
11918 (anything '(anything-c-source-mark-ring
11919 anything-c-source-global-mark-ring)))
11921 ;;;###autoload
11922 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11923 "Preconfigured `anything' to edit or view EmacsWiki page.
11925 Needs yaoddmuse.el.
11927 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11928 (interactive)
11929 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11931 ;;;###autoload
11932 (defun anything-yaoddmuse-emacswiki-post-library ()
11933 "Preconfigured `anything' to post library to EmacsWiki.
11935 Needs yaoddmuse.el.
11937 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11938 (interactive)
11939 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11941 ;;;###autoload
11942 (defun anything-eval-expression (arg)
11943 "Preconfigured anything for `anything-c-source-evaluation-result'."
11944 (interactive "P")
11945 (anything :sources 'anything-c-source-evaluation-result
11946 :input (when arg (thing-at-point 'sexp))
11947 :buffer "*anything eval*"
11948 :keymap anything-eval-expression-map))
11950 ;;;###autoload
11951 (defun anything-eval-expression-with-eldoc ()
11952 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11953 (interactive)
11954 (declare (special eldoc-idle-delay))
11955 (let ((timer (run-with-idle-timer eldoc-idle-delay
11956 'repeat 'anything-eldoc-show-in-eval))
11957 (minibuffer-completing-symbol t) ; Enable lisp completion.
11958 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11959 (unwind-protect
11960 (minibuffer-with-setup-hook
11961 'anything-eldoc-store-minibuffer
11962 (call-interactively 'anything-eval-expression))
11963 (and timer (cancel-timer timer))
11964 (setq anything-eldoc-active-minibuffers-list
11965 (cdr anything-eldoc-active-minibuffers-list)))))
11967 ;;;###autoload
11968 (defun anything-calcul-expression ()
11969 "Preconfigured anything for `anything-c-source-calculation-result'."
11970 (interactive)
11971 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11973 ;;;###autoload
11974 (defun anything-surfraw (pattern engine)
11975 "Preconfigured `anything' to search PATTERN with search ENGINE."
11976 (interactive (list (read-string "SearchFor: ")
11977 (anything-comp-read
11978 "Engine: "
11979 (anything-c-build-elvi-list)
11980 :must-match t
11981 :name "Surfraw Search Engines"
11982 :history anything-surfraw-engines-history)))
11983 (let* ((engine-nodesc (car (split-string engine)))
11984 (url (with-temp-buffer
11985 (apply 'call-process "surfraw" nil t nil
11986 ;;JAVE
11987 (append (list engine-nodesc "-p") (split-string pattern)))
11988 (replace-regexp-in-string
11989 "\n" "" (buffer-string))))
11990 (browse-url-browser-function (or anything-surfraw-default-browser-function
11991 browse-url-browser-function)))
11992 (if (string= engine-nodesc "W")
11993 (anything-c-browse-url)
11994 (anything-c-browse-url url)
11995 (setq anything-surfraw-engines-history
11996 (cons engine (delete engine anything-surfraw-engines-history))))))
11998 ;;;###autoload
11999 (defun anything-call-source ()
12000 "Preconfigured `anything' to call anything source."
12001 (interactive)
12002 (anything 'anything-c-source-call-source nil nil nil nil
12003 anything-source-select-buffer))
12005 ;;;###autoload
12006 (defun anything-execute-anything-command ()
12007 "Preconfigured `anything' to execute preconfigured `anything'."
12008 (interactive)
12009 (anything-other-buffer 'anything-c-source-anything-commands
12010 "*anything commands*"))
12012 ;;;###autoload
12013 (defun anything-create (&optional string initial-input)
12014 "Preconfigured `anything' to do many create actions from STRING.
12015 See also `anything-create--actions'."
12016 (interactive)
12017 (setq string (or string (read-string "Create Anything: " initial-input)))
12018 (anything '(((name . "Anything Create")
12019 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12020 (candidates . anything-create--actions)
12021 (candidate-number-limit)
12022 (action . (lambda (func) (funcall func string)))))))
12024 ;;;###autoload
12025 (defun anything-top ()
12026 "Preconfigured `anything' for top command."
12027 (interactive)
12028 (let ((anything-samewindow t)
12029 (anything-enable-shortcuts)
12030 (anything-display-function 'anything-default-display-buffer)
12031 (anything-candidate-number-limit 9999))
12032 (save-window-excursion
12033 (delete-other-windows)
12034 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12036 ;;;###autoload
12037 (defun anything-select-xfont ()
12038 "Preconfigured `anything' to select Xfont."
12039 (interactive)
12040 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12042 ;;;###autoload
12043 (defun anything-world-time ()
12044 "Preconfigured `anything' to show world time."
12045 (interactive)
12046 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12048 ;;;###autoload
12049 (defun anything-apt (arg query)
12050 "Preconfigured `anything' : frontend of APT package manager.
12051 With a prefix arg reload cache."
12052 (interactive "P\nsSearch Package: ")
12053 (when arg
12054 (setq anything-c-apt-installed-packages nil)
12055 (setq anything-c-apt-all-packages nil))
12056 (anything :sources 'anything-c-source-apt
12057 :prompt "Search Package: " :input query))
12059 ;;;###autoload
12060 (defun anything-esh-pcomplete ()
12061 "Preconfigured anything to provide anything completion in eshell."
12062 (interactive)
12063 (let* ((anything-quit-if-no-candidate t)
12064 (anything-execute-action-at-once-if-one t)
12065 (target (thing-at-point 'symbol))
12066 (end (point))
12067 (beg (or (and target (- end (length target)))
12068 ;; Nothing at point.
12069 (progn (insert " ") (point)))))
12070 (setq anything-ec-target (or target " "))
12071 (with-anything-show-completion beg end
12072 (anything :sources 'anything-c-source-esh
12073 :input (anything-ff-set-pattern ; Handle tramp filenames.
12074 (car (last (ignore-errors ; Needed in lisp symbols completion.
12075 (pcomplete-parse-arguments)))))))))
12077 ;;;###autoload
12078 (defun anything-eshell-history ()
12079 "Preconfigured anything for eshell history."
12080 (interactive)
12081 (let* ((end (point))
12082 (beg (save-excursion (eshell-bol) (point)))
12083 flag-empty)
12084 (when (eq beg end)
12085 (insert " ")
12086 (setq flag-empty t)
12087 (setq end (point)))
12088 (unwind-protect
12089 (with-anything-show-completion beg end
12090 (anything :sources 'anything-c-source-eshell-history
12091 :buffer "*Eshell history*"))
12092 (when (and flag-empty
12093 (looking-back " "))
12094 (delete-char -1)))))
12096 ;;;###autoload
12097 (defun anything-c-run-external-command (program)
12098 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12099 If program is already running exit with error.
12100 You can set your own list of commands with
12101 `anything-c-external-commands-list'."
12102 (interactive (list
12103 (anything-comp-read
12104 "RunProgram: "
12105 (anything-c-external-commands-list-1 'sort)
12106 :must-match t
12107 :name "External Commands"
12108 :history anything-external-command-history)))
12109 (anything-run-or-raise program)
12110 (setq anything-external-command-history
12111 (cons program (delete program
12112 (loop for i in anything-external-command-history
12113 when (executable-find i) collect i)))))
12115 ;;;###autoload
12116 (defun anything-ratpoison-commands ()
12117 "Preconfigured `anything' to execute ratpoison commands."
12118 (interactive)
12119 (anything-other-buffer 'anything-c-source-ratpoison-commands
12120 "*anything ratpoison commands*"))
12122 ;;;###autoload
12123 (defun anything-ucs ()
12124 "Preconfigured anything for `ucs-names' math symbols."
12125 (interactive)
12126 (anything :sources 'anything-c-source-ucs
12127 :keymap anything-c-ucs-map))
12129 ;;;###autoload
12130 (defun anything-c-apropos ()
12131 "Preconfigured anything to describe commands, functions, variables and faces."
12132 (interactive)
12133 (let ((default (thing-at-point 'symbol)))
12134 (anything :sources
12135 `(((name . "Commands")
12136 (init . (lambda ()
12137 (anything-c-apropos-init 'commandp ,default)))
12138 (persistent-action . anything-lisp-completion-persistent-action)
12139 (persistent-help . "Show brief doc in mode-line")
12140 (candidates-in-buffer)
12141 (action . (lambda (candidate)
12142 (describe-function (intern candidate)))))
12143 ((name . "Functions")
12144 (init . (lambda ()
12145 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12146 (not (commandp x))))
12147 ,default)))
12148 (persistent-action . anything-lisp-completion-persistent-action)
12149 (persistent-help . "Show brief doc in mode-line")
12150 (candidates-in-buffer)
12151 (action . (lambda (candidate)
12152 (describe-function (intern candidate)))))
12153 ((name . "Variables")
12154 (init . (lambda ()
12155 (anything-c-apropos-init 'boundp ,default)))
12156 (persistent-action . anything-lisp-completion-persistent-action)
12157 (persistent-help . "Show brief doc in mode-line")
12158 (candidates-in-buffer)
12159 (action . (lambda (candidate)
12160 (describe-variable (intern candidate)))))
12161 ((name . "Faces")
12162 (init . (lambda ()
12163 (anything-c-apropos-init 'facep ,default)))
12164 (persistent-action . anything-lisp-completion-persistent-action)
12165 (persistent-help . "Show brief doc in mode-line")
12166 (candidates-in-buffer)
12167 (filtered-candidate-transformer . (lambda (candidates source)
12168 (loop for c in candidates
12169 collect (propertize c 'face (intern c)))))
12170 (action . (lambda (candidate)
12171 (describe-face (intern candidate)))))
12172 ((name . "Anything attributes")
12173 (candidates . (lambda ()
12174 (mapcar 'symbol-name anything-additional-attributes)))
12175 (action . (lambda (candidate)
12176 (with-output-to-temp-buffer "*Help*"
12177 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12180 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12183 (provide 'anything-config)
12185 ;;; Local Variables:
12186 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12187 ;;; End:
12189 ;; How to save (DO NOT REMOVE!!)
12190 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12191 ;;; anything-config.el ends here
12193 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12194 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12195 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12196 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12197 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12198 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12199 ;;; LocalWords: dotimes Thierry online vname
12200 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12201 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12202 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12203 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12204 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12205 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12206 ;;; LocalWords: startpos noselect dont desc