* anything.el Reindent.
[anything-config.git] / anything-config.el
blob2277d09799e33b99e93d4c49ff00873b5b5f6bde
1 ;;; anything-config.el --- Applications libary for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Applications libary for `anything.el'
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
17 ;; Created: 2009-02-16 21:38:23
19 ;; X-URL: http://repo.or.cz/w/anything-config.git
21 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
23 ;; Keywords: anything, anything-config
25 ;; Compatibility: GNU Emacs 22 ~ 24
27 ;; Dependencies: `anything.el'
29 ;;; This file is NOT part of GNU Emacs
31 ;;; License
33 ;; This program is free software; you can redistribute it and/or modify
34 ;; it under the terms of the GNU General Public License as published by
35 ;; the Free Software Foundation; either version 3, or (at your option)
36 ;; any later version.
38 ;; This program is distributed in the hope that it will be useful,
39 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 ;; GNU General Public License for more details.
43 ;; You should have received a copy of the GNU General Public License
44 ;; along with this program; see the file COPYING. If not, write to
45 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
46 ;; Floor, Boston, MA 02110-1301, USA.
48 ;;; !NOTICE!
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
53 ;;; Commentary:
55 ;; Predefined configurations for `anything.el'
57 ;; For quick start, try `anything-for-files' to open files.
59 ;; To configure anything you should define anything command
60 ;; with your favorite sources, like below:
62 ;; (defun my-anything ()
63 ;; (interactive)
64 ;; (anything-other-buffer
65 ;; '(anything-c-source-buffers
66 ;; anything-c-source-file-name-history
67 ;; anything-c-source-info-pages
68 ;; anything-c-source-info-elisp
69 ;; anything-c-source-man-pages
70 ;; anything-c-source-locate
71 ;; anything-c-source-emacs-commands)
72 ;; " *my-anything*"))
74 ;; Then type M-x my-anything to use sources.
76 ;; Defining own command is better than setup `anything-sources'
77 ;; directly, because you can define multiple anything commands with
78 ;; different sources. Each anything command should have own anything
79 ;; buffer, because M-x anything-resume revives anything command.
82 ;;; Autodoc documentation:
83 ;; ---------------------
85 ;; * Commands defined here are:
86 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
87 ;; `anything-configuration'
88 ;; Customize `anything'.
89 ;; `anything-c-buffer-help'
90 ;; Help command for anything buffers.
91 ;; `anything-ff-help'
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
94 ;; Not documented.
95 ;; `anything-generic-file-help'
96 ;; Not documented.
97 ;; `anything-grep-help'
98 ;; Not documented.
99 ;; `anything-pdfgrep-help'
100 ;; Not documented.
101 ;; `anything-etags-help'
102 ;; The help function for etags.
103 ;; `anything-c-ucs-help'
104 ;; Help command for `anything-ucs'.
105 ;; `anything-show-this-source-only'
106 ;; Show all candidates of this source.
107 ;; `anything-test-sources'
108 ;; List all anything sources for test.
109 ;; `anything-select-source'
110 ;; [OBSOLETE] Select source.
111 ;; `anything-quit-and-find-file'
112 ;; Drop into `anything-find-files' from `anything'.
113 ;; `anything-mark-all'
114 ;; Mark all visible unmarked candidates in current source.
115 ;; `anything-unmark-all'
116 ;; Unmark all candidates in all sources of current anything session.
117 ;; `anything-toggle-all-marks'
118 ;; Toggle all marks.
119 ;; `anything-buffer-diff-persistent'
120 ;; Toggle diff buffer without quitting anything.
121 ;; `anything-buffer-revert-persistent'
122 ;; Revert buffer without quitting anything.
123 ;; `anything-buffer-save-persistent'
124 ;; Save buffer without quitting anything.
125 ;; `anything-buffer-run-kill-buffers'
126 ;; Run kill buffer action from `anything-c-source-buffers-list'.
127 ;; `anything-buffer-run-grep'
128 ;; Run Grep action from `anything-c-source-buffers-list'.
129 ;; `anything-buffer-run-zgrep'
130 ;; Run Grep action from `anything-c-source-buffers-list'.
131 ;; `anything-buffer-run-query-replace-regexp'
132 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
133 ;; `anything-buffer-run-query-replace'
134 ;; Run Query replace action from `anything-c-source-buffers-list'.
135 ;; `anything-buffer-switch-other-window'
136 ;; Run switch to other window action from `anything-c-source-buffers-list'.
137 ;; `anything-buffer-switch-other-frame'
138 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
139 ;; `anything-buffer-switch-to-elscreen'
140 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
141 ;; `anything-buffer-run-ediff'
142 ;; Run ediff action from `anything-c-source-buffers-list'.
143 ;; `anything-buffer-run-ediff-merge'
144 ;; Run ediff action from `anything-c-source-buffers-list'.
145 ;; `anything-ff-run-toggle-auto-update'
146 ;; Not documented.
147 ;; `anything-ff-run-switch-to-history'
148 ;; Run Switch to history action from `anything-c-source-find-files'.
149 ;; `anything-ff-run-grep'
150 ;; Run Grep action from `anything-c-source-find-files'.
151 ;; `anything-ff-run-pdfgrep'
152 ;; Run Pdfgrep action from `anything-c-source-find-files'.
153 ;; `anything-ff-run-zgrep'
154 ;; Run Grep action from `anything-c-source-find-files'.
155 ;; `anything-ff-run-copy-file'
156 ;; Run Copy file action from `anything-c-source-find-files'.
157 ;; `anything-ff-run-rename-file'
158 ;; Run Rename file action from `anything-c-source-find-files'.
159 ;; `anything-ff-run-byte-compile-file'
160 ;; Run Byte compile file action from `anything-c-source-find-files'.
161 ;; `anything-ff-run-load-file'
162 ;; Run Load file action from `anything-c-source-find-files'.
163 ;; `anything-ff-run-eshell-command-on-file'
164 ;; Run eshell command on file action from `anything-c-source-find-files'.
165 ;; `anything-ff-run-ediff-file'
166 ;; Run Ediff file action from `anything-c-source-find-files'.
167 ;; `anything-ff-run-ediff-merge-file'
168 ;; Run Ediff merge file action from `anything-c-source-find-files'.
169 ;; `anything-ff-run-symlink-file'
170 ;; Run Symlink file action from `anything-c-source-find-files'.
171 ;; `anything-ff-run-delete-file'
172 ;; Run Delete file action from `anything-c-source-find-files'.
173 ;; `anything-ff-run-complete-fn-at-point'
174 ;; Run complete file name action from `anything-c-source-find-files'.
175 ;; `anything-ff-run-switch-to-eshell'
176 ;; Run switch to eshell action from `anything-c-source-find-files'.
177 ;; `anything-ff-run-switch-other-window'
178 ;; Run switch to other window action from `anything-c-source-find-files'.
179 ;; `anything-ff-run-switch-other-frame'
180 ;; Run switch to other frame action from `anything-c-source-find-files'.
181 ;; `anything-ff-run-open-file-externally'
182 ;; Run open file externally command action from `anything-c-source-find-files'.
183 ;; `anything-ff-run-locate'
184 ;; Run locate action from `anything-c-source-find-files'.
185 ;; `anything-ff-run-gnus-attach-files'
186 ;; Run gnus attach files command action from `anything-c-source-find-files'.
187 ;; `anything-ff-run-etags'
188 ;; Run Etags command action from `anything-c-source-find-files'.
189 ;; `anything-ff-run-print-file'
190 ;; Run Print file action from `anything-c-source-find-files'.
191 ;; `anything-ff-run-toggle-basename'
192 ;; Not documented.
193 ;; `anything-find-files-down-one-level'
194 ;; Go down one level like unix command `cd ..'.
195 ;; `anything-ff-properties-persistent'
196 ;; Show properties without quitting anything.
197 ;; `anything-ff-run-kill-buffer-persistent'
198 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
199 ;; `anything-ff-rotate-left-persistent'
200 ;; Rotate image left without quitting anything.
201 ;; `anything-ff-rotate-right-persistent'
202 ;; Rotate image right without quitting anything.
203 ;; `anything-c-goto-precedent-file'
204 ;; Go to precedent file in anything grep/etags buffers.
205 ;; `anything-c-goto-next-file'
206 ;; Go to precedent file in anything grep/etags buffers.
207 ;; `anything-c-grep-run-persistent-action'
208 ;; Run grep persistent action from `anything-do-grep-1'.
209 ;; `anything-c-grep-run-default-action'
210 ;; Run grep default action from `anything-do-grep-1'.
211 ;; `anything-c-grep-run-other-window-action'
212 ;; Run grep goto other window action from `anything-do-grep-1'.
213 ;; `anything-c-grep-run-save-buffer'
214 ;; Run grep save results action from `anything-do-grep-1'.
215 ;; `anything-do-pdfgrep'
216 ;; Not documented.
217 ;; `anything-yank-text-at-point'
218 ;; Yank text at point in minibuffer.
219 ;; `anything-c-describe-attributes'
220 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
221 ;; `anything-yaoddmuse-cache-pages'
222 ;; Fetch the list of files on emacswiki and create cache file.
223 ;; `anything-eval-new-line-and-indent'
224 ;; Not documented.
225 ;; `anything-call-source-from-anything'
226 ;; Call anything source within `anything' session.
227 ;; `anything-create-from-anything'
228 ;; Run `anything-create' from `anything' as a fallback.
229 ;; `anything-c-ucs-persistent-insert'
230 ;; Not documented.
231 ;; `anything-c-ucs-persistent-forward'
232 ;; Not documented.
233 ;; `anything-c-ucs-persistent-backward'
234 ;; Not documented.
235 ;; `anything-c-ucs-persistent-delete'
236 ;; Not documented.
237 ;; `anything-lisp-completion-at-point'
238 ;; Anything lisp symbol completion at point.
239 ;; `anything-c-complete-file-name-at-point'
240 ;; Complete file name at point.
241 ;; `anything-lisp-completion-at-point-or-indent'
242 ;; First call indent and second call complete lisp symbol.
243 ;; `anything-lisp-completion-or-file-name-at-point'
244 ;; Complete lisp symbol or filename at point.
245 ;; `anything-c-set-variable'
246 ;; Set value to VAR interactively.
247 ;; `anything-c-adaptive-save-history'
248 ;; Save history information to file given by `anything-c-adaptive-history-file'.
249 ;; `anything-c-reset-adaptative-history'
250 ;; Delete all `anything-c-adaptive-history' and his file.
251 ;; `anything-c-toggle-match-plugin'
252 ;; Toggle anything-match-plugin.
253 ;; `anything-mini'
254 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
255 ;; `anything-for-files'
256 ;; Preconfigured `anything' for opening files.
257 ;; `anything-recentf'
258 ;; Preconfigured `anything' for `recentf'.
259 ;; `anything-info-at-point'
260 ;; Preconfigured `anything' for searching info at point.
261 ;; `anything-info-emacs'
262 ;; Preconfigured anything for Emacs manual index.
263 ;; `anything-show-kill-ring'
264 ;; Preconfigured `anything' for `kill-ring'.
265 ;; `anything-minibuffer-history'
266 ;; Preconfigured `anything' for `minibuffer-history'.
267 ;; `anything-gentoo'
268 ;; Preconfigured `anything' for gentoo linux.
269 ;; `anything-imenu'
270 ;; Preconfigured `anything' for `imenu'.
271 ;; `anything-google-suggest'
272 ;; Preconfigured `anything' for google search with google suggest.
273 ;; `anything-yahoo-suggest'
274 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
275 ;; `anything-for-buffers'
276 ;; Preconfigured `anything' for buffer.
277 ;; `anything-buffers-list'
278 ;; Enhanced preconfigured `anything' for buffer.
279 ;; `anything-bbdb'
280 ;; Preconfigured `anything' for BBDB.
281 ;; `anything-locate'
282 ;; Preconfigured `anything' for Locate.
283 ;; `anything-w3m-bookmarks'
284 ;; Preconfigured `anything' for w3m bookmark.
285 ;; `anything-firefox-bookmarks'
286 ;; Preconfigured `anything' for firefox bookmark.
287 ;; `anything-colors'
288 ;; Preconfigured `anything' for color.
289 ;; `anything-bookmarks'
290 ;; Preconfigured `anything' for bookmarks.
291 ;; `anything-c-pp-bookmarks'
292 ;; Preconfigured `anything' for bookmarks (pretty-printed).
293 ;; `anything-c-insert-latex-math'
294 ;; Preconfigured anything for latex math symbols completion.
295 ;; `anything-register'
296 ;; Preconfigured `anything' for Emacs registers.
297 ;; `anything-man-woman'
298 ;; Preconfigured `anything' for Man and Woman pages.
299 ;; `anything-org-keywords'
300 ;; Preconfigured `anything' for org keywords.
301 ;; `anything-emms'
302 ;; Preconfigured `anything' for emms sources.
303 ;; `anything-eev-anchors'
304 ;; Preconfigured `anything' for eev anchors.
305 ;; `anything-bm-list'
306 ;; Preconfigured `anything' for visible bookmarks.
307 ;; `anything-timers'
308 ;; Preconfigured `anything' for timers.
309 ;; `anything-list-emacs-process'
310 ;; Preconfigured `anything' for emacs process.
311 ;; `anything-occur'
312 ;; Preconfigured Anything for Occur source.
313 ;; `anything-browse-code'
314 ;; Preconfigured anything to browse code.
315 ;; `anything-org-headlines'
316 ;; Preconfigured anything to show org headlines.
317 ;; `anything-info-gnus'
318 ;; Preconfigured anything to browse Gnus Manual.
319 ;; `anything-regexp'
320 ;; Preconfigured anything to build regexps.
321 ;; `anything-c-copy-files-async'
322 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
323 ;; `anything-find-files'
324 ;; Preconfigured `anything' for anything implementation of `find-file'.
325 ;; `anything-write-file'
326 ;; Preconfigured `anything' providing completion for `write-file'.
327 ;; `anything-insert-file'
328 ;; Preconfigured `anything' providing completion for `insert-file'.
329 ;; `anything-dired-rename-file'
330 ;; Preconfigured `anything' to rename files from dired.
331 ;; `anything-dired-copy-file'
332 ;; Preconfigured `anything' to copy files from dired.
333 ;; `anything-dired-symlink-file'
334 ;; Preconfigured `anything' to symlink files from dired.
335 ;; `anything-dired-hardlink-file'
336 ;; Preconfigured `anything' to hardlink files from dired.
337 ;; `anything-do-grep'
338 ;; Preconfigured anything for grep.
339 ;; `anything-c-etags-select'
340 ;; Preconfigured anything for etags.
341 ;; `anything-filelist'
342 ;; Preconfigured `anything' to open files instantly.
343 ;; `anything-filelist+'
344 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
345 ;; `anything-M-x'
346 ;; Preconfigured `anything' for Emacs commands.
347 ;; `anything-manage-advice'
348 ;; Preconfigured `anything' to disable/enable function advices.
349 ;; `anything-bookmark-ext'
350 ;; Preconfigured `anything' for bookmark-extensions sources.
351 ;; `anything-simple-call-tree'
352 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
353 ;; `anything-mark-ring'
354 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
355 ;; `anything-global-mark-ring'
356 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
357 ;; `anything-all-mark-rings'
358 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
359 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
360 ;; Preconfigured `anything' to edit or view EmacsWiki page.
361 ;; `anything-yaoddmuse-emacswiki-post-library'
362 ;; Preconfigured `anything' to post library to EmacsWiki.
363 ;; `anything-eval-expression'
364 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
365 ;; `anything-eval-expression-with-eldoc'
366 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
367 ;; `anything-calcul-expression'
368 ;; Preconfigured anything for `anything-c-source-calculation-result'.
369 ;; `anything-surfraw'
370 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
371 ;; `anything-call-source'
372 ;; Preconfigured `anything' to call anything source.
373 ;; `anything-execute-anything-command'
374 ;; Preconfigured `anything' to execute preconfigured `anything'.
375 ;; `anything-create'
376 ;; Preconfigured `anything' to do many create actions from STRING.
377 ;; `anything-top'
378 ;; Preconfigured `anything' for top command.
379 ;; `anything-select-xfont'
380 ;; Preconfigured `anything' to select Xfont.
381 ;; `anything-world-time'
382 ;; Preconfigured `anything' to show world time.
383 ;; `anything-apt'
384 ;; Preconfigured `anything' : frontend of APT package manager.
385 ;; `anything-esh-pcomplete'
386 ;; Preconfigured anything to provide anything completion in eshell.
387 ;; `anything-eshell-history'
388 ;; Preconfigured anything for eshell history.
389 ;; `anything-c-run-external-command'
390 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
391 ;; `anything-ratpoison-commands'
392 ;; Preconfigured `anything' to execute ratpoison commands.
393 ;; `anything-ucs'
394 ;; Preconfigured anything for `ucs-names' math symbols.
395 ;; `anything-c-apropos'
396 ;; Preconfigured anything to describe commands, functions, variables and faces.
398 ;; * User variables defined here:
399 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
400 ;; `anything-c-adaptive-history-file'
401 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
402 ;; `anything-c-adaptive-history-length'
403 ;; Default Value: 50
404 ;; `anything-c-google-suggest-url'
405 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
406 ;; `anything-c-google-suggest-search-url'
407 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
408 ;; `anything-google-suggest-use-curl-p'
409 ;; Default Value: nil
410 ;; `anything-c-yahoo-suggest-url'
411 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
412 ;; `anything-c-yahoo-suggest-search-url'
413 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
414 ;; `anything-c-boring-buffer-regexp'
415 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\|\\*ac-mode\\| \\*Echo Area\\| \\*Minibuf"
416 ;; `anything-c-boring-file-regexp'
417 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
418 ;; `anything-kill-ring-threshold'
419 ;; Default Value: 10
420 ;; `anything-c-kill-ring-max-lines-number'
421 ;; Default Value: nil
422 ;; `anything-su-or-sudo'
423 ;; Default Value: "su"
424 ;; `anything-for-files-prefered-list'
425 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
426 ;; `anything-create--actions-private'
427 ;; Default Value: nil
428 ;; `anything-allow-skipping-current-buffer'
429 ;; Default Value: t
430 ;; `anything-c-enable-eval-defun-hack'
431 ;; Default Value: t
432 ;; `anything-tramp-verbose'
433 ;; Default Value: 0
434 ;; `anything-raise-command'
435 ;; Default Value: nil
436 ;; `anything-command-map-prefix-key'
437 ;; Default Value: "<f5> a"
438 ;; `anything-c-browse-code-regexp-lisp'
439 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
440 ;; `anything-c-browse-code-regexp-python'
441 ;; Default Value: "\\<def\\>\\|\\<class\\>"
442 ;; `anything-c-browse-code-regexp-alist'
443 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
444 ;; `anything-c-external-programs-associations'
445 ;; Default Value: nil
446 ;; `anything-ff-auto-update-initial-value'
447 ;; Default Value: t
448 ;; `anything-c-copy-async-prefered-emacs'
449 ;; Default Value: "emacs"
450 ;; `anything-ff-lynx-style-map'
451 ;; Default Value: t
452 ;; `anything-ff-history-max-length'
453 ;; Default Value: 100
454 ;; `anything-ff-smart-completion'
455 ;; Default Value: t
456 ;; `anything-ff-default-kbsize'
457 ;; Default Value: 1024.0
458 ;; `anything-ff-tramp-not-fancy'
459 ;; Default Value: t
460 ;; `anything-ff-exif-data-program'
461 ;; Default Value: "exiftran"
462 ;; `anything-ff-exif-data-program-args'
463 ;; Default Value: "-d"
464 ;; `anything-c-grep-use-ioccur-style-keys'
465 ;; Default Value: t
466 ;; `anything-c-pdfgrep-default-read-command'
467 ;; Default Value: "xpdf '%f' %p"
468 ;; `anything-c-etags-tag-file-name'
469 ;; Default Value: "TAGS"
470 ;; `anything-c-etags-tag-file-search-limit'
471 ;; Default Value: 10
472 ;; `anything-c-etags-use-regexp-search'
473 ;; Default Value: nil
474 ;; `anything-c-etags-search-regexp'
475 ;; Default Value: "^.+: .+ \\<%s"
476 ;; `anything-c-filelist-file-name'
477 ;; Default Value: nil
478 ;; `anything-c-eldoc-in-minibuffer-show-fn'
479 ;; Default Value: anything-c-show-info-in-mode-line
480 ;; `anything-c-turn-on-show-completion'
481 ;; Default Value: t
482 ;; `anything-lisp-completion-or-indent-delay'
483 ;; Default Value: 0.6
484 ;; `anything-c-default-external-file-browser'
485 ;; Default Value: "nautilus"
486 ;; `anything-c-use-adaptative-sorting'
487 ;; Default Value: nil
488 ;; `anything-ff-newfile-prompt-p'
489 ;; Default Value: t
490 ;; `anything-ff-avfs-directory'
491 ;; Default Value: nil
492 ;; `anything-ff-file-compressed-list'
493 ;; Default Value: ("gz" "bz2" "zip" "7z")
494 ;; `anything-locate-db-file-regexp'
495 ;; Default Value: "m?locate.db$"
496 ;; `anything-c-show-info-in-mode-line-delay'
497 ;; Default Value: 12
498 ;; `anything-c-copy-files-async-log-file'
499 ;; Default Value: "/tmp/dired.log"
500 ;; `anything-ff-printer-list'
501 ;; Default Value: nil
502 ;; `anything-ff-transformer-show-only-basename'
503 ;; Default Value: nil
504 ;; `anything-completing-read-handlers-alist'
505 ;; Default Value: ((describe-function . anything-completing-read-symbols) (describe-variabl [...]
507 ;; * Anything sources defined here:
508 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
509 ;; `anything-c-source-regexp' (Regexp Builder)
510 ;; `anything-c-source-buffers' (Buffers)
511 ;; `anything-c-source-buffer-not-found' (Create buffer)
512 ;; `anything-c-source-buffers-list' (Buffers)
513 ;; `anything-c-source-file-name-history' (File Name History)
514 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
515 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
516 ;; `anything-c-source-find-files' (Find Files)
517 ;; `anything-c-source-write-file' (Write File)
518 ;; `anything-c-source-insert-file' (Insert File)
519 ;; `anything-c-source-copy-files' (Copy Files)
520 ;; `anything-c-source-symlink-files' (Symlink Files)
521 ;; `anything-c-source-hardlink-files' (Hardlink Files)
522 ;; `anything-c-source-file-cache' (File Cache)
523 ;; `anything-c-source-locate' (Locate)
524 ;; `anything-c-source-recentf' (Recentf)
525 ;; `anything-c-source-ffap-guesser' (File at point)
526 ;; `anything-c-source-ffap-line' (File/Lineno at point)
527 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
528 ;; `anything-c-source-filelist' (FileList)
529 ;; `anything-c-source-info-pages' (Info Pages)
530 ;; `anything-c-source-info-elisp' (Info index: elisp)
531 ;; `anything-c-source-info-cl' (Info index: cl)
532 ;; `anything-c-source-info-org' (Info index: org)
533 ;; `anything-c-source-info-gnus' (Info index: Gnus)
534 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
535 ;; `anything-c-source-info-zsh' (Info index: zsh)
536 ;; `anything-c-source-info-bash' (Info index: bash)
537 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
538 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
539 ;; `anything-c-source-info-find' (Info index: find)
540 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
541 ;; `anything-c-source-info-textutils' (Info index: textutils)
542 ;; `anything-c-source-info-libc' (Info index: libc)
543 ;; `anything-c-source-info-make' (Info index: make)
544 ;; `anything-c-source-info-automake' (Info index: automake)
545 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
546 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
547 ;; `anything-c-source-info-emacs' (Info index: emacs)
548 ;; `anything-c-source-info-elib' (Info index: elib)
549 ;; `anything-c-source-info-eieio' (Info index: eieio)
550 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
551 ;; `anything-c-source-info-guile' (Info index: guile)
552 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
553 ;; `anything-c-source-info-goops' (Info index: goops)
554 ;; `anything-c-source-info-screen' (Info index: screen)
555 ;; `anything-c-source-info-latex' (Info index: latex)
556 ;; `anything-c-source-info-gawk' (Info index: gawk)
557 ;; `anything-c-source-info-sed' (Info index: sed)
558 ;; `anything-c-source-info-m4' (Info index: m4)
559 ;; `anything-c-source-info-wget' (Info index: wget)
560 ;; `anything-c-source-info-binutils' (Info index: binutils)
561 ;; `anything-c-source-info-as' (Info index: as)
562 ;; `anything-c-source-info-bfd' (Info index: bfd)
563 ;; `anything-c-source-info-gprof' (Info index: gprof)
564 ;; `anything-c-source-info-ld' (Info index: ld)
565 ;; `anything-c-source-info-diff' (Info index: diff)
566 ;; `anything-c-source-info-flex' (Info index: flex)
567 ;; `anything-c-source-info-grep' (Info index: grep)
568 ;; `anything-c-source-info-gzip' (Info index: gzip)
569 ;; `anything-c-source-info-libtool' (Info index: libtool)
570 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
571 ;; `anything-c-source-info-info' (Info index: info)
572 ;; `anything-c-source-info-gdb' (Info index: gdb)
573 ;; `anything-c-source-info-stabs' (Info index: stabs)
574 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
575 ;; `anything-c-source-info-cvs' (Info index: cvs)
576 ;; `anything-c-source-info-bison' (Info index: bison)
577 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
578 ;; `anything-c-source-info-global' (Info index: global)
579 ;; `anything-c-source-man-pages' (Manual Pages)
580 ;; `anything-c-source-complex-command-history' (Complex Command History)
581 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
582 ;; `anything-c-source-emacs-commands' (Emacs Commands)
583 ;; `anything-c-source-emacs-functions' (Emacs Functions)
584 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
585 ;; `anything-c-source-advice' (Function Advice)
586 ;; `anything-c-source-emacs-variables' (Emacs Variables)
587 ;; `anything-c-source-lacarte' (Lacarte)
588 ;; `anything-c-source-bookmarks' (Bookmarks)
589 ;; `anything-c-source-bookmark-set' (Set Bookmark)
590 ;; `anything-c-source-bm' (Visible Bookmarks)
591 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
592 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
593 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
594 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
595 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
596 ;; `anything-c-source-bookmark-images' (Bookmark Images)
597 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
598 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
599 ;; `anything-c-source-bookmark-info' (Bookmark Info)
600 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
601 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
602 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
603 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
604 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
605 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
606 ;; `anything-c-source-imenu' (Imenu)
607 ;; `anything-c-source-ctags' (Exuberant ctags)
608 ;; `anything-c-source-etags-select' (Etags)
609 ;; `anything-c-source-semantic' (Semantic Tags)
610 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
611 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
612 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
613 ;; `anything-c-source-customize-face' (Customize Face)
614 ;; `anything-c-source-colors' (Colors)
615 ;; `anything-c-source-tracker-search' (Tracker Search)
616 ;; `anything-c-source-mac-spotlight' (mdfind)
617 ;; `anything-c-source-picklist' (Picklist)
618 ;; `anything-c-source-kill-ring' (Kill Ring)
619 ;; `anything-c-source-mark-ring' (mark-ring)
620 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
621 ;; `anything-c-source-register' (Registers)
622 ;; `anything-c-source-latex-math' (Latex Math Menu)
623 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
624 ;; `anything-c-source-rd-headline' (RD HeadLine)
625 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
626 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
627 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
628 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
629 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
630 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
631 ;; `anything-c-source-eev-anchor' (Anchors)
632 ;; `anything-c-source-org-headline' (Org HeadLine)
633 ;; `anything-c-source-org-keywords' (Org Keywords)
634 ;; `anything-c-source-bbdb' (BBDB)
635 ;; `anything-c-source-evaluation-result' (Evaluation Result)
636 ;; `anything-c-source-calculation-result' (Calculation Result)
637 ;; `anything-c-source-google-suggest' (Google Suggest)
638 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
639 ;; `anything-c-source-emms-streams' (Emms Streams)
640 ;; `anything-c-source-emms-dired' (Music Directory)
641 ;; `anything-c-source-emms-files' (Emms files)
642 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
643 ;; `anything-c-source-call-source' (Call anything source)
644 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
645 ;; `anything-c-source-occur' (Occur)
646 ;; `anything-c-source-browse-code' (Browse code)
647 ;; `anything-c-source-create' (Create)
648 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
649 ;; `anything-c-source-elscreen' (Elscreen)
650 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
651 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
652 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
653 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
654 ;; `anything-c-source-xfonts' (X Fonts)
655 ;; `anything-c-source-ucs' (Ucs names)
656 ;; `anything-c-source-emacs-process' (Emacs Process)
657 ;; `anything-c-source-time-world' (Time World List)
658 ;; `anything-c-source-apt' (APT)
659 ;; `anything-c-source-gentoo' (Portage sources)
660 ;; `anything-c-source-use-flags' (Use Flags)
661 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
662 ;; `anything-c-source-esh' (Eshell completions)
663 ;; `anything-c-source-eshell-history' (Eshell history)
665 ;; *** END auto-documentation
667 ;;; For Maintainers:
669 ;; Install developer-tools/autodoc.el and
670 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
671 ;; This function generates anything-c-source-* / functions / options list.
673 ;; [EVAL IT] (autodoc-update-all)
675 ;; Please write details documentation about function, then others will
676 ;; read code more easier. -- Andy Stewart
680 ;;; Change log:
682 ;; Change log of this file is found at
683 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
685 ;; Change log of this project is found at
686 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
688 ;;; Contributors:
690 ;; Tamas Patrovics
691 ;; Tassilo Horn <tassilo@member.fsf.org>
692 ;; Vagn Johansen <gonz808@hotmail.com>
693 ;; Mathias Dahl <mathias.dahl@gmail.com>
694 ;; Bill Clementson <billclem@gmail.com>
695 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
696 ;; Drew Adams <drew.adams@oracle.com>
697 ;; Jason McBrayer <jmcbray@carcosa.net>
698 ;; Andy Stewart <lazycat.manatee@gmail.com>
699 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
700 ;; rubikitch <rubikitch@ruby-lang.org>
701 ;; Scott Vokes <vokes.s@gmail.com>
702 ;; Kenichirou Oyama <k1lowxb@gmail.com>
705 ;;; TODO
707 ;; - Fix documentation, now many functions haven't documentations.
711 ;;; Code:
713 ;;; Require
716 (require 'anything)
717 (require 'thingatpt)
718 (require 'ffap)
719 (require 'cl)
720 (require 'dired-aux)
721 (require 'dired-x)
722 (require 'tramp)
723 (require 'grep)
724 (require 'url)
725 (require 'xml)
726 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
727 (eval-when-compile (require 'semantic nil t))
728 (require 'anything-match-plugin)
732 ;;; Declare external functions
735 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
736 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
737 (declare-function image-dired-update-property "image-dired.el" (prop value))
738 (declare-function woman-file-name-all-completions "woman.el" (topic))
739 (declare-function Man-getpage-in-background "man.el" (topic))
740 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
741 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
742 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
743 (declare-function org-get-current-options "ext:org-exp.el")
744 (declare-function emms-streams "ext:emms-streams")
745 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
746 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
747 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
748 (declare-function emms-stream-quit "ext:emms-streams")
749 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
750 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
751 (declare-function emms-playlist-first "ext:emms")
752 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
753 (declare-function term-line-mode "term")
754 (declare-function term-char-mode "term")
755 (declare-function term-send-input "term")
756 (declare-function term-send-eof "term")
757 (declare-function Info-index-nodes "info" (&optional file))
758 (declare-function Info-goto-node "info" (&optional fork))
759 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
760 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
761 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
762 (declare-function elscreen-goto "ext:elscreen.el" (screen))
763 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
764 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
765 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
766 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
767 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
768 (declare-function bbdb "ext:bbdb-com")
769 (declare-function bbdb-current-record "ext:bbdb-com")
770 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
771 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
772 (declare-function bbdb-current-record "ext:bbdb-com")
773 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
774 (declare-function bbdb-records "ext:bbdb-com"
775 (&optional dont-check-disk already-in-db-buffer))
776 (declare-function eshell-read-aliases-list "em-alias")
777 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
778 (declare-function eshell-bol "esh-mode")
779 (declare-function eldoc-current-symbol "eldoc")
780 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
781 (declare-function eldoc-get-var-docstring "eldoc" (sym))
782 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
783 (declare-function find-library-name "find-func.el" (library))
784 (declare-function adoc-construct "ext:auto-document.el" (buf))
785 (declare-function adoc-first-line "ext:auto-document.el" (str))
786 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
787 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
791 ;;; compatibility
794 (unless (fboundp 'window-system)
795 (defun window-system (&optional arg)
796 window-system))
800 ;;; Customize
803 (defgroup anything-config nil
804 "Predefined configurations for `anything.el'."
805 :group 'anything)
807 (defcustom anything-c-adaptive-history-file
808 "~/.emacs.d/anything-c-adaptive-history"
809 "Path of file where history information is stored."
810 :type 'string
811 :group 'anything-config)
813 (defcustom anything-c-adaptive-history-length 50
814 "Maximum number of candidates stored for a source."
815 :type 'number
816 :group 'anything-config)
818 (defcustom anything-c-google-suggest-url
819 "http://google.com/complete/search?output=toolbar&q="
820 "URL used for looking up Google suggestions."
821 :type 'string
822 :group 'anything-config)
824 (defcustom anything-c-google-suggest-search-url
825 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
826 "URL used for Google searching."
827 :type 'string
828 :group 'anything-config)
830 (defcustom anything-google-suggest-use-curl-p nil
831 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
832 Otherwise `url-retrieve-synchronously' is used."
833 :type 'boolean
834 :group 'anything-config)
836 (defcustom anything-c-yahoo-suggest-url
837 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
838 "Url used for looking up Yahoo suggestions."
839 :type 'string
840 :group 'anything-config)
842 (defcustom anything-c-yahoo-suggest-search-url
843 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
844 "Url used for Yahoo searching."
845 :type 'string
846 :group 'anything-config)
848 (defcustom anything-c-boring-buffer-regexp
849 (rx (or
850 (group bos " ")
851 ;; anything-buffers
852 "*anything" "*ac-mode"
853 ;; echo area
854 " *Echo Area" " *Minibuf"))
855 "The regexp that match boring buffers.
856 Buffer candidates matching this regular expression will be
857 filtered from the list of candidates if the
858 `anything-c-skip-boring-buffers' candidate transformer is used, or
859 they will be displayed with face `file-name-shadow' if
860 `anything-c-shadow-boring-buffers' is used."
861 :type 'string
862 :group 'anything-config)
863 ;; (string-match anything-c-boring-buffer-regexp "buf")
864 ;; (string-match anything-c-boring-buffer-regexp " hidden")
865 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
867 (defcustom anything-c-boring-file-regexp
868 (rx (or
869 ;; Boring directories
870 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
871 ;; Boring files
872 (and line-start ".#")
873 (and (or ".class" ".la" ".o" "~") eol)))
874 "The regexp that match boring files.
875 File candidates matching this regular expression will be
876 filtered from the list of candidates if the
877 `anything-c-skip-boring-files' candidate transformer is used, or
878 they will be displayed with face `file-name-shadow' if
879 `anything-c-shadow-boring-files' is used."
880 :type 'string
881 :group 'anything-config)
883 (defcustom anything-kill-ring-threshold 10
884 "*Minimum length to be listed by `anything-c-source-kill-ring'."
885 :type 'integer
886 :group 'anything-config)
888 (defcustom anything-c-kill-ring-max-lines-number nil
889 "Max number of lines displayed per candidate in kill-ring browser.
890 If nil or zero, don't truncate candidate, show all."
891 :type 'integer
892 :group 'anything-config)
894 (defcustom anything-su-or-sudo "su"
895 "What command to use for root access."
896 :type 'string
897 :group 'anything-config)
899 (defcustom anything-for-files-prefered-list
900 '(anything-c-source-ffap-line
901 anything-c-source-ffap-guesser
902 anything-c-source-buffers-list
903 anything-c-source-recentf
904 anything-c-source-bookmarks
905 anything-c-source-file-cache
906 anything-c-source-files-in-current-dir+
907 anything-c-source-locate)
908 "Your prefered sources to find files."
909 :type 'list
910 :group 'anything-config)
912 (defcustom anything-create--actions-private nil
913 "User defined actions for `anything-create' / `anything-c-source-create'.
914 It is a list of (DISPLAY . FUNCTION) pairs like `action'
915 attribute of `anything-sources'.
917 It is prepended to predefined pairs."
918 :type 'list
919 :group 'anything-config)
921 (defcustom anything-allow-skipping-current-buffer t
922 "Show current buffer or not in anything buffer"
923 :type 'boolean
924 :group 'anything-config)
926 (defcustom anything-c-enable-eval-defun-hack t
927 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
928 This hack is invoked when pressing C-M-x in the form \
929 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
930 :type 'boolean
931 :group 'anything-config)
933 (defcustom anything-tramp-verbose 0
934 "*Just like `tramp-verbose' but specific to anything.
935 When set to 0 don't show tramp messages in anything.
936 If you want to have the default tramp messages set it to 3."
937 :type 'integer
938 :group 'anything-config)
940 (defcustom anything-raise-command nil
941 "*A shell command to jump to a window running specific program.
942 Need external program wmctrl.
943 This will be use with `format', so use something like \"wmctrl -xa %s\"."
944 :type 'string
945 :group 'anything-config)
947 (defun anything-set-anything-command-map-prefix-key (var key)
948 (declare (special anything-command-map-prefix-key))
949 (when (boundp 'anything-command-map-prefix-key)
950 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
951 (setq anything-command-map-prefix-key key)
952 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
953 'anything-command-map))
955 (defcustom anything-command-map-prefix-key "<f5> a"
956 "*The prefix key for all `anything-command-map' commands.
958 !!WARNING!!
959 This default value is very likely to be changed,
960 because it is under discussion."
961 :type 'string
962 :set 'anything-set-anything-command-map-prefix-key
963 :group 'anything-config)
965 (defcustom anything-c-browse-code-regexp-lisp
966 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
967 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
968 "*Regexp used to parse lisp buffer when browsing code."
969 :type 'string
970 :group 'anything-config)
972 (defcustom anything-c-browse-code-regexp-python
973 "\\<def\\>\\|\\<class\\>"
974 "*Regexp used to parse python buffer when browsing code."
975 :type 'string
976 :group 'anything-config)
978 (defcustom anything-c-browse-code-regexp-alist
979 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
980 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
981 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
982 (python-mode . ,anything-c-browse-code-regexp-python))
983 "*Alist to store regexps for browsing code corresponding \
984 to a specific `major-mode'."
985 :type 'list
986 :group 'anything-config)
988 (defcustom anything-c-external-programs-associations nil
989 "*Alist to store externals programs associated with file extension.
990 This variable overhide setting in .mailcap file.
991 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
992 :type 'list
993 :group 'anything-config)
995 (defcustom anything-ff-auto-update-initial-value t
996 "Auto update when only one candidate directory is matched.
997 This is the default value when starting `anything-find-files'."
998 :group 'anything-config
999 :type 'boolean)
1001 (defcustom anything-c-copy-async-prefered-emacs "emacs"
1002 "Path to the emacs you want to use for copying async.
1003 Emacs versions < 24 fail to copy directory due to a bug not fixed
1004 in `copy-directory'."
1005 :group 'anything-config
1006 :type 'string)
1008 (defcustom anything-ff-lynx-style-map t
1009 "Use arrow keys to navigate with `anything-find-files'.
1010 You will have to restart Emacs or reeval `anything-find-files-map'
1011 and `anything-c-read-file-map' for this take effect."
1012 :group 'anything-config
1013 :type 'boolean)
1015 (defcustom anything-ff-history-max-length 100
1016 "*Number of elements shown in `anything-find-files' history."
1017 :group 'anything-config
1018 :type 'integer)
1020 (defcustom anything-ff-smart-completion t
1021 "Try to complete filenames smarter when non--nil.
1022 See `anything-ff-transform-fname-for-completion' for more info."
1023 :group 'anything-config
1024 :type 'boolean)
1026 (defcustom anything-ff-default-kbsize 1024.0
1027 "Default Kbsize to use for showing files size.
1028 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1029 :group 'anything-config
1030 :type 'float)
1032 (defcustom anything-ff-tramp-not-fancy t
1033 "No colors when listing remote files when set to non--nil.
1034 This make listing much faster, specially on slow machines."
1035 :group 'anything-config
1036 :type 'boolean)
1038 (defcustom anything-ff-exif-data-program "exiftran"
1039 "*Program used to extract exif data of an image file."
1040 :group 'anything-config
1041 :type 'string)
1043 (defcustom anything-ff-exif-data-program-args "-d"
1044 "*Arguments used for `anything-ff-exif-data-program'."
1045 :group 'anything-config
1046 :type 'string)
1048 (defcustom anything-c-grep-use-ioccur-style-keys t
1049 "Use Arrow keys to jump to occurences."
1050 :group 'anything-config
1051 :type 'boolean)
1053 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1054 "Default command to read pdf files from pdfgrep.
1055 Where '%f' format spec is filename and '%p' is page number"
1056 :group 'anything-config
1057 :type 'string)
1059 (defcustom anything-c-etags-tag-file-name "TAGS"
1060 "Etags tag file name."
1061 :type 'string
1062 :group 'anything-config)
1064 (defcustom anything-c-etags-tag-file-search-limit 10
1065 "The limit level of directory to search tag file.
1066 Don't search tag file deeply if outside this value."
1067 :type 'number
1068 :group 'anything-config)
1070 (defcustom anything-c-etags-use-regexp-search nil
1071 "When non--nil search etags candidates by regexp.
1072 This disable anything-match-plugin when enabled.
1073 When nil search is performed directly on patter and *match-plugin is used
1074 if available. You can customize `anything-c-etags-search-regexp'."
1075 :group 'anything-config
1076 :type 'boolean)
1078 (defcustom anything-c-etags-search-regexp "^.+: .+ \\<%s"
1079 "Regexp that match tags in an anything etags buffer.
1080 The format spec is replaced by pattern.
1081 This regexp have no effect when `anything-c-etags-use-regexp-search'
1082 is nil."
1083 :group 'anything-config
1084 :type 'regexp)
1086 (defcustom anything-c-filelist-file-name nil
1087 "Filename of file list.
1088 Accept a list of string for multiple files.
1090 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1091 File list is created by make-filelist.rb script.
1093 Usage:
1094 ruby make-filelist.rb > /tmp/all.filelist
1096 Then
1097 ;; Assume that /tmp is ramdisk or tmpfs
1098 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1099 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1101 :type 'string
1102 :group 'anything-config)
1104 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1105 'anything-c-show-info-in-mode-line
1106 "A function to display eldoc info.
1107 Should take one arg: the string to display."
1108 :group 'anything-config
1109 :type 'symbol)
1111 (defcustom anything-c-turn-on-show-completion t
1112 "Display candidate in buffer while moving selection when non--nil."
1113 :group 'anything-config
1114 :type 'boolean)
1116 (defcustom anything-lisp-completion-or-indent-delay 0.6
1117 "After this delay `anything-lisp-completion-counter' is reset to 0.
1118 This allow to indent again without completing lisp symbol after this delay.
1119 Default is 0.6 seconds."
1120 :group 'anything-config
1121 :type 'number)
1123 (defcustom anything-c-default-external-file-browser "nautilus"
1124 "Default external file browser for your system.
1125 Directories will be opened externally with it.
1126 Set to nil if you do not have external file browser
1127 or do not want to use it."
1128 :group 'anything-config
1129 :type 'string)
1131 (defcustom anything-c-use-adaptative-sorting nil
1132 "*Wheter to use or not adaptative sorting.
1133 Even if a source use it, it will have no effect when set to nil."
1134 :type 'boolean
1135 :group 'anything-config)
1137 (defcustom anything-ff-newfile-prompt-p t
1138 "Whether Prompt or not when creating new file.
1139 This set `ffap-newfile-prompt'."
1140 :type 'boolean
1141 :group 'anything-config)
1144 (defcustom anything-ff-avfs-directory nil
1145 "*The default avfs directory, usually '.avfs'.
1146 When this is set you will be able to expand archive filenames with `C-z'
1147 inside an avfs directory mounted with mountavfs.
1148 See <http://sourceforge.net/projects/avf/>."
1149 :type 'boolean
1150 :group 'anything-config)
1152 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1153 "*Minimal list of compressed files extension."
1154 :type 'list
1155 :group 'anything-config)
1157 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1158 "Default regexp to match locate database.
1159 If nil Search in all files."
1160 :type 'string
1161 :group 'anything-config)
1163 (defcustom anything-c-show-info-in-mode-line-delay 12
1164 "Eldoc will show info in mode-line during this delay if user is idle."
1165 :type 'integer
1166 :group 'anything-config)
1168 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1169 "The file used to communicate with two emacs when copying files async."
1170 :type 'string
1171 :group 'anything-config)
1173 (defcustom anything-ff-printer-list nil
1174 "A list of available printers on your system.
1175 When non--nil let you choose a printer to print file.
1176 Otherwise when nil the variable `printer-name' will be used.
1177 On Unix based systems you can use `anything-ff-find-printers' to
1178 find a list of available printers."
1179 :type 'list
1180 :group 'anything-config)
1182 (defcustom anything-ff-transformer-show-only-basename nil
1183 "Show only basename of candidates in `anything-find-files'.
1184 This can be toggled at anytime from `anything-find-files' with \
1185 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1186 :type 'boolean
1187 :group 'anything-config)
1189 (defcustom anything-completing-read-handlers-alist
1190 '((describe-function . anything-completing-read-symbols)
1191 (describe-variable . anything-completing-read-symbols)
1192 (debug-on-entry . anything-completing-read-symbols)
1193 (find-function . anything-completing-read-symbols)
1194 (trace-function . anything-completing-read-symbols)
1195 (trace-function-background . anything-completing-read-symbols)
1196 (find-tag . anything-completing-read-with-cands-in-buffer)
1197 (ffap-alternate-file . nil))
1198 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1199 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1200 where key and value are symbols.
1202 Each key is an Emacs command that use originaly `completing-read'.
1204 Each value maybe an anything function that take same arguments as
1205 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1206 anything source and BUFFER the name of the buffer we will use.
1207 This function prefix name must start by \"anything\".
1209 See `anything-completing-read-symbols' for example.
1211 If the value of an entry is nil completion will fall back to
1212 emacs vanilla behavior.
1213 e.g If you want to disable anything completion for `describe-function':
1214 \(describe-function . nil\).
1216 Ido is also supported, you can use `ido-completing-read' and
1217 `ido-read-file-name' as value of an entry or just 'ido.
1218 e.g ido completion for `find-file':
1219 \(find-file . ido\)
1220 same as
1221 \(find-file . ido-read-file-name\)
1222 Note that you don't need to enable `ido-mode' for this to work."
1223 :group 'anything-config
1224 :type '(alist :key-type symbol :value-type symbol))
1228 ;;; General internal variables
1230 ;; Some internals variable that need to be loaded
1231 ;; here to avoid compiler warnings.
1232 (defvar anything-c-external-commands-list nil
1233 "A list of all external commands the user can execute. If this
1234 variable is not set by the user, it will be calculated
1235 automatically.")
1237 (defvar anything-c-show-completion-overlay nil)
1239 (defvar anything-c-locate-command
1240 (case system-type
1241 ('gnu/linux "locate -i -r %s")
1242 ('berkeley-unix "locate -i %s")
1243 ('windows-nt "es -i -r %s")
1244 (t "locate %s"))
1245 "A list of arguments for locate program.
1246 The \"-r\" option must be the last option.")
1249 ;;; Faces
1252 (defface anything-buffer-saved-out
1253 '((t (:foreground "red")))
1254 "*Face used for buffer files modified outside of emacs."
1255 :group 'anything-config)
1257 (defface anything-buffer-not-saved
1258 '((t (:foreground "Indianred2")))
1259 "*Face used for buffer files not already saved on disk."
1260 :group 'anything-config)
1262 (defface anything-ff-prefix
1263 '((t (:background "yellow" :foreground "black")))
1264 "*Face used to prefix new file or url paths in `anything-find-files'."
1265 :group 'anything-config)
1267 (defface anything-ff-executable
1268 '((t (:foreground "green")))
1269 "*Face used for executable files in `anything-find-files'."
1270 :group 'anything-config)
1272 (defface anything-ff-directory
1273 '((t (:foreground "DarkRed" :background "LightGray")))
1274 "*Face used for directories in `anything-find-files'."
1275 :group 'anything-config)
1277 (defface anything-ff-symlink
1278 '((t (:foreground "DarkOrange")))
1279 "*Face used for symlinks in `anything-find-files'."
1280 :group 'anything-config)
1282 (defface anything-ff-invalid-symlink
1283 '((t (:foreground "black" :background "red")))
1284 "*Face used for invalid symlinks in `anything-find-files'."
1285 :group 'anything-config)
1287 (defface anything-ff-file
1288 '((t (:foreground "CadetBlue" :underline t)))
1289 "*Face used for file names in `anything-find-files'."
1290 :group 'anything-config)
1292 (defface anything-grep-match
1293 '((t (:inherit match)))
1294 "Face used to highlight grep matches."
1295 :group 'anything-config)
1297 (defface anything-grep-file
1298 '((t (:foreground "BlueViolet" :underline t)))
1299 "Face used to highlight grep results filenames."
1300 :group 'anything-config)
1302 (defface anything-grep-lineno
1303 '((t (:foreground "Darkorange1")))
1304 "Face used to highlight grep number lines."
1305 :group 'anything-config)
1307 (defface anything-grep-running
1308 '((t (:foreground "Red")))
1309 "Face used in mode line when grep is running."
1310 :group 'anything-config)
1312 (defface anything-grep-finish
1313 '((t (:foreground "Green")))
1314 "Face used in mode line when grep is finish."
1315 :group 'anything-config)
1317 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1318 "*Face used in anything-M-x to show keybinding."
1319 :group 'anything)
1321 (defface anything-bmkext-info
1322 '((t (:foreground "green")))
1323 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1324 :group 'anything)
1326 (defface anything-bmkext-w3m
1327 '((t (:foreground "yellow")))
1328 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1329 :group 'anything)
1331 (defface anything-bmkext-gnus
1332 '((t (:foreground "magenta")))
1333 "*Face used for Gnus bookmarks."
1334 :group 'anything)
1336 (defface anything-bmkext-man
1337 '((t (:foreground "Orange4")))
1338 "*Face used for Woman/man bookmarks."
1339 :group 'anything)
1341 (defface anything-bmkext-no--file
1342 '((t (:foreground "grey")))
1343 "*Face used for non--file bookmarks."
1344 :group 'anything)
1346 (defface anything-bmkext-file
1347 '((t (:foreground "Deepskyblue2")))
1348 "*Face used for non--file bookmarks."
1349 :group 'anything)
1351 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1352 "Face for su/sudo bookmarks."
1353 :group 'anything)
1355 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1356 "Face for w3m bookmarks" :group 'anything)
1358 (defface anything-emms-playlist
1359 '((t (:foreground "Springgreen4" :underline t)))
1360 "*Face used for tracks in current emms playlist."
1361 :group 'anything)
1363 (defface anything-apt-installed
1364 '((t (:foreground "green")))
1365 "*Face used for apt installed candidates."
1366 :group 'anything)
1368 (defface anything-gentoo-match-face '((t (:foreground "red")))
1369 "Face for anything-gentoo installed packages."
1370 :group 'traverse-faces)
1372 (defface anything-lisp-show-completion
1373 '((t (:background "DarkSlateGray")))
1374 "*Face used for showing candidates in `anything-lisp-completion'."
1375 :group 'anything-config)
1377 (defface anything-lisp-completion-info
1378 '((t (:foreground "red")))
1379 "*Face used for showing info in `anything-lisp-completion'."
1380 :group 'anything-config)
1382 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1383 "Face for source header in the anything buffer." :group 'anything)
1385 ;;;###autoload
1386 (defun anything-configuration ()
1387 "Customize `anything'."
1388 (interactive)
1389 (customize-group "anything-config"))
1393 ;;; Anything-command-map
1396 ;;;###autoload
1397 (defvar anything-command-map)
1398 (define-prefix-command 'anything-command-map)
1401 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1402 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1403 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1404 (define-key anything-command-map (kbd "l") 'anything-locate)
1405 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1406 (define-key anything-command-map (kbd "r") 'anything-regexp)
1407 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1408 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1409 (define-key anything-command-map (kbd "#") 'anything-emms)
1410 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1411 (define-key anything-command-map (kbd "t") 'anything-top)
1412 (define-key anything-command-map (kbd "i") 'anything-imenu)
1413 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1414 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1415 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1416 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1417 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1418 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1419 (define-key anything-command-map (kbd "f") 'anything-for-files)
1420 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1421 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1422 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1423 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1424 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1425 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1426 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1427 (define-key anything-command-map (kbd "c") 'anything-colors)
1428 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1429 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1430 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1431 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1432 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1433 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1434 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1435 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1436 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1437 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1439 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1440 ;; minibuffer-local-filename-must-match-map.
1441 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1442 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1443 (dolist (map (list minibuffer-local-filename-completion-map
1444 minibuffer-local-completion-map
1445 minibuffer-local-must-match-filename-map
1446 minibuffer-local-filename-must-match-map
1447 minibuffer-local-map
1448 minibuffer-local-isearch-map
1449 minibuffer-local-must-match-map
1450 minibuffer-local-ns-map))
1451 (define-key map "\C-r" 'anything-minibuffer-history))
1455 ;;; Menu
1458 (easy-menu-define nil global-map
1459 "`anything' menu"
1460 '("Anything"
1461 ["All anything commands" anything-execute-anything-command t]
1462 ["Find any Files/Buffers" anything-for-files t]
1463 ["Anything Everywhere (Toggle)" ac-mode t]
1464 "----"
1465 ("Files:"
1466 ["Find files" anything-find-files t]
1467 ["Recent Files" anything-recentf t]
1468 ["Locate" anything-locate t]
1469 ["Bookmarks" anything-c-pp-bookmarks t])
1470 ("Buffers:"
1471 ["Find buffers" anything-buffers-list t])
1472 ("Commands:"
1473 ["Emacs Commands" anything-M-x t]
1474 ["Externals Commands" anything-c-run-external-command t])
1475 ("Help:"
1476 ["Anything Apropos" anything-c-apropos t])
1477 ("Info:"
1478 ["Info at point" anything-info-at-point t]
1479 ["Emacs Manual index" anything-info-emacs t]
1480 ["Gnus Manual index" anything-info-gnus t])
1481 ("Org:"
1482 ["Org keywords" anything-org-keywords t]
1483 ["Org headlines" anything-org-headlines t])
1484 ("Tools:"
1485 ["Occur" anything-occur t]
1486 ["Grep" anything-do-grep t]
1487 ["Etags" anything-c-etags-select t]
1488 ["Lisp complete at point" anything-lisp-completion-at-point t]
1489 ["Browse Kill ring" anything-show-kill-ring t]
1490 ["Browse register" anything-register t]
1491 ["Browse code" anything-browse-code t]
1492 ["Mark Ring" anything-all-mark-rings t]
1493 ["Regexp handler" anything-regexp t]
1494 ["Colors & Faces" anything-colors t]
1495 ["Show xfonts" anything-select-xfont t]
1496 ["Ucs Symbols" anything-ucs t]
1497 ["Imenu" anything-imenu t]
1498 ["Google Suggest" anything-google-suggest t]
1499 ["Eval expression" anything-eval-expression-with-eldoc t]
1500 ["Calcul expression" anything-calcul-expression t]
1501 ["Man pages" anything-man-woman t]
1502 ["Top externals process" anything-top t]
1503 ["Emacs internals process" anything-list-emacs-process t])
1504 "----"
1505 ["Prefered Options" anything-configuration t]))
1507 ;;; Anything map add ons
1510 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1511 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1512 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1515 ;;; Specialized keymaps
1518 (defvar anything-c-buffer-map
1519 (let ((map (copy-keymap anything-map)))
1520 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1521 ;; No need to have separate command for grep and zgrep
1522 ;; as we don't use recursivity for buffers.
1523 ;; So use zgrep for both as it is capable to handle non--compressed files.
1524 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1525 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1526 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1527 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1528 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1529 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1530 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1531 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1532 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1533 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1534 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1535 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1536 (define-key map (kbd "M-a") 'anything-mark-all)
1537 (when (locate-library "elscreen")
1538 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1539 (delq nil map))
1540 "Keymap for buffer sources in anything.")
1542 (defvar anything-find-files-map
1543 (let ((map (copy-keymap anything-map)))
1544 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1545 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1546 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1547 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1548 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1549 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1550 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1551 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1552 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1553 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1554 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1555 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1556 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1557 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1558 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1559 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1560 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1561 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1562 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1563 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1564 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1565 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1566 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1567 (define-key map (kbd "C-c ?") 'anything-ff-help)
1568 (define-key map (kbd "C-}") 'anything-narrow-window)
1569 (define-key map (kbd "C-{") 'anything-enlarge-window)
1570 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1571 (define-key map (kbd "M-a") 'anything-mark-all)
1572 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1573 (define-key map (kbd "M-u") 'anything-unmark-all)
1574 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1575 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1576 ;; Next 2 have no effect if candidate is not an image file.
1577 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1578 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1579 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1580 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1581 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1582 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1583 (when anything-ff-lynx-style-map
1584 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1585 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1586 (delq nil map))
1587 "Keymap for `anything-find-files'.")
1589 (defvar anything-c-read-file-map
1590 (let ((map (copy-keymap anything-map)))
1591 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1592 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1593 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1594 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1595 (when anything-ff-lynx-style-map
1596 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1597 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1598 (define-key map (kbd "<M-left>") 'anything-previous-source)
1599 (define-key map (kbd "<M-right>") 'anything-next-source))
1600 (delq nil map))
1601 "Keymap for `anything-c-read-file-name'.")
1603 (defvar anything-generic-files-map
1604 (let ((map (copy-keymap anything-map)))
1605 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1606 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1607 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1608 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1609 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1610 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1611 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1612 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1613 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1614 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1615 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1616 map)
1617 "Generic Keymap for files.")
1619 (defvar anything-c-grep-map
1620 (let ((map (copy-keymap anything-map)))
1621 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1622 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1623 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1624 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1625 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1626 (when anything-c-grep-use-ioccur-style-keys
1627 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1628 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1629 (define-key map (kbd "C-c ?") 'anything-grep-help)
1630 (delq nil map))
1631 "Keymap used in Grep sources.")
1633 (defvar anything-c-pdfgrep-map
1634 (let ((map (copy-keymap anything-map)))
1635 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1636 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1637 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1638 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1639 map)
1640 "Keymap used in pdfgrep.")
1642 (defvar anything-c-etags-map
1643 (let ((map (copy-keymap anything-map)))
1644 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1645 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1646 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1647 (define-key map (kbd "C-c ?") 'anything-etags-help)
1648 map)
1649 "Keymap used in Etags.")
1651 (defvar anything-eval-expression-map
1652 (let ((map (copy-keymap anything-map)))
1653 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1654 (define-key map (kbd "<tab>") 'lisp-indent-line)
1655 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1656 (define-key map (kbd "C-p") 'previous-line)
1657 (define-key map (kbd "C-n") 'next-line)
1658 (define-key map (kbd "<up>") 'previous-line)
1659 (define-key map (kbd "<down>") 'next-line)
1660 (define-key map (kbd "<right>") 'forward-char)
1661 (define-key map (kbd "<left>") 'backward-char)
1662 map))
1664 (defvar anything-c-ucs-map
1665 (let ((map (copy-keymap anything-map)))
1666 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1667 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1668 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1669 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1670 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1671 map)
1672 "Keymap for `anything-ucs'.")
1676 ;;; Embeded documentation.
1679 (defun anything-c-list-preconfigured-anything ()
1680 "Collect preconfigured anything functions in this file."
1681 (loop with doc
1682 with sym
1683 for entry in (cdr (assoc
1684 (file-truename (locate-library "anything-config"))
1685 load-history))
1686 if (and (consp entry)
1687 (eq (car entry) 'defun)
1688 (string-match "^Preconfigured.+$"
1689 (setq doc (or (documentation (setq sym (cdr entry)))
1690 ""))))
1691 collect (cons sym (match-string 0 doc))))
1693 (defun anything-c-format-preconfigured-anything ()
1694 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1695 (anything-c-list-preconfigured-anything)))
1697 ;;; Global help message - Used by `anything-help'
1700 (setq anything-help-message
1701 (lambda ()
1702 (concat
1703 "\\<anything-map>"
1704 "`anything' is QuickSilver-like candidate-selection framework.
1706 Narrow the list by typing some pattern,
1707 Multiple patterns are allowed by splitting by space.
1708 Select with natural Emacs operations, choose with RET.
1710 If you have any problems, press C-c C-x C-b!!
1711 Feel free to send bug reports. I'll fix them.
1712 The steps are described in the beginning of anything.el file.
1714 == Basic Operations ==
1715 C-p, Up: Previous Line
1716 C-n, Down : Next Line
1717 M-v, PageUp : Previous Page
1718 C-v, PageDown : Next Page
1719 Enter : Execute first (default) action / Select
1720 M-< : First Line
1721 M-> : Last Line
1722 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1723 M-PageDown, C-M-v : Next Page (other-window)
1725 Tab, C-i : Show action list
1726 Left : Previous Source
1727 Right, C-o : Next Source
1728 C-k : Delete pattern
1729 C-z : Persistent Action (Execute action with anything session kept)
1730 C-c C-x C-b: Send a bug report
1732 == Shortcuts For 2nd/3rd Action ==
1733 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1734 \\[anything-select-3rd-action] : Execute 3rd Action
1736 == Visible Marks ==
1737 Visible marks store candidate. Some actions uses marked candidates.
1739 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1740 \\[anything-prev-visible-mark] : Previous Mark
1741 \\[anything-next-visible-mark] : Next Mark
1743 == Miscellaneous Commands ==
1744 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1745 \\[anything-quit-and-find-file] : Drop into `find-file'
1746 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1747 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1748 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1749 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1750 \\[anything-force-update] : Recalculate And Redisplay Candidates
1752 == Global Commands ==
1753 \\<global-map>\\[anything-resume] revives last `anything' session.
1754 It is very useful, so you should bind any key.
1756 Single source is executed by \\[anything-call-source].
1758 == Preconfigured `anything' ==
1759 Preconfigured `anything' is commands that uses `anything' interface.
1760 You can use them without configuration.
1763 (apply 'concat (anything-c-format-preconfigured-anything))
1765 Enjoy!")))
1767 ;;; `anything-buffer-list' help
1770 ;;;###autoload
1771 (defun anything-c-buffer-help ()
1772 "Help command for anything buffers."
1773 (interactive)
1774 (let ((anything-help-message "== Anything Buffer ==
1775 \nTips:
1776 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1777 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1778 \nSpecific commands for `anything-buffers-list':
1779 \\<anything-c-buffer-map>
1780 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1781 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1782 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1783 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1784 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1785 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1786 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1787 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1788 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1789 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1790 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1791 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1792 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1793 \\[anything-mark-all]\t\t->Mark all.
1794 \\[anything-c-buffer-help]\t\t->Display this help.
1795 \n== Anything Map ==
1796 \\{anything-map}
1798 (anything-help)))
1801 ;;; Find files help (`anything-find-files')
1804 ;;;###autoload
1805 (defun anything-ff-help ()
1806 "Help command for `anything-find-files'."
1807 (interactive)
1808 (let ((anything-help-message "== Anything Find Files ==
1809 \nTips:
1810 \n- Enter `~/' at end of pattern to quickly reach home directory.
1811 - Enter `/' at end of pattern to quickly reach root of your file system.
1812 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1813 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1814 - Use `C-u C-z' to watch an image.
1815 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1816 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1818 \nSpecific commands for `anything-find-files':
1819 \\<anything-find-files-map>
1820 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1821 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1822 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1823 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1824 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1825 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1826 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1827 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1828 \\[anything-ff-run-load-file]\t\t->Load File.
1829 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1830 \\[anything-ff-run-delete-file]\t\t->Delete File.
1831 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1832 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1833 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1834 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1835 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1836 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1837 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1838 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1839 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1840 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1841 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1842 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1843 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1844 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1845 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1846 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1847 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1848 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1849 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1850 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1851 \\[anything-narrow-window]\t\t->Narrow anything window.
1852 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1853 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1854 \\[anything-ff-help]\t\t->Display this help info.
1855 \n== Anything Map ==
1856 \\{anything-map}
1858 (anything-help)))
1860 ;;; Help for `anything-c-read-file-name'
1863 ;;;###autoload
1864 (defun anything-read-file-name-help ()
1865 (interactive)
1866 (let ((anything-help-message "== Anything read file name Map ==\
1867 \nSpecific commands for anything-c-read-file-name:
1868 \\<anything-c-read-file-map>
1869 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1870 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1871 \\[anything-next-source]\t\t->Goto next source.
1872 \\[anything-previous-source]\t->Goto previous source.
1873 \\[anything-read-file-name-help]\t\t->Display this help info.
1874 \n== Anything Map ==
1875 \\{anything-map}
1877 (anything-help)))
1879 ;;; Generic file help - Used by locate.
1882 ;;;###autoload
1883 (defun anything-generic-file-help ()
1884 (interactive)
1885 (let ((anything-help-message "== Anything Generic files Map ==\
1886 \nSpecific commands for anything locate and others files sources:
1887 \\<anything-generic-files-map>
1888 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1889 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1890 \\[anything-ff-run-delete-file]\t\t->Delete file.
1891 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1892 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1893 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1894 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1895 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1896 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1897 \nLocate tips:
1898 You can add after writing search pattern any of the locate command line options.
1899 e.g -b, -e, -n <number>...etc.
1900 See Man locate for more infos.
1901 \n== Anything Map ==
1902 \\{anything-map}"))
1903 (anything-help)))
1906 ;;; Grep help
1909 ;;;###autoload
1910 (defun anything-grep-help ()
1911 (interactive)
1912 (let ((anything-help-message "== Anything Grep Map ==\
1913 \nSpecific commands for Grep and Etags:
1914 \\<anything-c-grep-map>
1915 \\[anything-c-goto-next-file]\t->Next File.
1916 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1917 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1918 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1919 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1920 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1921 \\[anything-grep-help]\t\t->Show this help.
1922 \n== Anything Map ==
1923 \\{anything-map}"))
1924 (anything-help)))
1926 ;;; Pdf grep help
1929 ;;;###autoload
1930 (defun anything-pdfgrep-help ()
1931 (interactive)
1932 (let ((anything-help-message "== Anything PdfGrep Map ==\
1933 \nSpecific commands for Pdf Grep:
1934 \\<anything-c-pdfgrep-map>
1935 \\[anything-c-goto-next-file]\t->Next File.
1936 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1937 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1938 \\[anything-pdfgrep-help]\t\t->Show this help.
1939 \n== Anything Map ==
1940 \\{anything-map}"))
1941 (anything-help)))
1943 ;;; Etags help
1946 ;;;###autoload
1947 (defun anything-etags-help ()
1948 "The help function for etags."
1949 (interactive)
1950 (let ((anything-help-message "== Anything Etags Map ==\
1951 \nSpecific commands for Etags:
1952 \\<anything-c-etags-map>
1953 \\[anything-c-goto-next-file]\t->Next File.
1954 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1955 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1956 \\[anything-etags-help]\t\t->Show this help.
1957 \n== Anything Map ==
1958 \\{anything-map}"))
1959 (anything-help)))
1961 ;;; Ucs help
1964 (defun anything-c-ucs-help ()
1965 "Help command for `anything-ucs'."
1966 (interactive)
1967 (let ((anything-help-message "== Anything Ucs ==
1968 \nSpecific commands for `anything-ucs':
1969 \\<anything-c-ucs-map>
1970 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1971 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1972 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1973 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1974 \\[anything-c-ucs-help]\t\t->Show this help.
1976 \n== Anything Map ==
1977 \\{anything-map}
1979 (anything-help)))
1983 ;;; Mode line strings
1986 (defvar anything-buffer-mode-line-string
1987 '("Buffer(s)"
1988 "\\<anything-c-buffer-map>\
1989 \\[anything-c-buffer-help]:Help, \
1990 \\<anything-map>\
1991 \\[anything-select-action]:Acts,\
1992 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1993 \\[anything-select-3rd-action]:NthAct,\
1994 \\[anything-send-bug-report-from-anything]:BugReport."
1995 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1997 (defvar anything-ff-mode-line-string
1998 "\\<anything-find-files-map>\
1999 \\[anything-ff-help]:Help, \
2000 \\[anything-send-bug-report-from-anything]:BugReport, \
2001 \\<anything-map>\
2002 \\[anything-select-action]:Acts, \
2003 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2004 \\[anything-select-3rd-action]:NthAct"
2005 "String displayed in mode-line in `anything-c-source-find-files'")
2007 (defvar anything-read-file-name-mode-line-string
2008 "\\<anything-c-read-file-map>\
2009 \\[anything-read-file-name-help]:Help, \
2010 \\<anything-map>\
2011 \\[anything-select-action]:Acts,\
2012 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2013 \\[anything-select-3rd-action]:NthAct"
2014 "String displayed in mode-line in `anything-c-source-find-files'")
2016 (defvar anything-generic-file-mode-line-string
2017 "\\<anything-generic-files-map>\
2018 \\[anything-generic-file-help]:Help, \
2019 \\<anything-map>\
2020 \\[anything-select-action]:Acts,\
2021 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2022 \\[anything-select-3rd-action]:NthAct,\
2023 \\[anything-send-bug-report-from-anything]:BugReport."
2024 "String displayed in mode-line in Locate.")
2026 (defvar anything-grep-mode-line-string
2027 "\\<anything-c-grep-map>\
2028 \\[anything-grep-help]:Help,\
2029 \\<anything-map>\
2030 \\[anything-select-action]:Acts,\
2031 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2032 \\[anything-select-3rd-action]:NthAct,\
2033 \\[anything-send-bug-report-from-anything]:BugReport."
2034 "String displayed in mode-line in `anything-do-grep'.")
2036 (defvar anything-pdfgrep-mode-line-string
2037 "\\<anything-c-pdfgrep-map>\
2038 \\[anything-pdfgrep-help]:Help,\
2039 \\<anything-map>\
2040 \\[anything-select-action]:Acts,\
2041 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2042 \\[anything-select-3rd-action]:NthAct,\
2043 \\[anything-send-bug-report-from-anything]:BugReport."
2044 "String displayed in mode-line in `anything-do-pdfgrep'.")
2046 (defvar anything-etags-mode-line-string
2047 "\\<anything-c-etags-map>\
2048 \\[anything-etags-help]:Help,\
2049 \\<anything-map>\
2050 \\[anything-select-action]:Acts,\
2051 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2052 \\[anything-select-3rd-action]:NthAct,\
2053 \\[anything-send-bug-report-from-anything]:BugReport."
2054 "String displayed in mode-line in `anything-c-etags-select'.")
2057 (defvar anything-c-ucs-mode-line-string
2058 "\\<anything-c-ucs-map>\
2059 \\[anything-c-ucs-help]:Help, \
2060 \\<anything-map>\
2061 \\[anything-select-action]:Acts,\
2062 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2063 \\[anything-select-3rd-action]:NthAct."
2064 "String displayed in mode-line in `anything-ucs'.")
2068 ;;; Utilities Functions
2071 (defun anything-ff-find-printers ()
2072 "Return a list of available printers on Unix systems."
2073 (let ((printer-list (with-temp-buffer
2074 (call-process "lpstat" nil t nil "-a")
2075 (split-string (buffer-string) "\n"))))
2076 (loop for p in printer-list
2077 for printer = (car (split-string p))
2078 when printer
2079 collect printer)))
2081 ;; Shut up byte compiler in emacs24*.
2082 (defun anything-c-switch-to-buffer (buffer-or-name)
2083 "Same as `switch-to-buffer' whithout warnings at compile time."
2084 (with-no-warnings
2085 (switch-to-buffer buffer-or-name)))
2087 (defsubst* anything-c-position (item seq &key (test 'eq))
2088 "A simple and faster replacement of CL `position'."
2089 (loop for i in seq for index from 0
2090 when (funcall test i item) return index))
2092 (defun anything-c-get-pid-from-process-name (process-name)
2093 "Get pid from running process PROCESS-NAME."
2094 (loop with process-list = (list-system-processes)
2095 for pid in process-list
2096 for process = (assoc-default 'comm (process-attributes pid))
2097 when (and process (string-match process-name process))
2098 return pid))
2100 (defun* anything-current-buffer-narrowed-p (&optional
2101 (buffer anything-current-buffer))
2102 "Check if BUFFER is narrowed.
2103 Default is `anything-current-buffer'."
2104 (with-current-buffer buffer
2105 (let ((beg (point-min))
2106 (end (point-max))
2107 (total (buffer-size)))
2108 (or (/= beg 1) (/= end (1+ total))))))
2110 (defun anything-region-active-p ()
2111 (and transient-mark-mode mark-active (/= (mark) (point))))
2113 (defun anything-goto-line (lineno)
2114 "Goto LINENO opening only outline headline if needed."
2115 (goto-char (point-min)) (forward-line (1- lineno))
2116 (when (or (eq major-mode 'org-mode)
2117 (and (boundp 'outline-minor-mode)
2118 outline-minor-mode))
2119 (require 'org) ; On some old Emacs versions org may not be loaded.
2120 (org-reveal))
2121 (anything-match-line-color-current-line) (sit-for 0.3)
2122 (anything-match-line-cleanup))
2124 (defun anything-show-this-source-only ()
2125 "Show all candidates of this source."
2126 (interactive)
2127 (setq anything-candidate-number-limit nil)
2128 (anything-set-source-filter
2129 (list (assoc-default 'name (anything-get-current-source)))))
2131 ;;;###autoload
2132 (defun anything-test-sources ()
2133 "List all anything sources for test.
2134 The output is sexps which are evaluated by \\[eval-last-sexp]."
2135 (interactive)
2136 (with-output-to-temp-buffer "*Anything Test Sources*"
2137 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2138 (apropos-internal "^anything-c-source" #'boundp))
2139 (pop-to-buffer standard-output)))
2141 (defun anything-nest (&rest same-as-anything)
2142 "Nested `anything'. If you use `anything' within `anything', use it."
2143 (with-selected-window (anything-window)
2144 (let (anything-current-position
2145 anything-current-buffer
2146 (orig-anything-buffer anything-buffer)
2147 anything-pattern
2148 anything-buffer
2149 anything-sources
2150 anything-compiled-sources
2151 anything-buffer-chars-modified-tick
2152 (anything-samewindow t)
2153 (enable-recursive-minibuffers t))
2154 (unwind-protect
2155 (apply #'anything same-as-anything)
2156 (anything-initialize-overlays orig-anything-buffer)
2157 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2159 (defun anything-displaying-source-names ()
2160 "Display sources name."
2161 (with-current-buffer anything-buffer
2162 (goto-char (point-min))
2163 (loop with pos
2164 while (setq pos (next-single-property-change (point) 'anything-header))
2165 do (goto-char pos)
2166 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2167 do (forward-line 1))))
2169 ;; [Obsolete]
2170 (defun anything-select-source ()
2171 "[OBSOLETE] Select source."
2172 (interactive)
2173 (let ((default (assoc-default 'name (anything-get-current-source)))
2174 (source-names (anything-displaying-source-names))
2175 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2176 (anything-get-sources))))
2177 (setq anything-candidate-number-limit 9999)
2178 (anything-aif
2179 (let (anything-source-filter)
2180 (anything-nest '(((name . "Anything Source")
2181 (candidates . source-names)
2182 (action . identity))
2183 ((name . "Anything Source (ALL)")
2184 (candidates . all-source-names)
2185 (action . identity)))
2186 nil "Source: " nil
2187 default "*anything select source*"))
2188 (anything-set-source-filter (list it))
2189 (anything-set-source-filter nil))))
2191 (defun anything-c-match-on-file-name (candidate)
2192 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2193 (string-match anything-pattern (file-name-nondirectory candidate)))
2195 (defun anything-c-match-on-directory-name (candidate)
2196 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2197 (anything-aif (file-name-directory candidate)
2198 (string-match anything-pattern it)))
2200 (defun anything-c-match-on-basename (candidate)
2201 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2202 (string-match anything-pattern (anything-c-basename candidate)))
2204 (defun anything-c-string-match (candidate)
2205 "Return non-nil if `anything-pattern' match CANDIDATE.
2206 The match is done with `string-match'."
2207 (string-match anything-pattern candidate))
2209 (defun anything-c-skip-entries (list regexp)
2210 "Remove entries which matches REGEXP from LIST."
2211 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2212 list))
2214 (defun anything-c-shadow-entries (list regexp)
2215 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2216 (mapcar (lambda (file)
2217 ;; Add shadow face property to boring files.
2218 (let ((face (if (facep 'file-name-shadow)
2219 'file-name-shadow
2220 ;; fall back to default on XEmacs
2221 'default)))
2222 (if (string-match regexp file)
2223 (setq file (propertize file 'face face))))
2224 file)
2225 list))
2227 (defsubst anything-c-stringify (str-or-sym)
2228 "Get string of STR-OR-SYM."
2229 (if (stringp str-or-sym)
2230 str-or-sym
2231 (symbol-name str-or-sym)))
2233 (defsubst anything-c-symbolify (str-or-sym)
2234 "Get symbol of STR-OR-SYM."
2235 (if (symbolp str-or-sym)
2236 str-or-sym
2237 (intern str-or-sym)))
2239 (defun anything-c-describe-function (func)
2240 "FUNC is symbol or string."
2241 (describe-function (anything-c-symbolify func)))
2243 (defun anything-c-describe-variable (var)
2244 "VAR is symbol or string."
2245 (describe-variable (anything-c-symbolify var)))
2247 (defun anything-c-find-function (func)
2248 "FUNC is symbol or string."
2249 (find-function (anything-c-symbolify func)))
2251 (defun anything-c-find-variable (var)
2252 "VAR is symbol or string."
2253 (find-variable (anything-c-symbolify var)))
2255 (defun anything-c-kill-new (candidate &optional replace)
2256 "CANDIDATE is symbol or string.
2257 See `kill-new' for argument REPLACE."
2258 (kill-new (anything-c-stringify candidate) replace))
2260 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2261 "Remove duplicates elements in list SEQ.
2262 This is same as `remove-duplicates' but with memoisation.
2263 It is much faster, especially in large lists.
2264 A test function can be provided with TEST argument key.
2265 Default is `eq'."
2266 (let ((cont (make-hash-table :test test)))
2267 (loop for elm in seq
2268 unless (gethash elm cont)
2269 do (puthash elm elm cont)
2270 finally return
2271 (loop for i being the hash-values in cont collect i))))
2273 (defadvice eval-defun (after anything-source-hack activate)
2274 "Allow immediate execution of anything source when evaling it.
2275 See `anything-c-enable-eval-defun-hack'."
2276 (when anything-c-enable-eval-defun-hack
2277 (let ((varsym (save-excursion
2278 (beginning-of-defun)
2279 (forward-char 1)
2280 (when (memq (read (current-buffer)) '(defvar setq))
2281 (read (current-buffer))))))
2282 (when (string-match "^anything-c-source-" (symbol-name varsym))
2283 (anything varsym)))))
2284 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2287 ;; Move this function from anything.el and redefine here
2288 ;; to avoid an unneeded defadvice.
2289 (defun anything-quit-and-find-file ()
2290 "Drop into `anything-find-files' from `anything'.
2291 If current selection is a buffer or a file, `anything-find-files'
2292 from its directory."
2293 (interactive)
2294 (anything-run-after-quit
2295 (lambda (f)
2296 (if (file-exists-p f)
2297 (anything-find-files-1 (file-name-directory f)
2298 (if anything-ff-transformer-show-only-basename
2299 (anything-c-basename f) f))
2300 (anything-find-files-1 f)))
2301 (anything-aif (get-buffer (anything-get-selection))
2302 (or (buffer-file-name it)
2303 (car (rassoc it dired-buffers))
2304 (and (with-current-buffer it
2305 (eq major-mode 'org-agenda-mode))
2306 org-directory
2307 (expand-file-name org-directory))
2308 default-directory)
2309 (let ((sel (anything-get-selection)))
2310 (if (file-exists-p sel)
2311 (expand-file-name sel)
2312 default-directory)))))
2315 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2316 "Walk through DIRECTORY tree.
2317 PATH can be one of basename, relative, or full.
2318 DIRECTORIES when non--nil (default) return also directories names, otherwise
2319 skip directories names.
2320 MATCH match only filenames matching regexp MATCH."
2321 `(let (result
2322 (fn (case ,path
2323 (basename 'file-name-nondirectory)
2324 (relative 'file-relative-name)
2325 (full 'identity)
2326 (t 'file-name-nondirectory))))
2327 (labels ((ls-R (dir)
2328 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2329 for f in ls
2330 if (file-directory-p f)
2331 do (progn (when ,directories
2332 (push (funcall fn f) result))
2333 ;; Don't recurse in directory symlink.
2334 (unless (file-symlink-p f)
2335 (ls-R f)))
2336 else do
2337 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2338 (push (funcall fn f) result)))))
2339 (ls-R ,directory)
2340 (nreverse result))))
2342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2344 ;;; Anything regexp.
2347 (defvar anything-build-regexp-history nil)
2348 (defun anything-c-query-replace-regexp (candidate)
2349 "Query replace regexp from `anything-regexp'.
2350 With a prefix arg replace only matches surrounded by word boundaries,
2351 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2352 (let ((regexp (funcall (anything-attr 'regexp))))
2353 (apply 'query-replace-regexp
2354 (anything-c-query-replace-args regexp))))
2356 (defun anything-c-kill-regexp-as-sexp (candidate)
2357 "Kill regexp in a format usable in lisp code."
2358 (anything-c-regexp-kill-new
2359 (prin1-to-string (funcall (anything-attr 'regexp)))))
2361 (defun anything-c-kill-regexp (candidate)
2362 "Kill regexp as it is in `anything-pattern'."
2363 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2365 (defun anything-c-query-replace-args (regexp)
2366 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2367 (let ((region-only (anything-region-active-p)))
2368 (list
2369 regexp
2370 (query-replace-read-to regexp
2371 (format "Query replace %sregexp %s"
2372 (if anything-current-prefix-arg "word " "")
2373 (if region-only "in region " ""))
2375 anything-current-prefix-arg
2376 (when region-only (region-beginning))
2377 (when region-only (region-end)))))
2379 (defvar anything-c-source-regexp
2380 '((name . "Regexp Builder")
2381 (init . (lambda ()
2382 (anything-candidate-buffer anything-current-buffer)))
2383 (candidates-in-buffer)
2384 (get-line . anything-c-regexp-get-line)
2385 (persistent-action . anything-c-regexp-persistent-action)
2386 (persistent-help . "Show this line")
2387 (multiline)
2388 (delayed)
2389 (requires-pattern . 2)
2390 (mode-line . "Press TAB to select action.")
2391 (regexp . (lambda () anything-input))
2392 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2393 ("Query Replace Regexp (C-u Not inside word.)"
2394 . anything-c-query-replace-regexp)
2395 ("Kill Regexp" . anything-c-kill-regexp)))))
2397 (defun anything-c-regexp-get-line (s e)
2398 (propertize
2399 (apply 'concat
2400 ;; Line contents
2401 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2402 ;; subexps
2403 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2404 collect (format "\n %s'%s'"
2405 (if (zerop i) "Group 0: " (format "Group %d: " i))
2406 (match-string i))))
2407 ;; match beginning
2408 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2409 ;; It is implementation problem of candidates-in-buffer.
2410 'anything-realvalue
2411 (1- s)))
2413 (defun anything-c-regexp-persistent-action (pt)
2414 (goto-char pt)
2415 (anything-persistent-highlight-point))
2417 (defun anything-c-regexp-kill-new (input)
2418 (kill-new input)
2419 (message "Killed: %s" input))
2423 ;;; Toggle all marks.
2426 ;;;###autoload
2427 (defun anything-mark-all ()
2428 "Mark all visible unmarked candidates in current source."
2429 (interactive)
2430 (with-anything-window
2431 (save-excursion
2432 (goto-char (anything-get-previous-header-pos))
2433 (anything-next-line)
2434 (let* ((next-head (anything-get-next-header-pos))
2435 (end (and next-head
2436 (save-excursion
2437 (goto-char next-head)
2438 (forward-line -1)
2439 (point))))
2440 (maxpoint (or end (point-max))))
2441 (while (< (point) maxpoint)
2442 (anything-mark-current-line)
2443 (let ((prefix (get-text-property (point-at-bol) 'display))
2444 (bn (anything-c-basename (anything-get-selection)))
2445 (src (assoc-default 'name (anything-get-current-source))))
2446 (when (and (not (anything-this-visible-mark))
2447 (not (or (string= prefix "[?]")
2448 (string= prefix "[@]"))))
2449 ;; Don't mark possibles directories ending with . or ..
2450 ;; and also autosave files/links.
2451 (unless
2452 (and (or (anything-file-completion-source-p)
2453 (equal src "Files from Current Directory"))
2454 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2455 (anything-make-visible-mark))))
2456 (forward-line 1) (end-of-line))))
2457 (anything-mark-current-line)
2458 (message "%s candidates marked" (length anything-marked-candidates))))
2460 ;;;###autoload
2461 (defun anything-unmark-all ()
2462 "Unmark all candidates in all sources of current anything session."
2463 (interactive)
2464 (with-anything-window
2465 (let ((len (length anything-marked-candidates)))
2466 (save-excursion
2467 (anything-clear-visible-mark))
2468 (setq anything-marked-candidates nil)
2469 (anything-mark-current-line)
2470 (message "%s candidates unmarked" len))))
2472 ;;;###autoload
2473 (defun anything-toggle-all-marks ()
2474 "Toggle all marks.
2475 Mark all visible candidates of current source or unmark all candidates
2476 visible or invisible in all sources of current anything session"
2477 (interactive)
2478 (let ((marked (anything-marked-candidates)))
2479 (if (and (>= (length marked) 1)
2480 (with-anything-window anything-visible-mark-overlays))
2481 (anything-unmark-all)
2482 (anything-mark-all))))
2486 ;;; Buffers
2489 (defun anything-c-buffer-list ()
2490 "Return the list of names of buffers with boring buffers filtered out.
2491 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2492 The first buffer in the list will be the last recently used
2493 buffer that is not the current buffer."
2494 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2495 (append (cdr buffers) (list (car buffers)))))
2497 (defvar anything-c-source-buffers
2498 '((name . "Buffers")
2499 (candidates . anything-c-buffer-list)
2500 (type . buffer)))
2501 ;; (anything 'anything-c-source-buffers)
2503 (defvar anything-c-source-buffer-not-found
2504 '((name . "Create buffer")
2505 (dummy)
2506 (filtered-candidate-transformer (lambda (cands source)
2507 (list anything-pattern)))
2508 (action . (lambda (candidate)
2509 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2510 ;; (anything 'anything-c-source-buffer-not-found)
2512 ;;; Buffers-list (was buffers+)
2515 (eval-when-compile (require 'dired))
2517 (defun anything-c-highlight-buffers (buffers)
2518 (loop for i in buffers
2519 for buf = (get-buffer i)
2520 for bfname = (buffer-file-name buf)
2521 collect
2522 (cond (;; A dired buffer.
2523 (rassoc buf dired-buffers)
2524 (propertize i 'face 'anything-ff-directory
2525 'help-echo (car (rassoc buf dired-buffers))))
2526 ;; A buffer file modified somewhere outside of emacs.
2527 ((and bfname (not (file-remote-p bfname))
2528 (file-exists-p bfname)
2529 (not (verify-visited-file-modtime buf)))
2530 (propertize i 'face 'anything-buffer-saved-out
2531 'help-echo bfname))
2532 ;; A new buffer file not already saved on disk.
2533 ((and bfname (not (file-remote-p bfname))
2534 (not (verify-visited-file-modtime buf)))
2535 (propertize i 'face 'anything-buffer-not-saved
2536 'help-echo bfname))
2537 ;; A Remote buffer file modified and not saved on disk.
2538 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2539 (let ((prefix (propertize
2540 " " 'display
2541 (propertize "@ " 'face 'anything-ff-prefix))))
2542 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2543 'help-echo bfname)) i)))
2544 ;; A buffer file modified and not saved on disk.
2545 ((and bfname (buffer-modified-p buf))
2546 (propertize i 'face 'anything-ff-symlink
2547 'help-echo bfname))
2548 ;; A remote buffer file not modified and saved on disk.
2549 ((and bfname (file-remote-p bfname))
2550 (let ((prefix (propertize
2551 " " 'display
2552 (propertize "@ " 'face 'anything-ff-prefix))))
2553 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2554 'help-echo bfname)) i)))
2555 ;; A buffer file not modified and saved on disk.
2556 (bfname
2557 (propertize i 'face 'font-lock-type-face
2558 'help-echo bfname))
2559 ;; Any non--file buffer.
2560 (t (propertize i 'face 'italic)))))
2563 (defvar anything-c-source-buffers-list
2564 '((name . "Buffers")
2565 (candidates . anything-c-buffer-list)
2566 (type . buffer)
2567 (match anything-c-buffer-match-major-mode)
2568 (diff-action . anything-buffer-toggle-diff)
2569 (revert-action . anything-buffer-revert-and-update)
2570 (save-action . anything-buffer-save-and-update)
2571 (candidate-transformer
2572 anything-c-skip-current-buffer
2573 anything-c-skip-boring-buffers
2574 anything-c-highlight-buffers)
2575 (persistent-action . anything-c-buffers-list-persistent-action)
2576 (volatile)
2577 (mode-line . anything-buffer-mode-line-string)
2578 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2579 ;; (anything 'anything-c-source-buffers-list)
2581 (defun anything-c-buffer-match-major-mode (candidate)
2582 "Match maybe buffer by major-mode.
2583 If you give a major-mode or partial major-mode,
2584 it will list all buffers of this major-mode and/or buffers with name
2585 matching this major-mode.
2586 If you add a space after major-mode and then a space,
2587 it will match all buffers of the major-mode
2588 before space matching pattern after space.
2589 If you give a pattern which doesn't match a major-mode, it will search buffer
2590 with name matching pattern."
2591 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2592 (buf (get-buffer cand)))
2593 (when buf
2594 (with-current-buffer buf
2595 (let ((mjm (symbol-name major-mode))
2596 (split (split-string anything-pattern)))
2597 (cond ((string-match "\\s-$" anything-pattern)
2598 (string-match (car split) mjm))
2599 ((string-match "\\s-" anything-pattern)
2600 (and (string-match (car split) mjm)
2601 (string-match (cadr split) cand)))
2602 (t (or (string-match anything-pattern mjm)
2603 (string-match anything-pattern cand)))))))))
2605 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2606 "Query replace in marked buffers.
2607 If REGEXP-FLAG is given use `query-replace-regexp'."
2608 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2609 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2610 (bufs (anything-marked-candidates)))
2611 (loop
2612 with replace = (query-replace-read-from prompt regexp-flag)
2613 with tostring = (unless (consp replace)
2614 (query-replace-read-to
2615 replace prompt regexp-flag))
2616 for buf in bufs
2618 (save-window-excursion
2619 (anything-c-switch-to-buffer buf)
2620 (save-excursion
2621 (let ((case-fold-search t))
2622 (goto-char (point-min))
2623 (if (consp replace)
2624 (apply fn (list (car replace) (cdr replace)))
2625 (apply fn (list replace tostring)))))))))
2627 (defun anything-c-buffer-query-replace-regexp (candidate)
2628 (anything-c-buffer-query-replace-1 'regexp))
2630 (defun anything-c-buffer-query-replace (candidate)
2631 (anything-c-buffer-query-replace-1))
2633 (defun anything-buffer-toggle-diff (candidate)
2634 "Toggle diff buffer CANDIDATE with it's file."
2635 (if (get-buffer-window "*Diff*")
2636 (kill-buffer "*Diff*")
2637 (diff-buffer-with-file (get-buffer candidate))))
2639 ;;;###autoload
2640 (defun anything-buffer-diff-persistent ()
2641 "Toggle diff buffer without quitting anything."
2642 (interactive)
2643 (anything-execute-persistent-action 'diff-action))
2645 (defun anything-buffer-revert-and-update (candidate)
2646 (let ((marked (anything-marked-candidates)))
2647 (loop for buf in marked do (anything-revert-buffer buf))
2648 (anything-force-update candidate)))
2650 ;;;###autoload
2651 (defun anything-buffer-revert-persistent ()
2652 "Revert buffer without quitting anything."
2653 (interactive)
2654 (anything-execute-persistent-action 'revert-action 'onewindow))
2656 (defun anything-buffer-save-and-update (candidate)
2657 (let ((marked (anything-marked-candidates))
2658 (enable-recursive-minibuffers t))
2659 (loop for buf in marked do
2660 (with-current-buffer (get-buffer buf)
2661 (save-buffer)))
2662 (anything-force-update candidate)))
2664 ;;;###autoload
2665 (defun anything-buffer-save-persistent ()
2666 "Save buffer without quitting anything."
2667 (interactive)
2668 (anything-execute-persistent-action 'save-action 'onewindow))
2670 ;;;###autoload
2671 (defun anything-buffer-run-kill-buffers ()
2672 "Run kill buffer action from `anything-c-source-buffers-list'."
2673 (interactive)
2674 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2676 ;;;###autoload
2677 (defun anything-buffer-run-grep ()
2678 "Run Grep action from `anything-c-source-buffers-list'."
2679 (interactive)
2680 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2682 ;;;###autoload
2683 (defun anything-buffer-run-zgrep ()
2684 "Run Grep action from `anything-c-source-buffers-list'."
2685 (interactive)
2686 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2688 ;;;###autoload
2689 (defun anything-buffer-run-query-replace-regexp ()
2690 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2691 (interactive)
2692 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2694 ;;;###autoload
2695 (defun anything-buffer-run-query-replace ()
2696 "Run Query replace action from `anything-c-source-buffers-list'."
2697 (interactive)
2698 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2700 ;;;###autoload
2701 (defun anything-buffer-switch-other-window ()
2702 "Run switch to other window action from `anything-c-source-buffers-list'."
2703 (interactive)
2704 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2706 ;;;###autoload
2707 (defun anything-buffer-switch-other-frame ()
2708 "Run switch to other frame action from `anything-c-source-buffers-list'."
2709 (interactive)
2710 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2712 ;;;###autoload
2713 (defun anything-buffer-switch-to-elscreen ()
2714 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2715 (interactive)
2716 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2718 ;;;###autoload
2719 (defun anything-buffer-run-ediff ()
2720 "Run ediff action from `anything-c-source-buffers-list'."
2721 (interactive)
2722 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2724 (defun anything-buffer-run-ediff-merge ()
2725 "Run ediff action from `anything-c-source-buffers-list'."
2726 (interactive)
2727 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2729 (defun anything-c-buffers-persistent-kill (buffer)
2730 "Persistent action to kill buffer."
2731 (with-current-buffer (get-buffer buffer)
2732 (if (and (buffer-modified-p)
2733 (buffer-file-name (current-buffer)))
2734 (progn
2735 (save-buffer)
2736 (kill-buffer buffer))
2737 (kill-buffer buffer)))
2738 (anything-delete-current-selection))
2740 (defun anything-c-buffers-list-persistent-action (candidate)
2741 (if current-prefix-arg
2742 (anything-c-buffers-persistent-kill candidate)
2743 (anything-c-switch-to-buffer candidate)))
2746 ;;;; <File>
2749 ;;; File name history
2750 (defvar anything-c-source-file-name-history
2751 '((name . "File Name History")
2752 (candidates . file-name-history)
2753 (match anything-c-match-on-basename)
2754 (type . file)))
2755 ;; (anything 'anything-c-source-file-name-history)
2757 ;;; Files in current dir
2760 (defvar anything-c-source-files-in-current-dir
2761 '((name . "Files from Current Directory")
2762 (candidates . (lambda ()
2763 (with-anything-current-buffer
2764 (directory-files (anything-c-current-directory)))))
2765 ;; volatile is not needed, I think.
2766 (type . file)))
2767 ;; (anything 'anything-c-source-files-in-current-dir)
2769 (defun anything-c-highlight-files (files)
2770 (loop for i in files
2771 if (file-directory-p i)
2772 collect (propertize (file-name-nondirectory i)
2773 'face 'anything-ff-directory
2774 'help-echo (expand-file-name i))
2775 else
2776 collect (propertize (file-name-nondirectory i)
2777 'face 'anything-ff-file
2778 'help-echo (expand-file-name i))))
2780 (defvar anything-c-source-files-in-current-dir+
2781 '((name . "Files from Current Directory")
2782 (candidates . (lambda ()
2783 (with-anything-current-buffer
2784 (directory-files (anything-c-current-directory) t))))
2785 (candidate-transformer anything-c-highlight-files)
2786 ;; volatile is not needed, I think.
2787 (type . file)))
2788 ;; (anything 'anything-c-source-files-in-current-dir+)
2792 ;;; Anything-find-files - The anything files browser.
2795 ;; Internal.
2796 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2797 "*The doc that is inserted in the Name header of a find-files or dired source.")
2798 (defvar anything-ff-auto-update-flag nil
2799 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2800 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2801 (defvar anything-ff-last-expanded nil
2802 "Store last expanded directory or file.")
2803 (defvar anything-ff-default-directory nil)
2804 (defvar anything-ff-history nil)
2805 (defvar anything-ff-cand-to-mark nil)
2808 (defvar anything-c-source-find-files
2809 `((name . "Find Files")
2810 (header-name . (lambda (name)
2811 (concat name anything-c-find-files-doc-header)))
2812 ;; It is needed for filenames with capital letters
2813 (disable-shortcuts)
2814 (init . (lambda ()
2815 (setq anything-ff-auto-update-flag
2816 anything-ff-auto-update-initial-value)))
2817 (candidates . anything-find-files-get-candidates)
2818 (filtered-candidate-transformer anything-c-find-files-transformer)
2819 (image-action1 . anything-ff-rotate-image-left)
2820 (image-action2 . anything-ff-rotate-image-right)
2821 (toggle-basename . anything-ff-toggle-basename)
2822 (properties-action . anything-ff-properties)
2823 (toggle-auto-update . anything-ff-toggle-auto-update)
2824 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2825 (persistent-action . anything-find-files-persistent-action)
2826 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2827 (mode-line . anything-ff-mode-line-string)
2828 (volatile)
2829 (candidate-number-limit . 9999)
2830 (action-transformer . anything-find-files-action-transformer)
2831 (action
2832 . ,(delq
2834 `(("Find File" . anything-c-find-file-or-marked)
2835 ("Find file in Dired" . anything-c-point-file-in-dired)
2836 ,(and (locate-library "elscreen")
2837 '("Find file in Elscreen" . anything-elscreen-find-file))
2838 ,(and (locate-library "popwin")
2839 '("Find file in popup window" . popwin:find-file))
2840 ("Checksum File" . anything-ff-checksum)
2841 ("Complete at point `M-tab'"
2842 . anything-c-insert-file-name-completion-at-point)
2843 ("Open file externally `C-c C-x, C-u to choose'"
2844 . anything-c-open-file-externally)
2845 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2846 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2847 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2848 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2849 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2850 . anything-find-files-eshell-command-on-file)
2851 ("Find file as root" . anything-find-file-as-root)
2852 ("Find file in hex dump" . hexl-find-file)
2853 ("Ediff File `C-='" . anything-find-files-ediff-files)
2854 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2855 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2856 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2857 ("Copy file(s) Async" . anything-ff-copy-async)
2858 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2859 ("Serial rename files" . anything-ff-serial-rename)
2860 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2861 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2862 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2863 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2864 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2865 ("Find file other window `C-o'" . find-file-other-window)
2866 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2867 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2868 ("Print File `C-c p'" . anything-ff-print)
2869 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2870 ;; (anything 'anything-c-source-find-files)
2872 (defun anything-find-files-set-prompt-for-action (action files)
2873 "Set prompt for action ACTION for FILES."
2874 (let ((len (length files)))
2875 (format "%s *%s File(s)\n%s to: "
2876 action len
2877 (mapconcat (lambda (f)
2878 (format "- %s\n" f)) files ""))))
2880 (defun anything-dwim-target-directory ()
2881 "Return value of `default-directory' of buffer in other window.
2882 If there is only one window return the value ot `default-directory'
2883 for current buffer."
2884 (with-anything-current-buffer
2885 (let ((num-windows (length (window-list))))
2886 (if (> num-windows 1)
2887 (save-window-excursion
2888 (other-window 1)
2889 default-directory)
2890 (car anything-ff-history)))))
2892 (defun anything-find-files-do-action (action)
2893 "Generic function for creating action from `anything-c-source-find-files'.
2894 ACTION must be an action supported by `anything-dired-action'."
2895 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2896 (anything-marked-candidates)))
2897 (cand (anything-get-selection)) ; Target
2898 (prompt (anything-find-files-set-prompt-for-action
2899 (capitalize (symbol-name action)) ifiles))
2900 (parg anything-current-prefix-arg)
2901 (dest (anything-c-read-file-name
2902 prompt
2903 :preselect (if anything-ff-transformer-show-only-basename
2904 (anything-c-basename cand) cand)
2905 :initial-input (anything-dwim-target-directory)
2906 :history (anything-find-files-history :comp-read nil))))
2907 (anything-dired-action
2908 dest :files ifiles :action action :follow parg)))
2910 (defun anything-find-files-copy (candidate)
2911 "Copy files from `anything-find-files'."
2912 (anything-find-files-do-action 'copy))
2914 (defun anything-find-files-rename (candidate)
2915 "Rename files from `anything-find-files'."
2916 (anything-find-files-do-action 'rename))
2918 (defun anything-find-files-symlink (candidate)
2919 "Symlink files from `anything-find-files'."
2920 (anything-find-files-do-action 'symlink))
2922 (defun anything-find-files-relsymlink (candidate)
2923 "Relsymlink files from `anything-find-files'."
2924 (anything-find-files-do-action 'relsymlink))
2926 (defun anything-find-files-hardlink (candidate)
2927 "Hardlink files from `anything-find-files'."
2928 (anything-find-files-do-action 'hardlink))
2930 (defun anything-find-files-byte-compile (candidate)
2931 "Byte compile elisp files from `anything-find-files'."
2932 (let ((files (anything-marked-candidates))
2933 (parg anything-current-prefix-arg))
2934 (loop for fname in files
2935 do (byte-compile-file fname parg))))
2937 (defun anything-find-files-load-files (candidate)
2938 "Load elisp files from `anything-find-files'."
2939 (let ((files (anything-marked-candidates)))
2940 (loop for fname in files
2941 do (load fname))))
2943 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2944 "Generic function to ediff/merge files in `anything-find-files'."
2945 (let ((bname (anything-c-basename candidate))
2946 (prompt (if merge "Ediff Merge `%s' With File: "
2947 "Ediff `%s' With File: "))
2948 (fun (if merge 'ediff-merge-files 'ediff-files)))
2949 (funcall fun
2950 candidate
2951 (condition-case quit
2952 (anything-c-read-file-name
2953 (format prompt bname))
2954 (quit ;; Hit C-g ask user to fallback to locate.
2955 (if (y-or-n-p "Search file for ediff with locate? ")
2956 (anything-c-locate-read-file-name
2957 (format prompt bname)
2958 ;; Check if -b option is available.
2959 (if (and (eq system-type 'windows-nt)
2960 (string-match "^es" anything-c-locate-command))
2961 bname
2962 (concat bname " -b")))
2963 (error "Error: Ediff Operation aborted")))))))
2965 (defun anything-find-files-ediff-files (candidate)
2966 (anything-find-files-ediff-files-1 candidate))
2968 (defun anything-find-files-ediff-merge-files (candidate)
2969 (anything-find-files-ediff-files-1 candidate 'merge))
2971 (defun anything-find-files-grep (candidate)
2972 "Default action to grep files from `anything-find-files'."
2973 (anything-do-grep-1 (anything-marked-candidates)
2974 anything-current-prefix-arg))
2976 (defun anything-ff-zgrep (candidate)
2977 "Default action to zgrep files from `anything-find-files'."
2978 (let ((prefarg anything-current-prefix-arg)
2979 (ls (anything-marked-candidates)))
2980 (anything-ff-zgrep-1 ls prefarg)))
2982 (defun anything-ff-pdfgrep (candidate)
2983 "Default action to pdfgrep files from `anything-find-files'."
2984 (let ((cands (loop for file in (anything-marked-candidates)
2985 if (or (string= (file-name-extension file) "pdf")
2986 (string= (file-name-extension file) "PDF"))
2987 collect file))
2988 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2989 (when cands
2990 (anything-do-pdfgrep-1 cands))))
2992 (defun anything-ff-etags-select (candidate)
2993 "Default action to jump to etags from `anything-find-files'."
2994 (when (get-buffer anything-action-buffer)
2995 (kill-buffer anything-action-buffer))
2996 (let ((default-directory anything-ff-default-directory))
2997 (anything-c-etags-select anything-current-prefix-arg)))
2999 (defun anything-find-files-switch-to-hist (candidate)
3000 "Switch to anything-find-files history."
3001 (anything-find-files t))
3003 ;;; Asynchronous copy of files.
3006 (defun anything-c-copy-files-async-1 (flist dest)
3007 "Copy a list of Files FLIST to DEST asynchronously.
3008 It use another emacs process to do the job.
3009 Communication with background emacs is done with temp file
3010 `anything-c-copy-files-async-log-file'."
3011 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3012 "-Q" "--batch" "--eval"
3013 (format "(progn
3014 (require 'dired) (require 'cl)
3015 (let ((dired-recursive-copies 'always)
3016 failures success
3017 (ovw-count 0)
3018 (cpf-count 0))
3019 (dolist (f '%S)
3020 (condition-case err
3021 (let ((file-exists (file-exists-p
3022 (expand-file-name
3023 (file-name-nondirectory (directory-file-name f))
3024 (file-name-directory
3025 (file-name-as-directory \"%s\"))))))
3026 (dired-copy-file f \"%s\" t)
3027 (if file-exists
3028 (progn (push (cons \"Overwriting\" f) success)
3029 (incf ovw-count))
3030 (push (cons \"Copying\" f) success)
3031 (incf cpf-count)))
3032 (file-error
3033 (push (dired-make-relative
3034 (expand-file-name
3035 (file-name-nondirectory (directory-file-name f))
3036 (file-name-directory \"%s\")))
3037 failures))))
3038 (with-current-buffer (find-file-noselect \"%s\")
3039 (erase-buffer)
3040 (when failures
3041 (dolist (fail (reverse failures))
3042 (insert (concat \"Failed to copy \" fail \"\n\"))))
3043 (when success
3044 (loop for (a . s) in (reverse success) do
3045 (insert (concat a \" \" s \" to %s done\n\"))))
3046 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3047 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3048 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3049 (save-buffer))))"
3050 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3052 (defun anything-c-copy-async-with-log (flist dest)
3053 "Copy file list FLIST to DEST showing log.
3054 Log is send to `anything-c-copy-files-async-log-file'.
3055 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3056 (declare (special auto-revert-interval))
3057 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3058 (set (make-local-variable 'auto-revert-interval) 1)
3059 (erase-buffer)
3060 (insert "Wait copying files...\n")
3061 (sit-for 0.5) (save-buffer)
3062 (goto-char (point-max))
3063 (auto-revert-mode 1)
3064 (anything-c-copy-files-async-1 flist dest))
3066 (defun anything-ff-copy-async (candidate)
3067 "Anything find files action to copy files async.
3068 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3069 (let* ((flist (anything-marked-candidates))
3070 (dest (anything-c-read-file-name
3071 (anything-find-files-set-prompt-for-action
3072 "Copy Async" flist)
3073 :preselect candidate
3074 :initial-input (car anything-ff-history)
3075 :history (anything-find-files-history :comp-read nil))))
3076 (anything-c-copy-async-with-log flist dest)))
3078 (defvar eshell-command-aliases-list nil)
3079 (defvar anything-eshell-command-on-file-input-history nil)
3080 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3081 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3083 Basename of CANDIDATE can be a wild-card.
3084 If MAP is given run `eshell-command' on all marked files at once,
3085 Otherwise, run `eshell-command' on each marked files.
3087 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3088 `eshell-command-aliases-list' will not be loaded first time you use this."
3089 (when (or eshell-command-aliases-list
3090 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3091 (and eshell-command-aliases-list (eshell-read-aliases-list))
3092 (let* ((cand-list (anything-marked-candidates))
3093 (default-directory (or anything-ff-default-directory
3094 ;; If candidate is an url *-ff-default-directory is nil
3095 ;; so keep value of default-directory.
3096 default-directory))
3097 (command (anything-comp-read
3098 "Command: "
3099 (loop for (a . c) in eshell-command-aliases-list
3100 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3101 collect (propertize a 'help-echo (car c)) into ls
3102 finally return (sort ls 'string<))
3103 :buffer "*esh command on file*"
3104 :name "Eshell command"
3105 :input-history
3106 'anything-eshell-command-on-file-input-history))
3107 (com-value (car (assoc-default command eshell-command-aliases-list))))
3108 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3109 (> (length cand-list) 1))
3110 ;; Run eshell-command with ALL marked files as arguments.
3111 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3112 (eshell-command (format "%s %s" command mapfiles)))
3113 ;; Run eshell-command on EACH marked files.
3114 (loop
3115 for i in cand-list
3116 for bn = (anything-c-basename i)
3117 for files = (if (and bn (string-match "^\*" bn))
3118 ;; Assume if fname is a wildcard
3119 ;; cand-list have a length of 1.
3120 (mapconcat
3121 'shell-quote-argument
3122 (file-expand-wildcards i t) " ")
3123 (format "'%s'" i))
3124 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3125 ;; This allow to enter other args AFTER filename
3126 ;; i.e <command %s some_more_args>
3127 (format command files)
3128 (format "%s %s" command files))
3129 do (eshell-command com))))))
3131 (defun anything-find-files-eshell-command-on-file (candidate)
3132 "Run `eshell-command' on CANDIDATE or marked candidates.
3133 See `anything-find-files-eshell-command-on-file-1' for more info."
3134 (anything-find-files-eshell-command-on-file-1
3135 candidate anything-current-prefix-arg))
3137 (defun anything-ff-switch-to-eshell (candidate)
3138 "Switch to eshell and cd to `anything-ff-default-directory'."
3139 (flet ((cd-eshell ()
3140 (goto-char (point-max))
3141 (insert
3142 (format "cd '%s'" anything-ff-default-directory))
3143 (eshell-send-input)))
3144 (if (get-buffer "*eshell*")
3145 (progn
3146 (anything-c-switch-to-buffer "*eshell*")
3147 (cd-eshell))
3148 (call-interactively 'eshell)
3149 (cd-eshell))))
3151 (defun anything-ff-serial-rename-action (method)
3152 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3153 See `anything-ff-serial-rename-1'."
3154 (let* ((cands (anything-marked-candidates))
3155 (name (read-string "NewName: "))
3156 (start (read-number "StartAtNumber: "))
3157 (extension (read-string "Extension: " (file-name-extension (car cands))))
3158 (dir (expand-file-name
3159 (anything-c-read-file-name
3160 "Serial Rename to directory: " :initial-input
3161 (expand-file-name anything-ff-default-directory)))))
3162 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3163 (length cands) dir name))
3164 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3165 (anything-find-files-1 dir))))
3167 (defun anything-ff-member-directory-p (file directory)
3168 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3169 (cur-dir (expand-file-name (file-name-as-directory directory))))
3170 (string= dir-file cur-dir)))
3172 (defun* anything-ff-serial-rename-1
3173 (directory collection new-name start-at-num extension &key (method 'rename))
3174 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3175 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3176 EXTENSION is the file extension to use, in empty prompt,
3177 reuse the original extension of file.
3178 METHOD can be one of rename, copy or symlink.
3179 Files will be renamed if they are files of current directory, otherwise they
3180 will be treated with METHOD.
3181 Default METHOD is rename."
3182 ;; Maybe remove directories selected by error in collection.
3183 (setq collection (remove-if 'file-directory-p collection))
3184 (flet ((symlink-file (file dest)
3185 (let ((flist (list file)))
3186 (anything-dired-action
3187 dest :action 'symlink :files flist))))
3189 (let* ((tmp-dir (file-name-as-directory
3190 (concat (file-name-as-directory directory)
3191 (symbol-name (gensym "tmp")))))
3192 (fn (case method
3193 (copy 'copy-file)
3194 (symlink 'symlink-file)
3195 (rename 'rename-file)
3196 (t (error "Error: Unknow method %s" method)))))
3197 (make-directory tmp-dir)
3198 (loop for i in collection
3199 for count from start-at-num
3200 for fnum = (if (< count 10) "0%s" "%s")
3201 for nname = (concat tmp-dir new-name (format fnum count)
3202 (if (not (string= extension ""))
3203 (format ".%s" (replace-regexp-in-string
3204 "[.]" "" extension))
3205 (file-name-extension i 'dot)))
3206 do (if (anything-ff-member-directory-p i directory)
3207 (rename-file i nname)
3208 (funcall fn i nname)))
3209 (loop with dirlist = (directory-files
3210 tmp-dir t directory-files-no-dot-files-regexp)
3211 for f in dirlist do
3212 (if (file-symlink-p f)
3213 (symlink-file (file-truename f)
3214 (concat (file-name-as-directory directory)
3215 (anything-c-basename f)))
3216 (rename-file f directory)))
3217 (delete-directory tmp-dir t))))
3219 (defun anything-ff-serial-rename (candidate)
3220 "Serial rename all marked files to `anything-ff-default-directory'.
3221 Rename only file of current directory, and symlink files coming from
3222 other directories.
3223 See `anything-ff-serial-rename-1'."
3224 (anything-ff-serial-rename-action 'rename))
3226 (defun anything-ff-serial-rename-by-symlink (candidate)
3227 "Serial rename all marked files to `anything-ff-default-directory'.
3228 Rename only file of current directory, and symlink files coming from
3229 other directories.
3230 See `anything-ff-serial-rename-1'."
3231 (anything-ff-serial-rename-action 'symlink))
3233 (defun anything-ff-serial-rename-by-copying (candidate)
3234 "Serial rename all marked files to `anything-ff-default-directory'.
3235 Rename only file of current directory, and copy files coming from
3236 other directories.
3237 See `anything-ff-serial-rename-1'."
3238 (anything-ff-serial-rename-action 'copy))
3240 (defun anything-c-quit-and-execute-action (action)
3241 "Quit current anything session and execute ACTION."
3242 (setq anything-saved-action action)
3243 (anything-exit-minibuffer))
3245 (defun anything-ff-toggle-auto-update (candidate)
3246 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3247 (message "[Auto expansion %s]"
3248 (if anything-ff-auto-update-flag "enabled" "disabled")))
3250 ;;;###autoload
3251 (defun anything-ff-run-toggle-auto-update ()
3252 (interactive)
3253 (anything-execute-persistent-action 'toggle-auto-update))
3255 ;;;###autoload
3256 (defun anything-ff-run-switch-to-history ()
3257 "Run Switch to history action from `anything-c-source-find-files'."
3258 (interactive)
3259 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3261 ;;;###autoload
3262 (defun anything-ff-run-grep ()
3263 "Run Grep action from `anything-c-source-find-files'."
3264 (interactive)
3265 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3267 ;;;###autoload
3268 (defun anything-ff-run-pdfgrep ()
3269 "Run Pdfgrep action from `anything-c-source-find-files'."
3270 (interactive)
3271 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3273 ;;;###autoload
3274 (defun anything-ff-run-zgrep ()
3275 "Run Grep action from `anything-c-source-find-files'."
3276 (interactive)
3277 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3279 ;;;###autoload
3280 (defun anything-ff-run-copy-file ()
3281 "Run Copy file action from `anything-c-source-find-files'."
3282 (interactive)
3283 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3285 ;;;###autoload
3286 (defun anything-ff-run-rename-file ()
3287 "Run Rename file action from `anything-c-source-find-files'."
3288 (interactive)
3289 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3291 ;;;###autoload
3292 (defun anything-ff-run-byte-compile-file ()
3293 "Run Byte compile file action from `anything-c-source-find-files'."
3294 (interactive)
3295 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3297 ;;;###autoload
3298 (defun anything-ff-run-load-file ()
3299 "Run Load file action from `anything-c-source-find-files'."
3300 (interactive)
3301 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3303 ;;;###autoload
3304 (defun anything-ff-run-eshell-command-on-file ()
3305 "Run eshell command on file action from `anything-c-source-find-files'."
3306 (interactive)
3307 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3309 ;;;###autoload
3310 (defun anything-ff-run-ediff-file ()
3311 "Run Ediff file action from `anything-c-source-find-files'."
3312 (interactive)
3313 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3315 ;;;###autoload
3316 (defun anything-ff-run-ediff-merge-file ()
3317 "Run Ediff merge file action from `anything-c-source-find-files'."
3318 (interactive)
3319 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3321 ;;;###autoload
3322 (defun anything-ff-run-symlink-file ()
3323 "Run Symlink file action from `anything-c-source-find-files'."
3324 (interactive)
3325 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3327 ;;;###autoload
3328 (defun anything-ff-run-delete-file ()
3329 "Run Delete file action from `anything-c-source-find-files'."
3330 (interactive)
3331 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3333 ;;;###autoload
3334 (defun anything-ff-run-complete-fn-at-point ()
3335 "Run complete file name action from `anything-c-source-find-files'."
3336 (interactive)
3337 (anything-c-quit-and-execute-action
3338 'anything-c-insert-file-name-completion-at-point))
3340 ;;;###autoload
3341 (defun anything-ff-run-switch-to-eshell ()
3342 "Run switch to eshell action from `anything-c-source-find-files'."
3343 (interactive)
3344 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3346 ;;;###autoload
3347 (defun anything-ff-run-switch-other-window ()
3348 "Run switch to other window action from `anything-c-source-find-files'."
3349 (interactive)
3350 (anything-c-quit-and-execute-action 'find-file-other-window))
3352 ;;;###autoload
3353 (defun anything-ff-run-switch-other-frame ()
3354 "Run switch to other frame action from `anything-c-source-find-files'."
3355 (interactive)
3356 (anything-c-quit-and-execute-action 'find-file-other-frame))
3358 ;;;###autoload
3359 (defun anything-ff-run-open-file-externally ()
3360 "Run open file externally command action from `anything-c-source-find-files'."
3361 (interactive)
3362 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3364 (defun anything-ff-locate (candidate)
3365 "Locate action function for `anything-find-files'."
3366 (let ((input (concat (anything-c-basename
3367 (expand-file-name
3368 candidate
3369 anything-ff-default-directory))
3370 ;; The locate '-b' option doesn't exists
3371 ;; in everything.
3372 (unless (and (eq system-type 'windows-nt)
3373 (string-match "^es" anything-c-locate-command))
3374 " -b")))
3375 (anything-mp-highlight-delay 0.7))
3376 (anything-locate-1 anything-current-prefix-arg input)))
3378 ;;;###autoload
3379 (defun anything-ff-run-locate ()
3380 "Run locate action from `anything-c-source-find-files'."
3381 (interactive)
3382 (anything-c-quit-and-execute-action 'anything-ff-locate))
3384 ;;;###autoload
3385 (defun anything-ff-run-gnus-attach-files ()
3386 "Run gnus attach files command action from `anything-c-source-find-files'."
3387 (interactive)
3388 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3390 ;;;###autoload
3391 (defun anything-ff-run-etags ()
3392 "Run Etags command action from `anything-c-source-find-files'."
3393 (interactive)
3394 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3397 (defun anything-ff-print (candidate)
3398 "Print marked files.
3399 You have to set in order
3400 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3402 e.g:
3403 \(setq lpr-command \"gtklp\"\)
3404 \(setq lpr-switches '(\"-P\")\)
3405 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3407 Same as `dired-do-print' but for anything."
3408 (let* ((file-list (anything-marked-candidates))
3409 (len (length file-list))
3410 (printer-name (if anything-ff-printer-list
3411 (anything-comp-read
3412 "Printer: " anything-ff-printer-list)
3413 printer-name))
3414 (command (read-string
3415 (format "Print *%s File(s):\n%s with: "
3417 (mapconcat
3418 (lambda (f) (format "- %s\n" f))
3419 file-list ""))
3420 (when (and lpr-command
3421 (or lpr-switches
3422 printer-name))
3423 (mapconcat 'identity
3424 (cons lpr-command
3425 (append (if (stringp lpr-switches)
3426 (list lpr-switches)
3427 lpr-switches)
3428 (list printer-name)))
3429 " "))))
3430 (file-args (mapconcat #'(lambda (x)
3431 (format "'%s'" x))
3432 file-list " "))
3433 (cmd-line (concat command " " file-args)))
3434 (if command
3435 (start-process-shell-command "anything-print" nil cmd-line)
3436 (error "Error: Please verify your printer settings in Emacs."))))
3438 ;;;###autoload
3439 (defun anything-ff-run-print-file ()
3440 "Run Print file action from `anything-c-source-find-files'."
3441 (interactive)
3442 (anything-c-quit-and-execute-action 'anything-ff-print))
3444 (defun anything-ff-checksum (file)
3445 "Calculate the checksum of FILE.
3446 Provide completion on different algorithms to use on Emacs24.
3447 On Emacs23 only 'sha1' is available.
3448 The checksum is copied to kill-ring."
3449 (let ((algo-list (and (fboundp 'secure-hash)
3450 '(md5 sha1 sha224 sha256 sha384 sha512))))
3451 (kill-new
3452 (if algo-list
3453 (secure-hash (intern
3454 (anything-comp-read
3455 "Algorithm: " algo-list))
3456 file)
3457 (sha1 (with-temp-buffer
3458 (insert-file-contents file)
3459 (buffer-string)))))
3460 (message "Checksum copied to kill-ring.")))
3462 (defun anything-ff-toggle-basename (candidate)
3463 (setq anything-ff-transformer-show-only-basename
3464 (not anything-ff-transformer-show-only-basename))
3465 (let ((target (if anything-ff-transformer-show-only-basename
3466 (anything-c-basename candidate) candidate)))
3467 (anything-force-update target)))
3469 (defun anything-ff-run-toggle-basename ()
3470 (interactive)
3471 (anything-execute-persistent-action 'toggle-basename))
3473 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3474 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3475 If LEVEL is positive reduce from end else from beginning.
3476 If UNIX-CLOSE is non--nil close filename with /.
3477 If EXPAND is non--nil expand-file-name."
3478 (let* ((exp-fname (expand-file-name fname))
3479 (fname-list (split-string (if (or (string= fname "~/") expand)
3480 exp-fname fname) "/" t))
3481 (len (length fname-list))
3482 (pop-list (if (< level 0)
3483 (subseq fname-list (* level -1))
3484 (subseq fname-list 0 (- len level))))
3485 (result (mapconcat 'identity pop-list "/"))
3486 (empty (string= result "")))
3487 (when unix-close (setq result (concat result "/")))
3488 (if (string-match "^~" result)
3489 (if (string= result "~/") "~/" result)
3490 (if (< level 0)
3491 (if empty "../" (concat "../" result))
3492 (cond ((eq system-type 'windows-nt)
3493 (if empty "c:/" result))
3494 (empty "/")
3496 (concat "/" result)))))))
3498 ;; Internal
3499 (defvar anything-file-completion-sources
3500 '("Find Files" "find-file" "Copy Files"
3501 "dired-do-copy" "dired-do-rename"
3502 "dired-do-symlink" "dired-do-hardlink"
3503 "write-file" "insert-file" "dired"
3504 "find-alternate-file" "find-alternate-file-other-window"
3505 "find-file-read-only" "list-directory"
3506 "Read File Name History" "mml-attach-file"
3507 "Rename Files" "Symlink Files" "elscreen-find-file"
3508 "Hardlink Files" "Write File" "dvc-bookmarks-find-file-in-tree"
3509 "Insert File" "Read File Name" "visit-tags-table")
3510 "Sources that use the *find-files mechanism can be added here.
3511 You should not modify this yourself and know what you do if you do so.")
3513 (defun anything-file-completion-source-p ()
3514 "Test if current source is a dired or find-files source."
3515 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3516 (loop for i in anything-file-completion-sources
3517 thereis (string= cur-source i))))
3519 (defun anything-find-files-down-one-level (arg)
3520 "Go down one level like unix command `cd ..'.
3521 If prefix numeric arg is given go ARG level down."
3522 (interactive "p")
3523 (when (and (anything-file-completion-source-p)
3524 (not (anything-ff-invalid-tramp-name-p)))
3525 (with-anything-window
3526 (setq anything-follow-mode nil))
3527 ;; When going to precedent level we want to be at the line
3528 ;; corresponding to actual directory, so store this info
3529 ;; in `anything-ff-last-expanded'.
3530 (if (and (not (file-directory-p anything-pattern))
3531 (file-exists-p anything-pattern))
3532 (setq anything-ff-last-expanded anything-pattern)
3533 (setq anything-ff-last-expanded anything-ff-default-directory))
3534 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3535 :unix-close t :expand t)))
3536 (anything-set-pattern new-pattern))))
3538 (defun anything-ff-retrieve-last-expanded ()
3539 "Move overlay to last visited directory `anything-ff-last-expanded'.
3540 This happen after using `anything-find-files-down-one-level',
3541 or hitting C-z on \"..\"."
3542 (when (and anything-ff-last-expanded
3543 (anything-file-completion-source-p))
3544 (let ((dirname (if anything-ff-transformer-show-only-basename
3545 (anything-c-basename
3546 (directory-file-name anything-ff-last-expanded))
3547 (directory-file-name anything-ff-last-expanded))))
3548 (with-anything-window
3549 (when (or (re-search-forward (concat dirname "$") nil t)
3550 (re-search-forward
3551 (concat anything-ff-last-expanded "$") nil t))
3552 (forward-line 0)
3553 (anything-mark-current-line)))
3554 (setq anything-ff-last-expanded nil))))
3555 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3557 ;; Auto-update - anything-find-files auto expansion of directories.
3559 (defun anything-ff-update-when-only-one-matched ()
3560 "Expand to directory when sole completion.
3561 When only one candidate is remaining and it is a directory,
3562 expand to this directory."
3563 (when (and anything-ff-auto-update-flag
3564 (anything-file-completion-source-p)
3565 (not (anything-ff-invalid-tramp-name-p)))
3566 (let* ((history-p (string= (assoc-default
3567 'name (anything-get-current-source))
3568 "Read File Name History"))
3569 (pat (if (string-match tramp-file-name-regexp
3570 anything-pattern)
3571 (anything-create-tramp-name anything-pattern)
3572 anything-pattern))
3573 (completed-p (string= (file-name-as-directory pat)
3574 anything-ff-default-directory)))
3575 (when (and (or
3576 ;; Only one candidate remaining
3577 ;; and at least 2 char in basename.
3578 (and (<= (anything-approximate-candidate-number) 2)
3579 (>= (length (anything-c-basename anything-pattern)) 2))
3580 ;; Already completed.
3581 completed-p)
3582 (not history-p)) ; Don't try to auto complete in history.
3583 (with-anything-window
3584 (let ((cur-cand (prog2
3585 (unless completed-p
3586 ;; Only one non--existing candidate
3587 ;; and one directory candidate, move to it.
3588 (anything-next-line))
3589 (anything-get-selection))))
3590 (when (file-directory-p cur-cand)
3591 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3592 ;; Maybe we are here because completed-p is true
3593 ;; but check this again to be sure. (Windows fix)
3594 (<= (anything-approximate-candidate-number) 2)) ; [2]
3595 ;; If after going to next line the candidate
3596 ;; is not one of "." or ".." [1]
3597 ;; and only one candidate is remaining [2],
3598 ;; assume candidate is a new directory to expand, and do it.
3599 (anything-set-pattern (file-name-as-directory cur-cand))
3600 ;; The candidate is one of "." or ".."
3601 ;; that mean we have entered the last letter of the directory name
3602 ;; in prompt, so expansion is already done, just add the "/" at end
3603 ;; of name unless anything-pattern ends with "."
3604 ;; (i.e we are writing something starting with ".")
3605 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3606 (anything-set-pattern
3607 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3608 (expand-file-name (file-name-as-directory anything-pattern)))))
3609 (anything-check-minibuffer-input-1))))))))
3610 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3612 ;; Allow expanding to home directory or root
3613 ;; when entering respectively "~/" or "//" at end of pattern.
3614 ;; e.g /home/thierry/labo/anything-config-qp/~/
3615 ;; will expand to "~/"
3616 ;; and /home/thierry/labo/anything-config-qp//
3617 ;; will expand to "/"
3618 (defun anything-ff-auto-expand-to-home-or-root ()
3619 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3620 This happen only in function using sources that are
3621 `anything-file-completion-source-p' compliant."
3622 (when (and (anything-file-completion-source-p)
3623 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3624 anything-pattern))
3625 (let ((match (match-string 1 anything-pattern)))
3626 (cond ((string= match "//")
3627 (if (eq system-type 'windows-nt)
3628 (setq anything-pattern "c:/")
3629 (setq anything-pattern "/")))
3630 ((string= match "/~/")
3631 (if (eq system-type 'windows-nt)
3632 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3633 (setq anything-pattern "~/")))
3634 ((string= match "/./")
3635 (setq anything-pattern
3636 (with-anything-current-buffer
3637 (expand-file-name default-directory))))))
3638 (setq anything-ff-default-directory anything-pattern)
3639 ;; For some reasons, i must use here with-current-buffer => mini buffer
3640 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3641 (with-current-buffer (window-buffer (minibuffer-window))
3642 (delete-minibuffer-contents)
3643 (insert anything-pattern))))
3645 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3647 (defun anything-c-point-file-in-dired (file)
3648 "Put point on filename FILE in dired buffer."
3649 (dired (file-name-directory file))
3650 (dired-goto-file file))
3652 (defun anything-create-tramp-name (fname)
3653 "Build filename for `anything-pattern' like /su:: or /sudo::."
3654 (apply #'tramp-make-tramp-file-name
3655 (loop with v = (tramp-dissect-file-name fname)
3656 for i across v collect i)))
3658 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3659 "Get a list of hosts for tramp method found in `anything-pattern'.
3660 Argument PATTERN default to `anything-pattern', it is here only for debugging
3661 purpose."
3662 (when (string-match tramp-file-name-regexp pattern)
3663 (let ((method (match-string 1 pattern))
3664 (tn (match-string 0 pattern))
3665 (all-methods (mapcar 'car tramp-methods)))
3666 (remove-duplicates
3667 (loop for (f . h) in (tramp-get-completion-function method)
3668 append (loop for e in (funcall f (car h))
3669 for host = (and (consp e) (cadr e))
3670 when (and host (not (member host all-methods)))
3671 collect (concat tn host)))
3672 :test 'equal))))
3674 (defun anything-ff-before-action-hook-fn ()
3675 "Exit anything when user try to execute action on an invalid tramp fname."
3676 (let ((cand (anything-get-selection)))
3677 (when (and (anything-file-completion-source-p)
3678 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3679 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3680 (error "Error: Unknow file or directory `%s'" cand))))
3681 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3683 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3684 "Return non--nil when PATTERN is an invalid tramp filename."
3685 (string= (anything-ff-set-pattern pattern)
3686 "Invalid tramp file name"))
3688 (defun anything-ff-set-pattern (pattern)
3689 "Handle tramp filenames in `anything-pattern'."
3690 (let ((methods (mapcar 'car tramp-methods))
3691 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3692 cur-method tramp-name)
3693 (cond ((string= pattern "") "")
3694 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3695 (with-anything-current-buffer
3696 (expand-file-name default-directory)))
3697 ((string-match ".*\\(~//\\|//\\)$" pattern)
3698 (if (eq system-type 'windows-nt) "c:/" "/"))
3699 ((string-match "^~\\|.*/~/$" pattern)
3700 (let* ((home (expand-file-name (getenv "HOME"))))
3701 (replace-match home nil t pattern)))
3702 ;; Match "/method:maybe_hostname:"
3703 ((and (string-match reg pattern)
3704 (setq cur-method (match-string 1 pattern))
3705 (member cur-method methods))
3706 (setq tramp-name (anything-create-tramp-name
3707 (match-string 0 pattern)))
3708 (replace-match tramp-name nil t pattern))
3709 ;; Match "/hostname:"
3710 ((and (string-match tramp-file-name-regexp pattern)
3711 (setq cur-method (match-string 1 pattern))
3712 (and cur-method (not (member cur-method methods))))
3713 (setq tramp-name (anything-create-tramp-name
3714 (match-string 0 pattern)))
3715 (replace-match tramp-name nil t pattern))
3716 ;; Match "/method:" in this case don't try to connect.
3717 ((and (not (string-match reg pattern))
3718 (string-match tramp-file-name-regexp pattern)
3719 (member (match-string 1 pattern) methods))
3720 "Invalid tramp file name") ; Write in anything-buffer.
3721 ;; PATTERN is a directory, end it with "/".
3722 ;; This will make PATTERN not ending yet with "/"
3723 ;; candidate for `anything-ff-default-directory',
3724 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3725 ;; when descending level.
3726 ((file-directory-p pattern)
3727 (file-name-as-directory pattern))
3728 ;; Return PATTERN unchanged.
3729 (t pattern))))
3731 (defun anything-find-files-get-candidates ()
3732 "Create candidate list for `anything-c-source-find-files'."
3733 (let* ((path (anything-ff-set-pattern anything-pattern))
3734 (path-name-dir (if (file-directory-p path)
3735 (file-name-as-directory path)
3736 (file-name-directory path)))
3737 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3738 (set-text-properties 0 (length path) nil path)
3739 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3740 ;; like that the actual value (e.g /ssh:) is passed to
3741 ;; `anything-ff-tramp-hostnames'.
3742 (unless (string= path "Invalid tramp file name")
3743 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3744 (setq anything-ff-default-directory
3745 (if (string= anything-pattern "")
3746 (if (eq system-type 'windows-nt) "c:/" "/")
3747 (unless (string-match ffap-url-regexp path)
3748 ;; If path is an url *default-directory have to be nil.
3749 path-name-dir)))
3750 (cond ((string= path "Invalid tramp file name")
3751 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3752 (prog2
3753 ;; `anything-pattern' have not been modified yet.
3754 ;; Set it here to the value of `path' that should be now
3755 ;; "Invalid tramp file name" and set the candidates list
3756 ;; to ("Invalid tramp file name") to make `anything-pattern'
3757 ;; match single candidate "Invalid tramp file name".
3758 (setq anything-pattern path)
3759 ;; "Invalid tramp file name" is now printed
3760 ;; in `anything-buffer'.
3761 (list path))))
3762 ((or (file-regular-p path)
3763 (and (not (file-exists-p path)) (string-match "/$" path))
3764 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3765 (list path))
3766 ((string= path "") (directory-files "/" t))
3767 ((and (file-directory-p path) (not (file-readable-p path)))
3768 (list (format "Opening directory: access denied, `%s'" path)))
3769 ((file-directory-p path) (directory-files path t))
3771 (append (list path) (directory-files path-name-dir t))))))
3773 (defun anything-ff-transform-fname-for-completion (fname)
3774 "Return FNAME with it's basename modified as a regexp.
3775 e.g foo => f.*o.*o .
3776 If basename contain one or more space or FNAME is a valid directory name
3777 return FNAME unchanged."
3778 (let ((bn (anything-c-basename fname)))
3779 (if (or (not anything-ff-smart-completion)
3780 (string-match "\\s-" bn)
3781 (string-match "/$" fname) ; Allow mkdir.
3782 (file-directory-p fname))
3783 fname ; Fall back to match-plugin.
3784 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3785 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3786 (concat (file-name-directory fname) bn))))
3788 (defun anything-ff-save-history ()
3789 "Store the last value of `anything-ff-default-directory' \
3790 in `anything-ff-history'."
3791 (when (and anything-ff-default-directory
3792 (anything-file-completion-source-p))
3793 (push anything-ff-default-directory anything-ff-history)))
3794 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3796 (defun anything-ff-valid-symlink-p (file)
3797 (file-exists-p (file-truename file)))
3799 (defun anything-ff-properties (candidate)
3800 "Show file properties of CANDIDATE in a tooltip or message."
3801 (let ((type (anything-ff-attributes candidate :type t))
3802 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3803 (if (window-system)
3804 (tooltip-show
3805 (concat
3806 (anything-c-basename candidate) ": \n"
3807 "Type: " type "\n"
3808 (when (string= type "symlink")
3809 (format "True name: '%s'\n"
3810 (cond ((string-match "^\.#" (anything-c-basename candidate))
3811 "Autosave symlink")
3812 ((anything-ff-valid-symlink-p candidate)
3813 (file-truename candidate))
3814 (t "Invalid Symlink"))))
3815 dired-line))
3816 (message dired-line) (sit-for 5))))
3818 ;;;###autoload
3819 (defun anything-ff-properties-persistent ()
3820 "Show properties without quitting anything."
3821 (interactive)
3822 (anything-execute-persistent-action 'properties-action))
3824 (defun anything-ff-kill-buffer-fname (candidate)
3825 (let* ((buf (get-file-buffer candidate))
3826 (buf-name (buffer-name buf)))
3827 (if buf
3828 (progn
3829 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3830 (message "No buffer to kill"))))
3832 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3833 "Find file CANDIDATE or kill it's buffer if it is visible.
3834 Never kill `anything-current-buffer'.
3835 Never kill buffer modified.
3836 This is called normally on third hit of \
3837 \\<anything-map>\\[anything-execute-persistent-action]
3838 in `anything-find-files-persistent-action'."
3839 (let* ((buf (get-file-buffer candidate))
3840 (buf-name (buffer-name buf)))
3841 (if (and buf (get-buffer-window buf)
3842 (not (eq buf (get-buffer anything-current-buffer)))
3843 (not (buffer-modified-p buf)))
3844 (progn
3845 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3846 (find-file candidate))))
3848 ;;;###autoload
3849 (defun anything-ff-run-kill-buffer-persistent ()
3850 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3851 (interactive)
3852 (anything-execute-persistent-action 'kill-buffer-fname))
3854 (defun anything-ff-human-size (size)
3855 "Return a string showing SIZE of a file in human readable form.
3856 SIZE can be an integer or a float depending it's value.
3857 `file-attributes' will take care of that to avoid overflow error.
3858 KBSIZE if a floating point number, default value is 1024.0."
3859 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3860 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3861 (K (cons "K" (/ size anything-ff-default-kbsize)))
3862 (B (cons "B" size)))
3863 (loop with result = B
3864 for (a . b) in
3865 (loop for (x . y) in (list M G K B)
3866 unless (< y 1) collect (cons x y))
3867 when (< b (cdr result)) do (setq result (cons a b))
3868 finally return (if (string= (car result) "B")
3869 (format "%s" size)
3870 (format "%.1f%s" (cdr result) (car result))))))
3872 (defun* anything-ff-attributes
3873 (file &key type links uid gid access-time modif-time
3874 status size mode gid-change inode device-num dired human-size)
3875 "Easy interface for `file-attributes'."
3876 (let ((all (destructuring-bind
3877 (type links uid gid access-time modif-time
3878 status size mode gid-change inode device-num)
3879 (file-attributes file 'string)
3880 (list :type type
3881 :links links
3882 :uid uid
3883 :gid gid
3884 :access-time access-time
3885 :modif-time modif-time
3886 :status status
3887 :size size
3888 :mode mode
3889 :gid-change gid-change
3890 :inode inode
3891 :device-num device-num))))
3892 (cond (type
3893 (let ((result (getf all :type)))
3894 (cond ((stringp result)
3895 "symlink")
3896 (result "directory")
3897 (t "file"))))
3898 (links (getf all :links))
3899 (uid (getf all :uid))
3900 (gid (getf all :gid))
3901 (access-time
3902 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3903 (modif-time
3904 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3905 (status
3906 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3907 (size (if human-size (anything-ff-human-size (getf all :size))
3908 (getf all :size)))
3909 (mode (getf all :mode))
3910 (gid-change (getf all :gid-change))
3911 (inode (getf all :inode))
3912 (device-num (getf all :device-num))
3913 (dired
3914 (concat
3915 (getf all :mode) " "
3916 (number-to-string (getf all :links)) " "
3917 (getf all :uid) ":"
3918 (getf all :gid) " "
3919 (if human-size (anything-ff-human-size (getf all :size))
3920 (int-to-string (getf all :size))) " "
3921 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3922 (t all))))
3924 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3925 "Return filename FNAME maybe prefixed with [?] or [@].
3926 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3927 existing filename or valid symlink and there is no need to test it.
3928 NEW-FILE when non--nil mean FNAME is a non existing file and
3929 return FNAME prefixed with [?]."
3930 (let* ((prefix-new (propertize
3931 " " 'display
3932 (propertize "[?]" 'face 'anything-ff-prefix)))
3933 (prefix-url (propertize
3934 " " 'display
3935 (propertize "[@]" 'face 'anything-ff-prefix))))
3936 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3937 ((string-match ffap-url-regexp fname)
3938 (concat prefix-url " " fname))
3939 ((or new-file (not (file-exists-p fname)))
3940 (concat prefix-new " " fname)))))
3942 (defun anything-c-find-files-transformer (files sources)
3943 "Transformer for `anything-c-source-find-files'.
3944 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3945 is non--nil."
3946 (if (and (string-match tramp-file-name-regexp anything-pattern)
3947 anything-ff-tramp-not-fancy)
3948 (if anything-ff-transformer-show-only-basename
3949 (loop for i in files collect
3950 (if (string-match "[.]\\{1,2\\}$" i)
3951 i (cons (anything-c-basename i) i)))
3952 files)
3953 (anything-ff-highlight-files files sources)))
3955 (defun anything-ff-highlight-files (files sources)
3956 "Candidate transformer for `anything-c-source-find-files' without icons."
3957 (loop for i in files
3958 for disp = (if (and anything-ff-transformer-show-only-basename
3959 (not (string-match "[.]\\{1,2\\}$" i))
3960 (not (string-match ffap-url-regexp i)))
3961 (anything-c-basename i) i)
3962 collect
3963 (cond ((and (stringp (car (file-attributes i)))
3964 (not (anything-ff-valid-symlink-p i))
3965 (not (string-match "^\.#" (anything-c-basename i))))
3966 (cons (anything-ff-prefix-filename
3967 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3969 ((stringp (car (file-attributes i)))
3970 (cons (anything-ff-prefix-filename
3971 (propertize disp 'face 'anything-ff-symlink) t)
3973 ((eq t (car (file-attributes i)))
3974 (cons (anything-ff-prefix-filename
3975 (propertize disp 'face 'anything-ff-directory) t)
3977 ((file-executable-p i)
3978 (cons (anything-ff-prefix-filename
3979 (propertize disp 'face 'anything-ff-executable) t)
3981 ((file-exists-p i)
3982 (cons (anything-ff-prefix-filename
3983 (propertize disp 'face 'anything-ff-file) t)
3986 (cons (anything-ff-prefix-filename
3987 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3988 i)))))
3990 (defun anything-find-files-action-transformer (actions candidate)
3991 "Action transformer for `anything-c-source-find-files'."
3992 (cond ((with-anything-current-buffer
3993 (eq major-mode 'message-mode))
3994 (append (subseq actions 0 4)
3995 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3996 (subseq actions 4)))
3997 ((string-match (image-file-name-regexp) candidate)
3998 (append (subseq actions 0 4)
3999 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4000 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4001 (subseq actions 4)))
4002 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4003 (car it) candidate))
4004 (append (subseq actions 0 4)
4005 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4006 . anything-find-files-byte-compile)
4007 ("Load File(s) `M-L'" . anything-find-files-load-files))
4008 (subseq actions 4)))
4009 ((and (string-match "\.html?$" candidate)
4010 (file-exists-p candidate))
4011 (append (subseq actions 0 4)
4012 '(("Browse url file" . browse-url-of-file))
4013 (subseq actions 5)))
4014 ((or (string= (file-name-extension candidate) "pdf")
4015 (string= (file-name-extension candidate) "PDF"))
4016 (append (subseq actions 0 4)
4017 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4018 (subseq actions 5)))
4019 (t actions)))
4021 (defun anything-ff-gnus-attach-files (candidate)
4022 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4023 (let ((flist (anything-marked-candidates)))
4024 (gnus-dired-attach flist)))
4026 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4027 "Rotate current image at NUM-ARG degrees.
4028 This is a destructive operation on FILE made by external tool mogrify."
4029 (declare (special image-dired-display-image-buffer))
4030 (setq file (file-truename file)) ; For symlinked images.
4031 ;; When FILE is not an image-file, do nothing.
4032 (when (string-match (image-file-name-regexp) file)
4033 (if (executable-find "mogrify")
4034 (progn
4035 (shell-command (format "mogrify -rotate %s %s"
4036 (or num-arg 90)
4037 (shell-quote-argument file)))
4038 (when (buffer-live-p image-dired-display-image-buffer)
4039 (kill-buffer image-dired-display-image-buffer))
4040 (image-dired-display-image file)
4041 (message nil)
4042 (display-buffer (get-buffer image-dired-display-image-buffer)))
4043 (error "mogrify not found"))))
4045 (defun anything-ff-rotate-image-left (candidate)
4046 "Rotate image file CANDIDATE left.
4047 This affect directly file CANDIDATE."
4048 (anything-ff-rotate-current-image-1 candidate -90))
4050 (defun anything-ff-rotate-image-right (candidate)
4051 "Rotate image file CANDIDATE right.
4052 This affect directly file CANDIDATE."
4053 (anything-ff-rotate-current-image-1 candidate))
4055 (defun anything-ff-rotate-left-persistent ()
4056 "Rotate image left without quitting anything."
4057 (interactive)
4058 (anything-execute-persistent-action 'image-action1))
4060 (defun anything-ff-rotate-right-persistent ()
4061 "Rotate image right without quitting anything."
4062 (interactive)
4063 (anything-execute-persistent-action 'image-action2))
4065 (defun anything-ff-exif-data (candidate)
4066 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4067 (if (and anything-ff-exif-data-program
4068 (executable-find anything-ff-exif-data-program))
4069 (shell-command-to-string (format "%s %s %s"
4070 anything-ff-exif-data-program
4071 anything-ff-exif-data-program-args
4072 candidate))
4073 (format "No program %s found to extract exif"
4074 anything-ff-exif-data-program)))
4076 (defun anything-find-files-persistent-action (candidate)
4077 "Open subtree CANDIDATE without quitting anything.
4078 If CANDIDATE is not a directory expand CANDIDATE filename.
4079 If CANDIDATE is alone, open file CANDIDATE filename.
4080 That's mean:
4081 First hit on C-z expand CANDIDATE second hit open file.
4082 If a prefix arg is given or `anything-follow-mode' is on open file."
4083 (let ((follow (buffer-local-value
4084 'anything-follow-mode
4085 (get-buffer-create anything-buffer)))
4086 (new-pattern (anything-get-selection))
4087 (num-lines-buf (with-current-buffer anything-buffer
4088 (count-lines (point-min) (point-max)))))
4089 (flet ((insert-in-minibuffer (fname)
4090 (with-selected-window (minibuffer-window)
4091 (unless follow
4092 (delete-minibuffer-contents)
4093 (set-text-properties 0 (length fname) nil fname)
4094 (insert fname)))))
4095 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4096 "Invalid tramp file name")
4097 (string-match tramp-file-name-regexp candidate))
4098 ;; First hit insert hostname and
4099 ;; second hit insert ":" and expand.
4100 (if (string= candidate anything-pattern)
4101 (insert-in-minibuffer (concat candidate ":"))
4102 (insert-in-minibuffer candidate)))
4103 (;; A symlink directory, expand it's truename.
4104 (and (file-directory-p candidate) (file-symlink-p candidate))
4105 (insert-in-minibuffer (file-name-as-directory
4106 (file-truename
4107 (expand-file-name candidate)))))
4108 ;; A directory, open it.
4109 ((file-directory-p candidate)
4110 (when (string= (anything-c-basename candidate) "..")
4111 (setq anything-ff-last-expanded anything-ff-default-directory))
4112 (insert-in-minibuffer (file-name-as-directory
4113 (expand-file-name candidate))))
4114 ;; A symlink file, expand to it's true name. (first hit)
4115 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4116 (insert-in-minibuffer (file-truename candidate)))
4117 ;; A regular file, expand it, (first hit)
4118 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4119 (insert-in-minibuffer new-pattern))
4120 ;; An image file and it is the second hit on C-z,
4121 ;; show the file in `image-dired'.
4122 ((string-match (image-file-name-regexp) candidate)
4123 (when (buffer-live-p image-dired-display-image-buffer)
4124 (kill-buffer image-dired-display-image-buffer))
4125 (image-dired-display-image candidate)
4126 (message nil)
4127 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4128 (with-current-buffer image-dired-display-image-buffer
4129 (let ((exif-data (anything-ff-exif-data candidate)))
4130 (image-dired-update-property 'help-echo exif-data))))
4131 ;; Allow browsing archive on avfs fs.
4132 ;; Assume volume is already mounted with mountavfs.
4133 ((and anything-ff-avfs-directory
4134 (string-match
4135 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4136 (file-name-directory candidate))
4137 (anything-ff-file-compressed-p candidate))
4138 (insert-in-minibuffer (concat candidate "#")))
4139 ;; On second hit we open file.
4140 ;; On Third hit we kill it's buffer maybe.
4142 (anything-ff-kill-or-find-buffer-fname candidate))))))
4144 (defun anything-ff-file-compressed-p (candidate)
4145 "Whether CANDIDATE is a compressed file or not."
4146 (member (file-name-extension candidate)
4147 anything-ff-file-compressed-list))
4149 (defun anything-c-insert-file-name-completion-at-point (candidate)
4150 "Insert file name completion at point."
4151 (with-anything-current-buffer
4152 (if buffer-read-only
4153 (error "Error: Buffer `%s' is read-only" (buffer-name))
4154 (let* ((end (point))
4155 (guess (substring-no-properties (thing-at-point 'filename)))
4156 (beg (- (point) (length guess)))
4157 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4158 (string-match-p "^[^\~]" guess))))
4159 (set-text-properties 0 (length candidate) nil candidate)
4160 (if (and guess (not (string= guess ""))
4161 (string-match-p "^~\\|/.*" guess))
4162 (progn
4163 (delete-region beg end)
4164 (insert (if full-path-p
4165 (expand-file-name candidate)
4166 (abbreviate-file-name candidate))))
4167 (error "Aborting completion: No valid file name at point"))))))
4169 (defun* anything-find-files-history (&key (comp-read t))
4170 "The `anything-find-files' history.
4171 Show the first `anything-ff-history-max-length' elements of
4172 `anything-ff-history' in an `anything-comp-read'."
4173 (let ((history (when anything-ff-history
4174 (anything-fast-remove-dups anything-ff-history
4175 :test 'equal))))
4176 (when history
4177 (setq anything-ff-history
4178 (if (>= (length history) anything-ff-history-max-length)
4179 (subseq history 0 anything-ff-history-max-length)
4180 history))
4181 (if comp-read
4182 (anything-comp-read
4183 "Switch to Directory: "
4184 anything-ff-history
4185 :name "Anything Find Files History"
4186 :must-match t)
4187 anything-ff-history))))
4189 (defun anything-find-files-1 (fname &optional preselect)
4190 "Find FNAME with `anything' completion.
4191 Like `find-file' but with `anything' support.
4192 Use it for non--interactive calls of `anything-find-files'."
4193 (when (get-buffer anything-action-buffer)
4194 (kill-buffer anything-action-buffer))
4195 (let ((anything-mp-highlight-delay nil)
4196 ;; Be sure we don't erase the precedent minibuffer if some.
4197 (anything-ff-auto-update-initial-value
4198 (not (minibuffer-window-active-p (minibuffer-window))))
4199 anything-samewindow)
4200 (anything :sources 'anything-c-source-find-files
4201 :input fname
4202 :preselect preselect
4203 :keymap anything-find-files-map
4204 :prompt "Find Files or Url: "
4205 :buffer "*Anything Find Files*")))
4208 (defun anything-find-files-initial-input (&optional input)
4209 "Return INPUT if present, otherwise try to guess it."
4210 (or (and input (expand-file-name input))
4211 (anything-find-files-input
4212 (ffap-guesser)
4213 (thing-at-point 'filename))))
4215 (defun anything-find-files-input (fap tap)
4216 "Default input of `anything-find-files'."
4217 (let* ((def-dir (anything-c-current-directory))
4218 (lib (anything-find-library-at-point))
4219 (url (anything-ff-find-url-at-point))
4220 (file-p (and fap (not (string= fap ""))
4221 (file-exists-p fap)
4222 tap (not (string= tap ""))
4223 (file-exists-p
4224 (file-name-directory (expand-file-name tap def-dir))))))
4225 (cond (lib) ; e.g we are inside a require sexp.
4226 (url) ; String at point is an hyperlink.
4227 (file-p (expand-file-name tap def-dir))
4228 (t (and (not (string= fap "")) fap)))))
4230 (defun anything-c-current-directory ()
4231 "Return current-directory name at point.
4232 Useful in dired buffers when there is inserted subdirs."
4233 (if (eq major-mode 'dired-mode)
4234 (dired-current-directory)
4235 default-directory))
4237 (defun anything-ff-find-url-at-point ()
4238 "Try to find link to an url in text-property at point."
4239 (let* ((he (get-text-property (point) 'help-echo))
4240 (ov (overlays-at (point)))
4241 (ov-he (and ov (overlay-get
4242 (car (overlays-at (point))) 'help-echo)))
4243 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4244 (nt-prop (get-text-property (point) 'nt-link)))
4245 ;; Org link.
4246 (when (and (stringp he) (string-match "^LINK: " he))
4247 (setq he (replace-match "" t t he)))
4248 (loop for i in (list he ov-he w3m-l nt-prop)
4249 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4251 (defun anything-find-library-at-point ()
4252 "Try to find library path at point.
4253 Find inside `require' and `declare-function' sexp."
4254 (require 'find-func)
4255 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4256 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4257 (sexp (and beg-sexp end-sexp
4258 (buffer-substring-no-properties
4259 (1+ beg-sexp) (1- end-sexp)))))
4260 (ignore-errors
4261 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4262 (find-library-name
4263 (replace-regexp-in-string
4264 "'\\|\)\\|\(" ""
4265 ;; If require use third arg, ignore it,
4266 ;; always use library path found in `load-path'.
4267 (second (split-string (match-string 0 sexp))))))
4268 ((and sexp (string-match-p "^declare-function" sexp))
4269 (find-library-name
4270 (replace-regexp-in-string
4271 "\"\\|ext:" ""
4272 (third (split-string sexp)))))
4273 (t nil)))))
4275 ;;; Anything completion for `write-file'.==> C-x C-w
4276 (defvar anything-c-source-write-file
4277 `((name . "Write File")
4278 (header-name . (lambda (name)
4279 (concat name anything-c-find-files-doc-header)))
4280 ;; It is needed for filenames with capital letters
4281 (disable-shortcuts)
4282 (candidates . anything-find-files-get-candidates)
4283 (filtered-candidate-transformer anything-c-find-files-transformer)
4284 (persistent-action . anything-find-files-persistent-action)
4285 (persistent-help . "Expand Candidate")
4286 (volatile)
4287 (action .
4288 (("Write File" . (lambda (candidate)
4289 (write-file candidate 'confirm)))))))
4291 ;;; Anything completion for `insert-file'.==> C-x i
4292 (defvar anything-c-source-insert-file
4293 `((name . "Insert File")
4294 (header-name . (lambda (name)
4295 (concat name anything-c-find-files-doc-header)))
4296 ;; It is needed for filenames with capital letters
4297 (disable-shortcuts)
4298 (candidates . anything-find-files-get-candidates)
4299 (filtered-candidate-transformer anything-c-find-files-transformer)
4300 (persistent-action . anything-find-files-persistent-action)
4301 (persistent-help . "Expand Candidate")
4302 (volatile)
4303 (action .
4304 (("Insert File" . (lambda (candidate)
4305 (when (y-or-n-p (format "Really insert %s in %s "
4306 candidate anything-current-buffer))
4307 (insert-file-contents candidate))))))))
4309 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4310 (defvar anything-c-source-copy-files
4311 `((name . "Copy Files")
4312 (header-name . (lambda (name)
4313 (concat name anything-c-find-files-doc-header)))
4314 ;; It is needed for filenames with capital letters
4315 (disable-shortcuts)
4316 (candidates . anything-find-files-get-candidates)
4317 (filtered-candidate-transformer anything-c-find-files-transformer)
4318 (persistent-action . anything-find-files-persistent-action)
4319 (persistent-help . "Expand Candidate")
4320 (volatile)
4321 (action .
4322 (("Copy File"
4323 . (lambda (candidate)
4324 (anything-dired-action candidate :action 'copy)))
4325 ("Copy and Follow"
4326 . (lambda (candidate)
4327 (anything-dired-action candidate :action 'copy :follow t)))))))
4330 (defvar anything-c-source-rename-files
4331 `((name . "Rename Files")
4332 (header-name . (lambda (name)
4333 (concat name anything-c-find-files-doc-header)))
4334 ;; It is needed for filenames with capital letters
4335 (disable-shortcuts)
4336 (candidates . anything-find-files-get-candidates)
4337 (filtered-candidate-transformer anything-c-find-files-transformer)
4338 (persistent-action . anything-find-files-persistent-action)
4339 (persistent-help . "Expand Candidate")
4340 (volatile)
4341 (action .
4342 (("Rename File"
4343 . (lambda (candidate)
4344 (anything-dired-action candidate :action 'rename)))
4345 ("Rename and Follow"
4346 . (lambda (candidate)
4347 (anything-dired-action candidate :action 'rename :follow t)))))))
4349 (defvar anything-c-source-symlink-files
4350 `((name . "Symlink Files")
4351 (header-name . (lambda (name)
4352 (concat name anything-c-find-files-doc-header)))
4353 ;; It is needed for filenames with capital letters
4354 (disable-shortcuts)
4355 (candidates . anything-find-files-get-candidates)
4356 (filtered-candidate-transformer anything-c-find-files-transformer)
4357 (persistent-action . anything-find-files-persistent-action)
4358 (persistent-help . "Expand Candidate")
4359 (volatile)
4360 (action
4361 . (("Symlink File"
4362 . (lambda (candidate)
4363 (anything-dired-action candidate :action 'symlink)))
4364 ("RelSymlink File"
4365 . (lambda (candidate)
4366 (anything-dired-action candidate :action 'relsymlink)))))))
4369 (defvar anything-c-source-hardlink-files
4370 `((name . "Hardlink Files")
4371 (header-name . (lambda (name)
4372 (concat name anything-c-find-files-doc-header)))
4373 ;; It is needed for filenames with capital letters
4374 (disable-shortcuts)
4375 (candidates . anything-find-files-get-candidates)
4376 (filtered-candidate-transformer anything-c-find-files-transformer)
4377 (persistent-action . anything-find-files-persistent-action)
4378 (persistent-help . "Expand Candidate")
4379 (volatile)
4380 (action
4381 . (("Hardlink File"
4382 . (lambda (candidate)
4383 (anything-dired-action candidate :action 'hardlink)))))))
4385 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4386 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4387 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4388 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4389 (let ((fn (case action
4390 ('copy 'dired-copy-file)
4391 ('rename 'dired-rename-file)
4392 ('symlink 'make-symbolic-link)
4393 ('relsymlink 'dired-make-relative-symlink)
4394 ('hardlink 'dired-hardlink)))
4395 (marker (case action
4396 ((copy rename) dired-keep-marker-copy)
4397 ('symlink dired-keep-marker-symlink)
4398 ('relsymlink dired-keep-marker-relsymlink)
4399 ('hardlink dired-keep-marker-hardlink)))
4400 (dirflag (and (= (length files) 1)
4401 (file-directory-p (car files))
4402 (not (file-directory-p candidate)))))
4403 (dired-create-files
4404 fn (symbol-name action) files
4405 ;; CANDIDATE is the destination.
4406 (if (file-directory-p candidate)
4407 ;; When CANDIDATE is a directory, build file-name in this directory.
4408 ;; Else we use CANDIDATE.
4409 #'(lambda (from)
4410 (expand-file-name (file-name-nondirectory from) candidate))
4411 #'(lambda (from) candidate))
4412 marker)
4413 (push (file-name-as-directory
4414 (if (file-directory-p candidate)
4415 candidate (file-name-directory candidate)))
4416 anything-ff-history)
4417 (when (and follow (not (get-buffer dired-log-buffer)))
4418 (let ((target (directory-file-name candidate)))
4419 (unwind-protect
4420 (progn
4421 (setq anything-ff-cand-to-mark
4422 (anything-get-dest-fnames-from-list files candidate dirflag))
4423 (if (and dirflag (eq action 'rename))
4424 (anything-find-files-1 (file-name-directory target)
4425 (if anything-ff-transformer-show-only-basename
4426 (anything-c-basename target) target))
4427 (anything-find-files-1 (expand-file-name candidate))))
4428 (setq anything-ff-cand-to-mark nil))))))
4431 (defun anything-c-basename (fname)
4432 "Resolve basename of file or directory named FNAME."
4433 (file-name-nondirectory (directory-file-name fname)))
4435 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4436 "Transform filenames of FLIST to abs of DEST-CAND.
4437 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4438 members of FLIST."
4439 ;; At this point files have been renamed/copied at destination.
4440 ;; That's mean DEST-CAND exists.
4441 (loop
4442 with dest = (expand-file-name dest-cand)
4443 for src in flist
4444 for basename-src = (anything-c-basename src)
4445 for fname = (cond (rename-dir-flag (directory-file-name dest))
4446 ((file-directory-p dest)
4447 (concat (file-name-as-directory dest) basename-src))
4448 (t dest))
4449 when (file-exists-p fname)
4450 collect fname into tmp-list
4451 finally return (sort tmp-list 'string<)))
4453 (defun anything-ff-maybe-mark-candidates ()
4454 "Mark all candidates of list `anything-ff-cand-to-mark'."
4455 (when (and (string= (assoc-default 'name (anything-get-current-source))
4456 (assoc-default 'name anything-c-source-find-files))
4457 anything-ff-cand-to-mark)
4458 (with-anything-window
4459 (while anything-ff-cand-to-mark
4460 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4461 (progn
4462 (anything-make-visible-mark)
4463 (anything-next-line)
4464 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4465 (anything-next-line)))
4466 (unless (anything-this-visible-mark)
4467 (anything-prev-visible-mark)))))
4469 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4471 (defun* anything-dired-do-action-on-file (&key action)
4472 (let* ((files (dired-get-marked-files))
4473 (len (length files))
4474 (fname (if (> len 1)
4475 (format "* %d Files" len)
4476 (car files)))
4477 (source (case action
4478 ('copy 'anything-c-source-copy-files)
4479 ('rename 'anything-c-source-rename-files)
4480 ('symlink 'anything-c-source-symlink-files)
4481 ('hardlink 'anything-c-source-hardlink-files)))
4482 (prompt-fm (case action
4483 ('copy "Copy %s to: ")
4484 ('rename "Rename %s to: ")
4485 ('symlink "Symlink %s to: ")
4486 ('hardlink "Hardlink %s to: ")))
4487 (buffer (case action
4488 ('copy "*Anything Copy Files*")
4489 ('rename "*Anything Rename Files*")
4490 ('symlink "*Anything Symlink Files*")
4491 ('hardlink "*Anything Hardlink Files*")))
4492 (anything-mp-highlight-delay nil))
4493 (anything :sources source
4494 :input (or (dired-dwim-target-directory)
4495 (expand-file-name (anything-c-current-directory)))
4496 :preselect (dired-get-filename)
4497 :prompt (format prompt-fm fname)
4498 :keymap anything-c-read-file-map
4499 :buffer buffer)))
4501 ;;;###autoload
4502 (define-minor-mode anything-dired-mode ()
4503 "Enable anything completion in Dired functions.
4504 Bindings affected are C, R, S, H.
4505 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4506 :group 'anything-config
4507 :global t
4508 (if anything-dired-mode
4509 (progn
4510 (substitute-key-definition
4511 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4512 (substitute-key-definition
4513 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4514 (substitute-key-definition
4515 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4516 (substitute-key-definition
4517 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4518 (substitute-key-definition
4519 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4520 (substitute-key-definition
4521 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4522 (substitute-key-definition
4523 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4524 (substitute-key-definition
4525 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4527 (defalias 'anything-dired-bindings 'anything-dired-mode)
4529 (defun* anything-c-read-file-name (prompt
4530 &key
4531 (name "Read File Name")
4532 (initial-input (expand-file-name default-directory))
4533 (buffer "*Anything Completions*")
4534 test
4535 (preselect nil)
4536 (history nil)
4537 (marked-candidates nil)
4538 (alistp t)
4539 (persistent-action 'anything-find-files-persistent-action)
4540 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4541 "Anything `read-file-name' emulation.
4542 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4543 (when (get-buffer anything-action-buffer)
4544 (kill-buffer anything-action-buffer))
4545 (let ((anything-mp-highlight-delay nil)
4546 ;; Be sure we don't erase the underlying minibuffer if some.
4547 (anything-ff-auto-update-initial-value
4548 (not (minibuffer-window-active-p (minibuffer-window))))
4549 anything-same-window
4550 (hist (and history (anything-comp-read-get-candidates
4551 history nil nil alistp))))
4552 (flet ((action-fn (candidate)
4553 (if marked-candidates
4554 (anything-marked-candidates)
4555 (identity candidate))))
4556 (or (anything
4557 :sources
4558 `(((name . ,(format "%s History" name))
4559 (header-name . (lambda (name)
4560 (concat name anything-c-find-files-doc-header)))
4561 (disable-shortcuts)
4562 (mode-line . anything-read-file-name-mode-line-string)
4563 (candidates . hist)
4564 (persistent-action . ,persistent-action)
4565 (persistent-help . ,persistent-help)
4566 (action . ,'action-fn))
4567 ((name . ,name)
4568 (header-name . (lambda (name)
4569 (concat name anything-c-find-files-doc-header)))
4570 ;; It is needed for filenames with capital letters
4571 (disable-shortcuts)
4572 (mode-line . anything-read-file-name-mode-line-string)
4573 (candidates . (lambda ()
4574 (let ((seq (anything-find-files-get-candidates)))
4575 (if test
4576 (loop for fname in seq
4577 when (funcall test fname) collect fname)
4578 seq))))
4579 (filtered-candidate-transformer anything-c-find-files-transformer)
4580 (persistent-action . ,persistent-action)
4581 (candidate-number-limit . 9999)
4582 (toggle-auto-update . anything-ff-toggle-auto-update)
4583 (persistent-help . ,persistent-help)
4584 (volatile)
4585 (action . ,'action-fn)))
4586 :input initial-input
4587 :prompt prompt
4588 :keymap anything-c-read-file-map
4589 :resume 'noresume
4590 :buffer buffer
4591 :preselect preselect)
4592 (keyboard-quit)))))
4595 ;;; File Cache
4596 (defvar anything-c-file-cache-initialized-p nil)
4598 (defvar anything-c-file-cache-files nil)
4600 (defvar anything-c-source-file-cache
4601 '((name . "File Cache")
4602 (init
4603 . (lambda ()
4604 (require 'filecache nil t)
4605 (unless anything-c-file-cache-initialized-p
4606 (setq anything-c-file-cache-files
4607 (loop for item in file-cache-alist append
4608 (destructuring-bind (base &rest dirs) item
4609 (loop for dir in dirs collect
4610 (concat dir base)))))
4611 (defadvice file-cache-add-file (after file-cache-list activate)
4612 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4613 (setq anything-c-file-cache-initialized-p t))))
4614 (candidates . anything-c-file-cache-files)
4615 (match anything-c-match-on-basename)
4616 (type . file)))
4617 ;; (anything 'anything-c-source-file-cache)
4620 ;;; Locate
4623 ;; NOTE for WINDOZE users:
4624 ;; You have to install Everything with his command line interface here:
4625 ;; http://www.voidtools.com/download.php
4627 (defun anything-locate-1 (&optional localdb init)
4628 "Generic function to run Locate.
4629 if LOCALDB is non--nil search and use a local locate db file.
4630 INIT is a string to use as initial input in prompt.
4631 See `anything-locate-with-db' and `anything-locate'."
4632 (anything-locate-with-db
4633 (and localdb
4634 (anything-c-read-file-name
4635 "LocateDBFiles: "
4636 :marked-candidates t
4637 :preselect anything-locate-db-file-regexp
4638 :test #'(lambda (x)
4639 (if anything-locate-db-file-regexp
4640 ;; Select only locate db files and directories
4641 ;; to allow navigation.
4642 (or (string-match
4643 anything-locate-db-file-regexp x)
4644 (file-directory-p x))
4645 x))))
4646 init))
4647 ;; (anything-locate-1 t)
4649 (defun anything-locate-with-db (&optional db initial-input)
4650 "Run locate -d DB.
4651 If DB is not given or nil use locate without -d option.
4652 Argument DB can be given as a string or list of db files.
4653 Argument INITIAL-INPUT is a string to use as initial-input.
4654 See also `anything-locate'."
4655 (when (and db (stringp db)) (setq db (list db)))
4656 (let ((anything-c-locate-command
4657 (if db
4658 (replace-regexp-in-string
4659 "locate"
4660 (format "locate -d %s"
4661 (mapconcat 'identity
4662 ;; Remove eventually
4663 ;; marked directories by error.
4664 (loop for i in db
4665 unless (file-directory-p i)
4666 collect i) ":"))
4667 anything-c-locate-command)
4668 anything-c-locate-command)))
4669 (anything :sources 'anything-c-source-locate
4670 :buffer "*anything locate*"
4671 :input initial-input
4672 :keymap anything-generic-files-map)))
4673 ;; (anything-locate-with-db "~/locate.db")
4675 (defun anything-c-locate-init ()
4676 "Initialize async locate process for `anything-c-source-locate'."
4677 (setq mode-line-format
4678 '(" " mode-line-buffer-identification " "
4679 (line-number-mode "%l") " "
4680 (:eval (propertize "(Locate Process Running) "
4681 'face '((:foreground "red"))))))
4682 (prog1
4683 (start-process-shell-command "locate-process" nil
4684 (format anything-c-locate-command
4685 anything-pattern))
4686 (set-process-sentinel (get-process "locate-process")
4687 #'(lambda (process event)
4688 (when (string= event "finished\n")
4689 (with-anything-window
4690 (force-mode-line-update nil)
4691 (anything-update-move-first-line)))))))
4693 (defvar anything-c-source-locate
4694 '((name . "Locate")
4695 (candidates . anything-c-locate-init)
4696 (type . file)
4697 (properties-action . anything-ff-properties)
4698 (requires-pattern . 3)
4699 (candidate-number-limit . 9999)
4700 (mode-line . anything-generic-file-mode-line-string)
4701 (delayed))
4702 "Find files matching the current input pattern with locate.")
4703 ;; (anything 'anything-c-source-locate)
4705 (defun anything-c-locate-read-file-name (prompt &optional init)
4706 "Search a file with locate and return it's filename.
4707 Use argument PROMPT and INIT for `anything' arguments
4708 prompt and input."
4709 (anything :sources
4710 '((name . "Locate")
4711 (candidates . anything-c-locate-init)
4712 (action . identity)
4713 (properties-action . anything-ff-properties)
4714 (requires-pattern . 3)
4715 (candidate-number-limit . 9999)
4716 (mode-line . anything-generic-file-mode-line-string)
4717 (delayed))
4718 :prompt prompt
4719 :input init
4720 :buffer "*anything locate rfn*"))
4724 ;;; Anything Incremental Grep.
4727 ;; Allow to grep incrementally with anything interface.
4728 ;; It allow also to Grep files recursively without using 'find' shell command.
4729 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4730 (defvar anything-c-grep-default-command
4731 "grep -d skip %e -niH -e %p %f"
4732 "Default grep format command for `anything-do-grep-1'.
4733 Where:
4734 '%e' format spec is for --exclude or --include grep options.
4735 '%p' format spec is for pattern.
4736 '%f' format spec is for filenames.")
4738 (defvar anything-c-grep-default-recurse-command
4739 "grep -d recurse %e -niH -e %p %f"
4740 "Default recursive grep format command for `anything-do-grep-1'.
4741 See `anything-c-grep-default-command' for format specs.")
4743 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4745 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4747 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4749 (defvar anything-c-grep-debug-command-line nil
4750 "Turn on anything grep command-line debugging when non--nil.")
4752 (defvar anything-c-zgrep-recurse-flag nil)
4754 (defvar anything-c-grep-history nil)
4756 (defvar anything-c-grep-max-length-history 100
4757 "*Max number of elements to save in `anything-c-grep-history'.")
4759 (defun anything-c-grep-prepare-candidates (candidates)
4760 "Prepare filenames and directories CANDIDATES for grep command line."
4761 ;; If one or more candidate is a directory, search in all files
4762 ;; of this candidate (e.g /home/user/directory/*).
4763 ;; If r option is enabled search also in subdidrectories.
4764 ;; We need here to expand wildcards to support crap windows filenames
4765 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4766 (if anything-c-zgrep-recurse-flag
4767 (mapconcat 'shell-quote-argument candidates " ")
4768 (loop for i in candidates append
4769 (cond ( ;; Candidate is a directory and we use recursion.
4770 (and (file-directory-p i)
4771 (anything-c-grep-recurse-p))
4772 (list (expand-file-name i)))
4773 ;; Candidate is a directory, search in all files.
4774 ((file-directory-p i)
4775 (file-expand-wildcards
4776 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4777 ;; Candidate is a file or wildcard and we use recursion, use the
4778 ;; current directory instead of candidate.
4779 ((and (or (file-exists-p i) (string-match "\*" i))
4780 (anything-c-grep-recurse-p))
4781 (list (expand-file-name
4782 (directory-file-name ; Needed for windoze.
4783 (file-name-directory (directory-file-name i))))))
4784 ;; Candidate use wildcard.
4785 ((string-match "^\*" (anything-c-basename i))
4786 (file-expand-wildcards i t))
4787 ;; Else should be one or more file.
4788 (t (list i))) into all-files
4789 finally return
4790 (mapconcat 'shell-quote-argument all-files " "))))
4792 (defun anything-c-grep-recurse-p ()
4793 "Check if `anything-do-grep-1' have switched to recursive."
4794 (let ((args (replace-regexp-in-string
4795 "grep" "" anything-c-grep-default-command)))
4796 (string-match-p "r\\|recurse" args)))
4798 (defun anything-c-grep-init (only-files &optional include zgrep)
4799 "Start an asynchronous grep process in ONLY-FILES list."
4800 (let* ((fnargs (anything-c-grep-prepare-candidates
4801 (if (file-remote-p anything-ff-default-directory)
4802 (mapcar #'(lambda (x)
4803 (file-remote-p x 'localname))
4804 only-files)
4805 only-files)))
4806 (ignored-files (mapconcat
4807 #'(lambda (x)
4808 (concat "--exclude=" (shell-quote-argument x)))
4809 grep-find-ignored-files " "))
4810 (ignored-dirs (mapconcat
4811 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4812 #'(lambda (x)
4813 (concat "--exclude-dir=" (shell-quote-argument x)))
4814 grep-find-ignored-directories " "))
4815 (exclude (if (anything-c-grep-recurse-p)
4816 (concat (or include ignored-files) " " ignored-dirs)
4817 ignored-files))
4818 (cmd-line (format-spec
4819 anything-c-grep-default-command
4820 (delq nil
4821 (list (unless zgrep (cons ?e exclude))
4822 (cons ?p (shell-quote-argument anything-pattern))
4823 (cons ?f fnargs))))))
4824 (when anything-c-grep-debug-command-line
4825 (with-current-buffer (get-buffer-create "*any grep debug*")
4826 (goto-char (point-max))
4827 (insert (concat ">>> " cmd-line "\n\n"))))
4828 (setq mode-line-format
4829 '(" " mode-line-buffer-identification " "
4830 (line-number-mode "%l") " "
4831 (:eval (when (get-process "grep-process")
4832 (propertize "[Grep Process Running] "
4833 'face 'anything-grep-running)))))
4834 (force-mode-line-update nil)
4835 (prog1
4836 (let ((default-directory anything-ff-default-directory))
4837 (start-file-process-shell-command "grep-process" nil cmd-line))
4838 (message nil)
4839 (set-process-sentinel
4840 (get-process "grep-process")
4841 #'(lambda (process event)
4842 (when (string= event "finished\n")
4843 (with-anything-window
4844 (anything-update-move-first-line)
4845 (setq mode-line-format
4846 '(" " mode-line-buffer-identification " "
4847 (line-number-mode "%l") " "
4848 (:eval (propertize
4849 (format "[Grep Process Finished - (%s results)] "
4850 (let ((nlines (1- (count-lines
4851 (point-min)
4852 (point-max)))))
4853 (if (> nlines 0) nlines 0)))
4854 'face 'anything-grep-finish))))
4855 (force-mode-line-update nil))))))))
4857 (defun anything-c-grep-action (candidate &optional where mark)
4858 "Define a default action for `anything-do-grep' on CANDIDATE.
4859 WHERE can be one of other-window, elscreen, other-frame."
4860 (let* ((split (anything-c-grep-split-line candidate))
4861 (lineno (string-to-number (nth 1 split)))
4862 (loc-fname (car split))
4863 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4864 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4865 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4866 (fname (if tramp-host
4867 (concat tramp-prefix loc-fname) loc-fname)))
4868 (case where
4869 (other-window (find-file-other-window fname))
4870 (elscreen (anything-elscreen-find-file fname))
4871 (other-frame (find-file-other-frame fname))
4872 (t (find-file fname)))
4873 (anything-goto-line lineno)
4874 (when mark
4875 (set-marker (mark-marker) (point))
4876 (push-mark (point) 'nomsg))
4877 ;; Save history
4878 (unless (or anything-in-persistent-action
4879 (string= anything-pattern ""))
4880 (setq anything-c-grep-history
4881 (cons anything-pattern
4882 (delete anything-pattern anything-c-grep-history)))
4883 (when (> (length anything-c-grep-history)
4884 anything-c-grep-max-length-history)
4885 (setq anything-c-grep-history
4886 (delete (car (last anything-c-grep-history))
4887 anything-c-grep-history))))))
4889 (defun anything-c-grep-other-window (candidate)
4890 "Jump to result in other window from anything grep."
4891 (anything-c-grep-action candidate 'other-window))
4893 (defun anything-c-grep-other-frame (candidate)
4894 "Jump to result in other frame from anything grep."
4895 (anything-c-grep-action candidate 'other-frame))
4897 (defun anything-c-grep-jump-elscreen (candidate)
4898 "Jump to result in elscreen from anything grep."
4899 (anything-c-grep-action candidate 'elscreen))
4901 (defun anything-c-grep-save-results (candidate)
4902 "Save anything grep result in a `grep-mode' buffer."
4903 (let ((buf "*grep*")
4904 new-buf)
4905 (when (get-buffer buf)
4906 (setq new-buf (read-string "GrepBufferName: " buf))
4907 (loop for b in (anything-c-buffer-list)
4908 when (and (string= new-buf b)
4909 (not (y-or-n-p
4910 (format "Buffer `%s' already exists overwrite? "
4911 new-buf))))
4912 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4913 (setq buf new-buf))
4914 (with-current-buffer (get-buffer-create buf)
4915 (let ((inhibit-read-only t))
4916 (erase-buffer)
4917 (insert "-*- mode: grep -*-\n\n"
4918 (format "Grep Results for `%s':\n\n" anything-pattern))
4919 (save-excursion
4920 (insert (with-current-buffer anything-buffer
4921 (forward-line 1)
4922 (buffer-substring (point) (point-max))))
4923 (grep-mode))))
4924 (message "Anything Grep Results saved in `%s' buffer" buf)))
4926 (defun anything-c-grep-persistent-action (candidate)
4927 "Persistent action for `anything-do-grep'.
4928 With a prefix arg record CANDIDATE in `mark-ring'."
4929 (if current-prefix-arg
4930 (anything-c-grep-action candidate nil 'mark)
4931 (anything-c-grep-action candidate))
4932 (anything-match-line-color-current-line))
4934 (defun anything-c-grep-guess-extensions (files)
4935 "Try to guess file extensions in FILES list when using grep recurse.
4936 These extensions will be added to command line with --include arg of grep."
4937 (loop
4938 with glob-list = nil
4939 with lst = (if (file-directory-p (car files))
4940 (directory-files
4941 (car files) nil
4942 directory-files-no-dot-files-regexp)
4943 files)
4944 for i in lst
4945 for ext = (file-name-extension i t)
4946 for glob = (and ext (not (string= ext ""))
4947 (concat "*" ext))
4948 unless (or (not glob)
4949 (member glob glob-list)
4950 (member glob grep-find-ignored-files))
4951 collect glob into glob-list
4952 finally return glob-list))
4954 (defun anything-do-grep-1 (only &optional recurse zgrep)
4955 "Launch grep with a list of ONLY files.
4956 When RECURSE is given use -r option of grep and prompt user
4957 to set the --include args of grep.
4958 You can give more than one arg separated by space.
4959 e.g *.el *.py *.tex.
4960 If it's empty --exclude `grep-find-ignored-files' is used instead."
4961 (let* ((anything-compile-source-functions
4962 ;; rule out anything-match-plugin because the input is one regexp.
4963 (delq 'anything-compile-source--match-plugin
4964 (copy-sequence anything-compile-source-functions)))
4965 (exts (anything-c-grep-guess-extensions only))
4966 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4967 (include-files (and recurse (not zgrep)
4968 (read-string "OnlyExt(*.[ext]): "
4969 globs)))
4970 ;; Set `minibuffer-history' AFTER includes-files
4971 ;; to avoid storing wild-cards here.
4972 (minibuffer-history anything-c-grep-history)
4973 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4974 (recurse anything-c-grep-default-recurse-command)
4975 (zgrep anything-c-default-zgrep-command)
4976 (t anything-c-grep-default-command)))
4977 ;; Disable match-plugin and use here own highlighting.
4978 (anything-mp-highlight-delay nil))
4979 (when include-files
4980 (setq include-files
4981 (and (not (string= include-files ""))
4982 (mapconcat #'(lambda (x)
4983 (concat "--include=" (shell-quote-argument x)))
4984 (split-string include-files) " "))))
4985 ;; When called as action from an other source e.g *-find-files
4986 ;; we have to kill action buffer.
4987 (when (get-buffer anything-action-buffer)
4988 (kill-buffer anything-action-buffer))
4989 ;; `anything-find-files' haven't already started,
4990 ;; give a default value to `anything-ff-default-directory'.
4991 (setq anything-ff-default-directory (or anything-ff-default-directory
4992 default-directory))
4993 (anything
4994 :sources
4995 `(((name . "Grep (C-c ? Help)")
4996 (candidates
4997 . (lambda ()
4998 (funcall anything-c-grep-default-function only include-files zgrep)))
4999 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5000 (candidate-number-limit . 9999)
5001 (mode-line . anything-grep-mode-line-string)
5002 (jump-persistent . anything-c-grep-persistent-action)
5003 (action . ,(delq
5005 `(("Find File" . anything-c-grep-action)
5006 ("Find file other frame" . anything-c-grep-other-frame)
5007 ,(and (locate-library "elscreen")
5008 '("Find file in Elscreen"
5009 . anything-c-grep-jump-elscreen))
5010 ("Save results in grep buffer" . anything-c-grep-save-results)
5011 ("Find file other window" . anything-c-grep-other-window))))
5012 (persistent-action . anything-c-grep-persistent-action)
5013 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5014 (requires-pattern . 3)
5015 (delayed)))
5016 :keymap anything-c-grep-map
5017 :buffer "*anything grep*")))
5019 (defun anything-ff-zgrep-1 (flist recursive)
5020 (unwind-protect
5021 (let* ((def-dir (or anything-ff-default-directory
5022 default-directory))
5023 (only (if recursive
5024 (or (gethash def-dir anything-c-rzgrep-cache)
5025 (puthash
5026 def-dir
5027 (anything-c-walk-directory
5028 def-dir
5029 :directories nil
5030 :path 'full
5031 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5032 anything-c-rzgrep-cache))
5033 flist)))
5034 (when recursive (setq anything-c-zgrep-recurse-flag t))
5035 (anything-do-grep-1 only recursive 'zgrep))
5036 (setq anything-c-zgrep-recurse-flag nil)))
5038 (defun anything-c-grep-split-line (line)
5039 "Split a grep output line."
5040 (let (beg fname lineno str)
5041 ;; Don't print until grep line is valid.
5042 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5043 (with-temp-buffer
5044 (insert line)
5045 (goto-char (point-min))
5046 (setq beg (point))
5047 (forward-char 2)
5048 (re-search-forward ":" nil t)
5049 (setq fname (buffer-substring-no-properties beg (1- (point))))
5050 (setq beg (point))
5051 (re-search-forward ":" nil t)
5052 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5053 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5054 (list fname lineno str))))
5056 (defun anything-c-grep-cand-transformer (candidates sources)
5057 "Filtered candidate transformer function for `anything-do-grep'."
5058 (loop for i in candidates
5059 for split = (and i (anything-c-grep-split-line i))
5060 for fname = (car split)
5061 for lineno = (nth 1 split)
5062 for str = (nth 2 split)
5063 when (and fname lineno str)
5064 collect
5065 (cons (concat (propertize (file-name-nondirectory fname)
5066 'face 'anything-grep-file
5067 'help-echo fname) ":"
5068 (propertize lineno 'face 'anything-grep-lineno) ":"
5069 (anything-c-grep-highlight-match str))
5070 i)))
5072 (defun anything-c-grep-highlight-match (str)
5073 "Highlight in string STR all occurences matching `anything-pattern'."
5074 (condition-case nil
5075 (with-temp-buffer
5076 (insert str)
5077 (goto-char (point-min))
5078 (while (and (re-search-forward anything-pattern nil t)
5079 (> (- (match-end 0) (match-beginning 0)) 0))
5080 (add-text-properties
5081 (match-beginning 0) (match-end 0)
5082 '(face anything-grep-match)))
5083 (buffer-string))
5084 (error nil)))
5086 ;; Go to next or precedent file (common to etags and grep).
5087 (defun anything-c-goto-next-or-prec-file (n)
5088 "Go to next or precedent candidate file in anything grep/etags buffers.
5089 If N is positive go forward otherwise go backward."
5090 (with-anything-window
5091 (let* ((current-line-list (split-string
5092 (buffer-substring
5093 (point-at-bol)
5094 (point-at-eol)) ":"))
5095 (current-fname (nth 0 current-line-list))
5096 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5097 (catch 'break
5098 (while (not (funcall fn-b-o-f))
5099 (forward-line n) ; Go forward or backward depending of n value.
5100 (unless (search-forward current-fname (point-at-eol) t)
5101 (anything-mark-current-line)
5102 (throw 'break nil))))
5103 (cond ((and (eq n 1) (eobp))
5104 (re-search-backward ".")
5105 (forward-line 0)
5106 (anything-mark-current-line))
5107 ((and (< n 1) (bobp))
5108 (forward-line 1)
5109 (anything-mark-current-line))))))
5111 ;;;###autoload
5112 (defun anything-c-goto-precedent-file ()
5113 "Go to precedent file in anything grep/etags buffers."
5114 (interactive)
5115 (anything-c-goto-next-or-prec-file -1))
5117 ;;;###autoload
5118 (defun anything-c-goto-next-file ()
5119 "Go to precedent file in anything grep/etags buffers."
5120 (interactive)
5121 (anything-c-goto-next-or-prec-file 1))
5123 ;;;###autoload
5124 (defun anything-c-grep-run-persistent-action ()
5125 "Run grep persistent action from `anything-do-grep-1'."
5126 (interactive)
5127 (anything-execute-persistent-action 'jump-persistent))
5129 ;;;###autoload
5130 (defun anything-c-grep-run-default-action ()
5131 "Run grep default action from `anything-do-grep-1'."
5132 (interactive)
5133 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5135 ;;;###autoload
5136 (defun anything-c-grep-run-other-window-action ()
5137 "Run grep goto other window action from `anything-do-grep-1'."
5138 (interactive)
5139 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5141 ;;;###autoload
5142 (defun anything-c-grep-run-save-buffer ()
5143 "Run grep save results action from `anything-do-grep-1'."
5144 (interactive)
5145 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5147 ;; Grep buffers
5148 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5149 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5150 If one of selected buffers is not a file--buffer,
5151 it is ignored and grep will run on all others file--buffers.
5152 If only one candidate is selected and it is not a file--buffer,
5153 switch to this buffer and run `anything-occur'.
5154 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5155 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5156 (cands (if prefarg
5157 (buffer-list)
5158 (anything-marked-candidates)))
5159 (win-conf (current-window-configuration))
5160 ;; Non--fname buffers are ignored.
5161 (bufs (loop for buf in cands
5162 for fname = (buffer-file-name (get-buffer buf))
5163 when fname
5164 collect (expand-file-name fname))))
5165 (if bufs
5166 (if zgrep
5167 (anything-do-grep-1 bufs nil 'zgrep)
5168 (anything-do-grep-1 bufs))
5169 ;; bufs is empty, thats mean we have only CANDIDATE
5170 ;; and it is not a buffer-filename, fallback to occur.
5171 (anything-c-switch-to-buffer candidate)
5172 (when (get-buffer anything-action-buffer)
5173 (kill-buffer anything-action-buffer))
5174 (anything-occur)
5175 (when (eq anything-exit-status 1)
5176 (set-window-configuration win-conf)))))
5178 (defun anything-c-grep-buffers (candidate)
5179 "Action to grep buffers."
5180 (anything-c-grep-buffers-1 candidate))
5182 (defun anything-c-zgrep-buffers (candidate)
5183 "Action to zgrep buffers."
5184 (anything-c-grep-buffers-1 candidate 'zgrep))
5187 ;;; Anything interface for pdfgrep
5188 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5189 ;; and a pdf-reader (e.g xpdf) are needed.
5191 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5192 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5193 (defvar anything-c-pdfgrep-debug-command-line nil)
5195 (defun anything-c-pdfgrep-init (only-files)
5196 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5197 (let* ((fnargs (anything-c-grep-prepare-candidates
5198 (if (file-remote-p anything-ff-default-directory)
5199 (mapcar #'(lambda (x)
5200 (file-remote-p x 'localname))
5201 only-files)
5202 only-files)))
5203 (cmd-line (format anything-c-pdfgrep-default-command
5204 anything-pattern
5205 fnargs)))
5206 (when anything-c-pdfgrep-debug-command-line
5207 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5208 (goto-char (point-max))
5209 (insert (concat ">>> " cmd-line "\n\n"))))
5210 (setq mode-line-format
5211 '(" " mode-line-buffer-identification " "
5212 (line-number-mode "%l") " "
5213 (:eval (propertize "(Pdfgrep Process Running) "
5214 'face '((:foreground "red"))))))
5215 (prog1
5216 (let ((default-directory anything-ff-default-directory))
5217 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5218 (message nil)
5219 (set-process-sentinel
5220 (get-process "pdfgrep-process")
5221 #'(lambda (process event)
5222 (when (string= event "finished\n")
5223 (with-anything-window
5224 (anything-update-move-first-line))
5225 (force-mode-line-update nil)))))))
5228 (defun anything-do-pdfgrep-1 (only)
5229 "Launch pdfgrep with a list of ONLY files."
5230 (unless (executable-find "pdfgrep")
5231 (error "Error: No such program `pdfgrep'."))
5232 (let* ((anything-compile-source-functions
5233 ;; rule out anything-match-plugin because the input is one regexp.
5234 (delq 'anything-compile-source--match-plugin
5235 (copy-sequence anything-compile-source-functions)))
5236 ;; Disable match-plugin and use here own highlighting.
5237 (anything-mp-highlight-delay nil))
5238 ;; When called as action from an other source e.g *-find-files
5239 ;; we have to kill action buffer.
5240 (when (get-buffer anything-action-buffer)
5241 (kill-buffer anything-action-buffer))
5242 ;; If `anything-find-files' haven't already started,
5243 ;; give a default value to `anything-ff-default-directory'.
5244 (setq anything-ff-default-directory (or anything-ff-default-directory
5245 default-directory))
5246 (anything
5247 :sources
5248 `(((name . "PdfGrep")
5249 (candidates
5250 . (lambda ()
5251 (funcall anything-c-pdfgrep-default-function only)))
5252 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5253 (candidate-number-limit . 9999)
5254 (mode-line . anything-pdfgrep-mode-line-string)
5255 (action . anything-c-pdfgrep-action)
5256 (persistent-help . "Jump to PDF Page")
5257 (requires-pattern . 3)
5258 (delayed)))
5259 :keymap anything-c-pdfgrep-map
5260 :buffer "*anything grep*")))
5263 (defun anything-c-pdfgrep-action (candidate)
5264 (let* ((split (anything-c-grep-split-line candidate))
5265 (pageno (nth 1 split))
5266 (fname (car split)))
5267 (start-file-process-shell-command
5268 "pdf-reader" nil
5269 (format-spec anything-c-pdfgrep-default-read-command
5270 (list (cons ?f fname) (cons ?p pageno))))))
5272 (defun anything-do-pdfgrep ()
5273 (interactive)
5274 (let ((only (anything-c-read-file-name
5275 "Search in file(s): "
5276 :marked-candidates t
5277 :test #'(lambda (file)
5278 (or (string= (file-name-extension file) "pdf")
5279 (string= (file-name-extension file) "PDF")
5280 (file-directory-p file)))
5281 :preselect (or (dired-get-filename nil t)
5282 (buffer-file-name (current-buffer)))))
5283 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5284 (anything-do-pdfgrep-1 only)))
5287 ;; Yank text at point.
5290 ;; Internal
5291 (defvar anything-yank-point nil)
5293 ;;;###autoload
5294 (defun anything-yank-text-at-point ()
5295 "Yank text at point in minibuffer."
5296 (interactive)
5297 (let (input)
5298 (flet ((insert-in-minibuffer (word)
5299 (with-selected-window (minibuffer-window)
5300 (let ((str anything-pattern))
5301 (delete-minibuffer-contents)
5302 (set-text-properties 0 (length word) nil word)
5303 (insert (concat str word))))))
5304 (with-anything-current-buffer
5305 ;; Start to initial point if C-w have never been hit.
5306 (unless anything-yank-point (setq anything-yank-point (point)))
5307 (and anything-yank-point (goto-char anything-yank-point))
5308 (forward-word 1)
5309 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5310 (setq anything-yank-point (point))) ; End of last forward-word
5311 (insert-in-minibuffer input))))
5313 (defun anything-reset-yank-point ()
5314 (setq anything-yank-point nil))
5316 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5317 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5320 ;;; Recentf files
5323 (defvar anything-c-source-recentf
5324 '((name . "Recentf")
5325 (init . (lambda ()
5326 (require 'recentf)
5327 (or recentf-mode (recentf-mode 1))))
5328 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5329 (candidates . recentf-list)
5330 (match anything-c-match-on-basename)
5331 (type . file))
5332 "See (info \"(emacs)File Conveniences\").
5333 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5334 ;; (anything 'anything-c-source-recentf)
5336 ;;; ffap
5337 (eval-when-compile (require 'ffap))
5338 (defvar anything-c-source-ffap-guesser
5339 '((name . "File at point")
5340 (init . (lambda () (require 'ffap)))
5341 (candidates . (lambda ()
5342 (anything-aif
5343 (with-anything-current-buffer
5344 (ffap-guesser))
5345 (list it))))
5346 (type . file)))
5347 ;; (anything 'anything-c-source-ffap-guesser)
5349 ;;; ffap with line number
5350 (defun anything-c-ffap-file-line-at-point ()
5351 "Get (FILENAME . LINENO) at point."
5352 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5353 (save-excursion
5354 (beginning-of-line)
5355 (when (and (search-forward it nil t)
5356 (looking-at ":\\([0-9]+\\)"))
5357 (cons it (string-to-number (match-string 1)))))))
5359 (defvar anything-c-ffap-line-location nil
5360 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5361 It is cleared after jumping line.")
5363 (defun anything-c-ffap-line-candidates ()
5364 (with-anything-current-buffer
5365 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5366 (when anything-c-ffap-line-location
5367 (destructuring-bind (file . line) anything-c-ffap-line-location
5368 (list (cons (format "%s (line %d)" file line) file)))))
5370 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5371 (defun anything-c-ffap-line-goto-line ()
5372 (when (car anything-c-ffap-line-location)
5373 (unwind-protect
5374 (ignore-errors
5375 (with-selected-window
5376 (get-buffer-window
5377 (get-file-buffer (car anything-c-ffap-line-location)))
5378 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5379 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5380 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5382 (defvar anything-c-source-ffap-line
5383 '((name . "File/Lineno at point")
5384 (init . (lambda () (require 'ffap)))
5385 (candidates . anything-c-ffap-line-candidates)
5386 (type . file)))
5387 ;; (anything 'anything-c-source-ffap-line)
5389 ;;; list of files gleaned from every dired buffer
5390 (defun anything-c-files-in-all-dired-candidates ()
5391 (save-excursion
5392 (mapcan
5393 (lambda (dir)
5394 (cond ((listp dir) ;filelist
5395 dir)
5396 ((equal "" (file-name-nondirectory dir)) ;dir
5397 (directory-files dir t))
5398 (t ;wildcard
5399 (file-expand-wildcards dir t))))
5400 (delq nil
5401 (mapcar (lambda (buf)
5402 (set-buffer buf)
5403 (when (eq major-mode 'dired-mode)
5404 (if (consp dired-directory)
5405 (cdr dired-directory) ;filelist
5406 dired-directory))) ;dir or wildcard
5407 (buffer-list))))))
5408 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5410 (defvar anything-c-source-files-in-all-dired
5411 '((name . "Files in all dired buffer.")
5412 (candidates . anything-c-files-in-all-dired-candidates)
5413 (type . file)))
5414 ;; (anything 'anything-c-source-files-in-all-dired)
5416 (defvar anything-c-source-filelist
5417 '((name . "FileList")
5418 (grep-candidates . anything-c-filelist-file-name)
5419 (candidate-number-limit . 200)
5420 (requires-pattern . 4)
5421 (type . file))
5422 "Source to find files instantly.
5423 See `anything-c-filelist-file-name' docstring for usage.")
5426 ;;;; <info>
5427 ;;; Info pages
5428 (defvar anything-c-info-pages nil
5429 "All info pages on system.
5430 Will be calculated the first time you invoke anything with this
5431 source.")
5433 (defun anything-c-info-pages-init ()
5434 "Collect candidates for initial Info node Top."
5435 (if anything-c-info-pages
5436 anything-c-info-pages
5437 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5438 topics)
5439 (require 'info)
5440 (with-temp-buffer
5441 (Info-find-node "dir" "top")
5442 (goto-char (point-min))
5443 (while (re-search-forward info-topic-regexp nil t)
5444 (push (match-string-no-properties 1) topics))
5445 (kill-buffer))
5446 (setq anything-c-info-pages topics))))
5448 (defvar anything-c-source-info-pages
5449 `((name . "Info Pages")
5450 (init . anything-c-info-pages-init)
5451 (candidates . anything-c-info-pages)
5452 (action . (("Show with Info" .(lambda (node-str)
5453 (info (replace-regexp-in-string
5454 "^[^:]+: " "" node-str))))))
5455 (requires-pattern . 2)))
5456 ;; (anything 'anything-c-source-info-pages)
5459 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5460 (defun anything-c-describe-attributes (anything-attribute)
5461 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5462 Same as `anything-describe-anything-attribute' but with anything completion."
5463 (interactive (list (intern
5464 (anything-comp-read
5465 "Describe anything attribute: "
5466 (mapcar 'symbol-name anything-additional-attributes)
5467 :must-match t
5468 :persistent-action
5469 #'(lambda (candidate)
5470 (with-output-to-temp-buffer "*Help*"
5471 (princ (get (intern candidate) 'anything-attrdoc))))))))
5472 (with-output-to-temp-buffer "*Help*"
5473 (princ (get anything-attribute 'anything-attrdoc))))
5476 ;;; Use info-index plug-in.
5479 ;; Note that `name' attribute is not needed since
5480 ;; `anything-c-insert-summary' have been removed.
5481 ;; Info Elisp
5482 (defvar anything-c-source-info-elisp
5483 '((name . "Info index: elisp")
5484 (info-index . "elisp")))
5485 ;; (anything 'anything-c-source-info-elisp)
5487 ;; Info-Common-Lisp
5488 (defvar anything-c-source-info-cl
5489 '((name . "Info index: cl")
5490 (info-index . "cl")))
5491 ;; (anything 'anything-c-source-info-cl)
5493 ;; Info Index org
5494 (defvar anything-c-source-info-org
5495 '((name . "Info index: org")
5496 (info-index . "org")))
5497 ;; (anything 'anything-c-source-info-org)
5499 ;; Info Index gnus
5500 (defvar anything-c-source-info-gnus
5501 '((name . "Info index: Gnus")
5502 (info-index . "gnus")))
5504 ;; Info Index ratpoison
5505 (defvar anything-c-source-info-ratpoison
5506 '((name . "Info index: ratpoison")
5507 (info-index . "ratpoison")))
5508 ;; (anything 'anything-c-source-info-ratpoison)
5510 ;; Info Index zsh
5511 (defvar anything-c-source-info-zsh
5512 '((name . "Info index: zsh")
5513 (info-index . "zsh")))
5514 ;; (anything 'anything-c-source-info-zsh)
5516 ;; Info Index bash
5517 (defvar anything-c-source-info-bash
5518 '((name . "Info index: bash")
5519 (info-index . "bash")))
5520 ;; (anything 'anything-c-source-info-bash)
5522 ;; Info Index coreutils
5523 (defvar anything-c-source-info-coreutils
5524 '((name . "Info index: coreutils")
5525 (info-index . "coreutils")))
5526 ;; (anything 'anything-c-source-info-coreutils)
5528 ;; Info Index fileutils
5529 (defvar anything-c-source-info-fileutils
5530 '((name . "Info index: fileutils")
5531 (info-index . "fileutils")))
5532 ;; (anything 'anything-c-source-info-fileutils)
5534 ;; Info Index find
5535 (defvar anything-c-source-info-find
5536 '((name . "Info index: find")
5537 (info-index . "find")))
5538 ;; (anything 'anything-c-source-info-find)
5540 ;; Info Index sh-utils
5541 (defvar anything-c-source-info-sh-utils
5542 '((name . "Info index: sh-utils")
5543 (info-index . "sh-utils")))
5544 ;; (anything 'anything-c-source-info-sh-utils)
5546 ;; Info Index textutils
5547 (defvar anything-c-source-info-textutils
5548 '((name . "Info index: textutils")
5549 (info-index . "textutils")))
5550 ;; (anything 'anything-c-source-info-textutils)
5552 ;; Info Index libc
5553 (defvar anything-c-source-info-libc
5554 '((name . "Info index: libc")
5555 (info-index . "libc")))
5556 ;; (anything 'anything-c-source-info-libc)
5558 ;; Info Index make
5559 (defvar anything-c-source-info-make
5560 '((name . "Info index: make")
5561 (info-index . "make")))
5562 ;; (anything 'anything-c-source-info-make)
5564 ;; Info Index automake
5565 (defvar anything-c-source-info-automake
5566 '((name . "Info index: automake")
5567 (info-index . "automake")))
5568 ;; (anything 'anything-c-source-info-automake)
5570 ;; Info Index autoconf
5571 (defvar anything-c-source-info-autoconf
5572 '((name . "Info index: autoconf")
5573 (info-index . "autoconf")))
5574 ;; (anything 'anything-c-source-info-autoconf)
5576 ;; Info Index emacs-lisp-intro
5577 (defvar anything-c-source-info-emacs-lisp-intro
5578 '((name . "Info index: emacs-lisp-intro")
5579 (info-index . "emacs-lisp-intro")))
5580 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5582 ;; Info Index emacs
5583 (defvar anything-c-source-info-emacs
5584 '((name . "Info index: emacs")
5585 (info-index . "emacs")))
5586 ;; (anything 'anything-c-source-info-emacs)
5588 ;; Info Index elib
5589 (defvar anything-c-source-info-elib
5590 '((name . "Info index: elib")
5591 (info-index . "elib")))
5592 ;; (anything 'anything-c-source-info-elib)
5594 ;; Info Index eieio
5595 (defvar anything-c-source-info-eieio
5596 '((name . "Info index: eieio")
5597 (info-index . "eieio")))
5598 ;; (anything 'anything-c-source-info-eieio)
5600 ;; Info Index gauche-refe
5601 (defvar anything-c-source-info-gauche-refe
5602 '((name . "Info index: gauche")
5603 (info-index . "gauche-refe")))
5604 ;; (anything 'anything-c-source-info-gauche-refe)
5606 ;; Info Index guile
5607 (defvar anything-c-source-info-guile
5608 '((name . "Info index: guile")
5609 (info-index . "guile")))
5610 ;; (anything 'anything-c-source-info-guile)
5612 ;; Info Index guile-tut
5613 (defvar anything-c-source-info-guile-tut
5614 '((name . "Info index: guile-tut")
5615 (info-index . "guile-tut")))
5616 ;; (anything 'anything-c-source-info-guile-tut)
5618 ;; Info Index goops
5619 (defvar anything-c-source-info-goops
5620 '((name . "Info index: goops")
5621 (info-index . "goops")))
5622 ;; (anything 'anything-c-source-info-goops)
5624 ;; Info Index screen
5625 (defvar anything-c-source-info-screen
5626 '((name . "Info index: screen")
5627 (info-index . "screen")
5628 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5629 ;; (anything 'anything-c-source-info-screen)
5631 ;; Info Index latex
5632 (defvar anything-c-source-info-latex
5633 '((name . "Info index: latex")
5634 (info-index . "latex")))
5635 ;; (anything 'anything-c-source-info-latex)
5637 ;; Info Index gawk
5638 (defvar anything-c-source-info-gawk
5639 '((name . "Info index: gawk")
5640 (info-index . "gawk")))
5641 ;; (anything 'anything-c-source-info-gawk)
5643 ;; Info Index sed
5644 (defvar anything-c-source-info-sed
5645 '((name . "Info index: sed")
5646 (info-index . "sed")))
5647 ;; (anything 'anything-c-source-info-sed)
5649 ;; Info Index m4
5650 (defvar anything-c-source-info-m4
5651 '((name . "Info index: m4")
5652 (info-index . "m4")))
5653 ;; (anything 'anything-c-source-info-m4)
5655 ;; Info Index wget
5656 (defvar anything-c-source-info-wget
5657 '((name . "Info index: wget")
5658 (info-index . "wget")))
5659 ;; (anything 'anything-c-source-info-wget)
5661 ;; Info Index binutils
5662 (defvar anything-c-source-info-binutils
5663 '((name . "Info index: binutils")
5664 (info-index . "binutils")))
5665 ;; (anything 'anything-c-source-info-binutils)
5667 ;; Info Index as
5668 (defvar anything-c-source-info-as
5669 '((name . "Info index: as")
5670 (info-index . "as")))
5671 ;; (anything 'anything-c-source-info-as)
5673 ;; Info Index bfd
5674 (defvar anything-c-source-info-bfd
5675 '((name . "Info index: bfd")
5676 (info-index . "bfd")))
5677 ;; (anything 'anything-c-source-info-bfd)
5679 ;; Info Index gprof
5680 (defvar anything-c-source-info-gprof
5681 '((name . "Info index: gprof")
5682 (info-index . "gprof")))
5683 ;; (anything 'anything-c-source-info-gprof)
5685 ;; Info Index ld
5686 (defvar anything-c-source-info-ld
5687 '((name . "Info index: ld")
5688 (info-index . "ld")))
5689 ;; (anything 'anything-c-source-info-ld)
5691 ;; Info Index diff
5692 (defvar anything-c-source-info-diff
5693 '((name . "Info index: diff")
5694 (info-index . "diff")))
5695 ;; (anything 'anything-c-source-info-diff)
5697 ;; Info Index flex
5698 (defvar anything-c-source-info-flex
5699 '((name . "Info index: flex")
5700 (info-index . "flex")))
5701 ;; (anything 'anything-c-source-info-flex)
5703 ;; Info Index grep
5704 (defvar anything-c-source-info-grep
5705 '((name . "Info index: grep")
5706 (info-index . "grep")))
5707 ;; (anything 'anything-c-source-info-grep)
5709 ;; Info Index gzip
5710 (defvar anything-c-source-info-gzip
5711 '((name . "Info index: gzip")
5712 (info-index . "gzip")))
5713 ;; (anything 'anything-c-source-info-gzip)
5715 ;; Info Index libtool
5716 (defvar anything-c-source-info-libtool
5717 '((name . "Info index: libtool")
5718 (info-index . "libtool")))
5719 ;; (anything 'anything-c-source-info-libtool)
5721 ;; Info Index texinfo
5722 (defvar anything-c-source-info-texinfo
5723 '((name . "Info index: texinfo")
5724 (info-index . "texinfo")))
5725 ;; (anything 'anything-c-source-info-texinfo)
5727 ;; Info Index info
5728 (defvar anything-c-source-info-info
5729 '((name . "Info index: info")
5730 (info-index . "info")))
5731 ;; (anything 'anything-c-source-info-info)
5733 ;; Info Index gdb
5734 (defvar anything-c-source-info-gdb
5735 '((name . "Info index: gdb")
5736 (info-index . "gdb")))
5737 ;; (anything 'anything-c-source-info-gdb)
5739 ;; Info Index stabs
5740 (defvar anything-c-source-info-stabs
5741 '((name . "Info index: stabs")
5742 (info-index . "stabs")))
5743 ;; (anything 'anything-c-source-info-stabs)
5745 ;; Info Index cvsbook
5746 (defvar anything-c-source-info-cvsbook
5747 '((name . "Info index: cvsbook")
5748 (info-index . "cvsbook")))
5749 ;; (anything 'anything-c-source-info-cvsbook)
5751 ;; Info Index cvs
5752 (defvar anything-c-source-info-cvs
5753 '((name . "Info index: cvs")
5754 (info-index . "cvs")))
5755 ;; (anything 'anything-c-source-info-cvs)
5757 ;; Info Index bison
5758 (defvar anything-c-source-info-bison
5759 '((name . "Info index: bison")
5760 (info-index . "bison")))
5761 ;; (anything 'anything-c-source-info-bison)
5763 ;; Info Index id-utils
5764 (defvar anything-c-source-info-id-utils
5765 '((name . "Info index: id-utils")
5766 (info-index . "id-utils")))
5767 ;; (anything 'anything-c-source-info-id-utils)
5769 ;; Info Index global
5770 (defvar anything-c-source-info-global
5771 '((name . "Info index: global")
5772 (info-index . "global")))
5773 ;; (anything 'anything-c-source-info-global)
5776 ;;; Man and woman UI
5779 (defvar anything-c-man-pages nil
5780 "All man pages on system.
5781 Will be calculated the first time you invoke anything with this
5782 source.")
5784 (defun anything-c-man-default-action (candidate)
5785 "Default action for jumping to a woman or man page from anything."
5786 (let ((wfiles (woman-file-name-all-completions candidate)))
5787 (condition-case err
5788 (if (> (length wfiles) 1)
5789 (woman-find-file
5790 (anything-comp-read
5791 "ManFile: " wfiles :must-match t))
5792 (woman candidate))
5793 ;; If woman is unable to format correctly
5794 ;; use man instead.
5795 (error (kill-buffer) ; Kill woman buffer.
5796 (let ((Man-notify-method 'meek))
5797 (Man-getpage-in-background candidate))))))
5799 (defvar anything-c-source-man-pages
5800 `((name . "Manual Pages")
5801 (candidates . (lambda ()
5802 (if anything-c-man-pages
5803 anything-c-man-pages
5804 ;; XEmacs doesn't have a woman :)
5805 (setq anything-c-man-pages
5806 (ignore-errors
5807 (require 'woman)
5808 (woman-file-name "")
5809 (sort (mapcar 'car woman-topic-all-completions)
5810 'string-lessp))))))
5811 (action ("Show with Woman" . anything-c-man-default-action))
5812 ;; Woman does not work OS X
5813 ;; http://xahlee.org/emacs/modernization_man_page.html
5814 (action-transformer . (lambda (actions candidate)
5815 (if (eq system-type 'darwin)
5816 '(("Show with Man" . man))
5817 actions)))
5818 (requires-pattern . 2)))
5819 ;; (anything 'anything-c-source-man-pages)
5822 ;;;; <Command>
5823 ;;; Anything M-x - Enhanced M-x UI
5826 ;; Another replacement of `M-x' that act exactly like the
5827 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5828 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5829 ;; anything invocation.
5830 ;; Documentation of commands available without quitting,
5831 ;; Show keybindings of commands.
5832 ;; Show history.
5833 (defvar anything-M-x-input-history nil)
5835 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5836 "Return alist of MODE-MAP."
5837 (loop for key being the key-seqs of mode-map using (key-bindings com)
5838 for str-key = (key-description key)
5839 for ismenu = (string-match "<menu-bar>" str-key)
5840 unless ismenu collect (cons str-key com)))
5842 (defun anything-get-mode-map-from-mode (mode)
5843 "Guess the mode-map name according to MODE.
5844 Some modes don't use conventional mode-map name
5845 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5846 Return nil if no mode-map found."
5847 (loop
5848 ;; Start with a conventional mode-map name.
5849 with mode-map = (intern-soft (format "%s-map" mode))
5850 with mode-string = (symbol-name mode)
5851 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5852 while (not mode-map)
5853 for count downfrom (length mode-name)
5854 ;; Return when no result after parsing entire string.
5855 when (eq count 0) return nil
5856 for sub-name = (substring mode-name 0 count)
5857 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5858 finally return mode-map))
5860 (defun anything-M-x-current-mode-map-alist ()
5861 "Return mode-map alist of current `major-mode'."
5862 (let ((map (anything-get-mode-map-from-mode major-mode)))
5863 (when (and map (boundp map))
5864 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5867 (defun anything-M-x-transformer (candidates sources)
5868 "filtered-candidate-transformer to show bindings in emacs commands.
5869 Show global bindings and local bindings according to current `major-mode'."
5870 (with-anything-current-buffer
5871 (loop
5872 with local-map = (anything-M-x-current-mode-map-alist)
5873 for cand in candidates
5874 for local-key = (car (rassq cand local-map))
5875 for key = (substitute-command-keys (format "\\[%s]" cand))
5876 collect
5877 (cons (cond ((and (string-match "^M-x" key) local-key)
5878 (format "%s (%s)"
5879 cand (propertize
5880 local-key
5881 'face 'anything-M-x-key-face)))
5882 ((string-match "^M-x" key) cand)
5883 (t (format "%s (%s)"
5884 cand (propertize
5886 'face 'anything-M-x-key-face))))
5887 cand) into ls
5888 finally return
5889 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5892 ;;; Complex command history
5895 (defvar anything-c-source-complex-command-history
5896 '((name . "Complex Command History")
5897 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5898 (type . sexp)))
5899 ;; (anything 'anything-c-source-complex-command-history)
5901 ;;; M-x history (not related to `anything-M-x')
5904 (defvar anything-c-source-extended-command-history
5905 '((name . "Emacs Commands History")
5906 (candidates . extended-command-history)
5907 (type . command)))
5908 ;; (anything 'anything-c-source-extended-command-history)
5910 ;;; Emacs commands (Basic source for emacs commands)
5913 (defvar anything-c-source-emacs-commands
5914 '((name . "Emacs Commands")
5915 (candidates . (lambda ()
5916 (let (commands)
5917 (mapatoms (lambda (a)
5918 (if (commandp a)
5919 (push (symbol-name a)
5920 commands))))
5921 (sort commands 'string-lessp))))
5922 (type . command)
5923 (requires-pattern . 2))
5924 "Source for completing and invoking Emacs commands.
5925 A command is a function with interactive spec that can
5926 be invoked with `M-x'.
5928 To get non-interactive functions listed, use
5929 `anything-c-source-emacs-functions'.")
5930 ;; (anything 'anything-c-source-emacs-commands)
5933 ;;;; <Function>
5934 ;;; Emacs functions
5937 (defvar anything-c-source-emacs-functions
5938 '((name . "Emacs Functions")
5939 (candidates . (lambda ()
5940 (let (commands)
5941 (mapatoms (lambda (a)
5942 (if (functionp a)
5943 (push (symbol-name a) commands))))
5944 (sort commands 'string-lessp))))
5945 (type . function)
5946 (requires-pattern . 2))
5947 "Source for completing Emacs functions.")
5948 ;; (anything 'anything-c-source-emacs-functions)
5950 ;;; With abbrev expansion
5951 ;;; Similar to my exec-abbrev-cmd.el
5952 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5953 (defvar anything-c-function-abbrev-regexp nil
5954 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5955 Regexp built from the current `anything-pattern' interpreting it
5956 as abbreviation.
5957 Only for internal use.")
5959 (defun anything-c-match-function-by-abbrev (candidate)
5960 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5962 Abbreviations are made by taking the first character from each
5963 word in the function's name, e.g. \"bb\" is an abbrev for
5964 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5965 (string-match anything-c-function-abbrev-regexp candidate))
5967 (defvar anything-c-source-emacs-functions-with-abbrevs
5968 (append anything-c-source-emacs-functions
5969 '((match anything-c-match-function-by-abbrev
5970 anything-c-string-match))
5971 '((init
5972 . (lambda ()
5973 (defadvice anything-update
5974 (before anything-c-update-function-abbrev-regexp activate)
5975 (let ((char-list (append anything-pattern nil))
5976 (str "^"))
5977 (dolist (c char-list)
5978 (setq str (concat str (list c) "[^-]*-")))
5979 (setq str (concat (substring str 0 (1- (length str))) "$"))
5980 (setq anything-c-function-abbrev-regexp str))))))))
5981 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5983 (defvar anything-c-source-advice
5984 '((name . "Function Advice")
5985 (candidates . anything-c-advice-candidates)
5986 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5987 (persistent-action . anything-c-advice-persistent-action)
5988 (multiline)
5989 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5990 ;; (anything 'anything-c-source-advice)
5991 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5992 ;; (testadvice)
5994 (defun anything-c-advice-candidates ()
5995 (require 'advice)
5996 (loop for (fname) in ad-advised-functions
5997 for function = (intern fname)
5998 append
5999 (loop for class in ad-advice-classes append
6000 (loop for advice in (ad-get-advice-info-field function class)
6001 for enabled = (ad-advice-enabled advice)
6002 collect
6003 (cons (format
6004 "%s %s %s"
6005 (if enabled "Enabled " "Disabled")
6006 (propertize fname 'face 'font-lock-function-name-face)
6007 (ad-make-single-advice-docstring advice class nil))
6008 (list function class advice))))))
6010 (defun anything-c-advice-persistent-action (func-class-advice)
6011 (if current-prefix-arg
6012 (anything-c-advice-toggle func-class-advice)
6013 (describe-function (car func-class-advice))))
6015 (defun anything-c-advice-toggle (func-class-advice)
6016 (destructuring-bind (function class advice) func-class-advice
6017 (cond ((ad-advice-enabled advice)
6018 (ad-advice-set-enabled advice nil)
6019 (message "Disabled"))
6020 (t ;disabled
6021 (ad-advice-set-enabled advice t)
6022 (message "Enabled")))
6023 (ad-activate function)
6024 (and anything-in-persistent-action
6025 (anything-c-advice-update-current-display-string))))
6027 (defun anything-c-advice-update-current-display-string ()
6028 (anything-edit-current-selection
6029 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6030 ((looking-at "Enabled") "Disabled")))
6031 realvalue)
6032 (when newword
6033 (delete-region (point) (progn (forward-word 1) (point)))
6034 (insert newword)))))
6037 ;;;; <Variable>
6038 ;;; Emacs variables
6041 (defvar anything-c-source-emacs-variables
6042 '((name . "Emacs Variables")
6043 (candidates . (lambda ()
6044 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6045 (type . variable)
6046 (requires-pattern . 2))
6047 "Source for completing Emacs variables.")
6048 ;; (anything 'anything-c-source-emacs-variables)
6051 ;;; LaCarte
6052 (defvar anything-c-source-lacarte
6053 '((name . "Lacarte")
6054 (init . (lambda () (require 'lacarte )))
6055 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6056 (candidate-number-limit . 9999)
6057 (action . anything-c-call-interactively))
6058 "Needs lacarte.el.
6060 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6061 ;; (anything 'anything-c-source-lacarte)
6064 ;;; Bookmarks
6067 ;; Bind some faces for bookmarks.
6068 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6069 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6070 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6072 (eval-when-compile (require 'bookmark))
6073 (defvar anything-c-source-bookmarks
6074 '((name . "Bookmarks")
6075 (init . (lambda ()
6076 (require 'bookmark)))
6077 (candidates . bookmark-all-names)
6078 (type . bookmark))
6079 "See (info \"(emacs)Bookmarks\").")
6080 ;; (anything 'anything-c-source-bookmarks)
6082 ;;; bookmark-set
6083 (defvar anything-c-source-bookmark-set
6084 '((name . "Set Bookmark")
6085 (dummy)
6086 (action . bookmark-set))
6087 "See (info \"(emacs)Bookmarks\").")
6088 ;; (anything 'anything-c-source-bookmark-set)
6090 ;;; Visible Bookmarks
6091 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6094 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6095 (defvar anything-c-source-bm
6096 '((name . "Visible Bookmarks")
6097 (init . anything-c-bm-init)
6098 (candidates-in-buffer)
6099 (type . line))
6100 "Needs bm.el.
6102 http://www.nongnu.org/bm/")
6104 (defun anything-c-bm-init ()
6105 "Init function for `anything-c-source-bm'."
6106 (when (require 'bm nil t)
6107 (with-no-warnings
6108 (let ((bookmarks (bm-lists))
6109 (buf (anything-candidate-buffer 'global)))
6110 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6111 '< :key 'overlay-start))
6112 (let ((start (overlay-start bm))
6113 (end (overlay-end bm))
6114 (annotation (or (overlay-get bm 'annotation) "")))
6115 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6116 (let ((str (format "%5d: [%s]: %s\n"
6117 (line-number-at-pos start)
6118 annotation
6119 (buffer-substring start (1- end)))))
6120 (with-current-buffer buf (insert str))))))))))
6122 ;;; Special bookmarks
6123 (defvar anything-c-source-bookmarks-ssh
6124 '((name . "Bookmarks-ssh")
6125 (init . (lambda ()
6126 (require 'bookmark)))
6127 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6128 (type . bookmark))
6129 "See (info \"(emacs)Bookmarks\").")
6130 ;; (anything 'anything-c-source-bookmarks-ssh)
6132 (defvar anything-c-source-bookmarks-su
6133 '((name . "Bookmarks-root")
6134 (init . (lambda ()
6135 (require 'bookmark)))
6136 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6137 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6139 (type . bookmark))
6140 "See (info \"(emacs)Bookmarks\").")
6141 ;; (anything 'anything-c-source-bookmarks-su)
6143 (defvar anything-c-source-bookmarks-local
6144 '((name . "Bookmarks-Local")
6145 (init . (lambda ()
6146 (require 'bookmark)))
6147 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6148 (filtered-candidate-transformer
6149 anything-c-adaptive-sort
6150 anything-c-highlight-bookmark)
6151 (type . bookmark))
6152 "See (info \"(emacs)Bookmarks\").")
6153 ;; (anything 'anything-c-source-bookmarks-local)
6155 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6156 (let* ((lis-all (bookmark-all-names))
6157 (lis-loc (cond (local (loop for i in lis-all
6158 unless (string-match "^(ssh)\\|^(su)" i)
6159 collect i))
6160 (su (loop for i in lis-all
6161 when (string-match "^(su)" i)
6162 collect i))
6163 (sudo (loop for i in lis-all
6164 when (string-match "^(sudo)" i)
6165 collect i))
6166 (ssh (loop for i in lis-all
6167 when (string-match "^(ssh)" i)
6168 collect i)))))
6169 (sort lis-loc 'string-lessp)))
6171 (defun anything-c-bookmark-root-logged-p ()
6172 (catch 'break
6173 (dolist (i (mapcar #'buffer-name (buffer-list)))
6174 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6175 (throw 'break t)))))
6177 (defun anything-c-highlight-bookmark-su (files source)
6178 (if (anything-c-bookmark-root-logged-p)
6179 (anything-c-highlight-bookmark files source)
6180 (anything-c-highlight-not-logged files source)))
6182 (defun anything-c-highlight-not-logged (files source)
6183 (loop for i in files
6184 collect (propertize i 'face anything-c-bookmarks-face3)))
6186 (defun anything-c-highlight-bookmark (bookmarks source)
6187 "Used as `candidate-transformer' to colorize bookmarks.
6188 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6189 (loop for i in bookmarks
6190 for isfile = (bookmark-get-filename i)
6191 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6192 (bmkext-get-buffer-name i))
6193 for handlerp = (and (fboundp 'bookmark-get-handler)
6194 (bookmark-get-handler i))
6195 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6196 (bmkext-w3m-bookmark-p i))
6197 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6198 (bmkext-gnus-bookmark-p i))
6199 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6200 (bmkext-man-bookmark-p i))
6201 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6202 (bmkext-woman-bookmark-p i))
6203 for handlerp = (bookmark-get-handler i)
6204 for isannotation = (bookmark-get-annotation i)
6205 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6206 for isinfo = (eq handlerp 'Info-bookmark-jump)
6207 ;; Add a * if bookmark have annotation
6208 if (and isannotation (not (string-equal isannotation "")))
6209 do (setq i (concat "*" i))
6210 collect (cond (;; info buffers
6211 isinfo
6212 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6213 (;; w3m buffers
6214 isw3m
6215 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6216 (;; gnus buffers
6217 isgnus
6218 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6219 (;; Man Woman
6220 (or iswoman isman)
6221 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6222 (;; Addressbook
6223 isabook
6224 (propertize i 'face '((:foreground "Tomato"))))
6225 (;; directories
6226 (and isfile (file-directory-p isfile))
6227 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6228 (;; regular files
6230 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6234 ;;; Sources to filter bookmark-extensions bookmarks.
6237 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6238 ;; If you want to enable google-maps in addressbook you will need
6239 ;; Julien Danjou google-maps-el package available here:
6240 ;; http://julien.danjou.info/google-maps-el.html
6242 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6243 "Return a filtered `bookmark-alist' sorted alphabetically."
6244 (loop
6245 with alist = (if args
6246 (apply #'(lambda (x) (funcall fn x)) args)
6247 (funcall fn))
6248 for i in alist
6249 for b = (car i)
6250 collect b into sa
6251 finally return (sort sa 'string-lessp)))
6253 ;;; Addressbook.
6256 (defvar anything-c-source-bmkext-addressbook
6257 '((name . "Bookmark Addressbook")
6258 (init . (lambda ()
6259 (require 'bookmark-extensions)
6260 (bookmark-maybe-load-default-file)))
6261 (candidates . anything-c-bmkext-addressbook-setup-alist)
6262 (persistent-action
6263 . (lambda (candidate)
6264 (let ((bmk (anything-bookmark-get-bookmark-from-name
6265 candidate)))
6266 (bookmark--jump-via bmk 'pop-to-buffer))))
6267 (persistent-help . "Show contact - Prefix with C-u to append")
6268 (filtered-candidate-transformer
6269 anything-c-adaptive-sort
6270 anything-c-highlight-bookmark)
6271 (action . (("Show Contact(s)"
6272 . (lambda (candidate)
6273 (let* ((contacts (anything-marked-candidates))
6274 (current-prefix-arg (or anything-current-prefix-arg
6275 (> (length contacts) 1))))
6276 (bookmark-jump
6277 (anything-bookmark-get-bookmark-from-name (car contacts)))
6278 (anything-aif (cdr contacts)
6279 (loop for bmk in it do
6280 (bookmark-jump
6281 (anything-bookmark-get-bookmark-from-name bmk)))))))
6282 ("Send Mail"
6283 . (lambda (candidate)
6284 (let* ((contacts (anything-marked-candidates))
6285 (bmk (anything-bookmark-get-bookmark-from-name
6286 (car contacts)))
6287 (append (message-buffers)))
6288 (if append
6289 (addressbook-set-mail-buffer1 bmk 'append)
6290 (addressbook-set-mail-buffer1 bmk))
6291 (setq contacts (cdr contacts))
6292 (when contacts
6293 (loop for bmk in contacts do
6294 (addressbook-set-mail-buffer1 bmk 'append))))))
6295 ("Edit Bookmark"
6296 . (lambda (candidate)
6297 (let ((bmk (anything-bookmark-get-bookmark-from-name
6298 candidate)))
6299 (addressbook-bookmark-edit
6300 (assoc bmk bookmark-alist)))))
6301 ("Insert Email at point"
6302 . (lambda (candidate)
6303 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6304 candidate))
6305 (mlist (split-string
6306 (assoc-default
6307 'email (assoc bmk bookmark-alist))
6308 ", ")))
6309 (insert
6310 (if (> (length mlist) 1)
6311 (anything-comp-read
6312 "Insert Mail Address: " mlist :must-match t)
6313 (car mlist))))))
6314 ("Show annotation"
6315 . (lambda (candidate)
6316 (let ((bmk (anything-bookmark-get-bookmark-from-name
6317 candidate)))
6318 (bookmark-show-annotation bmk))))
6319 ("Edit annotation"
6320 . (lambda (candidate)
6321 (let ((bmk (anything-bookmark-get-bookmark-from-name
6322 candidate)))
6323 (bookmark-edit-annotation bmk))))
6324 ("Show Google map"
6325 . (lambda (candidate)
6326 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6327 candidate))
6328 (full-bmk (assoc bmk bookmark-alist)))
6329 (addressbook-google-map full-bmk))))))))
6332 (defun anything-c-bmkext-addressbook-setup-alist ()
6333 "Specialized filter function for bookmarks w3m."
6334 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6336 ;; W3m bookmarks from bookmark-extensions.
6337 (defvar anything-c-source-bookmark-w3m
6338 '((name . "Bookmark W3m")
6339 (init . (lambda ()
6340 (require 'bookmark-extensions)
6341 (bookmark-maybe-load-default-file)))
6342 (candidates . anything-c-bookmark-w3m-setup-alist)
6343 (filtered-candidate-transformer
6344 anything-c-adaptive-sort
6345 anything-c-highlight-bookmark)
6346 (type . bookmark)))
6347 ;; (anything 'anything-c-source-bookmark-w3m)
6349 (defun anything-c-bookmark-w3m-setup-alist ()
6350 "Specialized filter function for bookmarks w3m."
6351 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6353 ;; Images
6354 (defvar anything-c-source-bookmark-images
6355 '((name . "Bookmark Images")
6356 (init . (lambda ()
6357 (require 'bookmark-extensions)
6358 (bookmark-maybe-load-default-file)))
6359 (candidates . anything-c-bookmark-images-setup-alist)
6360 (filtered-candidate-transformer
6361 anything-c-adaptive-sort
6362 anything-c-highlight-bookmark)
6363 (type . bookmark)))
6364 ;; (anything 'anything-c-source-bookmark-images)
6366 (defun anything-c-bookmark-images-setup-alist ()
6367 "Specialized filter function for images bookmarks."
6368 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6370 ;; Woman Man
6371 (defvar anything-c-source-bookmark-man
6372 '((name . "Bookmark Woman&Man")
6373 (init . (lambda ()
6374 (require 'bookmark-extensions)
6375 (bookmark-maybe-load-default-file)))
6376 (candidates . anything-c-bookmark-man-setup-alist)
6377 (filtered-candidate-transformer
6378 anything-c-adaptive-sort
6379 anything-c-highlight-bookmark)
6380 (type . bookmark)))
6381 ;; (anything 'anything-c-source-bookmark-man)
6383 (defun anything-c-bookmark-man-setup-alist ()
6384 "Specialized filter function for bookmarks w3m."
6385 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6386 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6388 ;; Gnus
6389 (defvar anything-c-source-bookmark-gnus
6390 '((name . "Bookmark Gnus")
6391 (init . (lambda ()
6392 (require 'bookmark-extensions)
6393 (bookmark-maybe-load-default-file)))
6394 (candidates . anything-c-bookmark-gnus-setup-alist)
6395 (filtered-candidate-transformer
6396 anything-c-adaptive-sort
6397 anything-c-highlight-bookmark)
6398 (type . bookmark)))
6399 ;; (anything 'anything-c-source-bookmark-gnus)
6401 (defun anything-c-bookmark-gnus-setup-alist ()
6402 "Specialized filter function for bookmarks gnus."
6403 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6405 ;; Info
6406 (defvar anything-c-source-bookmark-info
6407 '((name . "Bookmark Info")
6408 (init . (lambda ()
6409 (require 'bookmark-extensions)
6410 (bookmark-maybe-load-default-file)))
6411 (candidates . anything-c-bookmark-info-setup-alist)
6412 (filtered-candidate-transformer
6413 anything-c-adaptive-sort
6414 anything-c-highlight-bookmark)
6415 (type . bookmark)))
6416 ;; (anything 'anything-c-source-bookmark-info)
6418 (defun anything-c-bookmark-info-setup-alist ()
6419 "Specialized filter function for bookmarks info."
6420 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6422 ;; Local Files&directories
6423 (defvar anything-c-source-bookmark-files&dirs
6424 '((name . "Bookmark Files&Directories")
6425 (init . (lambda ()
6426 (require 'bookmark-extensions)
6427 (bookmark-maybe-load-default-file)))
6428 (candidates . anything-c-bookmark-local-files-setup-alist)
6429 (filtered-candidate-transformer
6430 anything-c-adaptive-sort
6431 anything-c-highlight-bookmark)
6432 (type . bookmark)))
6433 ;; (anything 'anything-c-source-bookmark-files&dirs)
6435 (defun anything-c-bookmark-local-files-setup-alist ()
6436 "Specialized filter function for bookmarks locals files."
6437 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6439 ;; Su Files&directories
6440 (defvar anything-c-source-bookmark-su-files&dirs
6441 '((name . "Bookmark Root-Files&Directories")
6442 (init . (lambda ()
6443 (require 'bookmark-extensions)
6444 (bookmark-maybe-load-default-file)))
6445 (candidates . anything-c-bookmark-su-files-setup-alist)
6446 (filtered-candidate-transformer
6447 anything-c-adaptive-sort
6448 anything-c-highlight-bookmark-su)
6449 (type . bookmark)))
6450 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6452 (defun anything-c-bookmark-su-files-setup-alist ()
6453 "Specialized filter function for bookmarks su/sudo files."
6454 (declare (special bmkext-su-or-sudo-regexp))
6455 (loop
6456 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6457 for i in l
6458 for isfile = (bookmark-get-filename i)
6459 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6460 (save-match-data
6461 (string-match tramp-file-name-regexp isfile)))
6462 for issu = (and istramp
6463 (string-match bmkext-su-or-sudo-regexp isfile))
6464 if issu
6465 collect i))
6467 ;; Ssh Files&directories
6468 (defvar anything-c-source-bookmark-ssh-files&dirs
6469 '((name . "Bookmark Ssh-Files&Directories")
6470 (init . (lambda ()
6471 (require 'bookmark-extensions)
6472 (bookmark-maybe-load-default-file)))
6473 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6474 (filtered-candidate-transformer . anything-c-adaptive-sort)
6475 (type . bookmark)))
6476 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6478 (defun anything-c-bookmark-ssh-files-setup-alist ()
6479 "Specialized filter function for bookmarks ssh files."
6480 (loop
6481 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6482 for i in l
6483 for isfile = (bookmark-get-filename i)
6484 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6485 (save-match-data
6486 (string-match tramp-file-name-regexp isfile)))
6487 for isssh = (and istramp
6488 (string-match "/ssh:" isfile))
6489 if isssh
6490 collect i))
6494 ;;; Firefox bookmarks
6497 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6498 ;; (only for firefox versions >=3)
6499 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6500 ;; to true:
6501 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6502 ;; You should have now:
6503 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6505 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6506 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6508 (defun anything-get-firefox-user-init-dir ()
6509 "Guess the default Firefox user directory name."
6510 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6511 (moz-user-dir
6512 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6513 (goto-char (point-min))
6514 (prog1
6515 (when (search-forward "Path=" nil t)
6516 (buffer-substring-no-properties (point) (point-at-eol)))
6517 (kill-buffer)))))
6518 (file-name-as-directory (concat moz-dir moz-user-dir))))
6520 (defun anything-guess-firefox-bookmark-file ()
6521 "Return the path of the Firefox bookmarks file."
6522 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6524 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6525 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6526 (let (bookmarks-alist url title)
6527 (with-temp-buffer
6528 (insert-file-contents file)
6529 (goto-char (point-min))
6530 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6531 (forward-line 0)
6532 (when (re-search-forward url-regexp nil t)
6533 (setq url (match-string 0)))
6534 (when (re-search-forward bmk-regexp nil t)
6535 (setq title (match-string 1)))
6536 (push (cons title url) bookmarks-alist)
6537 (forward-line)))
6538 (nreverse bookmarks-alist)))
6540 (defvar anything-c-firefox-bookmarks-alist nil)
6541 (defvar anything-c-source-firefox-bookmarks
6542 '((name . "Firefox Bookmarks")
6543 (init . (lambda ()
6544 (setq anything-c-firefox-bookmarks-alist
6545 (anything-html-bookmarks-to-alist
6546 (anything-guess-firefox-bookmark-file)
6547 anything-firefox-bookmark-url-regexp
6548 anything-firefox-bookmarks-regexp))))
6549 (candidates . (lambda ()
6550 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6551 (filtered-candidate-transformer
6552 anything-c-adaptive-sort
6553 anything-c-highlight-firefox-bookmarks)
6554 (action . (("Browse Url Firefox"
6555 . (lambda (candidate)
6556 (browse-url-firefox
6557 (anything-c-firefox-bookmarks-get-value candidate))))
6558 ("Browse Url w3m"
6559 . (lambda (candidate)
6560 (w3m-browse-url
6561 (anything-c-firefox-bookmarks-get-value candidate))))
6562 ("Copy Url"
6563 . (lambda (elm)
6564 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6566 ;; (anything 'anything-c-source-firefox-bookmarks)
6568 (defun anything-c-firefox-bookmarks-get-value (elm)
6569 (assoc-default elm anything-c-firefox-bookmarks-alist))
6571 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6572 (loop for i in bookmarks
6573 collect (propertize
6574 i 'face '((:foreground "YellowGreen"))
6575 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6579 ;;; W3m bookmark - anything interface.
6582 ;; Some users have the emacs-w3m library in load-path
6583 ;; without having the w3m executable :-;
6584 ;; So check if w3m program is present before trying to load
6585 ;; emacs-w3m.
6586 (eval-when-compile
6587 (when (executable-find "w3m")
6588 (require 'w3m-bookmark nil t)))
6590 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6591 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6592 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6593 (defvar anything-c-w3m-bookmarks-alist nil)
6594 (defvar anything-c-source-w3m-bookmarks
6595 '((name . "W3m Bookmarks")
6596 (init . (lambda ()
6597 (setq anything-c-w3m-bookmarks-alist
6598 (anything-html-bookmarks-to-alist
6599 w3m-bookmark-file
6600 anything-w3m-bookmark-url-regexp
6601 anything-w3m-bookmarks-regexp))))
6602 (candidates . (lambda ()
6603 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6604 (filtered-candidate-transformer
6605 anything-c-adaptive-sort
6606 anything-c-highlight-w3m-bookmarks)
6607 (action . (("Browse Url"
6608 . (lambda (candidate)
6609 (anything-c-w3m-browse-bookmark candidate)))
6610 ("Copy Url"
6611 . (lambda (elm)
6612 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6613 ("Browse Url Firefox"
6614 . (lambda (candidate)
6615 (anything-c-w3m-browse-bookmark candidate t)))
6616 ("Delete Bookmark"
6617 . (lambda (candidate)
6618 (anything-c-w3m-delete-bookmark candidate)))
6619 ("Rename Bookmark"
6620 . (lambda (candidate)
6621 (anything-c-w3m-rename-bookmark candidate)))))
6622 (persistent-action . (lambda (candidate)
6623 (if current-prefix-arg
6624 (anything-c-w3m-browse-bookmark candidate t)
6625 (anything-c-w3m-browse-bookmark candidate nil t))))
6626 (persistent-help . "Open URL with emacs-w3m in new tab / \
6627 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6628 "Needs w3m and emacs-w3m.
6630 http://w3m.sourceforge.net/
6631 http://emacs-w3m.namazu.org/")
6633 ;; (anything 'anything-c-source-w3m-bookmarks)
6635 (defun anything-c-w3m-bookmarks-get-value (elm)
6636 (replace-regexp-in-string
6637 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6639 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6640 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6641 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6642 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6644 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6645 (loop for i in bookmarks
6646 collect (propertize
6647 i 'face 'anything-w3m-bookmarks-face
6648 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6651 (defun anything-c-w3m-delete-bookmark (elm)
6652 "Delete w3m bookmark from `w3m-bookmark-file'."
6653 (with-current-buffer
6654 (find-file-literally w3m-bookmark-file)
6655 (goto-char (point-min))
6656 (when (re-search-forward elm nil t)
6657 (beginning-of-line)
6658 (delete-region (point)
6659 (line-end-position))
6660 (delete-blank-lines))
6661 (save-buffer)
6662 (kill-buffer)))
6664 (defun anything-c-w3m-rename-bookmark (elm)
6665 "Rename w3m bookmark in `w3m-bookmark-file'."
6666 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6667 (new-title (read-string "NewTitle: " old-title)))
6668 (with-current-buffer
6669 (find-file-literally w3m-bookmark-file)
6670 (goto-char (point-min))
6671 (when (re-search-forward (concat elm "<") nil t)
6672 (goto-char (1- (point)))
6673 (delete-char (- (length old-title)))
6674 (insert new-title))
6675 (save-buffer)
6676 (kill-buffer))))
6679 ;;;; <Library>
6680 ;;; Elisp library scan
6683 (defvar anything-c-source-elisp-library-scan
6684 '((name . "Elisp libraries (Scan)")
6685 (init . (anything-c-elisp-library-scan-init))
6686 (candidates-in-buffer)
6687 (action ("Find library"
6688 . (lambda (candidate) (find-file (find-library-name candidate))))
6689 ("Find library other window"
6690 . (lambda (candidate)
6691 (find-file-other-window (find-library-name candidate))))
6692 ("Load library"
6693 . (lambda (candidate) (load-library candidate))))))
6694 ;; (anything 'anything-c-source-elisp-library-scan)
6696 (defun anything-c-elisp-library-scan-init ()
6697 "Init anything buffer status."
6698 (let ((anything-buffer (anything-candidate-buffer 'global))
6699 (library-list (anything-c-elisp-library-scan-list)))
6700 (with-current-buffer anything-buffer
6701 (dolist (library library-list)
6702 (insert (format "%s\n" library))))))
6704 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6705 "Do completion for file names passed to `locate-file'.
6706 DIRS is directory to search path.
6707 STRING is string to match."
6708 ;; Use `load-path' as path when ignore `dirs'.
6709 (or dirs (setq dirs load-path))
6710 ;; Init with blank when ignore `string'.
6711 (or string (setq string ""))
6712 ;; Get library list.
6713 (let ((string-dir (file-name-directory string))
6714 ;; File regexp that suffix match `load-file-rep-suffixes'.
6715 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6716 name
6717 names)
6718 (dolist (dir dirs)
6719 (unless dir
6720 (setq dir default-directory))
6721 (if string-dir
6722 (setq dir (expand-file-name string-dir dir)))
6723 (when (file-directory-p dir)
6724 (dolist (file (file-name-all-completions
6725 (file-name-nondirectory string) dir))
6726 ;; Suffixes match `load-file-rep-suffixes'.
6727 (setq name (if string-dir (concat string-dir file) file))
6728 (if (string-match match-regexp name)
6729 (add-to-list 'names name)))))
6730 names))
6733 ;;;; <Programming>
6737 ;;; Imenu
6740 (defvar anything-c-imenu-delimiter " / ")
6742 (defvar anything-c-imenu-index-filter nil)
6743 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6745 (defvar anything-c-cached-imenu-alist nil)
6746 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6748 (defvar anything-c-cached-imenu-candidates nil)
6749 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6751 (defvar anything-c-cached-imenu-tick nil)
6752 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6754 (eval-when-compile (require 'imenu))
6755 (setq imenu-auto-rescan t)
6757 (defun anything-imenu-create-candidates (entry)
6758 "Create candidates with ENTRY."
6759 (if (listp (cdr entry))
6760 (mapcan
6761 (lambda (sub)
6762 (if (consp (cdr sub))
6763 (mapcar
6764 (lambda (subentry)
6765 (concat (car entry) anything-c-imenu-delimiter subentry))
6766 (anything-imenu-create-candidates sub))
6767 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6768 (cdr entry))
6769 (list entry)))
6771 (defvar anything-c-source-imenu
6772 '((name . "Imenu")
6773 (init . (lambda () (require 'imenu)))
6774 (candidates . anything-c-imenu-candidates)
6775 (persistent-action . (lambda (elm)
6776 (anything-c-imenu-default-action elm)
6777 (unless (fboundp 'semantic-imenu-tag-overlay)
6778 (anything-match-line-color-current-line))))
6779 (persistent-help . "Show this entry")
6780 (action . anything-c-imenu-default-action))
6781 "See (info \"(emacs)Imenu\")")
6783 ;; (anything 'anything-c-source-imenu)
6785 (defun anything-c-imenu-candidates ()
6786 (with-anything-current-buffer
6787 (let ((tick (buffer-modified-tick)))
6788 (if (eq anything-c-cached-imenu-tick tick)
6789 anything-c-cached-imenu-candidates
6790 (setq imenu--index-alist nil)
6791 (setq anything-c-cached-imenu-tick tick
6792 anything-c-cached-imenu-candidates
6793 (ignore-errors
6794 (mapcan
6795 'anything-imenu-create-candidates
6796 (setq anything-c-cached-imenu-alist
6797 (let ((index (imenu--make-index-alist)))
6798 (if anything-c-imenu-index-filter
6799 (funcall anything-c-imenu-index-filter index)
6800 index))))))
6801 (setq anything-c-cached-imenu-candidates
6802 (mapcar #'(lambda (x)
6803 (if (stringp x)
6805 (car x)))
6806 anything-c-cached-imenu-candidates))))))
6808 (setq imenu-default-goto-function 'imenu-default-goto-function)
6809 (defun anything-c-imenu-default-action (elm)
6810 "The default action for `anything-c-source-imenu'."
6811 (let ((path (split-string elm anything-c-imenu-delimiter))
6812 (alist anything-c-cached-imenu-alist))
6813 (dolist (elm path)
6814 (setq alist (assoc elm alist)))
6815 (imenu alist)))
6819 ;;; Ctags
6822 (defvar anything-c-ctags-modes
6823 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6824 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6825 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6827 (defun anything-c-source-ctags-init ()
6828 (when (and buffer-file-name
6829 (memq major-mode anything-c-ctags-modes)
6830 (anything-current-buffer-is-modified))
6831 (with-current-buffer (anything-candidate-buffer 'local)
6832 (call-process-shell-command
6833 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6834 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6835 anything-buffer-file-name)
6836 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6837 nil (current-buffer))
6838 (goto-char (point-min))
6839 (forward-line 2)
6840 (delete-region (point-min) (point))
6841 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6842 for lineno-start = (point)
6843 for lineno = (buffer-substring
6844 lineno-start
6845 (1- (search-forward "," (point-at-eol) t)))
6847 (beginning-of-line)
6848 (insert (format "%5s:" lineno))
6849 (search-forward "\177" (point-at-eol) t)
6850 (delete-region (1- (point)) (point-at-eol))
6851 (forward-line 1)))))
6853 (defvar anything-c-source-ctags
6854 '((name . "Exuberant ctags")
6855 (init . anything-c-source-ctags-init)
6856 (candidates-in-buffer)
6857 (adjust)
6858 (type . line))
6859 "Needs Exuberant Ctags.
6861 http://ctags.sourceforge.net/")
6862 ;; (anything 'anything-c-source-ctags)
6865 ;;; Etags
6868 ;; anything-etags.el is deprecated, if this file is found,
6869 ;; warn user at compile time.
6870 (eval-when-compile
6871 (when (locate-library "anything-etags.el")
6872 (display-warning
6873 '(anything-config)
6874 "You are using obsolete library `anything-etags.el' and should remove it."
6875 :warning)))
6877 (defvar anything-c-etags-tag-file-dir nil
6878 "Etags file directory.")
6879 (defvar anything-c-etags-mtime-alist nil
6880 "Store the last modification time of etags files here.")
6881 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6882 "Cache content of etags files used here for faster access.")
6884 (defun anything-c-etags-get-tag-file (&optional directory)
6885 "Return the path of etags file if found."
6886 ;; Get tag file from `default-directory' or upper directory.
6887 (let ((current-dir (anything-c-etags-find-tag-file-directory
6888 (or directory default-directory))))
6889 ;; Return nil if not find tag file.
6890 (when current-dir
6891 ;; Set tag file directory.
6892 (setq anything-c-etags-tag-file-dir current-dir)
6893 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6895 (defun anything-c-etags-find-tag-file-directory (current-dir)
6896 "Try to find the directory containing tag file.
6897 If not found in CURRENT-DIR search in upper directory."
6898 (flet ((file-exists? (dir)
6899 (let ((tag-path (expand-file-name
6900 anything-c-etags-tag-file-name dir)))
6901 (and (stringp tag-path)
6902 (file-exists-p tag-path)
6903 (file-readable-p tag-path)))))
6904 (loop with count = 0
6905 until (file-exists? current-dir)
6906 ;; Return nil if outside the value of
6907 ;; `anything-c-etags-tag-file-search-limit'.
6908 if (= count anything-c-etags-tag-file-search-limit)
6909 do (return nil)
6910 ;; Or search upper directories.
6911 else
6912 do (incf count)
6913 (setq current-dir (expand-file-name (concat current-dir "../")))
6914 finally return current-dir)))
6916 (defun anything-c-source-etags-header-name (x)
6917 "Create header name for this anything etags session."
6918 (concat "Etags in "
6919 (with-anything-current-buffer
6920 (anything-c-etags-get-tag-file))))
6922 (defmacro anything-c-etags-create-buffer (file)
6923 "Create the `anything-buffer' based on contents of etags tag FILE."
6924 `(let* ((tag-fname ,file)
6926 (split (with-current-buffer (find-file-noselect tag-fname)
6927 (prog1
6928 (split-string (buffer-string) "\n" 'omit-nulls)
6929 (setq max (line-number-at-pos (point-max)))
6930 (kill-buffer))))
6931 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6932 (loop
6933 with fname
6934 with cand
6935 for i in split for count from 0
6936 for elm = (unless (string-match "^\x0c" i)
6937 (anything-aif (string-match "\177" i)
6938 (substring i 0 it)
6940 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6941 (setq fname (match-string 1 elm)))
6942 (elm (setq cand (concat fname ": " elm)))
6943 (t (setq cand nil)))
6944 when cand do (progn
6945 (insert (concat cand "\n"))
6946 (progress-reporter-update progress-reporter count)))))
6948 (defun anything-c-etags-init ()
6949 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6950 If no entry in cache, create one."
6951 (let ((tagfile (anything-c-etags-get-tag-file)))
6952 (when tagfile
6953 (with-current-buffer (anything-candidate-buffer 'global)
6954 (anything-aif (gethash tagfile anything-c-etags-cache)
6955 ;; An entry is present in cache, insert it.
6956 (insert it)
6957 ;; No entry, create a new buffer using content of tag file (slower).
6958 (anything-c-etags-create-buffer tagfile)
6959 ;; Store content of buffer in cache.
6960 (puthash tagfile (buffer-string) anything-c-etags-cache)
6961 ;; Store or set the last modification of tag file.
6962 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6963 ;; If an entry exists modify it.
6964 (setcdr it (anything-c-etags-mtime tagfile))
6965 ;; No entry create a new one.
6966 (add-to-list 'anything-c-etags-mtime-alist
6967 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6969 (defvar anything-c-source-etags-select
6970 '((name . "Etags")
6971 (header-name . anything-c-source-etags-header-name)
6972 (init . anything-c-etags-init)
6973 (candidates-in-buffer)
6974 (search . (anything-c-etags-search-fn))
6975 (mode-line . anything-etags-mode-line-string)
6976 (action . anything-c-etags-default-action)
6977 (persistent-action . (lambda (candidate)
6978 (anything-c-etags-default-action candidate)
6979 (anything-match-line-color-current-line))))
6980 "Anything source for Etags.")
6982 (defun anything-c-etags-search-fn (pattern)
6983 "Search function for `anything-c-source-etags-select'."
6984 (re-search-forward
6985 (if anything-c-etags-use-regexp-search
6986 (format anything-c-etags-search-regexp pattern)
6987 pattern)
6988 nil t))
6990 (defun anything-c-etags-default-action (candidate)
6991 "Anything default action to jump to an etags entry."
6992 (let* ((split (split-string candidate ": "))
6993 (fname (expand-file-name
6994 (car split) anything-c-etags-tag-file-dir))
6995 (elm (cadr split)))
6996 (find-file fname)
6997 (goto-char (point-min))
6998 (search-forward elm nil t)
6999 (goto-char (match-beginning 0))))
7001 (defun anything-c-etags-mtime (file)
7002 "Last modification time of etags tag FILE."
7003 (cadr (nth 5 (file-attributes file))))
7005 (defun anything-c-etags-file-modified-p (file)
7006 "Check if tag FILE have been modified in this session.
7007 If FILE is nil return nil."
7008 (let ((last-modif (and file
7009 (assoc-default file anything-c-etags-mtime-alist))))
7010 (and last-modif
7011 (/= last-modif (anything-c-etags-mtime file)))))
7015 ;;; Semantic
7018 (defvar anything-semantic-candidates nil)
7020 (defun anything-semantic-construct-candidates (tags depth)
7021 (when (require 'semantic nil t)
7022 (apply
7023 'append
7024 (mapcar
7025 (lambda (tag)
7026 (if (listp tag)
7027 (let ((type (semantic-tag-type tag))
7028 (class (semantic-tag-class tag)))
7029 (if (or (and (stringp type)
7030 (or (string= type "class")
7031 (string= type "namespace")))
7032 (eq class 'function)
7033 (eq class 'variable))
7034 (cons (cons (concat (make-string (* depth 2) ?\s)
7035 (semantic-format-tag-summarize tag nil t))
7036 tag)
7037 (anything-semantic-construct-candidates
7038 (semantic-tag-components tag) (1+ depth)))))))
7039 tags))))
7041 (defun anything-semantic-default-action (candidate)
7042 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7043 (semantic-go-to-tag tag)))
7045 (defvar anything-c-source-semantic
7046 '((name . "Semantic Tags")
7047 (init . (lambda ()
7048 (setq anything-semantic-candidates
7049 (ignore-errors (anything-semantic-construct-candidates
7050 (semantic-fetch-tags) 0)))))
7051 (candidates . (lambda ()
7052 (if anything-semantic-candidates
7053 (mapcar 'car anything-semantic-candidates))))
7054 (persistent-action . (lambda (elm)
7055 (anything-semantic-default-action elm)
7056 (anything-match-line-color-current-line)))
7057 (persistent-help . "Show this entry")
7058 (action . anything-semantic-default-action)
7059 "Needs semantic in CEDET.
7061 http://cedet.sourceforge.net/semantic.shtml
7062 http://cedet.sourceforge.net/"))
7064 ;; (anything 'anything-c-source-semantic)
7067 ;;; Anything interface of `simple-call-tree.el'.
7069 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7071 ;; Function is called by
7072 (defvar anything-c-source-simple-call-tree-functions-callers
7073 '((name . "Function is called by")
7074 (init . anything-c-simple-call-tree-functions-callers-init)
7075 (multiline)
7076 (candidates . anything-c-simple-call-tree-candidates)
7077 (persistent-action . anything-c-simple-call-tree-persistent-action)
7078 (persistent-help . "Show function definitions by rotation")
7079 (action ("Find definition selected by persistent-action" .
7080 anything-c-simple-call-tree-find-definition)))
7081 "Needs simple-call-tree.el.
7082 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7084 (defvar anything-c-simple-call-tree-tick nil)
7085 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7086 (defun anything-c-simple-call-tree-analyze-maybe ()
7087 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7088 (simple-call-tree-analyze)
7089 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7091 (defun anything-c-simple-call-tree-init-base (function message)
7092 (require 'simple-call-tree)
7093 (with-no-warnings
7094 (when (anything-current-buffer-is-modified)
7095 (anything-c-simple-call-tree-analyze-maybe)
7096 (let ((list (funcall function simple-call-tree-alist)))
7097 (with-current-buffer (anything-candidate-buffer 'local)
7098 (dolist (entry list)
7099 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7100 (insert (car entry) message
7101 (if (string= funcs " ")
7102 " no functions."
7103 funcs)
7104 "\n\n"))))))))
7106 (defun anything-c-simple-call-tree-functions-callers-init ()
7107 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7108 " is called by\n"))
7110 (defun anything-c-simple-call-tree-candidates ()
7111 (with-current-buffer (anything-candidate-buffer)
7112 (split-string (buffer-string) "\n\n")))
7114 (defvar anything-c-simple-call-tree-related-functions nil)
7115 (defvar anything-c-simple-call-tree-function-index 0)
7116 (defun anything-c-simple-call-tree-persistent-action (candidate)
7117 (unless (eq last-command 'anything-execute-persistent-action)
7118 (setq anything-c-simple-call-tree-related-functions
7119 (delete "no functions."
7120 (split-string
7121 (replace-regexp-in-string " \\| is called by\\| calls "
7122 "" candidate)
7123 "\n")))
7124 (setq anything-c-simple-call-tree-function-index -1))
7125 (incf anything-c-simple-call-tree-function-index)
7126 (anything-c-simple-call-tree-find-definition candidate))
7128 (defun anything-c-simple-call-tree-find-definition (candidate)
7129 (find-function
7130 (intern
7131 (nth (mod anything-c-simple-call-tree-function-index
7132 (length anything-c-simple-call-tree-related-functions))
7133 anything-c-simple-call-tree-related-functions))))
7135 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7137 ;;; Function calls
7138 (defvar anything-c-source-simple-call-tree-callers-functions
7139 '((name . "Function calls")
7140 (init . anything-c-simple-call-tree-callers-functions-init)
7141 (multiline)
7142 (candidates . anything-c-simple-call-tree-candidates)
7143 (persistent-action . anything-c-simple-call-tree-persistent-action)
7144 (persistent-help . "Show function definitions by rotation")
7145 (action ("Find definition selected by persistent-action" .
7146 anything-c-simple-call-tree-find-definition)))
7147 "Needs simple-call-tree.el.
7148 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7150 (defun anything-c-simple-call-tree-callers-functions-init ()
7151 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7153 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7157 ;;; Anything UI of auto-document.el
7159 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7161 ;; Commands/Options with doc
7162 (defvar anything-c-auto-document-data nil)
7163 (make-variable-buffer-local 'anything-c-auto-document-data)
7164 (defvar anything-c-source-commands-and-options-in-file
7165 '((name . "Commands/Options in file")
7166 (header-name
7167 . (lambda (x) (format "Commands/Options in %s"
7168 (buffer-local-value 'buffer-file-name
7169 anything-current-buffer))))
7170 (candidates . anything-command-and-options-candidates)
7171 (multiline)
7172 (action . imenu))
7173 "List Commands and Options with doc. It needs auto-document.el .
7175 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7177 (eval-when-compile (require 'auto-document nil t))
7178 (defun anything-command-and-options-candidates ()
7179 (with-anything-current-buffer
7180 (when (and (require 'auto-document nil t)
7181 (eq major-mode 'emacs-lisp-mode)
7182 (or (anything-current-buffer-is-modified)
7183 (not anything-c-auto-document-data)))
7184 (or imenu--index-alist (imenu--make-index-alist t))
7185 (setq anything-c-auto-document-data
7186 (destructuring-bind (commands options)
7187 (adoc-construct anything-current-buffer)
7188 (append
7189 (loop for (command . doc) in commands
7190 for cmdname = (symbol-name command)
7191 collect
7192 (cons
7193 (format "Command: %s\n %s"
7194 (propertize cmdname 'face font-lock-function-name-face)
7195 (adoc-first-line doc))
7196 (assoc cmdname imenu--index-alist)))
7197 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7198 for (option doc default) in options
7199 for optname = (symbol-name option)
7200 collect
7201 (cons
7202 (format "Option: %s\n %s\n default = %s"
7203 (propertize optname 'face font-lock-variable-name-face)
7204 (adoc-first-line doc)
7205 (adoc-prin1-to-string default))
7206 (assoc optname
7207 var-alist)))))))
7208 anything-c-auto-document-data))
7210 ;; (anything 'anything-c-source-commands-and-options-in-file)
7213 ;;;; <Color and Face>
7216 ;;; Customize Face
7219 (defvar anything-c-source-customize-face
7220 '((name . "Customize Face")
7221 (init . (lambda ()
7222 (unless (anything-candidate-buffer)
7223 (save-window-excursion (list-faces-display))
7224 (anything-candidate-buffer (get-buffer "*Faces*")))))
7225 (candidates-in-buffer)
7226 (get-line . buffer-substring)
7227 (action . (lambda (line)
7228 (customize-face (intern (car (split-string line))))))
7229 (requires-pattern . 3))
7230 "See (info \"(emacs)Faces\")")
7231 ;; (anything 'anything-c-source-customize-face)
7233 ;;; Colors browser
7236 (defvar anything-c-source-colors
7237 '((name . "Colors")
7238 (init . (lambda () (unless (anything-candidate-buffer)
7239 (save-window-excursion (list-colors-display))
7240 (anything-candidate-buffer (get-buffer "*Colors*")))))
7241 (candidates-in-buffer)
7242 (get-line . buffer-substring)
7243 (action
7244 ("Copy Name" . (lambda (candidate)
7245 (kill-new (anything-c-colors-get-name candidate))))
7246 ("Copy RGB" . (lambda (candidate)
7247 (kill-new (anything-c-colors-get-rgb candidate))))
7248 ("Insert Name" . (lambda (candidate)
7249 (with-anything-current-buffer
7250 (insert (anything-c-colors-get-name candidate)))))
7251 ("Insert RGB" . (lambda (candidate)
7252 (with-anything-current-buffer
7253 (insert (anything-c-colors-get-rgb candidate))))))))
7254 ;; (anything 'anything-c-source-colors)
7256 (defun anything-c-colors-get-name (candidate)
7257 "Get color name."
7258 (replace-regexp-in-string
7259 " " ""
7260 (with-temp-buffer
7261 (insert (capitalize candidate))
7262 (goto-char (point-min))
7263 (search-forward-regexp "\\s-\\{2,\\}")
7264 (delete-region (point) (point-max))
7265 (buffer-string))))
7267 (defun anything-c-colors-get-rgb (candidate)
7268 "Get color RGB."
7269 (replace-regexp-in-string
7270 " " ""
7271 (with-temp-buffer
7272 (insert (capitalize candidate))
7273 (goto-char (point-max))
7274 (search-backward-regexp "\\s-\\{2,\\}")
7275 (delete-region (point) (point-min))
7276 (buffer-string))))
7279 ;;;; <Search Engine>
7280 ;;; Tracker desktop search
7281 (defvar anything-c-source-tracker-search
7282 '((name . "Tracker Search")
7283 (candidates . (lambda ()
7284 (start-process "tracker-search-process" nil
7285 "tracker-search"
7286 anything-pattern)))
7287 (type . file)
7288 (requires-pattern . 3)
7289 (delayed))
7290 "Source for retrieving files matching the current input pattern
7291 with the tracker desktop search.")
7292 ;; (anything 'anything-c-source-tracker-search)
7294 ;;; Spotlight (MacOS X desktop search)
7295 (defvar anything-c-source-mac-spotlight
7296 '((name . "mdfind")
7297 (candidates
7298 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7299 (type . file)
7300 (requires-pattern . 3)
7301 (delayed))
7302 "Source for retrieving files via Spotlight's command line
7303 utility mdfind.")
7304 ;; (anything 'anything-c-source-mac-spotlight)
7306 ;;; Picklist
7307 (defvar anything-c-source-picklist
7308 '((name . "Picklist")
7309 (candidates . (lambda () (mapcar 'car picklist-list)))
7310 (type . file)))
7311 ;; (anything 'anything-c-source-picklist)
7315 ;;; Kill ring
7318 (defvar anything-c-source-kill-ring
7319 '((name . "Kill Ring")
7320 (init . (lambda () (anything-attrset 'last-command last-command)))
7321 (candidates . anything-c-kill-ring-candidates)
7322 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7323 (action . anything-c-kill-ring-action)
7324 (last-command)
7325 (migemo)
7326 (multiline))
7327 "Source for browse and insert contents of kill-ring.")
7329 (defun anything-c-kill-ring-candidates ()
7330 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7331 unless (or (< (length kill) anything-kill-ring-threshold)
7332 (string-match "^[\\s\\t]+$" kill))
7333 collect kill))
7335 (defun anything-c-kill-ring-transformer (candidates source)
7336 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7337 (loop for i in candidates
7338 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7339 if (and anything-c-kill-ring-max-lines-number
7340 (> nlines anything-c-kill-ring-max-lines-number))
7341 collect (cons
7342 (with-temp-buffer
7343 (insert i)
7344 (goto-char (point-min))
7345 (concat
7346 (buffer-substring
7347 (point-min)
7348 (save-excursion
7349 (forward-line anything-c-kill-ring-max-lines-number)
7350 (point)))
7351 "[...]")) i)
7352 else collect i))
7354 (defun anything-c-kill-ring-action (str)
7355 "Insert STR in `kill-ring' and set STR to the head.
7356 If this action is executed just after `yank',
7357 replace with STR as yanked string."
7358 (setq kill-ring (delete str kill-ring))
7359 (if (not (eq (anything-attr 'last-command) 'yank))
7360 (insert-for-yank str)
7361 ;; from `yank-pop'
7362 (let ((inhibit-read-only t)
7363 (before (< (point) (mark t))))
7364 (if before
7365 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7366 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7367 (setq yank-undo-function nil)
7368 (set-marker (mark-marker) (point) (current-buffer))
7369 (insert-for-yank str)
7370 ;; Set the window start back where it was in the yank command,
7371 ;; if possible.
7372 (set-window-start (selected-window) yank-window-start t)
7373 (if before
7374 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7375 ;; It is cleaner to avoid activation, even though the command
7376 ;; loop would deactivate the mark because we inserted text.
7377 (goto-char (prog1 (mark t)
7378 (set-marker (mark-marker) (point) (current-buffer)))))))
7379 (kill-new str))
7381 ;; (anything 'anything-c-source-kill-ring)
7384 ;;;; <Mark ring>
7385 ;; DO NOT include these sources in `anything-sources' use
7386 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7387 ;; `anything-all-mark-rings' instead.
7389 (defun anything-c-source-mark-ring-candidates ()
7390 (flet ((get-marks (pos)
7391 (save-excursion
7392 (goto-char pos)
7393 (beginning-of-line)
7394 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7395 (when (string= "" line)
7396 (setq line "<EMPTY LINE>"))
7397 (format "%7d: %s" (line-number-at-pos) line)))))
7398 (with-anything-current-buffer
7399 (loop
7400 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7401 with recip = nil
7402 for i in marks
7403 for m = (get-marks i)
7404 unless (member m recip)
7405 collect m into recip
7406 finally return recip))))
7408 (defvar anything-mark-ring-cache nil)
7409 (defvar anything-c-source-mark-ring
7410 '((name . "mark-ring")
7411 (init . (lambda ()
7412 (setq anything-mark-ring-cache
7413 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7414 (candidates . (lambda ()
7415 (anything-aif anything-mark-ring-cache
7416 it)))
7417 (action . (("Goto line"
7418 . (lambda (candidate)
7419 (anything-goto-line (string-to-number candidate))))))
7420 (persistent-action . (lambda (candidate)
7421 (anything-goto-line (string-to-number candidate))
7422 (anything-match-line-color-current-line)))
7423 (persistent-help . "Show this line")))
7425 ;; (anything 'anything-c-source-mark-ring)
7427 ;;; Global-mark-ring
7428 (defvar anything-c-source-global-mark-ring
7429 '((name . "global-mark-ring")
7430 (candidates . anything-c-source-global-mark-ring-candidates)
7431 (action . (("Goto line"
7432 . (lambda (candidate)
7433 (let ((items (split-string candidate ":")))
7434 (anything-c-switch-to-buffer (second items))
7435 (anything-goto-line (string-to-number (car items))))))))
7436 (persistent-action . (lambda (candidate)
7437 (let ((items (split-string candidate ":")))
7438 (anything-c-switch-to-buffer (second items))
7439 (anything-goto-line (string-to-number (car items)))
7440 (anything-match-line-color-current-line))))
7441 (persistent-help . "Show this line")))
7443 (defun anything-c-source-global-mark-ring-candidates ()
7444 (flet ((buf-fn (m)
7445 (with-current-buffer (marker-buffer m)
7446 (goto-char m)
7447 (beginning-of-line)
7448 (let (line)
7449 (if (string= "" line)
7450 (setq line "<EMPTY LINE>")
7451 (setq line (car (split-string (thing-at-point 'line)
7452 "[\n\r]"))))
7453 (format "%7d:%s: %s"
7454 (line-number-at-pos) (marker-buffer m) line)))))
7455 (loop
7456 with marks = global-mark-ring
7457 with recip = nil
7458 for i in marks
7459 for gm = (unless (or (string-match
7460 "^ " (format "%s" (marker-buffer i)))
7461 (null (marker-buffer i)))
7462 (buf-fn i))
7463 when (and gm (not (member gm recip)))
7464 collect gm into recip
7465 finally return recip)))
7467 ;; (anything 'anything-c-source-global-mark-ring)
7470 ;;;; <Register>
7471 ;;; Insert from register
7472 (defvar anything-c-source-register
7473 '((name . "Registers")
7474 (candidates . anything-c-register-candidates)
7475 (action-transformer . anything-c-register-action-transformer)
7476 (multiline)
7477 (action))
7478 "See (info \"(emacs)Registers\")")
7480 (defun anything-c-register-candidates ()
7481 "Collecting register contents and appropriate commands."
7482 (loop for (char . val) in register-alist
7483 for key = (single-key-description char)
7484 for string-actions =
7485 (cond
7486 ((numberp val)
7487 (list (int-to-string val)
7488 'insert-register
7489 'increment-register))
7490 ((markerp val)
7491 (let ((buf (marker-buffer val)))
7492 (if (null buf)
7493 (list "a marker in no buffer")
7494 (list (concat
7495 "a buffer position:"
7496 (buffer-name buf)
7497 ", position "
7498 (int-to-string (marker-position val)))
7499 'jump-to-register
7500 'insert-register))))
7501 ((and (consp val) (window-configuration-p (car val)))
7502 (list "window configuration."
7503 'jump-to-register))
7504 ((and (consp val) (frame-configuration-p (car val)))
7505 (list "frame configuration."
7506 'jump-to-register))
7507 ((and (consp val) (eq (car val) 'file))
7508 (list (concat "file:"
7509 (prin1-to-string (cdr val))
7510 ".")
7511 'jump-to-register))
7512 ((and (consp val) (eq (car val) 'file-query))
7513 (list (concat "file:a file-query reference: file "
7514 (car (cdr val))
7515 ", position "
7516 (int-to-string (car (cdr (cdr val))))
7517 ".")
7518 'jump-to-register))
7519 ((consp val)
7520 (let ((lines (format "%4d" (length val))))
7521 (list (format "%s: %s\n" lines
7522 (truncate-string-to-width
7523 (mapconcat 'identity (list (car val))
7524 ;; (mapconcat (lambda (y) y) val
7525 "^J") (- (window-width) 15)))
7526 'insert-register)))
7527 ((stringp val)
7528 (list ;; without properties
7529 (substring-no-properties val)
7530 'insert-register
7531 'append-to-register
7532 'prepend-to-register))
7534 "GARBAGE!"))
7535 collect (cons (format "register %3s: %s" key (car string-actions))
7536 (cons char (cdr string-actions)))))
7538 (defun anything-c-register-action-transformer (actions register-and-functions)
7539 "Decide actions by the contents of register."
7540 (loop with func-actions =
7541 '((insert-register
7542 "Insert Register" .
7543 (lambda (c) (insert-register (car c))))
7544 (jump-to-register
7545 "Jump to Register" .
7546 (lambda (c) (jump-to-register (car c))))
7547 (append-to-register
7548 "Append Region to Register" .
7549 (lambda (c) (append-to-register
7550 (car c) (region-beginning) (region-end))))
7551 (prepend-to-register
7552 "Prepend Region to Register" .
7553 (lambda (c) (prepend-to-register
7554 (car c) (region-beginning) (region-end))))
7555 (increment-register
7556 "Increment Prefix Arg to Register" .
7557 (lambda (c) (increment-register
7558 anything-current-prefix-arg (car c)))))
7559 for func in (cdr register-and-functions)
7560 for cell = (assq func func-actions)
7561 when cell
7562 collect (cdr cell)))
7564 ;; (anything 'anything-c-source-register)
7567 ;;; Latex completion
7568 (defun anything-c-latex-math-candidates ()
7569 "Collect candidates for latex math completion."
7570 (declare (special LaTeX-math-menu))
7571 (loop for i in (cddr LaTeX-math-menu)
7572 for elm = (loop for s in i when (vectorp s)
7573 collect (cons (aref s 0) (aref s 1)))
7574 append elm))
7576 (defvar anything-c-source-latex-math
7577 '((name . "Latex Math Menu")
7578 (init . (lambda ()
7579 (with-anything-current-buffer
7580 (LaTeX-math-mode 1))))
7581 (candidate-number-limit . 9999)
7582 (candidates . anything-c-latex-math-candidates)
7583 (action . (lambda (candidate)
7584 (call-interactively candidate)))))
7587 ;;;; <Headline Extraction>
7588 (defvar anything-c-source-fixme
7589 '((name . "TODO/FIXME/DRY comments")
7590 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7591 (adjust)
7592 (recenter))
7593 "Show TODO/FIXME/DRY comments in current file.")
7594 ;; (anything 'anything-c-source-fixme)
7596 (defvar anything-c-source-rd-headline
7597 '((name . "RD HeadLine")
7598 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7599 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7600 (migemo)
7601 (subexp . 1))
7602 "Show RD headlines.
7604 RD is Ruby's POD.
7605 http://en.wikipedia.org/wiki/Ruby_Document_format")
7606 ;; (anything 'anything-c-source-rd-headline)
7608 (defvar anything-c-source-oddmuse-headline
7609 '((name . "Oddmuse HeadLine")
7610 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7611 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7612 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7613 (migemo)
7614 (subexp . 1))
7615 "Show Oddmuse headlines, such as EmacsWiki.")
7616 ;; (anything 'anything-c-source-oddmuse-headline)
7618 (defvar anything-c-source-emacs-source-defun
7619 '((name . "Emacs Source DEFUN")
7620 (headline . "DEFUN\\|DEFVAR")
7621 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7622 (or buffer-file-name ""))))
7623 "Show DEFUN/DEFVAR in Emacs C source file.")
7624 ;; (anything 'anything-c-source-emacs-source-defun)
7626 (defvar anything-c-source-emacs-lisp-expectations
7627 '((name . "Emacs Lisp Expectations")
7628 (headline . "(desc[ ]\\|(expectations")
7629 (condition . (eq major-mode 'emacs-lisp-mode)))
7630 "Show descriptions (desc) in Emacs Lisp Expectations.
7632 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7633 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7635 (defvar anything-c-source-emacs-lisp-toplevels
7636 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7637 (headline . "^(\\|(@\\*\\|^;;;;")
7638 (get-line . buffer-substring)
7639 (condition . (eq major-mode 'emacs-lisp-mode))
7640 (adjust))
7641 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7642 linkd.el is optional because linkd stars are extracted by regexp.
7643 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7644 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7647 ;;; Anything yaoddmuse
7649 ;; Be sure to have yaoddmuse.el installed
7650 ;; install-elisp may be required if you want to install elisp file from here.
7651 (defvar anything-yaoddmuse-use-cache-file nil)
7652 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7653 (defvar anything-c-yaoddmuse-ew-cache nil)
7655 (defun anything-yaoddmuse-get-candidates ()
7656 (declare (special yaoddmuse-pages-hash))
7657 (if anything-yaoddmuse-use-cache-file
7658 (ignore-errors
7659 (unless anything-c-yaoddmuse-ew-cache
7660 (load anything-c-yaoddmuse-cache-file)
7661 (setq anything-c-yaoddmuse-ew-cache
7662 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7663 anything-c-yaoddmuse-ew-cache)
7664 (yaoddmuse-update-pagename t)
7665 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7667 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7668 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7669 (candidates . anything-yaoddmuse-get-candidates)
7670 (action . (("Edit page" . (lambda (candidate)
7671 (yaoddmuse-edit "EmacsWiki" candidate)))
7672 ("Browse page"
7673 . (lambda (candidate)
7674 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7675 ("Browse page other window"
7676 . (lambda (candidate)
7677 (if (one-window-p)
7678 (split-window-vertically))
7679 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7680 ("Browse diff"
7681 . (lambda (candidate)
7682 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7683 ("Copy URL"
7684 . (lambda (candidate)
7685 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7686 (message "Have copy page %s's URL to yank." candidate)))
7687 ("Create page"
7688 . (lambda (candidate)
7689 (yaoddmuse-edit "EmacsWiki" anything-input)))
7690 ("Update cache"
7691 . (lambda (candidate)
7692 (if anything-yaoddmuse-use-cache-file
7693 (progn
7694 (anything-yaoddmuse-cache-pages t)
7695 (setq anything-c-yaoddmuse-ew-cache
7696 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7697 (yaoddmuse-update-pagename))))))
7698 (action-transformer anything-c-yaoddmuse-action-transformer))
7699 "Needs yaoddmuse.el.
7701 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7703 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7705 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7706 '((name . "Yaoddmuse Post library (EmacsWiki)")
7707 (init . (anything-yaoddmuse-init))
7708 (candidates-in-buffer)
7709 (action . (("Post library and Browse"
7710 . (lambda (candidate)
7711 (yaoddmuse-post-file
7712 (find-library-name candidate)
7713 "EmacsWiki"
7714 (file-name-nondirectory (find-library-name candidate))
7715 nil t)))
7716 ("Post library"
7717 . (lambda (candidate)
7718 (yaoddmuse-post-file
7719 (find-library-name candidate)
7720 "EmacsWiki"
7721 (file-name-nondirectory
7722 (find-library-name candidate))))))))
7723 "Needs yaoddmuse.el.
7725 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7727 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7729 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7730 "Allow the use of `install-elisp' only on elisp files."
7731 (if (string-match "\.el$" candidate)
7732 (append actions '(("Install Elisp"
7733 . (lambda (elm)
7734 (install-elisp-from-emacswiki elm)))))
7735 actions))
7737 ;;;###autoload
7738 (defun anything-yaoddmuse-cache-pages (&optional load)
7739 "Fetch the list of files on emacswiki and create cache file.
7740 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7741 (interactive)
7742 (declare (special yaoddmuse-pages-hash))
7743 (yaoddmuse-update-pagename)
7744 (save-excursion
7745 (find-file anything-c-yaoddmuse-cache-file)
7746 (erase-buffer)
7747 (insert "(puthash \"EmacsWiki\" '(")
7748 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7750 (insert (concat "(\"" (car i) "\") ")))
7751 (insert ") yaoddmuse-pages-hash)\n")
7752 (save-buffer)
7753 (kill-buffer (current-buffer))
7754 (when (or current-prefix-arg
7755 load)
7756 (load anything-c-yaoddmuse-cache-file))))
7758 (defun anything-yaoddmuse-init ()
7759 "Init anything buffer status."
7760 (let ((anything-buffer (anything-candidate-buffer 'global))
7761 (library-list (yaoddmuse-get-library-list)))
7762 (with-current-buffer anything-buffer
7763 ;; Insert library name.
7764 (dolist (library library-list)
7765 (insert (format "%s\n" library)))
7766 ;; Sort lines.
7767 (sort-lines nil (point-min) (point-max)))))
7770 ;;; Eev anchors
7771 (defvar anything-c-source-eev-anchor
7772 '((name . "Anchors")
7773 (candidates
7774 . (lambda ()
7775 (ignore-errors
7776 (with-anything-current-buffer
7777 (loop initially (goto-char (point-min))
7778 while (re-search-forward
7779 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7780 for anchor = (match-string-no-properties 1)
7781 collect (cons (format "%5d:%s"
7782 (line-number-at-pos (match-beginning 0))
7783 (format ee-anchor-format anchor))
7784 anchor))))))
7785 (persistent-action . (lambda (item)
7786 (ee-to item)
7787 (anything-match-line-color-current-line)))
7788 (persistent-help . "Show this entry")
7789 (action . (("Goto link" . ee-to)))))
7790 ;; (anything 'anything-c-source-eev-anchor)
7793 ;;; Org headlines
7796 (defvar anything-c-source-org-headline
7797 `((name . "Org HeadLine")
7798 (headline
7799 ,@(mapcar
7800 (lambda (num)
7801 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7802 num))
7803 (number-sequence 1 8)))
7804 (condition . (eq major-mode 'org-mode))
7805 (migemo)
7806 (subexp . 1)
7807 (persistent-action . (lambda (elm)
7808 (anything-c-action-line-goto elm)
7809 (org-cycle)))
7810 (action-transformer
7811 . (lambda (actions candidate)
7812 '(("Go to Line" . anything-c-action-line-goto)
7813 ("Refile to this Headline" . anything-c-org-headline-refile)
7814 ("Insert Link to This Headline"
7815 . anything-c-org-headline-insert-link-to-headline)))))
7816 "Show Org headlines.
7817 org-mode is very very much extended text-mode/outline-mode.
7819 See (find-library \"org.el\")
7820 See http://orgmode.org for the latest version.")
7821 ;; (anything 'anything-c-source-org-headline)
7823 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7824 (insert
7825 (save-excursion
7826 (anything-goto-line (car lineno-and-content))
7827 (and (looking-at org-complex-heading-regexp)
7828 (org-make-link-string (concat "*" (match-string 4)))))))
7830 (defun anything-c-org-headline-refile (lineno-and-content)
7831 "Refile current org entry to LINENO-AND-CONTENT."
7832 (with-anything-current-buffer
7833 (org-cut-subtree)
7834 (anything-goto-line (car lineno-and-content))
7835 (org-end-of-subtree t t)
7836 (let ((org-yank-adjusted-subtrees t))
7837 (org-yank))))
7840 ;;; Org keywords
7843 (defvar anything-c-source-org-keywords
7844 '((name . "Org Keywords")
7845 (init . anything-c-org-keywords-init)
7846 (candidates . anything-c-org-keywords-candidates)
7847 (action . anything-c-org-keywords-insert)
7848 (persistent-action . anything-c-org-keywords-show-help)
7849 (persistent-help . "Show an example and info page to describe this keyword.")
7850 (keywords-examples)
7851 (keywords)))
7852 ;; (anything 'anything-c-source-org-keywords)
7854 (defvar anything-c-org-keywords-info-location
7855 '(("#+TITLE:" . "(org)Export options")
7856 ("#+AUTHOR:" . "(org)Export options")
7857 ("#+DATE:" . "(org)Export options")
7858 ("#+EMAIL:" . "(org)Export options")
7859 ("#+DESCRIPTION:" . "(org)Export options")
7860 ("#+KEYWORDS:" . "(org)Export options")
7861 ("#+LANGUAGE:" . "(org)Export options")
7862 ("#+TEXT:" . "(org)Export options")
7863 ("#+TEXT:" . "(org)Export options")
7864 ("#+OPTIONS:" . "(org)Export options")
7865 ("#+BIND:" . "(org)Export options")
7866 ("#+LINK_UP:" . "(org)Export options")
7867 ("#+LINK_HOME:" . "(org)Export options")
7868 ("#+LATEX_HEADER:" . "(org)Export options")
7869 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7870 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7871 ("#+INFOJS_OPT" . "(org)Javascript support")
7872 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7873 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7874 ("#+ORGTBL" . "(org)Radio tables")
7875 ("#+HTML:" . "(org)Quoting HTML tags")
7876 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7877 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7878 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7879 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7880 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7881 ("#+BEGIN_SRC" . "(org)Literal examples")
7882 ("#+CAPTION" . "(org)Tables in HTML export")
7883 ("#+LABEL" . "(org)Tables in LaTeX export")
7884 ("#+ATTR_HTML" . "(org)Links")
7885 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7887 (defun anything-c-org-keywords-init ()
7888 (unless (anything-attr 'keywords-examples)
7889 (require 'org)
7890 (anything-attrset 'keywords-examples
7891 (append
7892 (mapcar
7893 (lambda (x)
7894 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7895 (cons (match-string 2 x) (match-string 1 x)))
7896 (org-split-string (org-get-current-options) "\n"))
7897 (mapcar 'list org-additional-option-like-keywords)))
7898 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7900 (defun anything-c-org-keywords-candidates ()
7901 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7902 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7903 (anything-attr 'keywords)))
7905 (defun anything-c-org-keywords-insert (keyword)
7906 (cond ((and (string-match "BEGIN" keyword)
7907 (anything-region-active-p))
7908 (let ((beg (region-beginning))
7909 (end (region-end)))
7910 (goto-char end)
7911 (insert "\n#+" (replace-regexp-in-string
7912 "BEGIN" "END" keyword) "\n")
7913 (goto-char beg)
7914 (insert "#+" keyword " ")
7915 (save-excursion (insert "\n"))))
7916 ((string-match "BEGIN" keyword)
7917 (insert "#+" keyword " ")
7918 (save-excursion
7919 (insert "\n#+" (replace-regexp-in-string
7920 "BEGIN" "END" keyword) "\n")))
7921 (t (insert "#+" keyword " "))))
7923 (defun anything-c-org-keywords-show-help (keyword)
7924 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7925 "(org)In-buffer settings"))
7926 (search-forward (concat "#+" keyword) nil t)
7927 (anything-persistent-highlight-point)
7928 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7932 ;;; bbdb
7935 (defvar bbdb-records)
7936 (defvar bbdb-buffer-name)
7938 (defun anything-c-bbdb-candidates ()
7939 "Return a list of all names in the bbdb database. The format
7940 is \"Firstname Lastname\"."
7941 (mapcar (lambda (bbdb-record)
7942 (replace-regexp-in-string
7943 "\\s-+$" ""
7944 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7945 (bbdb-records)))
7947 (defun anything-c-bbdb-create-contact (actions candidate)
7948 "Action transformer that returns only an entry to add the
7949 current `anything-pattern' as new contact. All other actions are
7950 removed."
7951 (if (string= candidate "*Add to contacts*")
7952 '(("Add to contacts" . (lambda (actions)
7953 (bbdb-create-internal
7954 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7955 (read-from-minibuffer "Company: ")
7956 (read-from-minibuffer "Email: ")
7959 (read-from-minibuffer "Note: ")))))
7960 actions))
7962 (defun anything-c-bbdb-get-record (candidate)
7963 "Return record that match CANDIDATE."
7964 (bbdb candidate nil)
7965 (set-buffer "*BBDB*")
7966 (bbdb-current-record))
7968 (defvar anything-c-bbdb-name nil
7969 "Only for internal use.")
7971 (defvar anything-c-source-bbdb
7972 '((name . "BBDB")
7973 (candidates . anything-c-bbdb-candidates)
7974 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7975 ("View person's data" . anything-c-bbdb-view-person-action))
7976 (filtered-candidate-transformer . (lambda (candidates source)
7977 (setq anything-c-bbdb-name anything-pattern)
7978 (if (not candidates)
7979 (list "*Add to contacts*")
7980 candidates)))
7981 (action-transformer . (lambda (actions candidate)
7982 (anything-c-bbdb-create-contact actions candidate))))
7983 "Needs BBDB.
7985 http://bbdb.sourceforge.net/")
7986 ;; (anything 'anything-c-source-bbdb)
7988 (defun anything-c-bbdb-view-person-action (candidate)
7989 "View BBDB data of single CANDIDATE or marked candidates."
7990 (anything-aif (anything-marked-candidates)
7991 (let ((bbdb-append-records (length it)))
7992 (dolist (i it)
7993 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7994 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7996 (defun anything-c-bbdb-collect-mail-addresses ()
7997 "Return a list of all mail addresses of records in bbdb buffer."
7998 (with-current-buffer bbdb-buffer-name
7999 (loop for i in bbdb-records
8000 if (bbdb-record-net (car i))
8001 collect (bbdb-dwim-net-address (car i)))))
8003 (defun anything-c-bbdb-compose-mail (candidate)
8004 "Compose a mail with all records of bbdb buffer."
8005 (anything-c-bbdb-view-person-action candidate)
8006 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8007 (address-str (mapconcat 'identity address-list ",\n ")))
8008 (compose-mail address-str)))
8011 ;;; Evaluation Result
8014 ;; Internal
8015 (defvar anything-eldoc-active-minibuffers-list nil)
8016 (defvar anything-eval-expression-input-history nil)
8018 (defvar anything-c-source-evaluation-result
8019 '((name . "Evaluation Result")
8020 (disable-shortcuts)
8021 (dummy)
8022 (multiline)
8023 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8024 (filtered-candidate-transformer . (lambda (candidates source)
8025 (list
8026 (condition-case nil
8027 (with-anything-current-buffer
8028 (pp-to-string
8029 (eval (read anything-pattern))))
8030 (error "Error")))))
8031 (action . (("Copy result to kill-ring" . (lambda (candidate)
8032 (with-current-buffer anything-buffer
8033 (let ((end (save-excursion
8034 (goto-char (point-max))
8035 (search-backward "\n")
8036 (point))))
8037 (kill-region (point) end)))))
8038 ("copy sexp to kill-ring" . (lambda (candidate)
8039 (kill-new anything-input)))))))
8040 ;; (anything 'anything-c-source-evaluation-result)
8042 (defun anything-eval-new-line-and-indent ()
8043 (interactive)
8044 (newline) (lisp-indent-line))
8046 (defun anything-eldoc-store-minibuffer ()
8047 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8048 (with-selected-window (minibuffer-window)
8049 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8051 (defun anything-eldoc-show-in-eval ()
8052 "Return eldoc in mode-line for current minibuffer input."
8053 (let ((buf (with-selected-window (minibuffer-window)
8054 (buffer-name))))
8055 (when (member buf anything-eldoc-active-minibuffers-list)
8056 (let* ((str-all (with-current-buffer buf
8057 (minibuffer-completion-contents)))
8058 (sym (when str-all
8059 (with-temp-buffer
8060 (insert str-all)
8061 (goto-char (point-max))
8062 (unless (looking-back ")\\|\"") (forward-char -1))
8063 (eldoc-current-symbol))))
8064 (info-fn (eldoc-fnsym-in-current-sexp))
8065 (doc (or (eldoc-get-var-docstring sym)
8066 (eldoc-get-fnsym-args-string
8067 (car info-fn) (cadr info-fn)))))
8068 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8070 (defun anything-c-show-info-in-mode-line (str)
8071 "Display string STR in mode-line."
8072 (save-window-excursion
8073 (with-current-buffer anything-buffer
8074 (let ((mode-line-format (concat " " str)))
8075 (force-mode-line-update)
8076 (sit-for anything-c-show-info-in-mode-line-delay))
8077 (force-mode-line-update))))
8079 ;;; Calculation Result
8082 (defvar anything-c-source-calculation-result
8083 '((name . "Calculation Result")
8084 (dummy)
8085 (filtered-candidate-transformer . (lambda (candidates source)
8086 (list
8087 (condition-case nil
8088 (calc-eval anything-pattern)
8089 (error "error")))))
8090 (action ("Copy result to kill-ring" . kill-new))))
8091 ;; (anything 'anything-c-source-calculation-result)
8094 ;;; Google Suggestions
8097 ;; Internal
8098 (defvar anything-ggs-max-length-real-flag 0)
8099 (defvar anything-ggs-max-length-num-flag 0)
8101 (defun anything-c-google-suggest-fetch (input)
8102 "Fetch suggestions for INPUT from XML buffer.
8103 Return an alist with elements like (data . number_results)."
8104 (setq anything-ggs-max-length-real-flag 0
8105 anything-ggs-max-length-num-flag 0)
8106 (let ((request (concat anything-c-google-suggest-url
8107 (url-hexify-string input))))
8108 (flet ((fetch ()
8109 (loop
8110 with result-alist = (xml-get-children
8111 (car (xml-parse-region
8112 (point-min) (point-max)))
8113 'CompleteSuggestion)
8114 for i in result-alist
8115 for data = (cdr (caadr (assoc 'suggestion i)))
8116 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8117 for lqueries = (length (anything-c-ggs-set-number-result
8118 nqueries))
8119 for ldata = (length data)
8121 (progn
8122 (when (> ldata anything-ggs-max-length-real-flag)
8123 (setq anything-ggs-max-length-real-flag ldata))
8124 (when (> lqueries anything-ggs-max-length-num-flag)
8125 (setq anything-ggs-max-length-num-flag lqueries)))
8126 collect (cons data nqueries) into cont
8127 finally return cont)))
8128 (if anything-google-suggest-use-curl-p
8129 (with-temp-buffer
8130 (call-process "curl" nil t nil request)
8131 (fetch))
8132 (with-current-buffer
8133 (url-retrieve-synchronously request)
8134 (fetch))))))
8136 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8137 "Set candidates with result and number of google results found."
8138 (let ((suggestions
8139 (loop with suggested-results = (anything-c-google-suggest-fetch
8140 (or (and request-prefix
8141 (concat request-prefix " " anything-pattern))
8142 anything-pattern))
8143 for (real . numresult) in suggested-results
8144 ;; Prepare number of results with ","
8145 for fnumresult = (anything-c-ggs-set-number-result numresult)
8146 ;; Calculate number of spaces to add before fnumresult
8147 ;; if it is smaller than longest result
8148 ;; `anything-ggs-max-length-num-flag'.
8149 ;; e.g 1,234,567
8150 ;; 345,678
8151 ;; To be sure it is aligned properly.
8152 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8153 (- anything-ggs-max-length-num-flag (length fnumresult))
8155 ;; Add now the spaces before fnumresult.
8156 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8157 for interval = (- anything-ggs-max-length-real-flag (length real))
8158 for spaces = (make-string (+ 2 interval) ? )
8159 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8160 collect (cons display real))))
8161 (if (loop for (disp . dat) in suggestions
8162 thereis (equal dat anything-pattern))
8163 suggestions
8164 ;; if there is no suggestion exactly matching the input then
8165 ;; prepend a Search on Google item to the list
8166 (append
8167 suggestions
8168 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8169 anything-input))))))
8171 (defun anything-c-ggs-set-number-result (num)
8172 (if num
8173 (progn
8174 (and (numberp num) (setq num (number-to-string num)))
8175 (loop for i in (reverse (split-string num "" t))
8176 for count from 1
8177 append (list i) into C
8178 when (= count 3)
8179 append (list ",") into C
8180 and do (setq count 0)
8181 finally return
8182 (replace-regexp-in-string
8183 "^," "" (mapconcat 'identity (reverse C) ""))))
8184 "?"))
8186 (defvar anything-c-google-suggest-default-browser-function nil
8187 "*The browse url function you prefer to use with google suggest.
8188 When nil, use the first browser function available
8189 See `anything-browse-url-default-browser-alist'.")
8191 (defun anything-c-google-suggest-action (candidate)
8192 "Default action to jump to a google suggested candidate."
8193 (let ((arg (concat anything-c-google-suggest-search-url
8194 (url-hexify-string candidate))))
8195 (anything-aif anything-c-google-suggest-default-browser-function
8196 (funcall it arg)
8197 (anything-c-browse-url arg))))
8199 (defvar anything-c-google-suggest-default-function
8200 'anything-c-google-suggest-set-candidates
8201 "Default function to use in anything google suggest.")
8203 (defvar anything-c-source-google-suggest
8204 '((name . "Google Suggest")
8205 (candidates . (lambda ()
8206 (funcall anything-c-google-suggest-default-function)))
8207 (action . (("Google Search" . anything-c-google-suggest-action)))
8208 (volatile)
8209 (requires-pattern . 3)
8210 (delayed)))
8212 (defun anything-c-google-suggest-emacs-lisp ()
8213 "Try to emacs lisp complete with google suggestions."
8214 (anything-c-google-suggest-set-candidates "emacs lisp"))
8216 ;; (anything 'anything-c-source-google-suggest)
8218 ;;; Yahoo suggestions
8221 (defun anything-c-yahoo-suggest-fetch (input)
8222 "Fetch Yahoo suggestions for INPUT from XML buffer.
8223 Return an alist with elements like (data . number_results)."
8224 (let ((request (concat anything-c-yahoo-suggest-url
8225 (url-hexify-string input))))
8226 (flet ((fetch ()
8227 (loop
8228 with result-alist = (xml-get-children
8229 (car (xml-parse-region (point-min) (point-max)))
8230 'Result)
8231 for i in result-alist
8232 collect (caddr i))))
8233 (with-current-buffer
8234 (url-retrieve-synchronously request)
8235 (fetch)))))
8237 (defun anything-c-yahoo-suggest-set-candidates ()
8238 "Set candidates with Yahoo results found."
8239 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8240 (or suggestions
8241 (append
8242 suggestions
8243 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8244 anything-input))))))
8246 (defun anything-c-yahoo-suggest-action (candidate)
8247 "Default action to jump to a Yahoo suggested candidate."
8248 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8249 (url-hexify-string candidate))))
8251 (defvar anything-c-source-yahoo-suggest
8252 '((name . "Yahoo Suggest")
8253 (candidates . anything-c-yahoo-suggest-set-candidates)
8254 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8255 (volatile)
8256 (requires-pattern . 3)
8257 (delayed)))
8259 ;; (anything 'anything-c-source-yahoo-suggest)
8262 ;;; Web browser functions.
8265 (require 'browse-url)
8266 ;; If default setting of `w3m-command' is not
8267 ;; what you want you and you modify it, you will have to reeval
8268 ;; also `anything-browse-url-default-browser-alist'.
8269 (defvar w3m-command "/usr/bin/w3m")
8270 (defvar anything-c-home-url "http://www.google.fr"
8271 "*Default url to use as home url.")
8273 (defvar ac-browse-url-chromium-program "chromium-browser")
8274 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8275 (defvar anything-browse-url-default-browser-alist
8276 `((,w3m-command . w3m-browse-url)
8277 (,browse-url-firefox-program . browse-url-firefox)
8278 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8279 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8280 (,browse-url-kde-program . browse-url-kde)
8281 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8282 (,browse-url-mozilla-program . browse-url-mozilla)
8283 (,browse-url-galeon-program . browse-url-galeon)
8284 (,browse-url-netscape-program . browse-url-netscape)
8285 (,browse-url-mosaic-program . browse-url-mosaic)
8286 (,browse-url-xterm-program . browse-url-text-xterm))
8287 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8289 (defun* anything-c-generic-browser (url name &rest args)
8290 "Browse URL with NAME browser."
8291 (let ((proc (concat name " " url)))
8292 (message "Starting %s..." name)
8293 (apply 'start-process proc nil name
8294 (append args (list url)))
8295 (set-process-sentinel
8296 (get-process proc)
8297 #'(lambda (process event)
8298 (when (string= event "finished\n")
8299 (message "%s process %s" process event))))))
8301 (defun ac-browse-url-chromium (url)
8302 "Browse URL with google chrome browser."
8303 (interactive "sURL: ")
8304 (anything-c-generic-browser
8305 url ac-browse-url-chromium-program))
8307 (defun ac-browse-url-uzbl (url &optional ignore)
8308 "Browse URL with uzbl browser."
8309 (interactive "sURL: ")
8310 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8312 (defun anything-browse-url-default-browser (url &rest args)
8313 "Find the first available browser and ask it to load URL."
8314 (let ((default-browser-fn
8315 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8316 thereis (and exe (executable-find exe) fn))))
8317 (if default-browser-fn
8318 (apply default-browser-fn url args)
8319 (error "No usable browser found"))))
8321 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8322 "Default command to browse URL."
8323 (if browse-url-browser-function
8324 (browse-url url)
8325 (anything-browse-url-default-browser url)))
8328 ;;; Surfraw
8330 ;; Need external program surfraw.
8331 ;; <http://surfraw.alioth.debian.org/>
8333 (defvar anything-surfraw-default-browser-function nil
8334 "*The browse url function you prefer to use with surfraw.
8335 When nil, fallback to `browse-url-browser-function'.")
8337 ;; Internal
8338 (defvar anything-surfraw-engines-history nil)
8339 (defvar anything-surfraw-input-history nil)
8341 (defun anything-c-build-elvi-list ()
8342 "Return list of all engines and descriptions handled by surfraw."
8343 (cdr
8344 (with-temp-buffer
8345 (call-process "surfraw" nil t nil
8346 "-elvi")
8347 (split-string (buffer-string) "\n"))))
8350 ;;; Emms
8353 (defun anything-emms-stream-edit-bookmark (elm)
8354 "Change the information of current emms-stream bookmark from anything."
8355 (declare (special emms-stream-list))
8356 (let* ((cur-buf anything-current-buffer)
8357 (bookmark (assoc elm emms-stream-list))
8358 (name (read-from-minibuffer "Description: "
8359 (nth 0 bookmark)))
8360 (url (read-from-minibuffer "URL: "
8361 (nth 1 bookmark)))
8362 (fd (read-from-minibuffer "Feed Descriptor: "
8363 (int-to-string (nth 2 bookmark))))
8364 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8365 (format "%s" (car (last bookmark))))))
8366 (save-excursion
8367 (emms-streams)
8368 (when (re-search-forward (concat "^" name) nil t)
8369 (beginning-of-line)
8370 (emms-stream-delete-bookmark)
8371 (emms-stream-add-bookmark name url (string-to-number fd) type)
8372 (emms-stream-save-bookmarks-file)
8373 (emms-stream-quit)
8374 (anything-c-switch-to-buffer cur-buf)))))
8376 (defun anything-emms-stream-delete-bookmark (elm)
8377 "Delete an emms-stream bookmark from anything."
8378 (let* ((cur-buf anything-current-buffer)
8379 (bookmark (assoc elm emms-stream-list))
8380 (name (nth 0 bookmark)))
8381 (save-excursion
8382 (emms-streams)
8383 (when (re-search-forward (concat "^" name) nil t)
8384 (beginning-of-line)
8385 (emms-stream-delete-bookmark)
8386 (emms-stream-save-bookmarks-file)
8387 (emms-stream-quit)
8388 (anything-c-switch-to-buffer cur-buf)))))
8390 (defvar anything-c-source-emms-streams
8391 '((name . "Emms Streams")
8392 (init . (lambda ()
8393 (emms-stream-init)))
8394 (candidates . (lambda ()
8395 (declare (special emms-stream-list))
8396 (mapcar 'car emms-stream-list)))
8397 (action . (("Play" . (lambda (elm)
8398 (declare (special emms-stream-list))
8399 (let* ((stream (assoc elm emms-stream-list))
8400 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8401 (url (second stream)))
8402 (funcall fn url))))
8403 ("Delete" . anything-emms-stream-delete-bookmark)
8404 ("Edit" . anything-emms-stream-edit-bookmark)))
8405 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8406 ;; (anything 'anything-c-source-emms-streams)
8408 ;; Don't forget to set `emms-source-file-default-directory'
8409 (defvar anything-c-source-emms-dired
8410 '((name . "Music Directory")
8411 (candidates . (lambda ()
8412 (cddr (directory-files emms-source-file-default-directory))))
8413 (action .
8414 (("Play Directory" . (lambda (item)
8415 (emms-play-directory
8416 (expand-file-name
8417 item
8418 emms-source-file-default-directory))))
8419 ("Open dired in file's directory" . (lambda (item)
8420 (anything-c-open-dired
8421 (expand-file-name
8422 item
8423 emms-source-file-default-directory))))))
8424 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8425 ;; (anything 'anything-c-source-emms-dired)
8428 (defun anything-c-emms-files-modifier (candidates source)
8429 (let ((current-playlist (with-current-emms-playlist
8430 (loop
8431 with cur-list = (emms-playlist-tracks-in-region
8432 (point-min) (point-max))
8433 for i in cur-list
8434 collect (assoc-default 'name i)))))
8435 (loop for i in candidates
8436 if (member (cdr i) current-playlist)
8437 collect (cons (propertize (car i)
8438 'face 'anything-emms-playlist)
8439 (cdr i)) into lis
8440 else collect i into lis
8441 finally return lis)))
8443 (defun anything-c-emms-play-current-playlist ()
8444 "Play current playlist."
8445 (with-current-emms-playlist
8446 (emms-playlist-first)
8447 (emms-playlist-mode-play-smart)))
8449 (defvar anything-c-source-emms-files
8450 '((name . "Emms files")
8451 (candidates . (lambda ()
8452 (loop for v being the hash-values in emms-cache-db
8453 for name = (assoc-default 'name v)
8454 for artist = (or (assoc-default 'info-artist v) "unknown")
8455 for genre = (or (assoc-default 'info-genre v) "unknown")
8456 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8457 for song = (or (assoc-default 'info-title v) "unknown")
8458 for info = (concat artist " - " genre " - " tracknum ": " song)
8459 unless (string-match "^http:" name) collect (cons info name))))
8460 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8461 (action . (("Play file" . emms-play-file)
8462 ("Add to Playlist and play (C-u clear current)"
8463 . (lambda (candidate)
8464 (when anything-current-prefix-arg
8465 (emms-playlist-current-clear))
8466 (emms-playlist-new)
8467 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8468 (unless emms-player-playing-p
8469 (anything-c-emms-play-current-playlist))))))))
8471 ;; (anything 'anything-c-source-emms-files)
8474 ;;; Jabber Contacts (jabber.el)
8475 (defun anything-c-jabber-online-contacts ()
8476 "List online Jabber contacts."
8477 (with-no-warnings
8478 (let (jids)
8479 (dolist (item (jabber-concat-rosters) jids)
8480 (when (get item 'connected)
8481 (push (if (get item 'name)
8482 (cons (get item 'name) item)
8483 (cons (symbol-name item) item)) jids))))))
8485 (defvar anything-c-source-jabber-contacts
8486 '((name . "Jabber Contacts")
8487 (init . (lambda () (require 'jabber)))
8488 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8489 (action . (lambda (x)
8490 (jabber-chat-with
8491 (jabber-read-account)
8492 (symbol-name
8493 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8494 ;; (anything 'anything-c-source-jabber-contacts)
8498 ;;; Call source.
8499 (defvar anything-source-select-buffer "*anything source select*")
8500 (defvar anything-c-source-call-source
8501 `((name . "Call anything source")
8502 (candidate-number-limit)
8503 (candidates
8504 . (lambda ()
8505 (loop for vname in (all-completions "anything-c-source-" obarray)
8506 for var = (intern vname)
8507 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8508 if name collect
8509 (cons (format "%s `%s'"
8510 name (propertize vname 'face 'font-lock-variable-name-face))
8511 var))))
8512 (action
8513 . (("Invoke anything with selected source"
8515 (lambda (candidate)
8516 (setq anything-candidate-number-limit 9999)
8517 (anything candidate nil nil nil nil
8518 anything-source-select-buffer)))
8519 ("Describe variable" . describe-variable)
8520 ("Find variable" . find-variable)))
8521 (persistent-action . describe-variable)
8522 (persistent-help . "Show description of this source")))
8523 ;; (anything 'anything-c-source-call-source)
8525 (defun anything-call-source-from-anything ()
8526 "Call anything source within `anything' session."
8527 (interactive)
8528 (setq anything-input-idle-delay 0)
8529 (anything-set-sources '(anything-c-source-call-source)))
8531 ;;; Execute Preconfigured anything.
8532 (defvar anything-c-source-anything-commands
8533 '((name . "Preconfigured Anything")
8534 (candidates . anything-c-anything-commands-candidates)
8535 (type . command)
8536 (candidate-number-limit)))
8537 ;; (anything 'anything-c-source-anything-commands)
8539 (defun anything-c-anything-commands-candidates ()
8540 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8541 collect (cons (if (where-is-internal cmd nil t)
8542 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8543 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8544 cmd)))
8547 ;;; Occur
8550 (defun anything-c-occur-init ()
8551 "Create the initial anything occur buffer.
8552 If region is active use region as buffer contents
8553 instead of whole buffer."
8554 (with-current-buffer (anything-candidate-buffer 'global)
8555 (erase-buffer)
8556 (let ((buf-contents
8557 (with-anything-current-buffer
8558 (if (anything-region-active-p)
8559 (buffer-substring (region-beginning) (region-end))
8560 (buffer-substring (point-min) (point-max))))))
8561 (insert buf-contents))))
8563 (defun anything-c-occur-get-line (s e)
8564 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8566 (defun anything-c-occur-query-replace-regexp (candidate)
8567 "Query replace regexp starting from CANDIDATE.
8568 If region is active ignore CANDIDATE and replace only in region.
8569 With a prefix arg replace only matches surrounded by word boundaries,
8570 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8571 (let ((regexp anything-input))
8572 (unless (anything-region-active-p)
8573 (anything-c-action-line-goto candidate))
8574 (apply 'query-replace-regexp
8575 (anything-c-query-replace-args regexp))))
8577 (defvar anything-c-source-occur
8578 '((name . "Occur")
8579 (init . anything-c-occur-init)
8580 (candidates-in-buffer)
8581 (migemo)
8582 (get-line . anything-c-occur-get-line)
8583 (display-to-real . anything-c-display-to-real-line)
8584 (action . (("Go to Line" . anything-c-action-line-goto)
8585 ("Query replace regexp (C-u Not inside word.)"
8586 . anything-c-occur-query-replace-regexp)))
8587 (recenter)
8588 (requires-pattern . 1)
8589 (delayed)
8590 (volatile)))
8591 ;; (anything 'anything-c-source-occur)
8594 ;;; Anything browse code.
8595 (defun anything-c-browse-code-get-line (beg end)
8596 "Select line if it match the regexp corresponding to current `major-mode'.
8597 Line is parsed for BEG position to END position."
8598 (let ((str-line (buffer-substring beg end))
8599 (regexp (assoc-default major-mode
8600 anything-c-browse-code-regexp-alist))
8601 (num-line (if (string= anything-pattern "") beg (1- beg))))
8602 (when (and regexp (string-match regexp str-line))
8603 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8606 (defvar anything-c-source-browse-code
8607 '((name . "Browse code")
8608 (init . (lambda ()
8609 (anything-candidate-buffer anything-current-buffer)
8610 (with-anything-current-buffer
8611 (jit-lock-fontify-now))))
8612 (candidate-number-limit . 9999)
8613 (candidates-in-buffer)
8614 (get-line . anything-c-browse-code-get-line)
8615 (type . line)
8616 (recenter)))
8619 ;; Do many actions for input
8620 (defvar anything-c-source-create
8621 '((name . "Create")
8622 (dummy)
8623 (action)
8624 (action-transformer . anything-create--actions))
8625 "Do many create actions from `anything-pattern'.
8626 See also `anything-create--actions'.")
8627 ;; (anything 'anything-c-source-create)
8629 (defun anything-create-from-anything ()
8630 "Run `anything-create' from `anything' as a fallback."
8631 (interactive)
8632 (anything-run-after-quit 'anything-create nil anything-pattern))
8634 (defun anything-create--actions (&rest ignored)
8635 "Default actions for `anything-create' / `anything-c-source-create'."
8636 (remove-if-not
8637 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8638 (append anything-create--actions-private
8639 '(("find-file" . find-file)
8640 ("find-file other window" . find-file-other-window)
8641 ("New buffer" . anything-c-switch-to-buffer)
8642 ("New buffer other window" . switch-to-buffer-other-window)
8643 ("Bookmark Set" . bookmark-set)
8644 ("Set Register" .
8645 (lambda (x) (set-register (read-char "Register: ") x)))
8646 ("Insert Linkd star" . linkd-insert-star)
8647 ("Insert Linkd Tag" . linkd-insert-tag)
8648 ("Insert Linkd Link" . linkd-insert-link)
8649 ("Insert Linkd Lisp" . linkd-insert-lisp)
8650 ("Insert Linkd Wiki" . linkd-insert-wiki)
8651 ("Google Search" . google)))))
8654 ;; Minibuffer History
8657 (defvar anything-c-source-minibuffer-history
8658 '((name . "Minibuffer History")
8659 (header-name . (lambda (name)
8660 (format "%s (%s)" name minibuffer-history-variable)))
8661 (candidates
8662 . (lambda ()
8663 (let ((history (loop
8664 for i in (symbol-value minibuffer-history-variable)
8665 unless (string= "" i) collect i)))
8666 (if (consp (car history))
8667 (mapcar 'prin1-to-string history)
8668 history))))
8669 (migemo)
8670 (action . insert)))
8671 ;; (anything 'anything-c-source-minibuffer-history)
8674 ;;; Elscreen
8677 (defvar anything-c-source-elscreen
8678 '((name . "Elscreen")
8679 (candidates . (lambda ()
8680 (if (cdr (elscreen-get-screen-to-name-alist))
8681 (sort
8682 (loop for sname in (elscreen-get-screen-to-name-alist)
8683 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8684 finally (return lst))
8685 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8686 (action . (("Change Screen".
8687 (lambda (candidate)
8688 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8689 ("Kill Screen(s)".
8690 (lambda (candidate)
8691 (dolist (i (anything-marked-candidates))
8692 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8693 (elscreen-kill))))
8694 ("Only Screen".
8695 (lambda (candidate)
8696 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8697 (elscreen-kill-others)))))))
8698 ;; (anything 'anything-c-source-elscreen)
8701 ;;;; <System>
8703 ;;; Top (process)
8704 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8705 "Top command (batch mode). %s is replaced with `frame-width'.")
8706 (defvar anything-c-source-top
8707 '((name . "Top (Press C-c C-u to refresh)")
8708 (init . anything-c-top-init)
8709 (candidates-in-buffer)
8710 (display-to-real . anything-c-top-display-to-real)
8711 (update . anything-c-top-update)
8712 (persistent-action . anything-c-top-sh-persistent-action)
8713 (persistent-help . "SIGTERM")
8714 (action
8715 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8716 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8717 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8718 ;; (anything 'anything-c-source-top)
8720 (defun anything-c-top-sh (cmd)
8721 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8723 (defun anything-c-top-sh-persistent-action (pid)
8724 (delete-other-windows)
8725 (anything-c-top-sh (format "kill -TERM %s" pid))
8726 (anything-force-update))
8728 (defun anything-c-top-init ()
8729 (with-current-buffer (anything-candidate-buffer 'global)
8730 (call-process-shell-command
8731 (format anything-c-top-command
8732 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8733 nil (current-buffer))))
8735 (defun anything-c-top-display-to-real (line)
8736 (car (split-string line)))
8738 (defun anything-c-top-update ()
8739 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8740 (anything-c-top-init)))
8742 ;;; Timers
8743 (defvar anything-c-source-absolute-time-timers
8744 '((name . "Absolute Time Timers")
8745 (candidates . timer-list)
8746 (type . timer)))
8747 ;; (anything 'anything-c-source-absolute-time-timers)
8749 (defvar anything-c-source-idle-time-timers
8750 '((name . "Idle Time Timers")
8751 (candidates . timer-idle-list)
8752 (type . timer)))
8753 ;; (anything 'anything-c-source-idle-time-timers)
8755 (defun anything-c-timer-real-to-display (timer)
8756 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8757 (append timer nil) ;use `append' to convert vector->list
8758 (format "%s repeat=%5S %s(%s)"
8759 (let ((time (list t1 t2 t3)))
8760 (if idle-delay
8761 (format-time-string "idle-for=%5s" time)
8762 (format-time-string "%m/%d %T" time)))
8763 repeat-delay
8764 func
8765 (mapconcat 'prin1-to-string args " "))))
8767 ;;; X RandR resolution change
8768 ;;; FIXME I do not care multi-display.
8769 (defvar anything-c-xrandr-output "VGA")
8770 (defvar anything-c-xrandr-screen "0")
8771 (defvar anything-c-source-xrandr-change-resolution
8772 '((name . "Change Resolution")
8773 (candidates
8774 . (lambda ()
8775 (with-temp-buffer
8776 (call-process "xrandr" nil (current-buffer) nil
8777 "--screen" anything-c-xrandr-screen "-q")
8778 (goto-char 1)
8779 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8780 collect (match-string 1)))))
8781 (action
8782 ("Change Resolution" . (lambda (mode)
8783 (call-process "xrandr" nil nil nil
8784 "--screen" anything-c-xrandr-screen
8785 "--output" anything-c-xrandr-output
8786 "--mode" mode))))))
8787 ;; (anything 'anything-c-source-xrandr-change-resolution)
8789 ;;; Xfont selection
8792 (defun anything-c-persistent-xfont-action (elm)
8793 "Show current font temporarily"
8794 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8795 (default-font elm))
8796 (unwind-protect
8797 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8798 (set-frame-font current-font))))
8800 (defvar anything-c-xfonts-cache nil)
8801 (defvar anything-c-source-xfonts
8802 '((name . "X Fonts")
8803 (init . (lambda ()
8804 (unless anything-c-xfonts-cache
8805 (setq anything-c-xfonts-cache
8806 (x-list-fonts "*")))))
8807 (candidates . anything-c-xfonts-cache)
8808 (action . (("Copy to kill ring" . (lambda (elm)
8809 (kill-new elm)))
8810 ("Set Font" . (lambda (elm)
8811 (kill-new elm)
8812 (set-frame-font elm 'keep-size)
8813 (message "New font have been copied to kill ring")))))
8814 (persistent-action . anything-c-persistent-xfont-action)
8815 (persistent-help . "Switch to this font temporarily")))
8816 ;; (anything 'anything-c-source-xfonts)
8818 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8821 (defvar anything-c-ucs-max-len 0)
8822 (defun anything-c-calculate-ucs-max-len ()
8823 "Calculate the length of longest `ucs-names' candidate."
8824 (loop with count = 0
8825 for (n . v) in (ucs-names)
8826 for len = (length n)
8827 if (> len count)
8828 do (setq count len)
8829 finally return count))
8831 (defun anything-c-ucs-init ()
8832 "Initialize an anything buffer with ucs symbols.
8833 Only math* symbols are collected."
8834 (unless (> anything-c-ucs-max-len 0)
8835 (setq anything-c-ucs-max-len
8836 (anything-c-calculate-ucs-max-len)))
8837 (with-current-buffer (anything-candidate-buffer
8838 (get-buffer-create "*anything ucs*"))
8839 ;; `ucs-names' fn will not run again, data is cached in
8840 ;; var `ucs-names'.
8841 (loop for (n . v) in (ucs-names)
8842 for len = (length n)
8843 for diff = (+ (- anything-c-ucs-max-len len) 2)
8844 unless (string= "" n)
8845 do (progn (insert (concat
8846 n ":"
8847 (make-string
8848 diff ? )))
8849 (ucs-insert v)
8850 (insert "\n")))))
8852 (defun anything-c-ucs-forward-char (candidate)
8853 (with-anything-current-buffer
8854 (forward-char 1)))
8856 (defun anything-c-ucs-backward-char (candidate)
8857 (with-anything-current-buffer
8858 (forward-char -1)))
8860 (defun anything-c-ucs-delete-backward (candidate)
8861 (with-anything-current-buffer
8862 (delete-char -1)))
8864 (defun anything-c-ucs-insert-char (candidate)
8865 (with-anything-current-buffer
8866 (insert
8867 (replace-regexp-in-string
8868 " " ""
8869 (cadr (split-string candidate ":"))))))
8871 (defun anything-c-ucs-persistent-insert ()
8872 (interactive)
8873 (anything-execute-persistent-action 'action-insert))
8875 (defun anything-c-ucs-persistent-forward ()
8876 (interactive)
8877 (anything-execute-persistent-action 'action-forward))
8879 (defun anything-c-ucs-persistent-backward ()
8880 (interactive)
8881 (anything-execute-persistent-action 'action-back))
8883 (defun anything-c-ucs-persistent-delete ()
8884 (interactive)
8885 (anything-execute-persistent-action 'action-delete))
8887 (defvar anything-c-source-ucs
8888 '((name . "Ucs names")
8889 (init . anything-c-ucs-init)
8890 (candidate-number-limit . 9999)
8891 (candidates-in-buffer)
8892 (mode-line . anything-c-ucs-mode-line-string)
8893 (action-insert . anything-c-ucs-insert-char)
8894 (action-forward . anything-c-ucs-forward-char)
8895 (action-back . anything-c-ucs-backward-char)
8896 (action-delete . anything-c-ucs-delete-backward)
8897 (action . (("Insert" . anything-c-ucs-insert-char)
8898 ("Forward char" . anything-c-ucs-forward-char)
8899 ("Backward char" . anything-c-ucs-backward-char)
8900 ("Delete char backward" . anything-c-ucs-delete-backward))))
8901 "Source for collecting `ucs-names' math symbols.")
8904 ;;; Emacs process
8907 (defvar anything-c-source-emacs-process
8908 '((name . "Emacs Process")
8909 (candidates . (lambda () (mapcar #'process-name (process-list))))
8910 (persistent-action . (lambda (elm)
8911 (delete-process (get-process elm))
8912 (anything-delete-current-selection)))
8913 (persistent-help . "Kill Process")
8914 (action ("Kill Process" . (lambda (elm)
8915 (delete-process (get-process elm)))))))
8916 ;; (anything 'anything-c-source-emacs-process)
8918 ;;; World time
8921 (defvar anything-c-source-time-world
8922 '((name . "Time World List")
8923 (init . (lambda ()
8924 (let ((anything-buffer (anything-candidate-buffer 'global)))
8925 (with-current-buffer anything-buffer
8926 (display-time-world-display display-time-world-list)))))
8927 (candidates-in-buffer)))
8931 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8934 (defvar anything-c-source-apt
8935 '((name . "APT")
8936 (init . anything-c-apt-init)
8937 (candidates-in-buffer)
8938 (candidate-transformer anything-c-apt-candidate-transformer)
8939 (display-to-real . anything-c-apt-display-to-real)
8940 (requires-pattern . 2)
8941 (update . anything-c-apt-refresh)
8942 (action
8943 ("Show package description" . anything-c-apt-cache-show)
8944 ("Install package" . anything-c-apt-install)
8945 ("Remove package" . anything-c-apt-uninstall)
8946 ("Purge package" . anything-c-apt-purge))
8947 (persistent-action . anything-c-apt-persistent-action)
8948 (persistent-help . "Show package description")))
8949 ;; (anything 'anything-c-source-apt)
8951 (defvar anything-c-apt-query "emacs")
8952 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8953 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8954 (defvar anything-c-apt-installed-packages nil)
8955 (defvar anything-c-apt-all-packages nil)
8956 (defvar anything-c-apt-input-history nil)
8958 (defun anything-c-apt-refresh ()
8959 "Refresh installed candidates list."
8960 (setq anything-c-apt-installed-packages nil)
8961 (setq anything-c-apt-all-packages nil))
8963 (defun anything-c-apt-persistent-action (candidate)
8964 "Persistent action for APT source."
8965 (anything-c-apt-cache-show candidate))
8967 (defun anything-c-apt-candidate-transformer (candidates)
8968 "Show installed candidates in a different color."
8969 (loop
8970 with all
8971 for cand in candidates
8972 for name = (anything-c-apt-display-to-real cand)
8973 if (member name anything-c-apt-installed-packages)
8974 collect (propertize cand 'face 'anything-apt-installed) into all
8975 else collect cand into all finally return all))
8977 (defun anything-c-apt-init ()
8978 "Initialize list of debian packages."
8979 (let ((query ""))
8980 (unless (and anything-c-apt-installed-packages
8981 anything-c-apt-all-packages)
8982 (message "Loading package list...")
8983 (setq anything-c-apt-installed-packages
8984 (with-temp-buffer
8985 (call-process-shell-command "dpkg --get-selections"
8986 nil (current-buffer))
8987 (loop for i in (split-string (buffer-string) "\n" t)
8988 collect (car (split-string i)))))
8989 (setq anything-c-apt-all-packages
8990 (with-current-buffer
8991 (anything-candidate-buffer
8992 (get-buffer-create (format "*anything-apt*")))
8993 (erase-buffer)
8994 (call-process-shell-command
8995 (format anything-c-apt-search-command query)
8996 nil (current-buffer))))
8997 (message "Loading package list done")
8998 (sit-for 0.5))))
9000 (defun anything-c-apt-display-to-real (line)
9001 "Return only name of a debian package.
9002 LINE is displayed like:
9003 package name - description."
9004 (car (split-string line " - ")))
9006 (defun anything-c-shell-command-if-needed (command)
9007 "Run shell command COMMAND to describe package.
9008 If a buffer named COMMAND already exists, just switch to it."
9009 (let ((buf (get-buffer command)))
9010 (anything-c-switch-to-buffer (get-buffer-create command))
9011 (unless buf (insert (shell-command-to-string command)))))
9013 (defun anything-c-apt-cache-show (package)
9014 "Show information on apt package PACKAGE."
9015 (anything-c-shell-command-if-needed
9016 (format anything-c-apt-show-command package)))
9018 (defun anything-c-apt-install (package)
9019 "Run 'apt-get install' shell command on PACKAGE."
9020 (anything-c-apt-generic-action :action 'install))
9022 (defun anything-c-apt-uninstall (package)
9023 "Run 'apt-get remove' shell command on PACKAGE."
9024 (anything-c-apt-generic-action :action 'uninstall))
9026 (defun anything-c-apt-purge (package)
9027 "Run 'apt-get purge' shell command on PACKAGE."
9028 (anything-c-apt-generic-action :action 'purge))
9030 (defun* anything-c-apt-generic-action (&key action)
9031 "Run 'apt-get ACTION'.
9032 Support install, remove and purge actions."
9033 (ansi-term (getenv "SHELL") "anything apt")
9034 (term-line-mode)
9035 (let ((command (case action
9036 ('install "sudo apt-get install ")
9037 ('uninstall "sudo apt-get remove ")
9038 ('purge "sudo apt-get purge ")
9039 (t (error "Unknow action"))))
9040 (beg (point))
9042 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9043 (anything-marked-candidates) " ")))
9044 (goto-char (point-max))
9045 (insert (concat command cand-list))
9046 (setq end (point))
9047 (if (y-or-n-p (format "%s package" (symbol-name action)))
9048 (progn
9049 (setq anything-c-external-commands-list nil)
9050 (setq anything-c-apt-installed-packages nil)
9051 (term-char-mode) (term-send-input))
9052 (delete-region beg end) (term-send-eof) (kill-buffer))))
9054 ;; (anything-c-apt-install "jed")
9057 ;;; Anything UI for gentoo portage.
9060 (defvar anything-c-gentoo-use-flags nil)
9061 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9062 (defvar anything-c-cache-gentoo nil)
9063 (defvar anything-c-cache-world nil)
9064 (defvar anything-c-source-gentoo
9065 '((name . "Portage sources")
9066 (init . (lambda ()
9067 (get-buffer-create anything-c-gentoo-buffer)
9068 (unless anything-c-cache-gentoo
9069 (anything-c-gentoo-setup-cache))
9070 (unless anything-c-cache-world
9071 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9072 (anything-c-gentoo-init-list)))
9073 (candidates-in-buffer)
9074 (match . identity)
9075 (candidate-transformer anything-c-highlight-world)
9076 (action . (("Show package" . (lambda (elm)
9077 (anything-c-gentoo-eshell-action elm "eix")))
9078 ("Show history" . (lambda (elm)
9079 (if (member elm anything-c-cache-world)
9080 (anything-c-gentoo-eshell-action elm "genlop -qe")
9081 (message "No infos on packages not yet installed"))))
9082 ("Copy in kill-ring" . kill-new)
9083 ("insert at point" . insert)
9084 ("Browse HomePage" . (lambda (elm)
9085 (let ((urls (anything-c-gentoo-get-url elm)))
9086 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9087 ("Show extra infos" . (lambda (elm)
9088 (if (member elm anything-c-cache-world)
9089 (anything-c-gentoo-eshell-action elm "genlop -qi")
9090 (message "No infos on packages not yet installed"))))
9091 ("Show use flags" . (lambda (elm)
9092 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9093 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9094 (font-lock-mode 1)))
9095 ("Run emerge pretend" . (lambda (elm)
9096 (anything-c-gentoo-eshell-action elm "emerge -p")))
9097 ("Emerge" . (lambda (elm)
9098 (anything-gentoo-install elm :action 'install)))
9099 ("Unmerge" . (lambda (elm)
9100 (anything-gentoo-install elm :action 'uninstall)))
9101 ("Show dependencies" . (lambda (elm)
9102 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9103 ("Show related files" . (lambda (elm)
9104 (anything-c-gentoo-default-action elm "equery" "files")))
9105 ("Refresh" . (lambda (elm)
9106 (anything-c-gentoo-setup-cache)
9107 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9109 ;; (anything 'anything-c-source-gentoo)
9111 (defun* anything-gentoo-install (candidate &key action)
9112 (setq anything-c-external-commands-list nil)
9113 (ansi-term (getenv "SHELL") "Gentoo emerge")
9114 (term-line-mode)
9115 (let ((command (case action
9116 ('install "sudo emerge -av ")
9117 ('uninstall "sudo emerge -avC ")
9118 (t (error "Unknow action"))))
9119 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9120 (beg (point)) end)
9121 (goto-char (point-max))
9122 (insert (concat command elms))
9123 (setq end (point))
9124 (term-char-mode) (term-send-input)))
9126 (defun anything-c-gentoo-default-action (elm command &rest args)
9127 "Gentoo default action that use `anything-c-gentoo-buffer'."
9128 (if (member elm anything-c-cache-world)
9129 (progn
9130 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9131 (erase-buffer)
9132 (let ((com-list (append args (list elm))))
9133 (apply #'call-process command nil t nil
9134 com-list)))
9135 (message "No infos on packages not yet installed")))
9137 (defvar anything-c-source-use-flags
9138 '((name . "Use Flags")
9139 (init . (lambda ()
9140 (unless anything-c-gentoo-use-flags
9141 (anything-c-gentoo-setup-use-flags-cache))
9142 (anything-c-gentoo-get-use)))
9143 (candidates-in-buffer)
9144 (match . identity)
9145 (candidate-transformer anything-c-highlight-local-use)
9146 (action . (("Description"
9147 . (lambda (elm)
9148 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9149 (erase-buffer)
9150 (apply #'call-process "euse" nil t nil
9151 `("-i"
9152 ,elm))
9153 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9154 (font-lock-mode 1)))
9155 ("Enable"
9156 . (lambda (elm)
9157 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9158 ("Disable"
9159 . (lambda (elm)
9160 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9161 ("Remove"
9162 . (lambda (elm)
9163 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9164 ("Show which dep use this flag"
9165 . (lambda (elm)
9166 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9167 (erase-buffer)
9168 (apply #'call-process "equery" nil t nil
9169 `("-C"
9171 ,elm))))))))
9174 ;; (anything 'anything-c-source-use-flags)
9176 (defun anything-c-gentoo-init-list ()
9177 "Initialize buffer with all packages in Portage."
9178 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9179 (buf (anything-candidate-buffer 'portage-buf)))
9180 (with-current-buffer buf
9181 (dolist (i anything-c-cache-gentoo)
9182 (insert (concat i "\n"))))))
9184 (defun anything-c-gentoo-setup-cache ()
9185 "Set up `anything-c-cache-gentoo'"
9186 (setq anything-c-cache-gentoo
9187 (split-string (with-temp-buffer
9188 (call-process "eix" nil t nil
9189 "--only-names")
9190 (buffer-string)))))
9192 (defun anything-c-gentoo-eshell-action (elm command)
9193 (when (get-buffer "*EShell Command Output*")
9194 (kill-buffer "*EShell Command Output*"))
9195 (message "Wait searching...")
9196 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9197 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9198 (progn
9199 (save-window-excursion
9200 (pop-to-buffer "*scratch*")
9201 (eshell-command (format "%s %s" command elm)))
9202 (pop-to-buffer "*EShell Command Output*"))
9203 (eshell-command (format "%s %s" command elm)))))
9205 (defun anything-c-gentoo-get-use ()
9206 "Initialize buffer with all use flags."
9207 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9208 (buf (anything-candidate-buffer 'use-buf)))
9209 (with-current-buffer buf
9210 (dolist (i anything-c-gentoo-use-flags)
9211 (insert (concat i "\n"))))))
9214 (defun anything-c-gentoo-setup-use-flags-cache ()
9215 "Setup `anything-c-gentoo-use-flags'"
9216 (setq anything-c-gentoo-use-flags
9217 (split-string (with-temp-buffer
9218 (call-process "eix" nil t nil
9219 "--print-all-useflags")
9220 (buffer-string)))))
9222 (defun anything-c-gentoo-get-url (elm)
9223 "Return a list of urls from eix output."
9224 (loop
9225 with url-list = (split-string
9226 (with-temp-buffer
9227 (call-process "eix" nil t nil
9228 elm "--format" "<homepage>\n")
9229 (buffer-string)))
9230 with all
9231 for i in url-list
9232 when (and (string-match "^http://.*" i)
9233 (not (member i all)))
9234 collect i into all
9235 finally return all))
9237 (defun anything-c-gentoo-get-world ()
9238 "Return list of all installed package on your system."
9239 (split-string (with-temp-buffer
9240 (call-process "qlist" nil t nil
9241 "-I")
9242 (buffer-string))))
9244 (defun anything-c-gentoo-get-local-use ()
9245 (split-string (with-temp-buffer
9246 (call-process "portageq" nil t nil
9247 "envvar"
9248 "USE")
9249 (buffer-string))))
9252 (defun anything-c-highlight-world (eix)
9253 "Highlight all installed package."
9254 (loop for i in eix
9255 if (member i anything-c-cache-world)
9256 collect (propertize i 'face 'anything-gentoo-match-face)
9257 else
9258 collect i))
9260 (defun anything-c-highlight-local-use (use-flags)
9261 (let ((local-uses (anything-c-gentoo-get-local-use)))
9262 (loop for i in use-flags
9263 if (member i local-uses)
9264 collect (propertize i 'face 'anything-gentoo-match-face)
9265 else
9266 collect i)))
9270 ;;; Anything ratpoison UI
9273 (defvar anything-c-source-ratpoison-commands
9274 '((name . "Ratpoison Commands")
9275 (init . anything-c-ratpoison-commands-init)
9276 (candidates-in-buffer)
9277 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9278 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9279 (candidate-number-limit)))
9280 ;; (anything 'anything-c-source-ratpoison-commands)
9282 (defun anything-c-ratpoison-commands-init ()
9283 (unless (anything-candidate-buffer)
9284 (with-current-buffer (anything-candidate-buffer 'global)
9285 ;; with ratpoison prefix key
9286 (save-excursion
9287 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9288 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9289 (replace-match "<ratpoison> \\1: \\2"))
9290 (goto-char (point-max))
9291 ;; direct binding
9292 (save-excursion
9293 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9294 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9295 (replace-match "\\1: \\2")))))
9297 (defun anything-c-ratpoison-commands-display-to-real (display)
9298 (and (string-match ": " display)
9299 (substring display (match-end 0))))
9301 (defun anything-c-ratpoison-commands-execute (candidate)
9302 (call-process "ratpoison" nil nil nil "-ic" candidate))
9306 ;;; Anything `completing-read' replacement
9309 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9310 "Convert COLLECTION to list removing elements that don't match TEST.
9311 See `anything-comp-read' about supported COLLECTION arguments.
9313 SORT-FN is a predicate to sort COLLECTION.
9315 ALISTP when non--nil will not use `all-completions' to collect
9316 candidates because it doesn't handle alists correctly for anything.
9317 i.e In `all-completions' the keys \(cars of elements\)
9318 are the possible completions. In anything we want to use the cdr instead
9319 like \(display . real\).
9320 See docstring of `all-completions' for more info.
9322 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9323 (let ((cands
9324 (cond ((and (eq collection obarray) test)
9325 (all-completions "" collection test))
9326 ((and (vectorp collection) test)
9327 (loop for i across collection when (funcall test i) collect i))
9328 ((vectorp collection)
9329 (loop for i across collection collect i))
9330 ((and alistp test)
9331 (loop for i in collection when (funcall test i) collect i))
9332 ((and (symbolp collection) (boundp collection))
9333 (symbol-value collection))
9334 (alistp collection)
9335 ((and collection test)
9336 (all-completions "" collection test))
9337 (t (all-completions "" collection)))))
9338 (if sort-fn (sort cands sort-fn) cands)))
9340 (defun anything-cr-default-transformer (candidates source)
9341 "Default filter candidate function for `anything-comp-read'.
9342 Do nothing, just return candidate list unmodified."
9343 candidates)
9345 (defun* anything-comp-read (prompt collection
9346 &key
9347 test
9348 initial-input
9349 default
9350 preselect
9351 (buffer "*Anything Completions*")
9352 must-match
9353 (requires-pattern 0)
9354 (history nil)
9355 input-history
9356 (persistent-action nil)
9357 (persistent-help "DoNothing")
9358 (name "Anything Completions")
9359 candidates-in-buffer
9360 exec-when-only-one
9361 (volatile t)
9362 sort
9363 (fc-transformer 'anything-cr-default-transformer)
9364 (marked-candidates nil)
9365 (alistp t))
9366 "Anything `completing-read' replacement.
9368 - PROMPT is the prompt name to use.
9370 - COLLECTION can be a list, vector, obarray or hash-table.
9371 It can be also a function that receives three arguments:
9372 the values string, predicate and t. See `all-completions' for more details.
9374 Keys description:
9376 - TEST: A predicate called with one arg i.e candidate.
9378 - INITIAL-INPUT: Same as input arg in `anything'.
9380 - PRESELECT: See preselect arg of `anything'.
9382 - DEFAULT: This option is used only for compatibility with regular
9383 Emacs `completing-read'.
9385 - BUFFER: Name of anything-buffer.
9387 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9389 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9391 - HISTORY: A list containing specific history, default is nil.
9392 When it is non--nil, all elements of HISTORY are displayed in
9393 a special source before COLLECTION.
9395 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9396 stored there, if nil or not provided, `minibuffer-history'
9397 will be used instead.
9399 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9401 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9403 - NAME: The name related to this local source.
9405 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9406 to non--nil. (possibles values are t or nil).
9408 - VOLATILE: Use volatile attribute \(enabled by default\).
9410 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9412 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9414 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9416 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9418 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9419 `anything-candidates-in-buffer' which is much faster. It is enabled by default.
9420 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9422 Any prefix args passed during `anything-comp-read' invocation will be recorded
9423 in `anything-current-prefix-arg', otherwise if prefix args where given before
9424 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9425 That's mean you can pass prefix args before or after calling a command
9426 that use `anything-comp-read' See `anything-M-x' for example."
9427 (when (get-buffer anything-action-buffer)
9428 (kill-buffer anything-action-buffer))
9429 (flet ((action-fn (candidate)
9430 (if marked-candidates
9431 (anything-marked-candidates)
9432 (identity candidate))))
9433 (let* ((src-hist `((name . ,(format "%s History" name))
9434 (candidates
9435 . (lambda ()
9436 (let ((all (anything-comp-read-get-candidates
9437 history nil nil ,alistp)))
9438 (anything-fast-remove-dups
9439 (if (and default (not (string= default "")))
9440 (delq nil (cons default (delete default all)))
9441 all)
9442 :test 'equal))))
9443 (filtered-candidate-transformer
9444 . (lambda (candidates sources)
9445 (loop for i in candidates
9446 do (set-text-properties 0 (length i) nil i)
9447 collect i)))
9448 (persistent-action . ,persistent-action)
9449 (persistent-help . ,persistent-help)
9450 (action . ,'action-fn)))
9451 (src `((name . ,name)
9452 (candidates
9453 . (lambda ()
9454 (let ((cands (anything-comp-read-get-candidates
9455 collection test sort alistp)))
9456 (unless (or must-match (string= anything-pattern ""))
9457 (setq cands (append (list anything-pattern) cands)))
9458 (if (and default (not (string= default "")))
9459 (delq nil (cons default (delete default cands)))
9460 cands))))
9461 (filtered-candidate-transformer ,fc-transformer)
9462 (requires-pattern . ,requires-pattern)
9463 (persistent-action . ,persistent-action)
9464 (persistent-help . ,persistent-help)
9465 (action . ,'action-fn)))
9466 (src-1 `((name . ,name)
9467 (init
9468 . (lambda ()
9469 (let ((cands (anything-comp-read-get-candidates
9470 collection test sort alistp)))
9471 (unless (or must-match (string= anything-pattern ""))
9472 (setq cands (append (list anything-pattern) cands)))
9473 (with-current-buffer (anything-candidate-buffer 'global)
9474 (loop for i in
9475 (if (and default (not (string= default "")))
9476 (delq nil (cons default (delete default cands)))
9477 cands)
9478 do (insert (concat i "\n")))))))
9479 (candidates-in-buffer)
9480 (filtered-candidate-transformer ,fc-transformer)
9481 (requires-pattern . ,requires-pattern)
9482 (persistent-action . ,persistent-action)
9483 (persistent-help . ,persistent-help)
9484 (action . ,'action-fn)))
9485 (src-list (list src-hist
9486 (if candidates-in-buffer
9487 src-1
9488 (if volatile
9489 (append src '((volatile)))
9490 src))))
9491 (anything-execute-action-at-once-if-one exec-when-only-one))
9493 (anything
9494 :sources src-list
9495 :input initial-input
9496 :default default
9497 :preselect preselect
9498 :prompt prompt
9499 :resume 'noresume
9500 :history input-history
9501 :buffer buffer)
9502 (unless (or (eq anything-exit-status 1) must-match)
9503 default)
9504 (keyboard-quit)))))
9506 ;; Generic completing-read
9508 ;; Support also function as collection.
9509 ;; e.g M-x man is supported.
9510 ;; Support hash-table and vectors as collection.
9511 ;; NOTE:
9512 ;; Some crap emacs functions may not be supported
9513 ;; like ffap-alternate-file (bad use of completing-read)
9514 ;; and maybe others.
9515 ;; Provide a mode `anything-completion-mode' which turn on
9516 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9518 (defvar anything-completion-mode-string " AC")
9520 (defvar anything-completion-mode-quit-message
9521 "Anything completion disabled")
9523 (defvar anything-completion-mode-start-message
9524 "Anything completion enabled")
9526 ;;; Specialized handlers
9529 (defun anything-completing-read-symbols
9530 (prompt collection test require-match init
9531 hist default inherit-input-method name buffer)
9532 "Specialized function for fast symbols completion in `ac-mode'."
9534 (anything
9535 :sources `((name . ,name)
9536 (init . (lambda ()
9537 (with-current-buffer (anything-candidate-buffer 'global)
9538 (goto-char (point-min))
9539 (when (and default (stringp default)
9540 ;; Some defaults args result as
9541 ;; (symbol-name nil) == "nil".
9542 ;; e.g debug-on-entry.
9543 (not (string= default "nil"))
9544 (not (string= default "")))
9545 (insert (concat default "\n")))
9546 (loop with all = (all-completions "" collection test)
9547 for sym in all
9548 unless (and default (eq sym default))
9549 do (insert (concat sym "\n"))))))
9550 (persistent-action . anything-lisp-completion-persistent-action)
9551 (persistent-help . "Show brief doc in mode-line")
9552 (candidates-in-buffer)
9553 (action . identity))
9554 :prompt prompt
9555 :buffer buffer
9556 :input init
9557 :history hist
9558 :resume 'noresume
9559 :default (or default ""))
9560 (keyboard-quit)))
9563 ;;; Generic completing read
9566 (defun anything-completing-read-default-1
9567 (prompt collection test require-match
9568 init hist default inherit-input-method
9569 name buffer &optional cands-in-buffer exec-when-only-one)
9570 "Call `anything-comp-read' with same args as `completing-read'.
9571 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9572 method which is faster.
9573 It should be used when candidate list don't need to rebuild dynamically."
9574 (let ((history (or (car-safe hist) hist)))
9575 (anything-comp-read
9576 prompt collection
9577 :test test
9578 :fc-transformer 'anything-completing-read-default-transformer
9579 :history history
9580 :input-history history
9581 :must-match require-match
9582 :alistp nil
9583 :name name
9584 :candidates-in-buffer cands-in-buffer
9585 :exec-when-only-one exec-when-only-one
9586 :buffer buffer
9587 ;; If DEF is not provided, fallback to empty string
9588 ;; to avoid `thing-at-point' to be appended on top of list
9589 :default (or default "")
9590 :initial-input init)))
9592 (defun anything-completing-read-default-transformer (candidates source)
9593 ;; In regular `completing-read'
9594 ;; when a candidate is a cons cell
9595 ;; the car is used. Anything use
9596 ;; normally the cdr, so modify that
9597 ;; to fit `completing-read'.
9598 (loop for i in candidates
9599 for cand = (if (consp i) (car i) i)
9600 do (set-text-properties 0 (length cand) nil cand)
9601 collect cand))
9603 (defun anything-completing-read-with-cands-in-buffer
9604 (prompt collection test require-match
9605 init hist default inherit-input-method
9606 name buffer)
9607 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9608 ;; Some commands like find-tag may use `read-file-name' from inside
9609 ;; the calculation of collection. in this case it clash with
9610 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9611 ;; So (re)calculate collection outside of main anything-session.
9612 (setq collection (all-completions "" collection))
9613 (anything-completing-read-default-1 prompt collection test require-match
9614 init hist default inherit-input-method
9615 name buffer t))
9617 (defun* anything-completing-read-default
9618 (prompt collection &optional
9619 predicate require-match
9620 initial-input hist def
9621 inherit-input-method)
9622 "An anything replacement of `completing-read'.
9623 This function should be used only as a `completing-read-function'.
9625 Don't use it directly, use instead `anything-comp-read' in your programs.
9627 See documentation of `completing-read' and `all-completions' for details."
9628 (declare (special anything-completion-mode))
9629 (let* ((current-command this-command)
9630 (str-command (symbol-name current-command))
9631 (buf-name (format "*ac-mode-%s*" str-command))
9632 (entry (assq current-command
9633 anything-completing-read-handlers-alist))
9634 (def-com (cdr-safe entry))
9635 (str-defcom (and def-com (symbol-name def-com)))
9636 (def-args (list prompt collection predicate require-match
9637 initial-input hist def inherit-input-method))
9638 ;; Append the two extra args needed to set the buffer and source name
9639 ;; in anything specialized functions.
9640 (any-args (append def-args (list str-command buf-name)))
9641 anything-completion-mode-start-message ; Be quiet
9642 anything-completion-mode-quit-message
9643 (minibuffer-completion-table collection)
9644 (minibuffer-completion-predicate predicate))
9645 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9646 (unless (or (not entry) def-com)
9647 ;; An entry in *read-handlers-alist exists but have
9648 ;; a nil value, so we exit from here, disable `ac-mode'
9649 ;; and run the command again with it original behavior.
9650 ;; `ac-mode' will be restored on exit.
9651 (return-from anything-completing-read-default
9652 (unwind-protect
9653 (progn
9654 (ac-mode -1)
9655 (call-interactively current-command))
9656 (ac-mode 1))))
9657 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9658 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9659 (when (or (eq def-com 'completing-read)
9660 ;; All specialized functions are prefixed by "anything"
9661 (and (stringp str-defcom)
9662 (not (string-match "^anything" str-defcom))))
9663 (ac-mode -1))
9664 (unwind-protect
9665 (cond (;; An anything specialized function exists, run it.
9666 (and def-com anything-completion-mode)
9667 (apply def-com any-args))
9668 (;; Try to handle `ido-completing-read' everywhere.
9669 (and def-com (eq def-com 'ido-completing-read))
9670 (setcar (memq collection def-args)
9671 (all-completions "" collection predicate))
9672 (apply def-com def-args))
9673 (;; User set explicitely `completing-read' or something similar
9674 ;; in *read-handlers-alist, use this with exactly the same
9675 ;; args as in `completing-read'.
9676 ;; If we are here `anything-completion-mode' is now disabled.
9677 def-com
9678 (apply def-com def-args))
9679 (t ; Fall back to classic `anything-comp-read'.
9680 (anything-completing-read-default-1
9681 prompt collection predicate require-match
9682 initial-input hist def inherit-input-method
9683 str-command buf-name)))
9684 (ac-mode 1)
9685 ;; When exiting minibuffer, `this-command' is set to
9686 ;; `anything-exit-minibuffer', which is unwanted when starting
9687 ;; on another `completing-read', so restore `this-command' to
9688 ;; initial value when exiting.
9689 (setq this-command current-command))))
9691 (defun* anything-generic-read-file-name
9692 (prompt &optional dir default-filename mustmatch initial predicate)
9693 "An anything replacement of `read-file-name'."
9694 (declare (special anything-completion-mode))
9695 (let* ((default (and default-filename
9696 (if (listp default-filename)
9697 (car default-filename)
9698 default-filename)))
9699 (init (or default initial dir default-directory))
9700 (ini-input (and init (expand-file-name init)))
9701 (current-command this-command)
9702 (str-command (symbol-name current-command))
9703 (anything-file-completion-sources
9704 (cons str-command
9705 (remove str-command anything-file-completion-sources)))
9706 (buf-name (format "*ac-mode-%s*" str-command))
9707 (entry (assq current-command
9708 anything-completing-read-handlers-alist))
9709 (def-com (cdr-safe entry))
9710 (str-defcom (symbol-name def-com))
9711 (def-args (list prompt dir default-filename mustmatch initial predicate))
9712 ;; Append the two extra args needed to set the buffer and source name
9713 ;; in anything specialized functions.
9714 (any-args (append def-args (list str-command buf-name)))
9715 (ido-state ido-mode)
9716 anything-completion-mode-start-message ; Be quiet
9717 anything-completion-mode-quit-message ; Same here
9718 fname)
9719 ;; Some functions that normally call `completing-read' can switch
9720 ;; brutally to `read-file-name' (e.g find-tag), in this case
9721 ;; the anything specialized function will fail because it is build
9722 ;; for `completing-read', so set it to 'incompatible to be sure
9723 ;; we switch to `anything-c-read-file-name' and don't try to call it
9724 ;; with wrong number of args.
9725 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9726 (setq def-com 'incompatible))
9727 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9728 (unless (or (not entry) def-com)
9729 (return-from anything-completing-read-default
9730 (unwind-protect
9731 (progn
9732 (ac-mode -1)
9733 (call-interactively current-command))
9734 (ac-mode 1))))
9735 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9736 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9737 (when (or (eq def-com 'read-file-name)
9738 (eq def-com 'ido-read-file-name)
9739 (and (stringp str-defcom)
9740 (not (string-match "^anything" str-defcom))))
9741 (ac-mode -1))
9742 (unwind-protect
9743 (setq fname
9744 (cond (;; A specialized function exists, run it
9745 ;; with the two extra args specific to anything..
9746 (and def-com anything-completion-mode
9747 (not (eq def-com 'ido-read-file-name))
9748 (not (eq def-com 'incompatible)))
9749 (apply def-com any-args))
9750 (;; Def-com value is `ido-read-file-name'
9751 ;; run it with default args.
9752 (and def-com (eq def-com 'ido-read-file-name))
9753 (ido-mode 1)
9754 (apply def-com def-args))
9755 (;; Def-com value is `read-file-name'
9756 ;; run it with default args.
9757 (eq def-com 'read-file-name)
9758 (apply def-com def-args))
9759 (t ; Fall back to classic `anything-c-read-file-name'.
9760 (anything-c-read-file-name
9761 prompt
9762 :name str-command
9763 :buffer buf-name
9764 :initial-input (expand-file-name init dir)
9765 :alistp nil
9766 :test predicate))))
9767 (ac-mode 1)
9768 (ido-mode (if ido-state 1 -1))
9769 ;; Same comment as in `anything-completing-read-default'.
9770 (setq this-command current-command))
9771 (if (and mustmatch (not (file-exists-p fname)))
9772 (if (y-or-n-p "File does not exists, create buffer?")
9773 fname (error "Abort file does not exists"))
9774 fname)))
9776 ;;;###autoload
9777 (define-minor-mode anything-completion-mode
9778 "Toggle generic anything completion.
9780 All functions in Emacs that use `completing-read'
9781 or `read-file-name' and friends will use anything interface
9782 when this mode is turned on.
9783 However you can modify this behavior for functions of your choice
9784 with `anything-completing-read-handlers-alist'.
9786 Called with a positive arg, turn on unconditionally, with a
9787 negative arg turn off.
9788 You can turn it on with `ac-mode'.
9790 Some crap emacs functions may not be supported,
9791 e.g `ffap-alternate-file' and maybe others
9792 You can add such functions to `anything-completing-read-handlers-alist'
9793 with a nil value.
9795 Note: This mode will work only partially on Emacs23."
9796 :group 'anything
9797 :global t
9798 :lighter anything-completion-mode-string
9799 (declare (special completing-read-function))
9800 (if anything-completion-mode
9801 (progn
9802 (setq completing-read-function 'anything-completing-read-default
9803 read-file-name-function 'anything-generic-read-file-name)
9804 (message anything-completion-mode-start-message))
9805 (setq completing-read-function (and (fboundp 'completing-read-default)
9806 'completing-read-default)
9807 read-file-name-function (and (fboundp 'read-file-name-default)
9808 'read-file-name-default))
9809 (message anything-completion-mode-quit-message)))
9811 (defalias 'ac-mode 'anything-completion-mode)
9815 ;;; Eshell completion.
9817 ;; Enable like this in .emacs:
9819 ;; (add-hook 'eshell-mode-hook
9820 ;; #'(lambda ()
9821 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9823 (defvar anything-c-source-esh
9824 '((name . "Eshell completions")
9825 (init . (lambda ()
9826 (setq pcomplete-current-completions nil
9827 pcomplete-last-completion-raw nil)
9828 ;; Eshell-command add this hook in all minibuffers
9829 ;; Remove it for the anything one. (Fixed in Emacs24)
9830 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9831 (candidates . anything-esh-get-candidates)
9832 (action . anything-ec-insert))
9833 "Anything source for Eshell completion.")
9835 ;; Internal.
9836 (defvar anything-ec-target "")
9837 (defun anything-ec-insert (candidate)
9838 "Insert CANDIDATE at point.
9839 This is the same as `ac-insert', just inlined here for compatibility."
9840 (let ((pt (point)))
9841 (when (and anything-ec-target
9842 (search-backward anything-ec-target nil t)
9843 (string= (buffer-substring (point) pt) anything-ec-target))
9844 (delete-region (point) pt)))
9845 (insert candidate))
9847 (defun anything-esh-get-candidates ()
9848 "Get candidates for eshell completion using `pcomplete'."
9849 (catch 'pcompleted
9850 (let* ((pcomplete-stub)
9851 pcomplete-seen pcomplete-norm-func
9852 pcomplete-args pcomplete-last pcomplete-index
9853 (pcomplete-autolist pcomplete-autolist)
9854 (pcomplete-suffix-list pcomplete-suffix-list))
9855 (with-anything-current-buffer
9856 (loop
9857 with table = (pcomplete-completions)
9858 with entry = (condition-case nil
9859 ;; For Emacs24
9860 (try-completion anything-pattern (pcomplete-entries))
9861 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9862 (error
9864 (let ((fc (car (last (pcomplete-parse-arguments)))))
9865 ;; Check if last arg require fname completion.
9866 (and (file-name-directory fc) fc))))
9867 for i in (if (listp table) table ; Emacs23 or commands.
9868 (all-completions pcomplete-stub table)) ; Emacs24
9869 for file-cand = (and entry
9870 (if (file-remote-p i) i
9871 (expand-file-name i (file-name-directory entry))))
9872 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9873 collect file-cand into ls
9874 else collect i into ls
9875 finally return
9876 (if (and entry (not (string= entry "")) (file-exists-p entry))
9877 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9879 ;;; Eshell history.
9882 (defvar anything-c-source-eshell-history
9883 '((name . "Eshell history")
9884 (init . (lambda ()
9885 (let (eshell-hist-ignoredups)
9886 ;; Dump the content's of hist file
9887 ;; to `eshell-history-ring'.
9888 (eshell-read-history eshell-history-file-name)
9889 ;; And now write the content's of ring to file.
9890 (eshell-write-history eshell-history-file-name t)
9891 (with-current-buffer (anything-candidate-buffer 'global)
9892 (insert-file-contents eshell-history-file-name)))
9893 ;; Same comment as in `anything-c-source-esh'
9894 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9895 (candidates-in-buffer)
9896 (filtered-candidate-transformer . (lambda (candidates sources)
9897 (reverse candidates)))
9898 (candidate-number-limit . 9999)
9899 (action . (lambda (candidate)
9900 (eshell-kill-input)
9901 (insert candidate))))
9902 "Anything source for Eshell history.")
9905 ;;; Show completion - an alternative of anything-show-completion.el.
9907 ;; Provide show completion with macro `with-anything-show-completion'.
9910 ;; Called each time cursor move in anything-buffer.
9911 (defun anything-c-show-completion ()
9912 (with-anything-current-buffer
9913 (overlay-put anything-c-show-completion-overlay
9914 'display (anything-get-selection))))
9916 (defun anything-c-show-completion-init-overlay (beg end)
9917 (and anything-c-turn-on-show-completion
9918 (setq anything-c-show-completion-overlay (make-overlay beg end))
9919 (overlay-put anything-c-show-completion-overlay
9920 'face 'anything-lisp-show-completion)))
9922 (defmacro with-anything-show-completion (beg end &rest body)
9923 "Show anything candidate in an overlay at point.
9924 BEG and END are the beginning and end position of the current completion
9925 in `anything-current-buffer'.
9926 BODY is an anything call where we want to enable show completion.
9927 If `anything-c-turn-on-show-completion' is nil just do nothing."
9928 (declare (indent 2) (debug t))
9929 `(let ((anything-move-selection-after-hook
9930 (and anything-c-turn-on-show-completion
9931 (append (list 'anything-c-show-completion)
9932 anything-move-selection-after-hook))))
9933 (unwind-protect
9934 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9935 ,@body)
9936 (and anything-c-turn-on-show-completion
9937 (delete-overlay anything-c-show-completion-overlay)))))
9940 ;;; Lisp symbol completion.
9943 ;;;###autoload
9944 (defun anything-lisp-completion-at-point ()
9945 "Anything lisp symbol completion at point."
9946 (interactive)
9947 (let* ((data (lisp-completion-at-point))
9948 (beg (car data))
9949 (end (point)) ; 'cadr data' is wrong when no space after point.
9950 (plist (nthcdr 3 data))
9951 (pred (plist-get plist :predicate))
9952 (lgst-len 0)
9953 (target (and beg end (buffer-substring-no-properties beg end)))
9954 (candidates (all-completions target (nth 2 data) pred))
9955 (anything-quit-if-no-candidate t)
9956 (anything-execute-action-at-once-if-one t)
9957 (anything-match-plugin-enabled
9958 (member 'anything-compile-source--match-plugin
9959 anything-compile-source-functions)))
9960 (if candidates
9961 (with-anything-show-completion beg end
9962 ;; Overlay is initialized now in anything-current-buffer.
9963 (anything
9964 :sources
9965 '((name . "Lisp completion")
9966 (init . (lambda ()
9967 (with-current-buffer (anything-candidate-buffer 'global)
9968 (loop for sym in candidates
9969 for len = (length sym)
9970 when (> len lgst-len) do (setq lgst-len len)
9971 do (insert (concat sym "\n"))))))
9972 (candidates-in-buffer)
9973 (persistent-action . anything-lisp-completion-persistent-action)
9974 (persistent-help . "Show brief doc in mode-line")
9975 (filtered-candidate-transformer anything-lisp-completion-transformer)
9976 (action . (lambda (candidate)
9977 (delete-region beg end)
9978 (insert candidate))))
9979 :input (if anything-match-plugin-enabled (concat target " ") target)))
9980 (message "[No Match]"))))
9982 (defun anything-lisp-completion-persistent-action (candidate)
9983 (let ((cursor-in-echo-area t)
9984 mode-line-in-non-selected-windows)
9985 (anything-c-show-info-in-mode-line
9986 (propertize
9987 (anything-c-get-first-line-documentation
9988 (intern candidate))
9989 'face 'anything-lisp-completion-info))))
9991 (defun anything-lisp-completion-transformer (candidates source)
9992 "Anything candidates transformer for lisp completion."
9993 (declare (special lgst-len))
9994 (loop for c in candidates
9995 for sym = (intern c)
9996 for annot = (cond ((commandp sym) " (Com)")
9997 ((fboundp sym) " (Fun)")
9998 ((boundp sym) " (Var)")
9999 ((facep sym) " (Face)"))
10000 for spaces = (make-string (- lgst-len (length c)) ? )
10001 collect (cons (concat c spaces annot) c)))
10003 (defun anything-c-get-first-line-documentation (sym)
10004 "Return first line documentation of symbol SYM.
10005 If SYM is not documented, return \"Not documented\"."
10006 (let ((doc (cond ((fboundp sym)
10007 (documentation sym t))
10008 ((boundp sym)
10009 (documentation-property sym 'variable-documentation t))
10010 ((facep sym)
10011 (face-documentation sym))
10012 (t nil))))
10013 (if (and doc (not (string= doc ""))
10014 ;; `documentation' return "\n\n(args...)"
10015 ;; for CL-style functions.
10016 (not (string-match-p "^\n\n" doc)))
10017 (car (split-string doc "\n"))
10018 "Not documented")))
10020 ;;; File completion.
10022 ;; Complete file name at point.
10023 (defun anything-c-thing-before-point ()
10024 "Get symbol name before point.
10025 Borrowed from anything-complete.el, inlined here for compatibility."
10026 (save-excursion
10027 (let ((beg (point)))
10028 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10029 (when (re-search-backward
10030 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10031 (buffer-substring-no-properties beg (match-end 0))))))
10033 ;;;###autoload
10034 (defun anything-c-complete-file-name-at-point ()
10035 "Complete file name at point."
10036 (interactive)
10037 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10038 (end (point))
10039 (beg (- (point) (length init)))
10040 (anything-quit-if-no-candidate t)
10041 (anything-execute-action-at-once-if-one t)
10042 completion)
10043 (with-anything-show-completion beg end
10044 (setq completion (anything-c-read-file-name "FileName: "
10045 :initial-input init)))
10046 (anything-c-insert-file-name-completion-at-point completion)))
10048 ;; Internal
10049 (defvar anything-lisp-completion-counter 0)
10050 ;;;###autoload
10051 (defun anything-lisp-completion-at-point-or-indent (arg)
10052 "First call indent and second call complete lisp symbol.
10053 The second call should happen before `anything-lisp-completion-or-indent-delay',
10054 after this delay, next call will indent again.
10055 After completion, next call is always indent.
10056 See that like click and double mouse click.
10057 One hit indent, two quick hits maybe indent and complete."
10058 (interactive "P")
10059 ;; Be sure `indent-for-tab-command' will not try
10060 ;; to use `completion-at-point'.
10061 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10062 t tab-always-indent)))
10063 (incf anything-lisp-completion-counter)
10064 (unwind-protect
10065 (if (> anything-lisp-completion-counter 1)
10066 (anything-lisp-completion-or-file-name-at-point)
10067 (indent-for-tab-command arg))
10068 ;; After `anything-lisp-completion-or-indent-delay' seconds
10069 ;; reset to 0.
10070 (run-with-timer anything-lisp-completion-or-indent-delay nil
10071 #'(lambda ()
10072 (setq anything-lisp-completion-counter 0)))
10073 ;; Always reset to 0 at second hit.
10074 (when (eq anything-lisp-completion-counter 2)
10075 (setq anything-lisp-completion-counter 0)))))
10077 ;;;###autoload
10078 (defun anything-lisp-completion-or-file-name-at-point ()
10079 "Complete lisp symbol or filename at point.
10080 Filename completion happen if filename is started in
10081 or between double quotes."
10082 (interactive)
10083 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10084 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10085 (save-excursion (search-backward "\"" (point-at-bol) t)))
10086 (anything-c-complete-file-name-at-point)
10087 (anything-lisp-completion-at-point))))
10089 (defun anything-c-apropos-init (test default)
10090 "Init candidates buffer for `anything-c-apropos' sources."
10091 (with-current-buffer (anything-candidate-buffer 'global)
10092 (goto-char (point-min))
10093 (when (and default (stringp default)
10094 ;; Some defaults args result as
10095 ;; (symbol-name nil) == "nil".
10096 ;; e.g debug-on-entry.
10097 (not (string= default "nil"))
10098 (funcall test (intern default)))
10099 (insert (concat default "\n")))
10100 (loop with all = (all-completions "" obarray test)
10101 for sym in all
10102 unless (and default (eq sym default))
10103 do (insert (concat sym "\n")))))
10106 ;;; Run Externals commands within Emacs with anything completion
10109 (defvar anything-external-command-history nil)
10111 (defun anything-c-external-commands-list-1 (&optional sort)
10112 "Returns a list of all external commands the user can execute.
10113 If `anything-c-external-commands-list' is non-nil it will
10114 return its contents. Else it calculates all external commands
10115 and sets `anything-c-external-commands-list'."
10116 (if anything-c-external-commands-list
10117 anything-c-external-commands-list
10118 (setq anything-c-external-commands-list
10119 (loop
10120 with paths = (split-string (getenv "PATH") path-separator)
10121 with completions = ()
10122 for dir in paths
10123 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10124 for lsdir = (loop for i in (directory-files dir t)
10125 for bn = (file-name-nondirectory i)
10126 when (and (not (member bn completions))
10127 (not (file-directory-p i))
10128 (file-executable-p i))
10129 collect bn)
10130 append lsdir into completions
10131 finally return (if sort (sort completions 'string-lessp) completions)))))
10133 (defun anything-run-or-raise (exe &optional file)
10134 "Generic command that run asynchronously EXE.
10135 If EXE is already running just jump to his window if `anything-raise-command'
10136 is non--nil.
10137 When FILE argument is provided run EXE with FILE.
10138 In this case EXE must be provided as \"EXE %s\"."
10139 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10140 "%s" "" exe))))
10141 (proc (if file (concat real-com " " file) real-com)))
10142 (if (get-process proc)
10143 (if anything-raise-command
10144 (shell-command (format anything-raise-command real-com))
10145 (error "Error: %s is already running" real-com))
10146 (when (loop for i in anything-c-external-commands-list thereis real-com)
10147 (message "Starting %s..." real-com)
10148 (if file
10149 (start-process-shell-command
10150 proc nil (format exe (shell-quote-argument file)))
10151 (start-process-shell-command proc nil real-com))
10152 (set-process-sentinel
10153 (get-process proc)
10154 #'(lambda (process event)
10155 (when (and (string= event "finished\n")
10156 anything-raise-command
10157 (not (anything-c-get-pid-from-process-name real-com)))
10158 (shell-command (format anything-raise-command "emacs")))
10159 (message "%s process...Finished." process))))
10160 (setq anything-c-external-commands-list
10161 (cons real-com
10162 (delete real-com anything-c-external-commands-list))))))
10166 ;;; Generic action functions
10169 (defun anything-c-file-buffers (filename)
10170 "Returns a list of buffer names corresponding to FILENAME."
10171 (let ((name (expand-file-name filename))
10172 (buf-list ()))
10173 (dolist (buf (buffer-list) buf-list)
10174 (let ((bfn (buffer-file-name buf)))
10175 (when (and bfn (string= name bfn))
10176 (push (buffer-name buf) buf-list))))))
10178 (defun anything-revert-buffer (candidate)
10179 (with-current-buffer candidate
10180 (when (or (buffer-modified-p)
10181 (not (verify-visited-file-modtime
10182 (get-buffer candidate))))
10183 (revert-buffer t t))))
10185 (defun anything-revert-marked-buffers (ignore)
10186 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10188 (defun anything-kill-marked-buffers (ignore)
10189 (mapc 'kill-buffer (anything-marked-candidates)))
10191 (defun anything-c-delete-file (file)
10192 "Delete the given file after querying the user.
10193 Ask to kill buffers associated with that file, too."
10194 (let ((buffers (anything-c-file-buffers file)))
10195 (if (< emacs-major-version 24)
10196 ;; `dired-delete-file' in Emacs versions < 24
10197 ;; doesn't support delete-by-moving-to-trash
10198 ;; so use `delete-directory' and `delete-file'
10199 ;; that handle it.
10200 (cond ((and (not (file-symlink-p file))
10201 (file-directory-p file)
10202 (directory-files file t dired-re-no-dot))
10203 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10204 (delete-directory file 'recursive)))
10205 ((and (not (file-symlink-p file))
10206 (file-directory-p file))
10207 (delete-directory file))
10208 (t (delete-file file)))
10209 (dired-delete-file
10210 file 'dired-recursive-deletes delete-by-moving-to-trash))
10211 (when buffers
10212 (dolist (buf buffers)
10213 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10214 (kill-buffer buf))))))
10216 (defun anything-get-mailcap-for-file (filename)
10217 "Get the command to use for FILENAME from mailcap files.
10218 The command is like <command %s> and is meant to use with `format'."
10219 (mailcap-parse-mailcaps)
10220 (let* ((ext (file-name-extension filename))
10221 (mime (when ext (mailcap-extension-to-mime ext)))
10222 (result (when mime (mailcap-mime-info mime))))
10223 ;; If elisp file have no associations in .mailcap
10224 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10225 (when (stringp result) result)))
10227 (defun anything-get-default-program-for-file (filename)
10228 "Try to find a default program to open FILENAME.
10229 Try first in `anything-c-external-programs-associations' and then in mailcap file
10230 if nothing found return nil."
10231 (let* ((ext (file-name-extension filename))
10232 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10233 (cond ((and def-prog (not (string= def-prog "")))
10234 (concat def-prog " %s"))
10235 ((and anything-c-default-external-file-browser
10236 (file-directory-p filename))
10237 (concat anything-c-default-external-file-browser " %s"))
10238 (t (anything-get-mailcap-for-file filename)))))
10240 (defun anything-c-open-file-externally (file)
10241 "Open FILE with an external program.
10242 Try to guess which program to use with `anything-get-default-program-for-file'.
10243 If not found or a prefix arg is given query the user which tool to use."
10244 (let* ((fname (expand-file-name file))
10245 (collection (anything-c-external-commands-list-1 'sort))
10246 (def-prog (anything-get-default-program-for-file fname))
10247 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10248 ;; Prefix arg or no default program.
10249 (prog1
10250 (anything-comp-read
10251 "Program: " collection
10252 :must-match t
10253 :name "Open file Externally"
10254 :history anything-external-command-history)
10255 ;; Always prompt to set this program as default.
10256 (setq def-prog nil))
10257 ;; No prefix arg or default program exists.
10258 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10259 (program (concat real-prog-name " %s")))
10260 (unless (or def-prog ; Association exists, no need to record it.
10261 ;; Don't try to record non--filenames associations (e.g urls).
10262 (not (file-exists-p fname)))
10263 (when
10264 (y-or-n-p
10265 (format
10266 "Do you want to make `%s' the default program for this kind of files? "
10267 real-prog-name))
10268 (anything-aif (assoc (file-name-extension fname)
10269 anything-c-external-programs-associations)
10270 (setq anything-c-external-programs-associations
10271 (delete it anything-c-external-programs-associations)))
10272 (push (cons (file-name-extension fname)
10273 (read-string
10274 "Program (Add args maybe and confirm): " real-prog-name))
10275 anything-c-external-programs-associations)
10276 (customize-save-variable 'anything-c-external-programs-associations
10277 anything-c-external-programs-associations)))
10278 (anything-run-or-raise program file)
10279 (setq anything-external-command-history
10280 (cons real-prog-name
10281 (delete real-prog-name
10282 (loop for i in anything-external-command-history
10283 when (executable-find i) collect i))))))
10285 (defun anything-c-find-file-or-marked (candidate)
10286 "Open file CANDIDATE or open anything marked files in background."
10287 (let ((marked (anything-marked-candidates))
10288 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10289 (find-file-wildcards nil))
10290 (if (> (length marked) 1)
10291 ;; Open all marked files in background and display
10292 ;; the first one.
10293 (progn (mapc 'find-file-noselect (cdr marked))
10294 (find-file (car marked)))
10295 (if (and (not (file-exists-p candidate))
10296 (and ffap-url-regexp
10297 (not (string-match ffap-url-regexp candidate)))
10298 (string-match "/$" candidate))
10299 ;; A a non--existing filename ending with /
10300 ;; Create a directory and jump to it.
10301 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10302 (let ((dirfname (directory-file-name candidate)))
10303 (if (file-exists-p dirfname)
10304 (error "Mkdir: Unable to create directory `%s': file exists."
10305 (anything-c-basename dirfname))
10306 (make-directory candidate 'parent)))
10307 (anything-find-files-1 candidate))
10308 ;; A non--existing filename NOT ending with / or
10309 ;; an existing filename, create or jump to it.
10310 (find-file-at-point (car marked))))))
10312 (defun anything-delete-marked-files (ignore)
10313 (let* ((files (anything-marked-candidates))
10314 (len (length files)))
10315 (if (not (y-or-n-p
10316 (format "Delete *%s File(s):\n%s"
10318 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10319 (message "(No deletions performed)")
10320 (dolist (i files)
10321 (set-text-properties 0 (length i) nil i)
10322 (anything-c-delete-file i))
10323 (message "%s File(s) deleted" len))))
10325 (defun anything-ediff-marked-buffers (candidate &optional merge)
10326 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10327 With optional arg MERGE call `ediff-merge-buffers'."
10328 (let ((lg-lst (length (anything-marked-candidates)))
10329 buf1 buf2)
10330 (case lg-lst
10332 (error "Error:You have to mark at least 1 buffer"))
10334 (setq buf1 anything-current-buffer
10335 buf2 (first (anything-marked-candidates))))
10337 (setq buf1 (first (anything-marked-candidates))
10338 buf2 (second (anything-marked-candidates))))
10340 (error "Error:To much buffers marked!")))
10341 (if merge
10342 (ediff-merge-buffers buf1 buf2)
10343 (ediff-buffers buf1 buf2))))
10345 (defun anything-ediff-marked-buffers-merge (candidate)
10346 "Ediff merge `anything-current-buffer' with CANDIDATE.
10347 See `anything-ediff-marked-buffers'."
10348 (anything-ediff-marked-buffers candidate t))
10350 (defun anything-bookmark-get-bookmark-from-name (bmk)
10351 "Return bookmark name even if it is a bookmark with annotation.
10352 e.g prepended with *.
10353 Return nil if bmk is not a valid bookmark."
10354 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10355 (if (assoc bookmark bookmark-alist)
10356 bookmark
10357 (when (assoc bmk bookmark-alist)
10358 bmk))))
10360 (defun anything-delete-marked-bookmarks (ignore)
10361 "Delete this bookmark or all marked bookmarks."
10362 (dolist (i (anything-marked-candidates))
10363 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10364 'batch)))
10366 (defun anything-require-or-error (feature function)
10367 (or (require feature nil t)
10368 (error "Need %s to use `%s'." feature function)))
10370 (defun anything-find-buffer-on-elscreen (candidate)
10371 "Open buffer in new screen, if marked buffers open all in elscreens."
10372 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10373 (anything-aif (anything-marked-candidates)
10374 (dolist (i it)
10375 (let ((target-screen (elscreen-find-screen-by-buffer
10376 (get-buffer i) 'create)))
10377 (elscreen-goto target-screen)))
10378 (let ((target-screen (elscreen-find-screen-by-buffer
10379 (get-buffer candidate) 'create)))
10380 (elscreen-goto target-screen))))
10382 (defun anything-elscreen-find-file (file)
10383 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10384 (elscreen-find-file file))
10386 ;;;###autoload
10387 (defun w32-shell-execute-open-file (file)
10388 (interactive "fOpen file:")
10389 (with-no-warnings
10390 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10391 "/" "\\"
10392 (replace-regexp-in-string ; strip cygdrive paths
10393 "/cygdrive/\\(.\\)" "\\1:"
10394 file nil nil) nil t))))
10396 (defun anything-c-open-file-with-default-tool (file)
10397 "Open FILE with the default tool on this platform."
10398 (if (eq system-type 'windows-nt)
10399 (w32-shell-execute-open-file file)
10400 (start-process "anything-c-open-file-with-default-tool"
10402 (cond ((eq system-type 'gnu/linux)
10403 "xdg-open")
10404 ((or (eq system-type 'darwin) ;; Mac OS X
10405 (eq system-type 'macos)) ;; Mac OS 9
10406 "open"))
10407 file)))
10409 (defun anything-c-open-dired (file)
10410 "Opens a dired buffer in FILE's directory. If FILE is a
10411 directory, open this directory."
10412 (if (file-directory-p file)
10413 (dired file)
10414 (dired (file-name-directory file))
10415 (dired-goto-file file)))
10417 (defun anything-c-display-to-real-line (candidate)
10418 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10419 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10420 (error "Line number not found")))
10422 (defun anything-c-action-line-goto (lineno-and-content)
10423 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10424 (append lineno-and-content
10425 (list (if (and (anything-attr-defined 'target-file)
10426 (not anything-in-persistent-action))
10427 'find-file-other-window
10428 'find-file)))))
10430 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10431 (apply #'anything-goto-file-line
10432 (if (stringp file-line-content)
10433 ;; Case: filtered-candidate-transformer is skipped
10434 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10435 file-line-content)))
10437 (require 'compile)
10438 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10439 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10441 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10442 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10443 (let ((filename (match-string 1 candidate))
10444 (lineno (match-string 2 candidate))
10445 (content (match-string 3 candidate)))
10446 (cons (format "%s:%s\n %s"
10447 (propertize filename 'face compilation-info-face)
10448 (propertize lineno 'face compilation-line-face)
10449 content)
10450 (list (expand-file-name
10451 filename
10452 (or (anything-interpret-value (anything-attr 'default-directory))
10453 (and (anything-candidate-buffer)
10454 (buffer-local-value
10455 'default-directory (anything-candidate-buffer)))))
10456 (string-to-number lineno) content)))))
10458 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10459 (anything-aif (anything-attr 'before-jump-hook)
10460 (funcall it))
10461 (when file (funcall find-file-function file))
10462 (if (anything-attr-defined 'adjust)
10463 (anything-c-goto-line-with-adjustment lineno content)
10464 (anything-goto-line lineno))
10465 (unless (anything-attr-defined 'recenter)
10466 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10467 (anything-aif (anything-attr 'after-jump-hook)
10468 (funcall it))
10469 (when anything-in-persistent-action
10470 (anything-match-line-color-current-line)))
10472 (defun anything-find-file-as-root (candidate)
10473 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10475 (defun anything-find-many-files (ignore)
10476 (mapc 'find-file (anything-marked-candidates)))
10478 ;; borrowed from etags.el
10479 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10480 (defun anything-c-goto-line-with-adjustment (line line-content)
10481 (let ((startpos)
10482 offset found pat)
10483 ;; This constant is 1/2 the initial search window.
10484 ;; There is no sense in making it too small,
10485 ;; since just going around the loop once probably
10486 ;; costs about as much as searching 2000 chars.
10487 (setq offset 1000
10488 found nil
10489 pat (concat (if (eq selective-display t)
10490 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10491 (regexp-quote line-content)))
10492 ;; If no char pos was given, try the given line number.
10493 (setq startpos (progn (anything-goto-line line) (point)))
10494 (or startpos (setq startpos (point-min)))
10495 ;; First see if the tag is right at the specified location.
10496 (goto-char startpos)
10497 (setq found (looking-at pat))
10498 (while (and (not found)
10499 (progn
10500 (goto-char (- startpos offset))
10501 (not (bobp))))
10502 (setq found
10503 (re-search-forward pat (+ startpos offset) t)
10504 offset (* 3 offset))) ; expand search window
10505 (or found
10506 (re-search-forward pat nil t)
10507 (error "not found")))
10508 ;; Position point at the right place
10509 ;; if the search string matched an extra Ctrl-m at the beginning.
10510 (and (eq selective-display t)
10511 (looking-at "\^m")
10512 (forward-char 1))
10513 (beginning-of-line))
10515 (anything-document-attribute 'default-directory "type . file-line"
10516 "`default-directory' to interpret file.")
10517 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10518 "Function to call before jumping to the target location.")
10519 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10520 "Function to call after jumping to the target location.")
10521 (anything-document-attribute 'adjust "type . file-line"
10522 "Search around line matching line contents.")
10523 (anything-document-attribute 'recenter "type . file-line / line"
10524 "`recenter' after jumping.")
10525 (anything-document-attribute 'target-file "type . line"
10526 "Goto line of target-file.")
10528 ;;;###autoload
10529 (defun anything-c-call-interactively (cmd-or-name)
10530 "Execute CMD-OR-NAME as Emacs command.
10531 It is added to `extended-command-history'.
10532 `anything-current-prefix-arg' is used as the command's prefix argument."
10533 (setq extended-command-history
10534 (cons (anything-c-stringify cmd-or-name)
10535 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10536 (let ((current-prefix-arg anything-current-prefix-arg)
10537 (cmd (anything-c-symbolify cmd-or-name)))
10538 (if (stringp (symbol-function cmd))
10539 (execute-kbd-macro (symbol-function cmd))
10540 (setq this-command cmd)
10541 (call-interactively cmd))))
10543 ;;;###autoload
10544 (defun anything-c-set-variable (var)
10545 "Set value to VAR interactively."
10546 (interactive)
10547 (let ((sym (anything-c-symbolify var)))
10548 (set sym (eval-minibuffer (format "Set %s: " var)
10549 (prin1-to-string (symbol-value sym))))))
10550 ;; (setq hh 12)
10551 ;; (anything-c-set-variable 'hh)
10555 ;;; Persistent Action Helpers
10558 (defvar anything-match-line-overlay-face nil)
10559 (defvar anything-match-line-overlay nil)
10561 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10562 "Highlight and underline current position"
10563 (let ((args (list (or start (line-beginning-position))
10564 (or end (1+ (line-end-position)))
10565 buf)))
10566 (if (not anything-match-line-overlay)
10567 (setq anything-match-line-overlay (apply 'make-overlay args))
10568 (apply 'move-overlay anything-match-line-overlay args)))
10569 (overlay-put anything-match-line-overlay
10570 'face (or face anything-match-line-overlay-face))
10571 (when rec
10572 (goto-char start)
10573 (recenter)))
10575 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10578 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10580 (defun anything-match-line-cleanup ()
10581 (when anything-match-line-overlay
10582 (delete-overlay anything-match-line-overlay)
10583 (setq anything-match-line-overlay nil)))
10585 (defun anything-match-line-update ()
10586 (when anything-match-line-overlay
10587 (delete-overlay anything-match-line-overlay)
10588 (anything-match-line-color-current-line)))
10590 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10591 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10594 ;;; Actions Transformers
10597 ;;; Files
10598 (defun anything-c-transform-file-load-el (actions candidate)
10599 "Add action to load the file CANDIDATE if it is an emacs lisp
10600 file. Else return ACTIONS unmodified."
10601 (if (member (file-name-extension candidate) '("el" "elc"))
10602 (append actions '(("Load Emacs Lisp File" . load-file)))
10603 actions))
10605 (defun anything-c-transform-file-browse-url (actions candidate)
10606 "Add an action to browse the file CANDIDATE if it in a html
10607 file or URL. Else return ACTIONS unmodified."
10608 (let ((browse-action '("Browse with Browser" . browse-url)))
10609 (cond ((string-match "^http\\|^ftp" candidate)
10610 (cons browse-action actions))
10611 ((string-match "\\.html?$" candidate)
10612 (append actions (list browse-action)))
10613 (t actions))))
10615 ;;; Function
10616 (defun anything-c-transform-function-call-interactively (actions candidate)
10617 "Add an action to call the function CANDIDATE interactively if
10618 it is a command. Else return ACTIONS unmodified."
10619 (if (commandp (intern-soft candidate))
10620 (append actions '(("Call Interactively"
10622 anything-c-call-interactively)))
10623 actions))
10625 ;;;; S-Expressions
10626 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10627 "If CANDIDATE's `car' is a command, then add an action to
10628 evaluate it and put it onto the `command-history'."
10629 (if (commandp (car (read candidate)))
10630 ;; Make it first entry
10631 (cons '("Eval and put onto command-history" .
10632 (lambda (sexp)
10633 (let ((sym (read sexp)))
10634 (eval sym)
10635 (setq command-history
10636 (cons sym command-history)))))
10637 actions)
10638 actions))
10641 ;;; Candidate Transformers
10644 ;;; Buffers
10645 (defun anything-c-skip-boring-buffers (buffers)
10646 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10648 (defun anything-c-skip-current-buffer (buffers)
10649 (if anything-allow-skipping-current-buffer
10650 (remove (buffer-name anything-current-buffer) buffers)
10651 buffers))
10653 (defun anything-c-shadow-boring-buffers (buffers)
10654 "Buffers matching `anything-c-boring-buffer-regexp' will be
10655 displayed with the `file-name-shadow' face if available."
10656 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10658 (defvar anything-c-buffer-display-string-functions
10659 '(anything-c-buffer-display-string--compilation
10660 anything-c-buffer-display-string--shell
10661 anything-c-buffer-display-string--eshell)
10662 "Functions to setup display string for buffer.
10664 Function has one argument, buffer name.
10665 If it returns string, use it.
10666 If it returns nil, display buffer name.
10667 See `anything-c-buffer-display-string--compilation' for example.")
10669 (defun anything-c-transform-buffer-display-string (buffers)
10670 "Setup display string for buffer candidates
10671 using `anything-c-buffer-display-string-functions'."
10672 (loop for buf in buffers
10673 if (consp buf)
10674 collect buf
10675 else
10676 for disp = (progn (set-buffer buf)
10677 (run-hook-with-args-until-success
10678 'anything-c-buffer-display-string-functions buf))
10679 collect (if disp (cons disp buf) buf)))
10681 (defun anything-c-buffer-display-string--compilation (buf)
10682 (anything-aif (car compilation-arguments)
10683 (format "%s: %s [%s]" buf it default-directory)))
10685 (defun anything-c-buffer-display-string--eshell (buf)
10686 (declare (special eshell-history-ring))
10687 (when (eq major-mode 'eshell-mode)
10688 (format "%s: %s [%s]" buf
10689 (ignore-errors (ring-ref eshell-history-ring 0))
10690 default-directory)))
10692 (defun anything-c-buffer-display-string--shell (buf)
10693 (when (eq major-mode 'shell-mode)
10694 (format "%s: %s [%s]" buf
10695 (ignore-errors (ring-ref comint-input-ring 0))
10696 default-directory)))
10698 ;;; Files
10699 (defun anything-c-shadow-boring-files (files)
10700 "Files matching `anything-c-boring-file-regexp' will be
10701 displayed with the `file-name-shadow' face if available."
10702 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10704 (defun anything-c-skip-boring-files (files)
10705 "Files matching `anything-c-boring-file-regexp' will be skipped."
10706 (anything-c-skip-entries files anything-c-boring-file-regexp))
10707 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10709 (defun anything-c-skip-current-file (files)
10710 "Current file will be skipped."
10711 (remove (buffer-file-name anything-current-buffer) files))
10713 (defun anything-c-w32-pathname-transformer (args)
10714 "Change undesirable features of windows pathnames to ones more acceptable to
10715 other candidate transformers."
10716 (if (eq system-type 'windows-nt)
10717 (mapcar (lambda (x)
10718 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10719 (mapcar (lambda (y)
10720 (replace-regexp-in-string "\\\\" "/" y)) args))
10721 args))
10723 (defun anything-c-shorten-home-path (files)
10724 "Replaces /home/user with ~."
10725 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10726 (getenv "HOME"))))
10727 (mapcar (lambda (file)
10728 (if (and (stringp file) (string-match home file))
10729 (cons (replace-match "~" nil nil file) file)
10730 file))
10731 files)))
10733 ;;; Functions
10734 (defun anything-c-mark-interactive-functions (functions)
10735 "Mark interactive functions (commands) with (i) after the function name."
10736 (let (list)
10737 (loop for function in functions
10738 do (push (cons (concat function
10739 (when (commandp (intern-soft function)) " (i)"))
10740 function)
10741 list)
10742 finally (return (nreverse list)))))
10745 ;;; Adaptive Sorting of Candidates
10748 ;; Internal
10749 (defvar anything-c-adaptive-done nil
10750 "nil if history information is not yet stored for the current
10751 selection.")
10753 (defvar anything-c-adaptive-history nil
10754 "Contains the stored history information.
10755 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10757 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10758 "Reset `anything-c-adaptive-done' when anything is started."
10759 (when anything-c-use-adaptative-sorting
10760 (setq anything-c-adaptive-done nil)))
10762 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10763 "Store history information when action is executed on selected candidate."
10764 (when anything-c-use-adaptative-sorting
10765 (anything-c-adaptive-store-selection)))
10767 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10768 "Store history information when the user goes to the action buffer."
10769 (when anything-c-use-adaptative-sorting
10770 (anything-c-adaptive-store-selection)))
10772 (defun anything-c-source-use-adaptative-p (&optional source-name)
10773 "Return current source only if it use adaptative history, nil otherwise."
10774 (when anything-c-use-adaptative-sorting
10775 (let* ((source (or source-name (anything-get-current-source)))
10776 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10777 (assoc (assoc-default 'type source)
10778 anything-type-attributes))
10779 (assoc-default 'candidate-transformer
10780 (assoc (assoc-default 'type source)
10781 anything-type-attributes))
10782 (assoc-default 'filtered-candidate-transformer source)
10783 (assoc-default 'candidate-transformer source))))
10784 (if (listp adapt-source)
10785 (when (member 'anything-c-adaptive-sort adapt-source) source)
10786 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10788 (defun anything-c-adaptive-store-selection ()
10789 "Store history information for the selected candidate."
10790 (unless anything-c-adaptive-done
10791 (setq anything-c-adaptive-done t)
10792 (let ((source (anything-c-source-use-adaptative-p)))
10793 (when source
10794 (let* ((source-name (or (assoc-default 'type source)
10795 (assoc-default 'name source)))
10796 (source-info (or (assoc source-name anything-c-adaptive-history)
10797 (progn
10798 (push (list source-name) anything-c-adaptive-history)
10799 (car anything-c-adaptive-history))))
10800 (selection (anything-get-selection))
10801 (selection-info (progn
10802 (setcdr source-info
10803 (cons
10804 (let ((found (assoc selection (cdr source-info))))
10805 (if (not found)
10806 ;; new entry
10807 (list selection)
10809 ;; move entry to the beginning of the
10810 ;; list, so that it doesn't get
10811 ;; trimmed when the history is
10812 ;; truncated
10813 (setcdr source-info
10814 (delete found (cdr source-info)))
10815 found))
10816 (cdr source-info)))
10817 (cadr source-info)))
10818 (pattern-info (progn
10819 (setcdr selection-info
10820 (cons
10821 (let ((found (assoc anything-pattern (cdr selection-info))))
10822 (if (not found)
10823 ;; new entry
10824 (cons anything-pattern 0)
10826 ;; move entry to the beginning of the
10827 ;; list, so if two patterns used the
10828 ;; same number of times then the one
10829 ;; used last appears first in the list
10830 (setcdr selection-info
10831 (delete found (cdr selection-info)))
10832 found))
10833 (cdr selection-info)))
10834 (cadr selection-info))))
10836 ;; increase usage count
10837 (setcdr pattern-info (1+ (cdr pattern-info)))
10839 ;; truncate history if needed
10840 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10841 (setcdr selection-info
10842 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10844 (defun anything-c-adaptative-maybe-load-history ()
10845 (when (and anything-c-use-adaptative-sorting
10846 (file-readable-p anything-c-adaptive-history-file))
10847 (load-file anything-c-adaptive-history-file)))
10849 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10850 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10852 (defun anything-c-adaptive-save-history (&optional arg)
10853 "Save history information to file given by `anything-c-adaptive-history-file'."
10854 (interactive "p")
10855 (when anything-c-use-adaptative-sorting
10856 (with-temp-buffer
10857 (insert
10858 ";; -*- mode: emacs-lisp -*-\n"
10859 ";; History entries used for anything adaptive display.\n")
10860 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10861 (current-buffer))
10862 (insert ?\n)
10863 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10864 (unless arg 'quiet)))))
10866 (defun anything-c-adaptive-sort (candidates source)
10867 "Sort the CANDIDATES for SOURCE by usage frequency.
10868 This is a filtered candidate transformer you can use for the
10869 attribute `filtered-candidate-transformer' of a source in
10870 `anything-sources' or a type in `anything-type-attributes'."
10871 (let* ((source-name (or (assoc-default 'type source)
10872 (assoc-default 'name source)))
10873 (source-info (assoc source-name anything-c-adaptive-history)))
10874 (if source-info
10875 (let ((usage
10876 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10877 ;; pairs
10878 (mapcar (lambda (candidate-info)
10879 (let ((count 0))
10880 (dolist (pattern-info (cdr candidate-info))
10881 (if (not (equal (car pattern-info)
10882 anything-pattern))
10883 (incf count (cdr pattern-info))
10885 ;; if current pattern is equal to the previously
10886 ;; used one then this candidate has priority
10887 ;; (that's why its count is boosted by 10000) and
10888 ;; it only has to compete with other candidates
10889 ;; which were also selected with the same pattern
10890 (setq count (+ 10000 (cdr pattern-info)))
10891 (return)))
10892 (cons (car candidate-info) count)))
10893 (cdr source-info)))
10894 sorted)
10895 (if (and usage (consp usage))
10896 ;; sort the list in descending order, so candidates with highest
10897 ;; priorty come first
10898 (progn
10899 (setq usage (sort usage (lambda (first second)
10900 (> (cdr first) (cdr second)))))
10902 ;; put those candidates first which have the highest usage count
10903 (dolist (info usage)
10904 (when (member* (car info) candidates
10905 :test 'anything-c-adaptive-compare)
10906 (push (car info) sorted)
10907 (setq candidates (remove* (car info) candidates
10908 :test 'anything-c-adaptive-compare))))
10910 ;; and append the rest
10911 (append (reverse sorted) candidates nil))
10912 (message "Your `%s' is maybe corrupted or too old, \
10913 you should reinitialize it with `anything-c-reset-adaptative-history'"
10914 anything-c-adaptive-history-file)
10915 (sit-for 1)
10916 candidates))
10917 ;; if there is no information stored for this source then do nothing
10918 candidates)))
10920 ;;;###autoload
10921 (defun anything-c-reset-adaptative-history ()
10922 "Delete all `anything-c-adaptive-history' and his file.
10923 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10924 (interactive)
10925 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10926 (setq anything-c-adaptive-history nil)
10927 (delete-file anything-c-adaptive-history-file)))
10929 (defun anything-c-adaptive-compare (x y)
10930 "Compare candidates X and Y taking into account that the
10931 candidate can be in (DISPLAY . REAL) format."
10932 (equal (if (listp x)
10933 (cdr x)
10935 (if (listp y)
10936 (cdr y)
10937 y)))
10941 ;;; Outliner
10944 (defvar anything-outline-goto-near-line-flag t)
10945 (defvar anything-outline-using nil)
10946 (defun anything-after-update-hook--outline ()
10947 (if (and (eq anything-outline-using t)
10948 (eq anything-outline-goto-near-line-flag t))
10949 (anything-outline-goto-near-line)))
10950 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10952 (defun anything-outline-goto-near-line ()
10953 (with-anything-window
10954 ;; TODO need consideration whether to update position by every input.
10955 (when t ; (equal anything-pattern "")
10956 (anything-goto-line 2)
10957 (let ((lineno (with-anything-current-buffer
10958 (line-number-at-pos (car anything-current-position)))))
10959 (block exit
10960 (while (<= (progn (skip-chars-forward " ")
10961 (or (number-at-point) lineno))
10962 lineno)
10963 (forward-line 1)
10964 (when (eobp)
10965 (forward-line -1)
10966 (return-from exit))))
10967 (forward-line -1)
10968 (and (bobp) (forward-line 1))
10969 (and (anything-pos-header-line-p) (forward-line -2))
10970 (anything-mark-current-line)))))
10974 ;;; Plug-in
10977 ;; Plug-in: info-index
10978 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10979 (let (result)
10980 (unless (anything-candidate-buffer)
10981 (save-window-excursion
10982 (info file)
10983 (let (Info-history
10984 (tobuf (anything-candidate-buffer 'global))
10985 (infobuf (current-buffer))
10986 s e)
10987 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10988 (Info-goto-node node)
10989 (goto-char (point-min))
10990 (while (search-forward "\n* " nil t)
10991 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10992 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10993 (setq s (point-at-bol)
10994 e (point-at-eol))
10995 (with-current-buffer tobuf
10996 (insert-buffer-substring infobuf s e)
10997 (insert "\n"))))))))))
10999 (defun anything-c-info-goto (node-line)
11000 (Info-goto-node (car node-line))
11001 (anything-goto-line (cdr node-line)))
11003 (defun anything-c-info-display-to-real (line)
11004 (and (string-match
11005 ;; This regexp is stolen from Info-apropos-matches
11006 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11007 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11008 (string-to-number (or (match-string 3 line) "1")))))
11010 (defun anything-c-make-info-source (source file)
11011 `(,@source
11012 (name . ,(concat "Info Index: " file))
11013 (info-file . ,file)
11014 (init . anything-c-info-init)
11015 (display-to-real . anything-c-info-display-to-real)
11016 (get-line . buffer-substring)
11017 (candidates-in-buffer)
11018 (action ("Goto node" . anything-c-info-goto))))
11020 (defun anything-compile-source--info-index (source)
11021 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11022 (anything-c-make-info-source source it)
11023 source))
11024 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11026 (anything-document-attribute 'info-index "info-index plugin"
11027 "Create a source of info index very easily.
11029 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11031 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11032 "Index nodes of info file.
11034 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11035 Some info files are missing index specification.
11037 ex. See `anything-c-source-info-screen'.")
11039 ;; Plug-in: candidates-file
11040 (defun anything-compile-source--candidates-file (source)
11041 (if (assoc-default 'candidates-file source)
11042 `((init anything-p-candidats-file-init
11043 ,@(let ((orig-init (assoc-default 'init source)))
11044 (cond ((null orig-init) nil)
11045 ((functionp orig-init) (list orig-init))
11046 (t orig-init))))
11047 (candidates-in-buffer)
11048 ,@source)
11049 source))
11050 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11052 (defun anything-p-candidats-file-init ()
11053 (destructuring-bind (file &optional updating)
11054 (anything-mklist (anything-attr 'candidates-file))
11055 (setq file (anything-interpret-value file))
11056 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11057 (when updating
11058 (buffer-disable-undo)
11059 (font-lock-mode -1)
11060 (auto-revert-mode 1)))))
11062 (anything-document-attribute 'candidates-file "candidates-file plugin"
11063 "Use a file as the candidates buffer.
11065 1st argument is a filename, string or function name or variable name.
11066 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11068 ;; Plug-in: headline
11069 (defun anything-compile-source--anything-headline (source)
11070 (if (assoc-default 'headline source)
11071 (append '((init . anything-headline-init)
11072 (get-line . buffer-substring)
11073 (type . line))
11074 source
11075 '((candidates-in-buffer)
11076 (persistent-help . "Show this line")))
11077 source))
11078 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11080 (defun anything-headline-init ()
11081 (when (and (anything-current-buffer-is-modified)
11082 (with-anything-current-buffer
11083 (eval (or (anything-attr 'condition) t))))
11084 (anything-headline-make-candidate-buffer
11085 (anything-interpret-value (anything-attr 'headline))
11086 (anything-interpret-value (anything-attr 'subexp)))))
11088 (anything-document-attribute 'headline "Headline plug-in"
11089 "Regexp string for anything-headline to scan.")
11090 (anything-document-attribute 'condition "Headline plug-in"
11091 "A sexp representing the condition to use anything-headline.")
11092 (anything-document-attribute 'subexp "Headline plug-in"
11093 "Display (match-string-no-properties subexp).")
11095 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11096 ;; of regexps.
11098 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11099 ;; 2. Sort this list by start-of-match.
11100 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11102 ;; It's quite brilliantly written.
11106 (defun anything-headline-get-candidates (regexp subexp)
11107 (with-anything-current-buffer
11108 (save-excursion
11109 (goto-char (point-min))
11110 (if (functionp regexp) (setq regexp (funcall regexp)))
11111 (let (hierarchy curhead)
11112 (flet ((matched ()
11113 (if (numberp subexp)
11114 (cons (match-string-no-properties subexp) (match-beginning subexp))
11115 (cons (buffer-substring (point-at-bol) (point-at-eol))
11116 (point-at-bol))))
11117 (hierarchies (headlines)
11118 (1+ (loop for (_ . hierarchy) in headlines
11119 maximize hierarchy)))
11120 (vector-0-n (v n)
11121 (loop for i from 0 to hierarchy
11122 collecting (aref curhead i)))
11123 (arrange (headlines)
11124 (unless (null headlines) ; FIX headlines empty bug!
11125 (loop with curhead = (make-vector (hierarchies headlines) "")
11126 for ((str . pt) . hierarchy) in headlines
11127 do (aset curhead hierarchy str)
11128 collecting
11129 (cons
11130 (format "H%d:%s" (1+ hierarchy)
11131 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11132 pt)))))
11133 (if (listp regexp)
11134 (arrange
11135 (sort
11136 (loop for re in regexp
11137 for hierarchy from 0
11138 do (goto-char (point-min))
11139 appending
11140 (loop
11141 while (re-search-forward re nil t)
11142 collect (cons (matched) hierarchy)))
11143 (lambda (a b) (> (cdar b) (cdar a)))))
11144 (loop while (re-search-forward regexp nil t)
11145 collect (matched))))))))
11148 (defun anything-headline-make-candidate-buffer (regexp subexp)
11149 (with-current-buffer (anything-candidate-buffer 'local)
11150 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11151 do (insert
11152 (format "%5d:%s\n"
11153 (with-anything-current-buffer
11154 (line-number-at-pos pos))
11155 content)))))
11157 (defun anything-headline-goto-position (pos recenter)
11158 (goto-char pos)
11159 (unless recenter
11160 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11163 ;; Plug-in: persistent-help
11164 (defun anything-compile-source--persistent-help (source)
11165 (append source '((header-line . anything-persistent-help-string))))
11166 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11168 (defun anything-persistent-help-string ()
11169 (substitute-command-keys
11170 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11171 (or (anything-interpret-value (anything-attr 'persistent-help))
11172 (anything-aif (or (assoc-default 'persistent-action
11173 (anything-get-current-source))
11174 (assoc-default 'action
11175 (anything-get-current-source)))
11176 (cond ((symbolp it) (symbol-name it))
11177 ((listp it) (or (ignore-errors (caar it)) ""))))
11179 " (keeping session)")))
11181 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11182 "A string to explain persistent-action of this source.
11183 It also accepts a function or a variable name.")
11185 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11187 ;; Plug-in: Type customize
11188 (defun anything-c-uniq-list (lst)
11189 "Like `remove-duplicates' in CL.
11190 But cut deeper duplicates and test by `equal'. "
11191 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11192 (defvar anything-additional-type-attributes nil)
11193 (defun anything-c-arrange-type-attribute (type spec)
11194 "Override type attributes by `define-anything-type-attribute'.
11196 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11198 Example: Set `play-sound-file' as default action
11199 (anything-c-arrange-type-attribute 'file
11200 '((action (\"Play sound\" . play-sound-file)
11201 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11204 (add-to-list 'anything-additional-type-attributes
11205 (cons type
11206 (loop with typeattr = (assoc-default type anything-type-attributes)
11207 for (attr . value) in spec
11208 if (listp value)
11209 collect (cons attr
11210 (anything-c-uniq-list
11211 (loop for v in value
11212 if (eq v 'REST)
11213 append (assoc-default attr typeattr)
11214 else
11215 collect v)))
11216 else
11217 collect (cons attr value)))))
11218 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11220 (defun anything-compile-source--type-customize (source)
11221 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11222 (append it source)
11223 source))
11224 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11226 ;; Plug-in: default-action
11227 (defun anything-compile-source--default-action (source)
11228 (anything-aif (assoc-default 'default-action source)
11229 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11230 source)
11231 source))
11232 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11233 (anything-document-attribute 'default-action "default-action plug-in"
11234 "Default action.")
11237 ;;; Toggle anything-match-plugin
11240 (defvar anything-mp-initial-highlight-delay nil)
11242 ;;;###autoload
11243 (defun anything-c-toggle-match-plugin ()
11244 "Toggle anything-match-plugin."
11245 (interactive)
11246 (let ((anything-match-plugin-enabled
11247 (member 'anything-compile-source--match-plugin
11248 anything-compile-source-functions)))
11249 (flet ((disable-match-plugin ()
11250 (setq anything-compile-source-functions
11251 (delq 'anything-compile-source--match-plugin
11252 anything-compile-source-functions))
11253 (setq anything-mp-initial-highlight-delay
11254 anything-mp-highlight-delay)
11255 (setq anything-mp-highlight-delay nil))
11256 (enable-match-plugin ()
11257 (require 'anything-match-plugin)
11258 (unless anything-mp-initial-highlight-delay
11259 (setq anything-mp-initial-highlight-delay
11260 anything-mp-highlight-delay))
11261 (setq anything-compile-source-functions
11262 (cons 'anything-compile-source--match-plugin
11263 anything-compile-source-functions))
11264 (unless anything-mp-highlight-delay
11265 (setq anything-mp-highlight-delay
11266 anything-mp-initial-highlight-delay))))
11267 (if anything-match-plugin-enabled
11268 (when (y-or-n-p "Really disable match-plugin? ")
11269 (disable-match-plugin)
11270 (message "Anything-match-plugin disabled"))
11271 (when (y-or-n-p "Really enable match-plugin? ")
11272 (enable-match-plugin)
11273 (message "Anything-match-plugin enabled"))))))
11277 ;;; Type Attributes
11280 (define-anything-type-attribute 'buffer
11281 `((action
11282 ("Switch to buffer" . anything-c-switch-to-buffer)
11283 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11284 ("Switch to buffer other window" . switch-to-buffer-other-window)
11285 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11286 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11287 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11288 ("Query replace" . anything-c-buffer-query-replace)
11289 ("View buffer" . view-buffer)
11290 ("Display buffer" . display-buffer)
11291 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11292 ("Revert buffer(s)" . anything-revert-marked-buffers)
11293 ("Insert buffer" . insert-buffer)
11294 ("Kill buffer(s)" . anything-kill-marked-buffers)
11295 ("Diff with file" . diff-buffer-with-file)
11296 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11297 ("Ediff Merge marked buffers" . (lambda (candidate)
11298 (anything-ediff-marked-buffers candidate t))))
11299 (persistent-help . "Show this buffer")
11300 (candidate-transformer anything-c-skip-current-buffer
11301 anything-c-skip-boring-buffers
11302 anything-c-transform-buffer-display-string))
11303 "Buffer or buffer name.")
11305 (define-anything-type-attribute 'file
11306 `((action
11307 ("Find file" . anything-find-many-files)
11308 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11309 ("Find file as root" . anything-find-file-as-root)
11310 ("Find file other window" . find-file-other-window)
11311 ("Find file other frame" . find-file-other-frame)
11312 ("Open dired in file's directory" . anything-c-open-dired)
11313 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11314 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11315 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11316 ("Checksum File" . anything-ff-checksum)
11317 ("Ediff File" . anything-find-files-ediff-files)
11318 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11319 ("View file" . view-file)
11320 ("Insert file" . insert-file)
11321 ("Delete file(s)" . anything-delete-marked-files)
11322 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11323 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11324 ("Find file in hex dump" . hexl-find-file))
11325 (persistent-help . "Show this file")
11326 (action-transformer anything-c-transform-file-load-el
11327 anything-c-transform-file-browse-url)
11328 (candidate-transformer anything-c-w32-pathname-transformer
11329 anything-c-skip-current-file
11330 anything-c-skip-boring-files
11331 anything-c-shorten-home-path))
11332 "File name.")
11334 (let ((actions '(("Describe command" . describe-function)
11335 ("Add command to kill ring" . anything-c-kill-new)
11336 ("Go to command's definition" . find-function)
11337 ("Debug on entry" . debug-on-entry)
11338 ("Cancel debug on entry" . cancel-debug-on-entry)
11339 ("Trace function" . trace-function)
11340 ("Trace function (background)" . trace-function-background)
11341 ("Untrace function" . untrace-function))))
11342 (define-anything-type-attribute 'command
11343 `((action ("Call interactively" . anything-c-call-interactively)
11344 ,@actions)
11345 ;; Sort commands according to their usage count.
11346 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11347 (coerce . anything-c-symbolify)
11348 (persistent-action . describe-function))
11349 "Command. (string or symbol)")
11351 (define-anything-type-attribute 'function
11352 `((action . ,actions)
11353 (action-transformer anything-c-transform-function-call-interactively)
11354 (candidate-transformer anything-c-mark-interactive-functions)
11355 (coerce . anything-c-symbolify))
11356 "Function. (string or symbol)"))
11358 (define-anything-type-attribute 'variable
11359 '((action ("Describe variable" . describe-variable)
11360 ("Add variable to kill ring" . anything-c-kill-new)
11361 ("Go to variable's definition" . find-variable)
11362 ("Set variable" . anything-c-set-variable))
11363 (coerce . anything-c-symbolify))
11364 "Variable.")
11366 (define-anything-type-attribute 'sexp
11367 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11368 ("Add s-expression to kill ring" . kill-new))
11369 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11370 "String representing S-Expressions.")
11372 (define-anything-type-attribute 'bookmark
11373 `((coerce . anything-bookmark-get-bookmark-from-name)
11374 (action
11375 ("Jump to bookmark" . (lambda (bookmark)
11376 (let ((current-prefix-arg anything-current-prefix-arg))
11377 (bookmark-jump bookmark))
11378 (anything-update)))
11379 ("Jump to BM other window" . (lambda (bookmark)
11380 (bookmark-jump-other-window bookmark)
11381 (anything-update)))
11382 ("Bookmark edit annotation" . bookmark-edit-annotation)
11383 ("Bookmark show annotation" . bookmark-show-annotation)
11384 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11385 ,@(and (locate-library "bookmark-extensions")
11386 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11387 ("Rename bookmark" . bookmark-rename)
11388 ("Relocate bookmark" . bookmark-relocate)))
11389 "Bookmark name.")
11391 (define-anything-type-attribute 'line
11392 '((display-to-real . anything-c-display-to-real-line)
11393 (action ("Go to Line" . anything-c-action-line-goto)))
11394 "LINENO:CONTENT string, eg. \" 16:foo\".
11396 Optional `target-file' attribute is a name of target file.
11398 Optional `before-jump-hook' attribute is a function with no
11399 arguments which is called before jumping to position.
11401 Optional `after-jump-hook' attribute is a function with no
11402 arguments which is called after jumping to position.
11404 If `adjust' attribute is specified, searches the line whose
11405 content is CONTENT near the LINENO.
11407 If `recenter' attribute is specified, the line is displayed at
11408 the center of window, otherwise at the top of window.
11411 (define-anything-type-attribute 'file-line
11412 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11413 (multiline)
11414 (action ("Go to" . anything-c-action-file-line-goto)))
11415 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11417 Optional `default-directory' attribute is a default-directory
11418 FILENAME is interpreted.
11420 Optional `before-jump-hook' attribute is a function with no
11421 arguments which is called before jumping to position.
11423 Optional `after-jump-hook' attribute is a function with no
11424 arguments which is called after jumping to position.
11426 If `adjust' attribute is specified, searches the line whose
11427 content is CONTENT near the LINENO.
11429 If `recenter' attribute is specified, the line is displayed at
11430 the center of window, otherwise at the top of window.
11433 (define-anything-type-attribute 'timer
11434 '((real-to-display . anything-c-timer-real-to-display)
11435 (action ("Cancel Timer" . cancel-timer)
11436 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11437 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11438 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11439 (persistent-help . "Describe Function"))
11440 "Timer.")
11443 ;;; Default `anything-sources'
11444 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11445 ;; tend to invoke M-x anything directly. So I offer default setting.
11446 (setq anything-sources
11447 '(anything-c-source-buffers-list
11448 anything-c-source-recentf
11449 anything-c-source-files-in-current-dir+))
11452 ;;; Preconfigured Anything
11455 ;;;###autoload
11456 (defun anything-mini ()
11457 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11458 (interactive)
11459 (anything-other-buffer '(anything-c-source-buffers-list
11460 anything-c-source-recentf
11461 anything-c-source-buffer-not-found)
11462 "*anything mini*"))
11463 ;;;###autoload
11464 (defun anything-for-files ()
11465 "Preconfigured `anything' for opening files.
11466 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11467 (interactive)
11468 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11470 ;;;###autoload
11471 (defun anything-recentf ()
11472 "Preconfigured `anything' for `recentf'."
11473 (interactive)
11474 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11476 ;;;###autoload
11477 (defun anything-info-at-point (arg)
11478 "Preconfigured `anything' for searching info at point.
11479 With a prefix-arg insert symbol at point."
11480 (interactive "P")
11481 (let ((anything-c-google-suggest-default-function
11482 'anything-c-google-suggest-emacs-lisp))
11483 (anything :sources '(anything-c-source-info-elisp
11484 anything-c-source-info-cl
11485 anything-c-source-info-pages
11486 anything-c-source-google-suggest)
11487 :input (and arg (thing-at-point 'symbol))
11488 :buffer "*anything info*")))
11490 ;;;###autoload
11491 (defun anything-info-emacs ()
11492 "Preconfigured anything for Emacs manual index."
11493 (interactive)
11494 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11496 ;;;###autoload
11497 (defun anything-show-kill-ring ()
11498 "Preconfigured `anything' for `kill-ring'.
11499 It is drop-in replacement of `yank-pop'.
11500 You may bind this command to M-y.
11501 First call open the kill-ring browser, next calls move to next line."
11502 (interactive)
11503 (let ((buf "*anything kill-ring*"))
11504 (if (get-buffer-window buf)
11505 (with-anything-window
11506 (if (eq (overlay-end anything-selection-overlay) (point-max))
11507 (anything-beginning-of-buffer)
11508 (anything-next-line)))
11509 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11511 ;;;###autoload
11512 (defun anything-minibuffer-history ()
11513 "Preconfigured `anything' for `minibuffer-history'."
11514 (interactive)
11515 (let ((enable-recursive-minibuffers t))
11516 (anything-other-buffer 'anything-c-source-minibuffer-history
11517 "*anything minibuffer-history*")))
11519 ;;;###autoload
11520 (defun anything-gentoo ()
11521 "Preconfigured `anything' for gentoo linux."
11522 (interactive)
11523 (anything-other-buffer '(anything-c-source-gentoo
11524 anything-c-source-use-flags)
11525 "*anything gentoo*"))
11527 ;;;###autoload
11528 (defun anything-imenu ()
11529 "Preconfigured `anything' for `imenu'."
11530 (interactive)
11531 (anything :sources 'anything-c-source-imenu
11532 :buffer "*anything imenu*"))
11534 ;;;###autoload
11535 (defun anything-google-suggest ()
11536 "Preconfigured `anything' for google search with google suggest."
11537 (interactive)
11538 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11540 ;;;###autoload
11541 (defun anything-yahoo-suggest ()
11542 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11543 (interactive)
11544 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11546 ;;; Converted from anything-show-*-only
11547 ;;;###autoload
11548 (defun anything-for-buffers ()
11549 "Preconfigured `anything' for buffer."
11550 (interactive)
11551 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11553 ;;;###autoload
11554 (defun anything-buffers-list ()
11555 "Enhanced preconfigured `anything' for buffer."
11556 (interactive)
11557 (anything :sources '(anything-c-source-buffers-list
11558 anything-c-source-buffer-not-found)
11559 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11561 ;;;###autoload
11562 (defun anything-bbdb ()
11563 "Preconfigured `anything' for BBDB.
11565 Needs BBDB.
11567 http://bbdb.sourceforge.net/"
11568 (interactive)
11569 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11571 ;;;###autoload
11572 (defun anything-locate (arg)
11573 "Preconfigured `anything' for Locate.
11574 Note: you can add locate options after entering pattern.
11575 See 'man locate' for valid options.
11577 You can specify a specific database with prefix argument ARG \(C-u\).
11578 Many databases can be used: navigate and mark them.
11579 See also `anything-locate-with-db'.
11581 To create a user specific db, use
11582 \"updatedb -l 0 -o db_path -U directory\".
11583 Where db_path is a filename matched by
11584 `anything-locate-db-file-regexp'."
11585 (interactive "P")
11586 (anything-locate-1 arg))
11588 ;;;###autoload
11589 (defun anything-w3m-bookmarks ()
11590 "Preconfigured `anything' for w3m bookmark.
11592 Needs w3m and emacs-w3m.
11594 http://w3m.sourceforge.net/
11595 http://emacs-w3m.namazu.org/"
11596 (interactive)
11597 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11598 "*anything w3m bookmarks*"))
11600 ;;;###autoload
11601 (defun anything-firefox-bookmarks ()
11602 "Preconfigured `anything' for firefox bookmark.
11603 You will have to enable html bookmarks in firefox:
11604 open about:config in firefox and double click on this line to enable value \
11605 to true:
11607 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11609 You should have now:
11611 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11613 After closing firefox, you will be able to browse you bookmarks.
11615 (interactive)
11616 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11617 "*Anything Firefox*"))
11619 ;;;###autoload
11620 (defun anything-colors ()
11621 "Preconfigured `anything' for color."
11622 (interactive)
11623 (anything-other-buffer
11624 '(anything-c-source-colors anything-c-source-customize-face)
11625 "*anything colors*"))
11627 ;;;###autoload
11628 (defun anything-bookmarks ()
11629 "Preconfigured `anything' for bookmarks."
11630 (interactive)
11631 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11633 ;;;###autoload
11634 (defun anything-c-pp-bookmarks ()
11635 "Preconfigured `anything' for bookmarks (pretty-printed)."
11636 (interactive)
11637 (anything-other-buffer '(anything-c-source-bookmarks-local
11638 anything-c-source-bookmarks-su
11639 anything-c-source-bookmarks-ssh)
11640 "*anything pp bookmarks*"))
11642 ;;;###autoload
11643 (defun anything-c-insert-latex-math ()
11644 "Preconfigured anything for latex math symbols completion."
11645 (interactive)
11646 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11648 ;;;###autoload
11649 (defun anything-register ()
11650 "Preconfigured `anything' for Emacs registers."
11651 (interactive)
11652 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11654 ;;;###autoload
11655 (defun anything-man-woman ()
11656 "Preconfigured `anything' for Man and Woman pages."
11657 (interactive)
11658 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11660 ;;;###autoload
11661 (defun anything-org-keywords ()
11662 "Preconfigured `anything' for org keywords."
11663 (interactive)
11664 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11666 ;;;###autoload
11667 (defun anything-emms ()
11668 "Preconfigured `anything' for emms sources."
11669 (interactive)
11670 (anything :sources '(anything-c-source-emms-streams
11671 anything-c-source-emms-files
11672 anything-c-source-emms-dired)
11673 :buffer "*Anything Emms*"))
11675 ;;;###autoload
11676 (defun anything-eev-anchors ()
11677 "Preconfigured `anything' for eev anchors."
11678 (interactive)
11679 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11681 ;;;###autoload
11682 (defun anything-bm-list ()
11683 "Preconfigured `anything' for visible bookmarks.
11685 Needs bm.el
11687 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11688 (interactive)
11689 (let ((anything-outline-using t))
11690 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11692 ;;;###autoload
11693 (defun anything-timers ()
11694 "Preconfigured `anything' for timers."
11695 (interactive)
11696 (anything-other-buffer '(anything-c-source-absolute-time-timers
11697 anything-c-source-idle-time-timers)
11698 "*anything timers*"))
11700 ;;;###autoload
11701 (defun anything-list-emacs-process ()
11702 "Preconfigured `anything' for emacs process."
11703 (interactive)
11704 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11706 ;;;###autoload
11707 (defun anything-occur ()
11708 "Preconfigured Anything for Occur source.
11709 If region is active, search only in region,
11710 otherwise search in whole buffer."
11711 (interactive)
11712 (let ((anything-compile-source-functions
11713 ;; rule out anything-match-plugin because the input is one regexp.
11714 (delq 'anything-compile-source--match-plugin
11715 (copy-sequence anything-compile-source-functions))))
11716 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11718 ;;;###autoload
11719 (defun anything-browse-code ()
11720 "Preconfigured anything to browse code."
11721 (interactive)
11722 (anything :sources 'anything-c-source-browse-code
11723 :buffer "*anything browse code*"
11724 :default (thing-at-point 'symbol)))
11726 ;;;###autoload
11727 (defun anything-org-headlines ()
11728 "Preconfigured anything to show org headlines."
11729 (interactive)
11730 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11732 ;;;###autoload
11733 (defun anything-info-gnus ()
11734 "Preconfigured anything to browse Gnus Manual."
11735 (interactive)
11736 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11738 ;;;###autoload
11739 (defun anything-regexp ()
11740 "Preconfigured anything to build regexps.
11741 `query-replace-regexp' can be run from there against found regexp."
11742 (interactive)
11743 (save-restriction
11744 (let ((anything-compile-source-functions
11745 ;; rule out anything-match-plugin because the input is one regexp.
11746 (delq 'anything-compile-source--match-plugin
11747 (copy-sequence anything-compile-source-functions))))
11748 (when (and (anything-region-active-p)
11749 ;; Don't narrow to region if buffer is already narrowed.
11750 (not (anything-current-buffer-narrowed-p)))
11751 (narrow-to-region (region-beginning) (region-end)))
11752 (anything :sources anything-c-source-regexp
11753 :buffer "*anything regexp*"
11754 :prompt "Regexp: "
11755 :history 'anything-build-regexp-history))))
11757 (defun anything-c-copy-files-async ()
11758 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11759 (interactive)
11760 (let* ((flist (anything-c-read-file-name
11761 "Copy File async: "
11762 :marked-candidates t))
11763 (dest (anything-c-read-file-name
11764 "Copy File async To: "
11765 :preselect (car flist)
11766 :initial-input (car anything-ff-history)
11767 :history (anything-find-files-history :comp-read nil))))
11768 (anything-c-copy-async-with-log flist dest)))
11770 ;;;###autoload
11771 (defun anything-find-files (arg)
11772 "Preconfigured `anything' for anything implementation of `find-file'.
11773 Called with a prefix arg show history if some.
11774 Don't call it from programs, use `anything-find-files-1' instead.
11775 This is the starting point for nearly all actions you can do on files."
11776 (interactive "P")
11777 (let ((any-input (if (and arg anything-ff-history)
11778 (anything-find-files-history)
11779 (anything-find-files-initial-input)))
11780 (presel (buffer-file-name (current-buffer))))
11781 (when (and (eq major-mode 'org-agenda-mode)
11782 org-directory
11783 (not any-input))
11784 (setq any-input (expand-file-name org-directory)))
11785 (set-text-properties 0 (length any-input) nil any-input)
11786 (if any-input
11787 (anything-find-files-1 any-input)
11788 (setq any-input (expand-file-name (anything-c-current-directory)))
11789 (anything-find-files-1
11790 any-input (if anything-ff-transformer-show-only-basename
11791 (and presel (anything-c-basename presel))
11792 presel)))))
11794 ;;;###autoload
11795 (defun anything-write-file ()
11796 "Preconfigured `anything' providing completion for `write-file'."
11797 (interactive)
11798 (let ((anything-mp-highlight-delay nil))
11799 (anything :sources 'anything-c-source-write-file
11800 :input (expand-file-name default-directory)
11801 :prompt "Write buffer to file: "
11802 :buffer "*Anything write file*")))
11804 ;;;###autoload
11805 (defun anything-insert-file ()
11806 "Preconfigured `anything' providing completion for `insert-file'."
11807 (interactive)
11808 (let ((anything-mp-highlight-delay nil))
11809 (anything :sources 'anything-c-source-insert-file
11810 :input (expand-file-name default-directory)
11811 :prompt "Insert file: "
11812 :buffer "*Anything insert file*")))
11814 ;;;###autoload
11815 (defun anything-dired-rename-file ()
11816 "Preconfigured `anything' to rename files from dired."
11817 (interactive)
11818 (anything-dired-do-action-on-file :action 'rename))
11820 ;;;###autoload
11821 (defun anything-dired-copy-file ()
11822 "Preconfigured `anything' to copy files from dired."
11823 (interactive)
11824 (anything-dired-do-action-on-file :action 'copy))
11826 ;;;###autoload
11827 (defun anything-dired-symlink-file ()
11828 "Preconfigured `anything' to symlink files from dired."
11829 (interactive)
11830 (anything-dired-do-action-on-file :action 'symlink))
11832 ;;;###autoload
11833 (defun anything-dired-hardlink-file ()
11834 "Preconfigured `anything' to hardlink files from dired."
11835 (interactive)
11836 (anything-dired-do-action-on-file :action 'hardlink))
11838 ;;;###autoload
11839 (defun anything-do-grep ()
11840 "Preconfigured anything for grep.
11841 Contrarily to Emacs `grep' no default directory is given, but
11842 the full path of candidates in ONLY.
11843 That allow to grep different files not only in `default-directory' but anywhere
11844 by marking them (C-<SPACE>). If one or more directory is selected
11845 grep will search in all files of these directories.
11846 You can use also wildcard in the base name of candidate.
11847 If a prefix arg is given use the -r option of grep.
11848 The prefix arg can be passed before or after start.
11849 See also `anything-do-grep-1'."
11850 (interactive)
11851 (let ((only (anything-c-read-file-name
11852 "Search in file(s): "
11853 :marked-candidates t
11854 :preselect (or (dired-get-filename nil t)
11855 (buffer-file-name (current-buffer)))))
11856 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11857 (anything-do-grep-1 only prefarg)))
11859 ;;;###autoload
11860 (defun anything-do-zgrep (candidate)
11861 "Preconfigured anything for zgrep."
11862 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11863 (ls (anything-c-read-file-name
11864 "Search in file(s): "
11865 :marked-candidates t
11866 :preselect (or (dired-get-filename nil t)
11867 (buffer-file-name (current-buffer))))))
11868 (anything-ff-zgrep-1 ls prefarg)))
11870 (defun anything-c-etags-select (arg)
11871 "Preconfigured anything for etags.
11872 Called with one prefix arg use symbol at point as initial input.
11873 Called with two prefix arg reinitialize cache.
11874 If tag file have been modified reinitialize cache."
11875 (interactive "P")
11876 (let ((tag (anything-c-etags-get-tag-file))
11877 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11878 (anything-quit-if-no-candidate t)
11879 (anything-execute-action-at-once-if-one t)
11880 (anything-compile-source-functions
11881 (if anything-c-etags-use-regexp-search
11882 ;; rule out anything-match-plugin because the input is one regexp.
11883 (delq 'anything-compile-source--match-plugin
11884 (copy-sequence anything-compile-source-functions))
11885 anything-compile-source-functions)))
11886 (when (or (equal arg '(16))
11887 (and anything-c-etags-mtime-alist
11888 (anything-c-etags-file-modified-p tag)))
11889 (remhash tag anything-c-etags-cache))
11890 (if (and tag (file-exists-p tag))
11891 (anything :sources 'anything-c-source-etags-select
11892 :keymap anything-c-etags-map
11893 :input init
11894 :buffer "*anything etags*")
11895 (message "Error: No tag file found, please create one with etags shell command."))))
11897 ;;;###autoload
11898 (defun anything-filelist ()
11899 "Preconfigured `anything' to open files instantly.
11901 See `anything-c-filelist-file-name' docstring for usage."
11902 (interactive)
11903 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11905 ;;;###autoload
11906 (defun anything-filelist+ ()
11907 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11909 This is a replacement for `anything-for-files'.
11910 See `anything-c-filelist-file-name' docstring for usage."
11911 (interactive)
11912 (anything-other-buffer
11913 '(anything-c-source-ffap-line
11914 anything-c-source-ffap-guesser
11915 anything-c-source-buffers-list
11916 anything-c-source-recentf
11917 anything-c-source-bookmarks
11918 anything-c-source-file-cache
11919 anything-c-source-filelist)
11920 "*anything file list*"))
11922 ;;;###autoload
11923 (defun anything-M-x ()
11924 "Preconfigured `anything' for Emacs commands.
11925 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11926 (interactive)
11927 (let* (in-help
11928 help-cand
11929 special-display-buffer-names
11930 special-display-regexps
11931 anything-persistent-action-use-special-display
11932 (history (loop with hist
11933 for i in extended-command-history
11934 for com = (intern i)
11935 when (fboundp com)
11936 collect i into hist finally return hist)))
11937 (flet ((pers-help (candidate)
11938 (let ((hbuf (get-buffer (help-buffer))))
11939 (if (and in-help (string= candidate help-cand))
11940 (progn
11941 ;; When M-x is started from a help buffer,
11942 ;; Don't kill it as it is anything-current-buffer.
11943 (unless (equal hbuf anything-current-buffer)
11944 (kill-buffer hbuf))
11945 (setq in-help nil))
11946 ;; Be sure anything-current-buffer
11947 ;; have not a dedicated window.
11948 (set-window-dedicated-p
11949 (get-buffer-window anything-current-buffer) nil)
11950 (describe-function (intern candidate))
11951 (message nil) ; Erase the new stupid message Type "q"[...]
11952 (setq in-help t))
11953 (setq help-cand candidate))))
11954 (let* ((command
11956 (anything
11957 :sources
11958 `(((name . "Emacs Commands history")
11959 (candidates . ,history)
11960 (filtered-candidate-transformer
11961 . (lambda (candidates sources)
11962 (loop for i in candidates
11963 do (set-text-properties 0 (length i) nil i)
11964 collect i)))
11965 (persistent-action . pers-help)
11966 (persistent-help . "Describe this command")
11967 (action . identity))
11968 ((name . "Emacs Commands")
11969 (init
11970 . (lambda ()
11971 (with-current-buffer (anything-candidate-buffer 'global)
11972 (goto-char (point-min))
11973 (loop
11974 for sym in (all-completions "" obarray 'commandp)
11975 do (insert (concat sym "\n"))))))
11976 (persistent-action . pers-help)
11977 (persistent-help . "Describe this command")
11978 (filtered-candidate-transformer . anything-M-x-transformer)
11979 (candidates-in-buffer)
11980 (action . identity)))
11981 :resume 'noresume
11982 :history 'anything-M-x-input-history
11983 :buffer "*anything M-x*")
11984 (keyboard-quit)))
11985 (sym-com (intern command)))
11986 (unless current-prefix-arg
11987 (setq current-prefix-arg anything-current-prefix-arg))
11988 ;; Avoid having `this-command' set to *exit-minibuffer.
11989 (setq this-command sym-com)
11990 (call-interactively sym-com)
11991 (setq extended-command-history
11992 (cons command (delete command history)))))))
11994 ;;;###autoload
11995 (defun anything-manage-advice ()
11996 "Preconfigured `anything' to disable/enable function advices."
11997 (interactive)
11998 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12000 ;;;###autoload
12001 (defun anything-bookmark-ext ()
12002 "Preconfigured `anything' for bookmark-extensions sources.
12003 Needs bookmark-ext.el:
12004 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12005 Contain also `anything-c-source-google-suggest'."
12006 (interactive)
12007 (anything
12008 :sources
12009 '(anything-c-source-bookmark-files&dirs
12010 anything-c-source-bookmark-w3m
12011 anything-c-source-google-suggest
12012 anything-c-source-bmkext-addressbook
12013 anything-c-source-bookmark-gnus
12014 anything-c-source-bookmark-info
12015 anything-c-source-bookmark-man
12016 anything-c-source-bookmark-images
12017 anything-c-source-bookmark-su-files&dirs
12018 anything-c-source-bookmark-ssh-files&dirs)
12019 :prompt "SearchBookmark: "
12020 :buffer "*anything bmkext*"))
12022 ;;;###autoload
12023 (defun anything-simple-call-tree ()
12024 "Preconfigured `anything' for simple-call-tree. List function relationships.
12026 Needs simple-call-tree.el.
12027 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12028 (interactive)
12029 (anything-other-buffer
12030 '(anything-c-source-simple-call-tree-functions-callers
12031 anything-c-source-simple-call-tree-callers-functions)
12032 "*anything simple-call-tree*"))
12034 ;;;###autoload
12035 (defun anything-mark-ring ()
12036 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12037 (interactive)
12038 (anything :sources 'anything-c-source-mark-ring))
12040 ;;;###autoload
12041 (defun anything-global-mark-ring ()
12042 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12043 (interactive)
12044 (anything :sources 'anything-c-source-global-mark-ring))
12046 ;;;###autoload
12047 (defun anything-all-mark-rings ()
12048 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12049 `anything-c-source-mark-ring'."
12050 (interactive)
12051 (anything :sources '(anything-c-source-mark-ring
12052 anything-c-source-global-mark-ring)))
12054 ;;;###autoload
12055 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12056 "Preconfigured `anything' to edit or view EmacsWiki page.
12058 Needs yaoddmuse.el.
12060 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12061 (interactive)
12062 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12064 ;;;###autoload
12065 (defun anything-yaoddmuse-emacswiki-post-library ()
12066 "Preconfigured `anything' to post library to EmacsWiki.
12068 Needs yaoddmuse.el.
12070 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12071 (interactive)
12072 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12074 ;;;###autoload
12075 (defun anything-eval-expression (arg)
12076 "Preconfigured anything for `anything-c-source-evaluation-result'."
12077 (interactive "P")
12078 (anything :sources 'anything-c-source-evaluation-result
12079 :input (when arg (thing-at-point 'sexp))
12080 :buffer "*anything eval*"
12081 :history 'anything-eval-expression-input-history
12082 :keymap anything-eval-expression-map))
12084 ;;;###autoload
12085 (defun anything-eval-expression-with-eldoc ()
12086 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12087 (interactive)
12088 (declare (special eldoc-idle-delay))
12089 (let ((timer (run-with-idle-timer eldoc-idle-delay
12090 'repeat 'anything-eldoc-show-in-eval))
12091 (minibuffer-completing-symbol t) ; Enable lisp completion.
12092 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12093 (unwind-protect
12094 (minibuffer-with-setup-hook
12095 'anything-eldoc-store-minibuffer
12096 (call-interactively 'anything-eval-expression))
12097 (and timer (cancel-timer timer))
12098 (setq anything-eldoc-active-minibuffers-list
12099 (cdr anything-eldoc-active-minibuffers-list)))))
12101 ;;;###autoload
12102 (defun anything-calcul-expression ()
12103 "Preconfigured anything for `anything-c-source-calculation-result'."
12104 (interactive)
12105 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12107 ;;;###autoload
12108 (defun anything-surfraw (pattern engine)
12109 "Preconfigured `anything' to search PATTERN with search ENGINE."
12110 (interactive (list (read-string "SearchFor: "
12111 nil 'anything-surfraw-input-history)
12112 (anything-comp-read
12113 "Engine: "
12114 (anything-c-build-elvi-list)
12115 :must-match t
12116 :name "Surfraw Search Engines"
12117 :history anything-surfraw-engines-history)))
12118 (let* ((engine-nodesc (car (split-string engine)))
12119 (url (with-temp-buffer
12120 (apply 'call-process "surfraw" nil t nil
12121 ;;JAVE
12122 (append (list engine-nodesc "-p") (split-string pattern)))
12123 (replace-regexp-in-string
12124 "\n" "" (buffer-string))))
12125 (browse-url-browser-function (or anything-surfraw-default-browser-function
12126 browse-url-browser-function)))
12127 (if (string= engine-nodesc "W")
12128 (anything-c-browse-url)
12129 (anything-c-browse-url url)
12130 (setq anything-surfraw-engines-history
12131 (cons engine (delete engine anything-surfraw-engines-history))))))
12133 ;;;###autoload
12134 (defun anything-call-source ()
12135 "Preconfigured `anything' to call anything source."
12136 (interactive)
12137 (anything :sources 'anything-c-source-call-source
12138 :buffer anything-source-select-buffer))
12140 ;;;###autoload
12141 (defun anything-execute-anything-command ()
12142 "Preconfigured `anything' to execute preconfigured `anything'."
12143 (interactive)
12144 (anything-other-buffer 'anything-c-source-anything-commands
12145 "*anything commands*"))
12147 ;;;###autoload
12148 (defun anything-create (&optional string initial-input)
12149 "Preconfigured `anything' to do many create actions from STRING.
12150 See also `anything-create--actions'."
12151 (interactive)
12152 (setq string (or string (read-string "Create Anything: " initial-input)))
12153 (anything :sources '(((name . "Anything Create")
12154 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12155 (candidates . anything-create--actions)
12156 (candidate-number-limit)
12157 (action . (lambda (func) (funcall func string)))))))
12159 ;;;###autoload
12160 (defun anything-top ()
12161 "Preconfigured `anything' for top command."
12162 (interactive)
12163 (let ((anything-samewindow t)
12164 (anything-enable-shortcuts)
12165 (anything-display-function 'anything-default-display-buffer)
12166 (anything-candidate-number-limit 9999))
12167 (save-window-excursion
12168 (delete-other-windows)
12169 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12171 ;;;###autoload
12172 (defun anything-select-xfont ()
12173 "Preconfigured `anything' to select Xfont."
12174 (interactive)
12175 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12177 ;;;###autoload
12178 (defun anything-world-time ()
12179 "Preconfigured `anything' to show world time."
12180 (interactive)
12181 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12183 ;;;###autoload
12184 (defun anything-apt (arg)
12185 "Preconfigured `anything' : frontend of APT package manager.
12186 With a prefix arg reload cache."
12187 (interactive "P")
12188 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12189 (when arg (anything-c-apt-refresh))
12190 (anything :sources 'anything-c-source-apt
12191 :prompt "Search Package: "
12192 :input query
12193 :history 'anything-c-apt-input-history)))
12195 ;;;###autoload
12196 (defun anything-esh-pcomplete ()
12197 "Preconfigured anything to provide anything completion in eshell."
12198 (interactive)
12199 (let* ((anything-quit-if-no-candidate t)
12200 (anything-execute-action-at-once-if-one t)
12201 (target (thing-at-point 'symbol))
12202 (end (point))
12203 (beg (or (and target (- end (length target)))
12204 ;; Nothing at point.
12205 (progn (insert " ") (point)))))
12206 (setq anything-ec-target (or target " "))
12207 (with-anything-show-completion beg end
12208 (anything :sources 'anything-c-source-esh
12209 :input (anything-ff-set-pattern ; Handle tramp filenames.
12210 (car (last (ignore-errors ; Needed in lisp symbols completion.
12211 (pcomplete-parse-arguments)))))))))
12213 ;;;###autoload
12214 (defun anything-eshell-history ()
12215 "Preconfigured anything for eshell history."
12216 (interactive)
12217 (let* ((end (point))
12218 (beg (save-excursion (eshell-bol) (point)))
12219 flag-empty)
12220 (when (eq beg end)
12221 (insert " ")
12222 (setq flag-empty t)
12223 (setq end (point)))
12224 (unwind-protect
12225 (with-anything-show-completion beg end
12226 (anything :sources 'anything-c-source-eshell-history
12227 :buffer "*Eshell history*"))
12228 (when (and flag-empty
12229 (looking-back " "))
12230 (delete-char -1)))))
12232 ;;;###autoload
12233 (defun anything-c-run-external-command (program)
12234 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12235 If program is already running exit with error.
12236 You can set your own list of commands with
12237 `anything-c-external-commands-list'."
12238 (interactive (list
12239 (anything-comp-read
12240 "RunProgram: "
12241 (anything-c-external-commands-list-1 'sort)
12242 :must-match t
12243 :name "External Commands"
12244 :history anything-external-command-history)))
12245 (anything-run-or-raise program)
12246 (setq anything-external-command-history
12247 (cons program (delete program
12248 (loop for i in anything-external-command-history
12249 when (executable-find i) collect i)))))
12251 ;;;###autoload
12252 (defun anything-ratpoison-commands ()
12253 "Preconfigured `anything' to execute ratpoison commands."
12254 (interactive)
12255 (anything-other-buffer 'anything-c-source-ratpoison-commands
12256 "*anything ratpoison commands*"))
12258 ;;;###autoload
12259 (defun anything-ucs ()
12260 "Preconfigured anything for `ucs-names' math symbols."
12261 (interactive)
12262 (anything :sources 'anything-c-source-ucs
12263 :keymap anything-c-ucs-map))
12265 ;;;###autoload
12266 (defun anything-c-apropos ()
12267 "Preconfigured anything to describe commands, functions, variables and faces."
12268 (interactive)
12269 (let ((default (thing-at-point 'symbol)))
12270 (anything :sources
12271 `(((name . "Commands")
12272 (init . (lambda ()
12273 (anything-c-apropos-init 'commandp ,default)))
12274 (persistent-action . anything-lisp-completion-persistent-action)
12275 (persistent-help . "Show brief doc in mode-line")
12276 (candidates-in-buffer)
12277 (action . (lambda (candidate)
12278 (describe-function (intern candidate)))))
12279 ((name . "Functions")
12280 (init . (lambda ()
12281 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12282 (not (commandp x))))
12283 ,default)))
12284 (persistent-action . anything-lisp-completion-persistent-action)
12285 (persistent-help . "Show brief doc in mode-line")
12286 (candidates-in-buffer)
12287 (action . (lambda (candidate)
12288 (describe-function (intern candidate)))))
12289 ((name . "Variables")
12290 (init . (lambda ()
12291 (anything-c-apropos-init 'boundp ,default)))
12292 (persistent-action . anything-lisp-completion-persistent-action)
12293 (persistent-help . "Show brief doc in mode-line")
12294 (candidates-in-buffer)
12295 (action . (lambda (candidate)
12296 (describe-variable (intern candidate)))))
12297 ((name . "Faces")
12298 (init . (lambda ()
12299 (anything-c-apropos-init 'facep ,default)))
12300 (persistent-action . anything-lisp-completion-persistent-action)
12301 (persistent-help . "Show brief doc in mode-line")
12302 (candidates-in-buffer)
12303 (filtered-candidate-transformer . (lambda (candidates source)
12304 (loop for c in candidates
12305 collect (propertize c 'face (intern c)))))
12306 (action . (lambda (candidate)
12307 (describe-face (intern candidate)))))
12308 ((name . "Anything attributes")
12309 (candidates . (lambda ()
12310 (mapcar 'symbol-name anything-additional-attributes)))
12311 (action . (lambda (candidate)
12312 (with-output-to-temp-buffer "*Help*"
12313 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12316 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12319 (provide 'anything-config)
12321 ;;; Local Variables:
12322 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12323 ;;; End:
12325 ;; How to save (DO NOT REMOVE!!)
12326 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12327 ;;; anything-config.el ends here
12329 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12330 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12331 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12332 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12333 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12334 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12335 ;;; LocalWords: dotimes Thierry online vname
12336 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12337 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12338 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12339 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12340 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12341 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12342 ;;; LocalWords: startpos noselect dont desc