* anything-config.el (anything-ff-before-action-hook-fn): Improve error message.
[anything-config.git] / anything-config.el
blobe006839167e1bfe8c31c3b0e3c36b508670a30d2
1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
15 ;; Version: 0.4.1
16 ;; X-URL: http://repo.or.cz/w/anything-config.git
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 24
20 ;; Features that might be required by this library:
22 ;; `anything'
25 ;;; This file is NOT part of GNU Emacs
27 ;;; License
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
32 ;; any later version.
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
44 ;;; !NOTICE!
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
49 ;;; Commentary:
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
59 ;; (interactive)
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
68 ;; " *my-anything*"))
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
78 ;;; Autodoc documentation:
79 ;; ---------------------
81 ;; * Commands defined here are:
82 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
83 ;; `anything-configuration'
84 ;; Customize `anything'.
85 ;; `anything-c-buffer-help'
86 ;; Help command for anything buffers.
87 ;; `anything-ff-help'
88 ;; Help command for `anything-find-files'.
89 ;; `anything-read-file-name-help'
90 ;; Not documented.
91 ;; `anything-generic-file-help'
92 ;; Not documented.
93 ;; `anything-grep-help'
94 ;; Not documented.
95 ;; `anything-pdfgrep-help'
96 ;; Not documented.
97 ;; `anything-etags-help'
98 ;; The help function for etags.
99 ;; `anything-c-ucs-help'
100 ;; Help command for `anything-ucs'.
101 ;; `anything-mini'
102 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
103 ;; `anything-for-files'
104 ;; Preconfigured `anything' for opening files.
105 ;; `anything-recentf'
106 ;; Preconfigured `anything' for `recentf'.
107 ;; `anything-info-at-point'
108 ;; Preconfigured `anything' for searching info at point.
109 ;; `anything-info-emacs'
110 ;; Preconfigured anything for Emacs manual index.
111 ;; `anything-show-kill-ring'
112 ;; Preconfigured `anything' for `kill-ring'.
113 ;; `anything-minibuffer-history'
114 ;; Preconfigured `anything' for `minibuffer-history'.
115 ;; `anything-gentoo'
116 ;; Preconfigured `anything' for gentoo linux.
117 ;; `anything-imenu'
118 ;; Preconfigured `anything' for `imenu'.
119 ;; `anything-google-suggest'
120 ;; Preconfigured `anything' for google search with google suggest.
121 ;; `anything-yahoo-suggest'
122 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
123 ;; `anything-for-buffers'
124 ;; Preconfigured `anything' for buffer.
125 ;; `anything-buffers-list'
126 ;; Enhanced preconfigured `anything' for buffer.
127 ;; `anything-bbdb'
128 ;; Preconfigured `anything' for BBDB.
129 ;; `anything-locate'
130 ;; Preconfigured `anything' for Locate.
131 ;; `anything-w3m-bookmarks'
132 ;; Preconfigured `anything' for w3m bookmark.
133 ;; `anything-firefox-bookmarks'
134 ;; Preconfigured `anything' for firefox bookmark.
135 ;; `anything-colors'
136 ;; Preconfigured `anything' for color.
137 ;; `anything-bookmarks'
138 ;; Preconfigured `anything' for bookmarks.
139 ;; `anything-c-pp-bookmarks'
140 ;; Preconfigured `anything' for bookmarks (pretty-printed).
141 ;; `anything-c-insert-latex-math'
142 ;; Preconfigured anything for latex math symbols completion.
143 ;; `anything-register'
144 ;; Preconfigured `anything' for Emacs registers.
145 ;; `anything-man-woman'
146 ;; Preconfigured `anything' for Man and Woman pages.
147 ;; `anything-org-keywords'
148 ;; Preconfigured `anything' for org keywords.
149 ;; `anything-emms'
150 ;; Preconfigured `anything' for emms sources.
151 ;; `anything-eev-anchors'
152 ;; Preconfigured `anything' for eev anchors.
153 ;; `anything-bm-list'
154 ;; Preconfigured `anything' for visible bookmarks.
155 ;; `anything-timers'
156 ;; Preconfigured `anything' for timers.
157 ;; `anything-list-emacs-process'
158 ;; Preconfigured `anything' for emacs process.
159 ;; `anything-occur'
160 ;; Preconfigured Anything for Occur source.
161 ;; `anything-browse-code'
162 ;; Preconfigured anything to browse code.
163 ;; `anything-org-headlines'
164 ;; Preconfigured anything to show org headlines.
165 ;; `anything-info-gnus'
166 ;; Preconfigured anything to browse Gnus Manual.
167 ;; `anything-regexp'
168 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
169 ;; `anything-c-copy-files-async'
170 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
171 ;; `anything-find-files'
172 ;; Preconfigured `anything' for anything implementation of `find-file'.
173 ;; `anything-write-file'
174 ;; Preconfigured `anything' providing completion for `write-file'.
175 ;; `anything-insert-file'
176 ;; Preconfigured `anything' providing completion for `insert-file'.
177 ;; `anything-dired-rename-file'
178 ;; Preconfigured `anything' to rename files from dired.
179 ;; `anything-dired-copy-file'
180 ;; Preconfigured `anything' to copy files from dired.
181 ;; `anything-dired-symlink-file'
182 ;; Preconfigured `anything' to symlink files from dired.
183 ;; `anything-dired-hardlink-file'
184 ;; Preconfigured `anything' to hardlink files from dired.
185 ;; `anything-do-grep'
186 ;; Preconfigured anything for grep.
187 ;; `anything-c-etags-select'
188 ;; Preconfigured anything for etags.
189 ;; `anything-filelist'
190 ;; Preconfigured `anything' to open files instantly.
191 ;; `anything-filelist+'
192 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
193 ;; `anything-M-x'
194 ;; Preconfigured `anything' for Emacs commands.
195 ;; `anything-manage-advice'
196 ;; Preconfigured `anything' to disable/enable function advices.
197 ;; `anything-bookmark-ext'
198 ;; Preconfigured `anything' for bookmark-extensions sources.
199 ;; `anything-simple-call-tree'
200 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
201 ;; `anything-mark-ring'
202 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
203 ;; `anything-global-mark-ring'
204 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
205 ;; `anything-all-mark-rings'
206 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
207 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
208 ;; Preconfigured `anything' to edit or view EmacsWiki page.
209 ;; `anything-yaoddmuse-emacswiki-post-library'
210 ;; Preconfigured `anything' to post library to EmacsWiki.
211 ;; `anything-eval-expression'
212 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
213 ;; `anything-eval-expression-with-eldoc'
214 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
215 ;; `anything-calcul-expression'
216 ;; Preconfigured anything for `anything-c-source-calculation-result'.
217 ;; `anything-surfraw'
218 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
219 ;; `anything-call-source'
220 ;; Preconfigured `anything' to call anything source.
221 ;; `anything-execute-anything-command'
222 ;; Preconfigured `anything' to execute preconfigured `anything'.
223 ;; `anything-create'
224 ;; Preconfigured `anything' to do many create actions from STRING.
225 ;; `anything-top'
226 ;; Preconfigured `anything' for top command.
227 ;; `anything-select-xfont'
228 ;; Preconfigured `anything' to select Xfont.
229 ;; `anything-world-time'
230 ;; Preconfigured `anything' to show world time.
231 ;; `anything-apt'
232 ;; Preconfigured `anything' : frontend of APT package manager.
233 ;; `anything-esh-pcomplete'
234 ;; Preconfigured anything to provide anything completion in eshell.
235 ;; `anything-eshell-history'
236 ;; Preconfigured anything for eshell history.
237 ;; `anything-c-run-external-command'
238 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
239 ;; `anything-ratpoison-commands'
240 ;; Preconfigured `anything' to execute ratpoison commands.
241 ;; `anything-ucs'
242 ;; Preconfigured anything for `ucs-names' math symbols.
243 ;; `anything-show-this-source-only'
244 ;; Show all candidates of this source.
245 ;; `anything-test-sources'
246 ;; List all anything sources for test.
247 ;; `anything-select-source'
248 ;; [OBSOLETE] Select source.
249 ;; `anything-mark-all'
250 ;; Mark all visible unmarked candidates in current source.
251 ;; `anything-unmark-all'
252 ;; Unmark all candidates in all sources of current anything session.
253 ;; `anything-toggle-all-marks'
254 ;; Toggle all marks.
255 ;; `anything-buffer-diff-persistent'
256 ;; Toggle diff buffer without quitting anything.
257 ;; `anything-buffer-revert-persistent'
258 ;; Revert buffer without quitting anything.
259 ;; `anything-buffer-save-persistent'
260 ;; Save buffer without quitting anything.
261 ;; `anything-buffer-run-kill-buffers'
262 ;; Run kill buffer action from `anything-c-source-buffers-list'.
263 ;; `anything-buffer-run-grep'
264 ;; Run Grep action from `anything-c-source-buffers-list'.
265 ;; `anything-buffer-run-zgrep'
266 ;; Run Grep action from `anything-c-source-buffers-list'.
267 ;; `anything-buffer-run-query-replace-regexp'
268 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
269 ;; `anything-buffer-run-query-replace'
270 ;; Run Query replace action from `anything-c-source-buffers-list'.
271 ;; `anything-buffer-switch-other-window'
272 ;; Run switch to other window action from `anything-c-source-buffers-list'.
273 ;; `anything-buffer-switch-other-frame'
274 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
275 ;; `anything-buffer-switch-to-elscreen'
276 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
277 ;; `anything-buffer-run-ediff'
278 ;; Run ediff action from `anything-c-source-buffers-list'.
279 ;; `anything-buffer-run-ediff-merge'
280 ;; Run ediff action from `anything-c-source-buffers-list'.
281 ;; `anything-ff-run-toggle-auto-update'
282 ;; Not documented.
283 ;; `anything-ff-run-switch-to-history'
284 ;; Run Switch to history action from `anything-c-source-find-files'.
285 ;; `anything-ff-run-grep'
286 ;; Run Grep action from `anything-c-source-find-files'.
287 ;; `anything-ff-run-pdfgrep'
288 ;; Run Pdfgrep action from `anything-c-source-find-files'.
289 ;; `anything-ff-run-zgrep'
290 ;; Run Grep action from `anything-c-source-find-files'.
291 ;; `anything-ff-run-copy-file'
292 ;; Run Copy file action from `anything-c-source-find-files'.
293 ;; `anything-ff-run-rename-file'
294 ;; Run Rename file action from `anything-c-source-find-files'.
295 ;; `anything-ff-run-byte-compile-file'
296 ;; Run Byte compile file action from `anything-c-source-find-files'.
297 ;; `anything-ff-run-load-file'
298 ;; Run Load file action from `anything-c-source-find-files'.
299 ;; `anything-ff-run-eshell-command-on-file'
300 ;; Run eshell command on file action from `anything-c-source-find-files'.
301 ;; `anything-ff-run-ediff-file'
302 ;; Run Ediff file action from `anything-c-source-find-files'.
303 ;; `anything-ff-run-ediff-merge-file'
304 ;; Run Ediff merge file action from `anything-c-source-find-files'.
305 ;; `anything-ff-run-symlink-file'
306 ;; Run Symlink file action from `anything-c-source-find-files'.
307 ;; `anything-ff-run-delete-file'
308 ;; Run Delete file action from `anything-c-source-find-files'.
309 ;; `anything-ff-run-complete-fn-at-point'
310 ;; Run complete file name action from `anything-c-source-find-files'.
311 ;; `anything-ff-run-switch-to-eshell'
312 ;; Run switch to eshell action from `anything-c-source-find-files'.
313 ;; `anything-ff-run-switch-other-window'
314 ;; Run switch to other window action from `anything-c-source-find-files'.
315 ;; `anything-ff-run-switch-other-frame'
316 ;; Run switch to other frame action from `anything-c-source-find-files'.
317 ;; `anything-ff-run-open-file-externally'
318 ;; Run open file externally command action from `anything-c-source-find-files'.
319 ;; `anything-ff-run-locate'
320 ;; Run locate action from `anything-c-source-find-files'.
321 ;; `anything-ff-run-gnus-attach-files'
322 ;; Run gnus attach files command action from `anything-c-source-find-files'.
323 ;; `anything-ff-run-etags'
324 ;; Run Etags command action from `anything-c-source-find-files'.
325 ;; `anything-ff-run-print-file'
326 ;; Run Print file action from `anything-c-source-find-files'.
327 ;; `anything-ff-run-toggle-basename'
328 ;; Not documented.
329 ;; `anything-find-files-down-one-level'
330 ;; Go down one level like unix command `cd ..'.
331 ;; `anything-ff-properties-persistent'
332 ;; Show properties without quitting anything.
333 ;; `anything-ff-run-kill-buffer-persistent'
334 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
335 ;; `anything-ff-rotate-left-persistent'
336 ;; Rotate image left without quitting anything.
337 ;; `anything-ff-rotate-right-persistent'
338 ;; Rotate image right without quitting anything.
339 ;; `anything-c-goto-precedent-file'
340 ;; Go to precedent file in anything grep/etags buffers.
341 ;; `anything-c-goto-next-file'
342 ;; Go to precedent file in anything grep/etags buffers.
343 ;; `anything-c-grep-run-persistent-action'
344 ;; Run grep persistent action from `anything-do-grep-1'.
345 ;; `anything-c-grep-run-default-action'
346 ;; Run grep default action from `anything-do-grep-1'.
347 ;; `anything-c-grep-run-other-window-action'
348 ;; Run grep goto other window action from `anything-do-grep-1'.
349 ;; `anything-c-grep-run-save-buffer'
350 ;; Run grep save results action from `anything-do-grep-1'.
351 ;; `anything-do-pdfgrep'
352 ;; Not documented.
353 ;; `anything-yank-text-at-point'
354 ;; Yank text at point in minibuffer.
355 ;; `anything-c-describe-attributes'
356 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
357 ;; `anything-yaoddmuse-cache-pages'
358 ;; Fetch the list of files on emacswiki and create cache file.
359 ;; `anything-eval-new-line-and-indent'
360 ;; Not documented.
361 ;; `anything-call-source-from-anything'
362 ;; Call anything source within `anything' session.
363 ;; `anything-create-from-anything'
364 ;; Run `anything-create' from `anything' as a fallback.
365 ;; `anything-c-ucs-persistent-insert'
366 ;; Not documented.
367 ;; `anything-c-ucs-persistent-forward'
368 ;; Not documented.
369 ;; `anything-c-ucs-persistent-backward'
370 ;; Not documented.
371 ;; `anything-c-ucs-persistent-delete'
372 ;; Not documented.
373 ;; `anything-lisp-completion-at-point'
374 ;; Anything lisp symbol completion at point.
375 ;; `anything-c-complete-file-name-at-point'
376 ;; Complete file name at point.
377 ;; `anything-lisp-completion-at-point-or-indent'
378 ;; First call indent and second call complete lisp symbol.
379 ;; `anything-lisp-completion-or-file-name-at-point'
380 ;; Complete lisp symbol or filename at point.
381 ;; `anything-c-set-variable'
382 ;; Set value to VAR interactively.
383 ;; `anything-c-adaptive-save-history'
384 ;; Save history information to file given by `anything-c-adaptive-history-file'.
385 ;; `anything-c-reset-adaptative-history'
386 ;; Delete all `anything-c-adaptive-history' and his file.
387 ;; `anything-c-toggle-match-plugin'
388 ;; Toggle anything-match-plugin.
390 ;; * User variables defined here:
391 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
392 ;; `anything-c-adaptive-history-file'
393 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
394 ;; `anything-c-adaptive-history-length'
395 ;; Default Value: 50
396 ;; `anything-c-google-suggest-url'
397 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
398 ;; `anything-c-google-suggest-search-url'
399 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
400 ;; `anything-google-suggest-use-curl-p'
401 ;; Default Value: nil
402 ;; `anything-c-yahoo-suggest-url'
403 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
404 ;; `anything-c-yahoo-suggest-search-url'
405 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
406 ;; `anything-c-boring-buffer-regexp'
407 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
408 ;; `anything-c-boring-file-regexp'
409 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
410 ;; `anything-kill-ring-threshold'
411 ;; Default Value: 10
412 ;; `anything-c-kill-ring-max-lines-number'
413 ;; Default Value: nil
414 ;; `anything-su-or-sudo'
415 ;; Default Value: "su"
416 ;; `anything-for-files-prefered-list'
417 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
418 ;; `anything-create--actions-private'
419 ;; Default Value: nil
420 ;; `anything-allow-skipping-current-buffer'
421 ;; Default Value: t
422 ;; `anything-c-enable-eval-defun-hack'
423 ;; Default Value: t
424 ;; `anything-tramp-verbose'
425 ;; Default Value: 0
426 ;; `anything-raise-command'
427 ;; Default Value: nil
428 ;; `anything-command-map-prefix-key'
429 ;; Default Value: "<f5> a"
430 ;; `anything-c-browse-code-regexp-lisp'
431 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
432 ;; `anything-c-browse-code-regexp-python'
433 ;; Default Value: "\\<def\\>\\|\\<class\\>"
434 ;; `anything-c-browse-code-regexp-alist'
435 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
436 ;; `anything-c-external-programs-associations'
437 ;; Default Value: nil
438 ;; `anything-ff-auto-update-initial-value'
439 ;; Default Value: t
440 ;; `anything-c-copy-async-prefered-emacs'
441 ;; Default Value: "emacs"
442 ;; `anything-ff-lynx-style-map'
443 ;; Default Value: t
444 ;; `anything-ff-history-max-length'
445 ;; Default Value: 100
446 ;; `anything-ff-smart-completion'
447 ;; Default Value: t
448 ;; `anything-ff-default-kbsize'
449 ;; Default Value: 1024.0
450 ;; `anything-ff-tramp-not-fancy'
451 ;; Default Value: t
452 ;; `anything-ff-exif-data-program'
453 ;; Default Value: "exiftran"
454 ;; `anything-ff-exif-data-program-args'
455 ;; Default Value: "-d"
456 ;; `anything-c-grep-use-ioccur-style-keys'
457 ;; Default Value: t
458 ;; `anything-c-pdfgrep-default-read-command'
459 ;; Default Value: "xpdf '%f' %p"
460 ;; `anything-c-etags-tag-file-name'
461 ;; Default Value: "TAGS"
462 ;; `anything-c-etags-tag-file-search-limit'
463 ;; Default Value: 10
464 ;; `anything-c-etags-use-regexp-search'
465 ;; Default Value: nil
466 ;; `anything-c-filelist-file-name'
467 ;; Default Value: nil
468 ;; `anything-c-eldoc-in-minibuffer-show-fn'
469 ;; Default Value: anything-c-eldoc-show-in-mode-line
470 ;; `anything-c-turn-on-show-completion'
471 ;; Default Value: t
472 ;; `anything-lisp-completion-or-indent-delay'
473 ;; Default Value: 0.6
474 ;; `anything-c-default-external-file-browser'
475 ;; Default Value: "nautilus"
476 ;; `anything-c-use-adaptative-sorting'
477 ;; Default Value: nil
478 ;; `anything-ff-newfile-prompt-p'
479 ;; Default Value: t
480 ;; `anything-ff-avfs-directory'
481 ;; Default Value: nil
482 ;; `anything-ff-file-compressed-list'
483 ;; Default Value: ("gz" "bz2" "zip" "7z")
484 ;; `anything-locate-db-file-regexp'
485 ;; Default Value: "m?locate.db$"
486 ;; `anything-c-eldoc-show-in-mode-line-delay'
487 ;; Default Value: 12
488 ;; `anything-c-copy-files-async-log-file'
489 ;; Default Value: "/tmp/dired.log"
490 ;; `anything-ff-printer-list'
491 ;; Default Value: nil
492 ;; `anything-ff-transformer-show-only-basename'
493 ;; Default Value: nil
495 ;; * Anything sources defined here:
496 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
497 ;; `anything-c-source-regexp' (Regexp Builder)
498 ;; `anything-c-source-buffers' (Buffers)
499 ;; `anything-c-source-buffer-not-found' (Create buffer)
500 ;; `anything-c-source-buffers-list' (Buffers)
501 ;; `anything-c-source-file-name-history' (File Name History)
502 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
503 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
504 ;; `anything-c-source-find-files' (Find Files)
505 ;; `anything-c-source-write-file' (Write File)
506 ;; `anything-c-source-insert-file' (Insert File)
507 ;; `anything-c-source-copy-files' (Copy Files)
508 ;; `anything-c-source-symlink-files' (Symlink Files)
509 ;; `anything-c-source-hardlink-files' (Hardlink Files)
510 ;; `anything-c-source-file-cache' (File Cache)
511 ;; `anything-c-source-locate' (Locate)
512 ;; `anything-c-source-recentf' (Recentf)
513 ;; `anything-c-source-ffap-guesser' (File at point)
514 ;; `anything-c-source-ffap-line' (File/Lineno at point)
515 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
516 ;; `anything-c-source-filelist' (FileList)
517 ;; `anything-c-source-info-pages' (Info Pages)
518 ;; `anything-c-source-info-elisp' (Info index: elisp)
519 ;; `anything-c-source-info-cl' (Info index: cl)
520 ;; `anything-c-source-info-org' (Info index: org)
521 ;; `anything-c-source-info-gnus' (Info index: Gnus)
522 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
523 ;; `anything-c-source-info-zsh' (Info index: zsh)
524 ;; `anything-c-source-info-bash' (Info index: bash)
525 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
526 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
527 ;; `anything-c-source-info-find' (Info index: find)
528 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
529 ;; `anything-c-source-info-textutils' (Info index: textutils)
530 ;; `anything-c-source-info-libc' (Info index: libc)
531 ;; `anything-c-source-info-make' (Info index: make)
532 ;; `anything-c-source-info-automake' (Info index: automake)
533 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
534 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
535 ;; `anything-c-source-info-emacs' (Info index: emacs)
536 ;; `anything-c-source-info-elib' (Info index: elib)
537 ;; `anything-c-source-info-eieio' (Info index: eieio)
538 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
539 ;; `anything-c-source-info-guile' (Info index: guile)
540 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
541 ;; `anything-c-source-info-goops' (Info index: goops)
542 ;; `anything-c-source-info-screen' (Info index: screen)
543 ;; `anything-c-source-info-latex' (Info index: latex)
544 ;; `anything-c-source-info-gawk' (Info index: gawk)
545 ;; `anything-c-source-info-sed' (Info index: sed)
546 ;; `anything-c-source-info-m4' (Info index: m4)
547 ;; `anything-c-source-info-wget' (Info index: wget)
548 ;; `anything-c-source-info-binutils' (Info index: binutils)
549 ;; `anything-c-source-info-as' (Info index: as)
550 ;; `anything-c-source-info-bfd' (Info index: bfd)
551 ;; `anything-c-source-info-gprof' (Info index: gprof)
552 ;; `anything-c-source-info-ld' (Info index: ld)
553 ;; `anything-c-source-info-diff' (Info index: diff)
554 ;; `anything-c-source-info-flex' (Info index: flex)
555 ;; `anything-c-source-info-grep' (Info index: grep)
556 ;; `anything-c-source-info-gzip' (Info index: gzip)
557 ;; `anything-c-source-info-libtool' (Info index: libtool)
558 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
559 ;; `anything-c-source-info-info' (Info index: info)
560 ;; `anything-c-source-info-gdb' (Info index: gdb)
561 ;; `anything-c-source-info-stabs' (Info index: stabs)
562 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
563 ;; `anything-c-source-info-cvs' (Info index: cvs)
564 ;; `anything-c-source-info-bison' (Info index: bison)
565 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
566 ;; `anything-c-source-info-global' (Info index: global)
567 ;; `anything-c-source-man-pages' (Manual Pages)
568 ;; `anything-c-source-complex-command-history' (Complex Command History)
569 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
570 ;; `anything-c-source-emacs-commands' (Emacs Commands)
571 ;; `anything-c-source-lacarte' (Lacarte)
572 ;; `anything-c-source-emacs-functions' (Emacs Functions)
573 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
574 ;; `anything-c-source-advice' (Function Advice)
575 ;; `anything-c-source-emacs-variables' (Emacs Variables)
576 ;; `anything-c-source-bookmarks' (Bookmarks)
577 ;; `anything-c-source-bookmark-set' (Set Bookmark)
578 ;; `anything-c-source-bm' (Visible Bookmarks)
579 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
580 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
581 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
582 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
583 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
584 ;; `anything-c-source-bookmark-images' (Bookmark Images)
585 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
586 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
587 ;; `anything-c-source-bookmark-info' (Bookmark Info)
588 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
589 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
590 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
591 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
592 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
593 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
594 ;; `anything-c-source-imenu' (Imenu)
595 ;; `anything-c-source-ctags' (Exuberant ctags)
596 ;; `anything-c-source-etags-select' (Etags)
597 ;; `anything-c-source-semantic' (Semantic Tags)
598 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
599 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
600 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
601 ;; `anything-c-source-customize-face' (Customize Face)
602 ;; `anything-c-source-colors' (Colors)
603 ;; `anything-c-source-tracker-search' (Tracker Search)
604 ;; `anything-c-source-mac-spotlight' (mdfind)
605 ;; `anything-c-source-picklist' (Picklist)
606 ;; `anything-c-source-kill-ring' (Kill Ring)
607 ;; `anything-c-source-mark-ring' (mark-ring)
608 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
609 ;; `anything-c-source-register' (Registers)
610 ;; `anything-c-source-latex-math' (Latex Math Menu)
611 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
612 ;; `anything-c-source-rd-headline' (RD HeadLine)
613 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
614 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
615 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
616 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
617 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
618 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
619 ;; `anything-c-source-eev-anchor' (Anchors)
620 ;; `anything-c-source-org-headline' (Org HeadLine)
621 ;; `anything-c-source-org-keywords' (Org Keywords)
622 ;; `anything-c-source-bbdb' (BBDB)
623 ;; `anything-c-source-evaluation-result' (Evaluation Result)
624 ;; `anything-c-source-calculation-result' (Calculation Result)
625 ;; `anything-c-source-google-suggest' (Google Suggest)
626 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
627 ;; `anything-c-source-emms-streams' (Emms Streams)
628 ;; `anything-c-source-emms-dired' (Music Directory)
629 ;; `anything-c-source-emms-files' (Emms files)
630 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
631 ;; `anything-c-source-call-source' (Call anything source)
632 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
633 ;; `anything-c-source-occur' (Occur)
634 ;; `anything-c-source-browse-code' (Browse code)
635 ;; `anything-c-source-create' (Create)
636 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
637 ;; `anything-c-source-elscreen' (Elscreen)
638 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
639 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
640 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
641 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
642 ;; `anything-c-source-xfonts' (X Fonts)
643 ;; `anything-c-source-ucs' (Ucs names)
644 ;; `anything-c-source-emacs-process' (Emacs Process)
645 ;; `anything-c-source-time-world' (Time World List)
646 ;; `anything-c-source-apt' (APT)
647 ;; `anything-c-source-gentoo' (Portage sources)
648 ;; `anything-c-source-use-flags' (Use Flags)
649 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
650 ;; `anything-c-source-esh' (Eshell completions)
651 ;; `anything-c-source-eshell-history' (Eshell history)
653 ;; *** END auto-documentation
655 ;;; For Maintainers:
657 ;; Install developer-tools/autodoc.el and
658 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
659 ;; This function generates anything-c-source-* / functions / options list.
661 ;; [EVAL IT] (autodoc-update-all)
663 ;; Please write details documentation about function, then others will
664 ;; read code more easier. -- Andy Stewart
668 ;;; Change log:
670 ;; Change log of this file is found at
671 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
673 ;; Change log of this project is found at
674 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
676 ;;; Contributors:
678 ;; Tamas Patrovics
679 ;; Tassilo Horn <tassilo@member.fsf.org>
680 ;; Vagn Johansen <gonz808@hotmail.com>
681 ;; Mathias Dahl <mathias.dahl@gmail.com>
682 ;; Bill Clementson <billclem@gmail.com>
683 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
684 ;; Drew Adams <drew.adams@oracle.com>
685 ;; Jason McBrayer <jmcbray@carcosa.net>
686 ;; Andy Stewart <lazycat.manatee@gmail.com>
687 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
688 ;; rubikitch <rubikitch@ruby-lang.org>
689 ;; Scott Vokes <vokes.s@gmail.com>
690 ;; Kenichirou Oyama <k1lowxb@gmail.com>
693 ;;; TODO
695 ;; - Fix documentation, now many functions haven't documentations.
699 ;;; Code:
701 ;;; Require
704 (require 'anything)
705 (require 'thingatpt)
706 (require 'ffap)
707 (require 'cl)
708 (require 'dired-aux)
709 (require 'dired-x)
710 (require 'tramp)
711 (require 'grep)
712 (require 'url)
713 (require 'xml)
714 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
715 (eval-when-compile (require 'semantic nil t))
716 (require 'anything-match-plugin)
720 ;;; Declare external functions
723 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
724 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
725 (declare-function image-dired-update-property "image-dired.el" (prop value))
726 (declare-function woman-file-name-all-completions "woman.el" (topic))
727 (declare-function Man-getpage-in-background "man.el" (topic))
728 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
729 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
730 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
731 (declare-function org-get-current-options "ext:org-exp.el")
732 (declare-function emms-streams "ext:emms-streams")
733 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
734 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
735 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
736 (declare-function emms-stream-quit "ext:emms-streams")
737 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
738 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
739 (declare-function emms-playlist-first "ext:emms")
740 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
741 (declare-function term-line-mode "term")
742 (declare-function term-char-mode "term")
743 (declare-function term-send-input "term")
744 (declare-function term-send-eof "term")
745 (declare-function Info-index-nodes "info" (&optional file))
746 (declare-function Info-goto-node "info" (&optional fork))
747 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
748 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
749 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
750 (declare-function elscreen-goto "ext:elscreen.el" (screen))
751 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
752 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
753 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
754 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
755 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
756 (declare-function bbdb "ext:bbdb-com")
757 (declare-function bbdb-current-record "ext:bbdb-com")
758 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
759 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
760 (declare-function bbdb-current-record "ext:bbdb-com")
761 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
762 (declare-function bbdb-records "ext:bbdb-com"
763 (&optional dont-check-disk already-in-db-buffer))
764 (declare-function eshell-read-aliases-list "em-alias")
765 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
766 (declare-function eshell-bol "esh-mode")
767 (declare-function eldoc-current-symbol "eldoc")
768 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
769 (declare-function eldoc-get-var-docstring "eldoc" (sym))
770 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
771 (declare-function find-library-name "find-func.el" (library))
772 (declare-function adoc-construct "ext:auto-document.el" (buf))
773 (declare-function adoc-first-line "ext:auto-document.el" (str))
774 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
775 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
779 ;;; compatibility
782 (unless (fboundp 'window-system)
783 (defun window-system (&optional arg)
784 window-system))
788 ;;; Customize
791 (defgroup anything-config nil
792 "Predefined configurations for `anything.el'."
793 :group 'anything)
795 (defcustom anything-c-adaptive-history-file
796 "~/.emacs.d/anything-c-adaptive-history"
797 "Path of file where history information is stored."
798 :type 'string
799 :group 'anything-config)
801 (defcustom anything-c-adaptive-history-length 50
802 "Maximum number of candidates stored for a source."
803 :type 'number
804 :group 'anything-config)
806 (defcustom anything-c-google-suggest-url
807 "http://google.com/complete/search?output=toolbar&q="
808 "URL used for looking up Google suggestions."
809 :type 'string
810 :group 'anything-config)
812 (defcustom anything-c-google-suggest-search-url
813 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
814 "URL used for Google searching."
815 :type 'string
816 :group 'anything-config)
818 (defcustom anything-google-suggest-use-curl-p nil
819 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
820 Otherwise `url-retrieve-synchronously' is used."
821 :type 'boolean
822 :group 'anything-config)
824 (defcustom anything-c-yahoo-suggest-url
825 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
826 "Url used for looking up Yahoo suggestions."
827 :type 'string
828 :group 'anything-config)
830 (defcustom anything-c-yahoo-suggest-search-url
831 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
832 "Url used for Yahoo searching."
833 :type 'string
834 :group 'anything-config)
836 (defcustom anything-c-boring-buffer-regexp
837 (rx (or
838 (group bos " ")
839 ;; anything-buffer
840 "*anything"
841 ;; echo area
842 " *Echo Area" " *Minibuf"))
843 "The regexp that match boring buffers.
844 Buffer candidates matching this regular expression will be
845 filtered from the list of candidates if the
846 `anything-c-skip-boring-buffers' candidate transformer is used, or
847 they will be displayed with face `file-name-shadow' if
848 `anything-c-shadow-boring-buffers' is used."
849 :type 'string
850 :group 'anything-config)
851 ;; (string-match anything-c-boring-buffer-regexp "buf")
852 ;; (string-match anything-c-boring-buffer-regexp " hidden")
853 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
855 (defcustom anything-c-boring-file-regexp
856 (rx (or
857 ;; Boring directories
858 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
859 ;; Boring files
860 (and line-start ".#")
861 (and (or ".class" ".la" ".o" "~") eol)))
862 "The regexp that match boring files.
863 File candidates matching this regular expression will be
864 filtered from the list of candidates if the
865 `anything-c-skip-boring-files' candidate transformer is used, or
866 they will be displayed with face `file-name-shadow' if
867 `anything-c-shadow-boring-files' is used."
868 :type 'string
869 :group 'anything-config)
871 (defcustom anything-kill-ring-threshold 10
872 "*Minimum length to be listed by `anything-c-source-kill-ring'."
873 :type 'integer
874 :group 'anything-config)
876 (defcustom anything-c-kill-ring-max-lines-number nil
877 "Max number of lines displayed per candidate in kill-ring browser.
878 If nil or zero, don't truncate candidate, show all."
879 :type 'integer
880 :group 'anything-config)
882 (defcustom anything-su-or-sudo "su"
883 "What command to use for root access."
884 :type 'string
885 :group 'anything-config)
887 (defcustom anything-for-files-prefered-list
888 '(anything-c-source-ffap-line
889 anything-c-source-ffap-guesser
890 anything-c-source-buffers-list
891 anything-c-source-recentf
892 anything-c-source-bookmarks
893 anything-c-source-file-cache
894 anything-c-source-files-in-current-dir+
895 anything-c-source-locate)
896 "Your prefered sources to find files."
897 :type 'list
898 :group 'anything-config)
900 (defcustom anything-create--actions-private nil
901 "User defined actions for `anything-create' / `anything-c-source-create'.
902 It is a list of (DISPLAY . FUNCTION) pairs like `action'
903 attribute of `anything-sources'.
905 It is prepended to predefined pairs."
906 :type 'list
907 :group 'anything-config)
909 (defcustom anything-allow-skipping-current-buffer t
910 "Show current buffer or not in anything buffer"
911 :type 'boolean
912 :group 'anything-config)
914 (defcustom anything-c-enable-eval-defun-hack t
915 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
916 This hack is invoked when pressing C-M-x in the form \
917 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
918 :type 'boolean
919 :group 'anything-config)
921 (defcustom anything-tramp-verbose 0
922 "*Just like `tramp-verbose' but specific to anything.
923 When set to 0 don't show tramp messages in anything.
924 If you want to have the default tramp messages set it to 3."
925 :type 'integer
926 :group 'anything-config)
928 (defcustom anything-raise-command nil
929 "*A shell command to jump to a window running specific program.
930 Need external program wmctrl.
931 This will be use with `format', so use something like \"wmctrl -xa %s\"."
932 :type 'string
933 :group 'anything-config)
935 (defun anything-set-anything-command-map-prefix-key (var key)
936 (declare (special anything-command-map-prefix-key))
937 (when (boundp 'anything-command-map-prefix-key)
938 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
939 (setq anything-command-map-prefix-key key)
940 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
941 'anything-command-map))
943 (defcustom anything-command-map-prefix-key "<f5> a"
944 "*The prefix key for all `anything-command-map' commands.
946 !!WARNING!!
947 This default value is very likely to be changed,
948 because it is under discussion."
949 :type 'string
950 :set 'anything-set-anything-command-map-prefix-key
951 :group 'anything-config)
953 (defcustom anything-c-browse-code-regexp-lisp
954 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
955 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
956 "*Regexp used to parse lisp buffer when browsing code."
957 :type 'string
958 :group 'anything-config)
960 (defcustom anything-c-browse-code-regexp-python
961 "\\<def\\>\\|\\<class\\>"
962 "*Regexp used to parse python buffer when browsing code."
963 :type 'string
964 :group 'anything-config)
966 (defcustom anything-c-browse-code-regexp-alist
967 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
968 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
969 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
970 (python-mode . ,anything-c-browse-code-regexp-python))
971 "*Alist to store regexps for browsing code corresponding \
972 to a specific `major-mode'."
973 :type 'list
974 :group 'anything-config)
976 (defcustom anything-c-external-programs-associations nil
977 "*Alist to store externals programs associated with file extension.
978 This variable overhide setting in .mailcap file.
979 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
980 :type 'list
981 :group 'anything-config)
983 (defcustom anything-ff-auto-update-initial-value t
984 "Auto update when only one candidate directory is matched.
985 This is the default value when starting `anything-find-files'."
986 :group 'anything-config
987 :type 'boolean)
989 (defcustom anything-c-copy-async-prefered-emacs "emacs"
990 "Path to the emacs you want to use for copying async.
991 Emacs versions < 24 fail to copy directory due to a bug not fixed
992 in `copy-directory'."
993 :group 'anything-config
994 :type 'string)
996 (defcustom anything-ff-lynx-style-map t
997 "Use arrow keys to navigate with `anything-find-files'.
998 You will have to restart Emacs or reeval `anything-find-files-map'
999 and `anything-c-read-file-map' for this take effect."
1000 :group 'anything-config
1001 :type 'boolean)
1003 (defcustom anything-ff-history-max-length 100
1004 "*Number of elements shown in `anything-find-files' history."
1005 :group 'anything-config
1006 :type 'integer)
1008 (defcustom anything-ff-smart-completion t
1009 "Try to complete filenames smarter when non--nil.
1010 See `anything-ff-transform-fname-for-completion' for more info."
1011 :group 'anything-config
1012 :type 'boolean)
1014 (defcustom anything-ff-default-kbsize 1024.0
1015 "Default Kbsize to use for showing files size.
1016 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1017 :group 'anything-config
1018 :type 'float)
1020 (defcustom anything-ff-tramp-not-fancy t
1021 "No colors when listing remote files when set to non--nil.
1022 This make listing much faster, specially on slow machines."
1023 :group 'anything-config
1024 :type 'boolean)
1026 (defcustom anything-ff-exif-data-program "exiftran"
1027 "*Program used to extract exif data of an image file."
1028 :group 'anything-config
1029 :type 'string)
1031 (defcustom anything-ff-exif-data-program-args "-d"
1032 "*Arguments used for `anything-ff-exif-data-program'."
1033 :group 'anything-config
1034 :type 'string)
1036 (defcustom anything-c-grep-use-ioccur-style-keys t
1037 "Use Arrow keys to jump to occurences."
1038 :group 'anything-config
1039 :type 'boolean)
1041 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1042 "Default command to read pdf files from pdfgrep.
1043 Where '%f' format spec is filename and '%p' is page number"
1044 :group 'anything-config
1045 :type 'string)
1047 (defcustom anything-c-etags-tag-file-name "TAGS"
1048 "Etags tag file name."
1049 :type 'string
1050 :group 'anything-config)
1052 (defcustom anything-c-etags-tag-file-search-limit 10
1053 "The limit level of directory to search tag file.
1054 Don't search tag file deeply if outside this value."
1055 :type 'number
1056 :group 'anything-config)
1058 (defcustom anything-c-etags-use-regexp-search nil
1059 "When non--nil search etags candidates by regexp.
1060 This disable anything-match-plugin when enabled.
1061 When nil search is performed literally and *match-plugin is used
1062 if available."
1063 :group 'anything-config
1064 :type 'boolean)
1066 (defcustom anything-c-filelist-file-name nil
1067 "Filename of file list.
1068 Accept a list of string for multiple files.
1070 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1071 File list is created by make-filelist.rb script.
1073 Usage:
1074 ruby make-filelist.rb > /tmp/all.filelist
1076 Then
1077 ;; Assume that /tmp is ramdisk or tmpfs
1078 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1079 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1081 :type 'string
1082 :group 'anything-config)
1084 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1085 'anything-c-eldoc-show-in-mode-line
1086 "A function to display eldoc info.
1087 Should take one arg: the string to display."
1088 :group 'anything-config
1089 :type 'symbol)
1091 (defcustom anything-c-turn-on-show-completion t
1092 "Display candidate in buffer while moving selection when non--nil."
1093 :group 'anything-config
1094 :type 'boolean)
1096 (defcustom anything-lisp-completion-or-indent-delay 0.6
1097 "After this delay `anything-lisp-completion-counter' is reset to 0.
1098 This allow to indent again without completing lisp symbol after this delay.
1099 Default is 0.6 seconds."
1100 :group 'anything-config
1101 :type 'number)
1103 (defcustom anything-c-default-external-file-browser "nautilus"
1104 "Default external file browser for your system.
1105 Directories will be opened externally with it.
1106 Set to nil if you do not have external file browser
1107 or do not want to use it."
1108 :group 'anything-config
1109 :type 'string)
1111 (defcustom anything-c-use-adaptative-sorting nil
1112 "*Wheter to use or not adaptative sorting.
1113 Even if a source use it, it will have no effect when set to nil."
1114 :type 'boolean
1115 :group 'anything-config)
1117 (defcustom anything-ff-newfile-prompt-p t
1118 "Whether Prompt or not when creating new file.
1119 This set `ffap-newfile-prompt'."
1120 :type 'boolean
1121 :group 'anything-config)
1124 (defcustom anything-ff-avfs-directory nil
1125 "*The default avfs directory, usually '.avfs'.
1126 When this is set you will be able to expand archive filenames with `C-z'
1127 inside an avfs directory mounted with mountavfs.
1128 See <http://sourceforge.net/projects/avf/>."
1129 :type 'boolean
1130 :group 'anything-config)
1132 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1133 "*Minimal list of compressed files extension."
1134 :type 'list
1135 :group 'anything-config)
1137 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1138 "Default regexp to match locate database.
1139 If nil Search in all files."
1140 :type 'string
1141 :group 'anything-config)
1143 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1144 "Eldoc will show info in mode-line during this delay if user is idle."
1145 :type 'integer
1146 :group 'anything-config)
1148 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1149 "The file used to communicate with two emacs when copying files async."
1150 :type 'string
1151 :group 'anything-config)
1153 (defcustom anything-ff-printer-list nil
1154 "A list of available printers on your system.
1155 When non--nil let you choose a printer to print file.
1156 Otherwise when nil the variable `printer-name' will be used.
1157 On Unix based systems you can use `anything-ff-find-printers' to
1158 find a list of available printers."
1159 :type 'list
1160 :group 'anything-config)
1162 (defcustom anything-ff-transformer-show-only-basename nil
1163 "Show only basename of candidates in `anything-find-files'.
1164 This can be toggled at anytime from `anything-find-files' with \
1165 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1166 :type 'boolean
1167 :group 'anything-config)
1169 (defcustom anything-completing-read-handlers-alist
1170 '((describe-function . anything-completing-read-symbols)
1171 (describe-variable . anything-completing-read-symbols)
1172 (debug-on-entry . anything-completing-read-symbols)
1173 (ffap-alternate-file . nil))
1174 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1175 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1176 where key and value are symbols.
1178 Each key is an Emacs command that use originaly `completing-read'.
1180 Each value maybe an anything function that take same arguments as
1181 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1182 anything source and BUFFER the name of the buffer we will use.
1183 This function prefix name must start by \"anything\".
1185 See `anything-completing-read-symbols' for example.
1187 If the value of an entry is nil completion will fall back to
1188 emacs vanilla behavior.
1189 e.g If you want to disable anything completion for `describe-function':
1190 \(describe-function . nil\).
1192 Ido is also supported, you can use `ido-completing-read' and
1193 `ido-read-file-name' as value of an entry or just 'ido.
1194 e.g ido completion for `find-file':
1195 \(find-file . ido\)
1196 same as
1197 \(find-file . ido-read-file-name\)
1198 Note that you don't need to enable `ido-mode' for this to work."
1199 :group 'anything-config
1200 :type '(alist :key-type symbol :value-type symbol))
1204 ;;; General internal variables
1206 ;; Some internals variable that need to be loaded
1207 ;; here to avoid compiler warnings.
1208 (defvar anything-c-external-commands-list nil
1209 "A list of all external commands the user can execute. If this
1210 variable is not set by the user, it will be calculated
1211 automatically.")
1213 (defvar anything-c-show-completion-overlay nil)
1215 (defvar anything-c-locate-command
1216 (case system-type
1217 ('gnu/linux "locate -i -r %s")
1218 ('berkeley-unix "locate -i %s")
1219 ('windows-nt "es -i -r %s")
1220 (t "locate %s"))
1221 "A list of arguments for locate program.
1222 The \"-r\" option must be the last option.")
1225 ;;; Faces
1228 (defface anything-buffer-saved-out
1229 '((t (:foreground "red")))
1230 "*Face used for buffer files modified outside of emacs."
1231 :group 'anything-config)
1233 (defface anything-buffer-not-saved
1234 '((t (:foreground "Indianred2")))
1235 "*Face used for buffer files not already saved on disk."
1236 :group 'anything-config)
1238 (defface anything-ff-prefix
1239 '((t (:background "yellow" :foreground "black")))
1240 "*Face used to prefix new file or url paths in `anything-find-files'."
1241 :group 'anything-config)
1243 (defface anything-ff-executable
1244 '((t (:foreground "green")))
1245 "*Face used for executable files in `anything-find-files'."
1246 :group 'anything-config)
1248 (defface anything-ff-directory
1249 '((t (:foreground "DarkRed" :background "LightGray")))
1250 "*Face used for directories in `anything-find-files'."
1251 :group 'anything-config)
1253 (defface anything-ff-symlink
1254 '((t (:foreground "DarkOrange")))
1255 "*Face used for symlinks in `anything-find-files'."
1256 :group 'anything-config)
1258 (defface anything-ff-invalid-symlink
1259 '((t (:foreground "black" :background "red")))
1260 "*Face used for invalid symlinks in `anything-find-files'."
1261 :group 'anything-config)
1263 (defface anything-ff-file
1264 '((t (:foreground "CadetBlue" :underline t)))
1265 "*Face used for file names in `anything-find-files'."
1266 :group 'anything-config)
1268 (defface anything-grep-match
1269 '((t (:inherit match)))
1270 "Face used to highlight grep matches."
1271 :group 'anything-config)
1273 (defface anything-grep-file
1274 '((t (:foreground "BlueViolet" :underline t)))
1275 "Face used to highlight grep results filenames."
1276 :group 'anything-config)
1278 (defface anything-grep-lineno
1279 '((t (:foreground "Darkorange1")))
1280 "Face used to highlight grep number lines."
1281 :group 'anything-config)
1283 (defface anything-grep-running
1284 '((t (:foreground "Red")))
1285 "Face used in mode line when grep is running."
1286 :group 'anything-config)
1288 (defface anything-grep-finish
1289 '((t (:foreground "Green")))
1290 "Face used in mode line when grep is finish."
1291 :group 'anything-config)
1293 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1294 "*Face used in anything-M-x to show keybinding."
1295 :group 'anything)
1297 (defface anything-bmkext-info
1298 '((t (:foreground "green")))
1299 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1300 :group 'anything)
1302 (defface anything-bmkext-w3m
1303 '((t (:foreground "yellow")))
1304 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1305 :group 'anything)
1307 (defface anything-bmkext-gnus
1308 '((t (:foreground "magenta")))
1309 "*Face used for Gnus bookmarks."
1310 :group 'anything)
1312 (defface anything-bmkext-man
1313 '((t (:foreground "Orange4")))
1314 "*Face used for Woman/man bookmarks."
1315 :group 'anything)
1317 (defface anything-bmkext-no--file
1318 '((t (:foreground "grey")))
1319 "*Face used for non--file bookmarks."
1320 :group 'anything)
1322 (defface anything-bmkext-file
1323 '((t (:foreground "Deepskyblue2")))
1324 "*Face used for non--file bookmarks."
1325 :group 'anything)
1327 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1328 "Face for su/sudo bookmarks."
1329 :group 'anything)
1331 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1332 "Face for w3m bookmarks" :group 'anything)
1334 (defface anything-emms-playlist
1335 '((t (:foreground "Springgreen4" :underline t)))
1336 "*Face used for tracks in current emms playlist."
1337 :group 'anything)
1339 (defface anything-apt-installed
1340 '((t (:foreground "green")))
1341 "*Face used for apt installed candidates."
1342 :group 'anything)
1344 (defface anything-gentoo-match-face '((t (:foreground "red")))
1345 "Face for anything-gentoo installed packages."
1346 :group 'traverse-faces)
1348 (defface anything-lisp-show-completion
1349 '((t (:background "DarkSlateGray")))
1350 "*Face used for showing candidates in `anything-lisp-completion'."
1351 :group 'anything-config)
1353 (defface anything-lisp-completion-info
1354 '((t (:foreground "red")))
1355 "*Face used for showing info in `anything-lisp-completion'."
1356 :group 'anything-config)
1358 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1359 "Face for source header in the anything buffer." :group 'anything)
1361 ;;;###autoload
1362 (defun anything-configuration ()
1363 "Customize `anything'."
1364 (interactive)
1365 (customize-group "anything-config"))
1369 ;;; Anything-command-map
1372 ;;;###autoload
1373 (defvar anything-command-map)
1374 (define-prefix-command 'anything-command-map)
1377 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1378 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1379 (define-key anything-command-map (kbd "l") 'anything-locate)
1380 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1381 (define-key anything-command-map (kbd "r") 'anything-regexp)
1382 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1383 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1384 (define-key anything-command-map (kbd "#") 'anything-emms)
1385 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1386 (define-key anything-command-map (kbd "t") 'anything-top)
1387 (define-key anything-command-map (kbd "i") 'anything-imenu)
1388 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1389 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1390 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1391 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1392 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1393 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1394 (define-key anything-command-map (kbd "f") 'anything-for-files)
1395 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1396 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1397 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1398 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1399 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1400 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1401 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1402 (define-key anything-command-map (kbd "c") 'anything-colors)
1403 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1404 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1405 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1406 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1407 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1408 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1409 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1410 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1411 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1412 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1414 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1415 ;; minibuffer-local-filename-must-match-map.
1416 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1417 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1418 (dolist (map (list minibuffer-local-filename-completion-map
1419 minibuffer-local-completion-map
1420 minibuffer-local-must-match-filename-map
1421 minibuffer-local-filename-must-match-map
1422 minibuffer-local-map
1423 minibuffer-local-isearch-map
1424 minibuffer-local-must-match-map
1425 minibuffer-local-ns-map))
1426 (define-key map "\C-r" 'anything-minibuffer-history))
1430 ;;; Menu
1433 (easy-menu-define nil global-map
1434 "`anything' menu"
1435 '("Anything"
1436 ["All anything commands" anything-execute-anything-command t]
1437 ["Find any Files/Buffers" anything-for-files t]
1438 "----"
1439 ("Files:"
1440 ["Find files" anything-find-files t]
1441 ["Recent Files" anything-recentf t]
1442 ["Locate" anything-locate t]
1443 ["Bookmarks" anything-c-pp-bookmarks t])
1444 ("Buffers:"
1445 ["Find buffers" anything-buffers-list t])
1446 ("Commands:"
1447 ["Emacs Commands" anything-M-x t]
1448 ["Externals Commands" anything-c-run-external-command t])
1449 ("Info:"
1450 ["Info at point" anything-info-at-point t]
1451 ["Emacs Manual index" anything-info-emacs t]
1452 ["Gnus Manual index" anything-info-gnus t])
1453 ("Org:"
1454 ["Org keywords" anything-org-keywords t]
1455 ["Org headlines" anything-org-headlines t])
1456 ("Tools:"
1457 ["Occur" anything-occur t]
1458 ["Grep" anything-do-grep t]
1459 ["Etags" anything-c-etags-select t]
1460 ["Lisp complete at point" anything-lisp-completion-at-point t]
1461 ["Browse Kill ring" anything-show-kill-ring t]
1462 ["Browse register" anything-register t]
1463 ["Browse code" anything-browse-code t]
1464 ["Mark Ring" anything-all-mark-rings t]
1465 ["Regexp handler" anything-regexp t]
1466 ["Colors & Faces" anything-colors t]
1467 ["Show xfonts" anything-select-xfont t]
1468 ["Ucs Symbols" anything-ucs t]
1469 ["Imenu" anything-imenu t]
1470 ["Google Suggest" anything-google-suggest t]
1471 ["Eval expression" anything-eval-expression-with-eldoc t]
1472 ["Calcul expression" anything-calcul-expression t]
1473 ["Man pages" anything-man-woman t]
1474 ["Top externals process" anything-top t]
1475 ["Emacs internals process" anything-list-emacs-process t])
1476 "----"
1477 ["Prefered Options" anything-configuration t]))
1479 ;;; Anything map add ons
1482 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1483 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1484 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1487 ;;; Specialized keymaps
1490 (defvar anything-c-buffer-map
1491 (let ((map (copy-keymap anything-map)))
1492 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1493 ;; No need to have separate command for grep and zgrep
1494 ;; as we don't use recursivity for buffers.
1495 ;; So use zgrep for both as it is capable to handle non--compressed files.
1496 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1497 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1498 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1499 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1500 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1501 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1502 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1503 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1504 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1505 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1506 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1507 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1508 (define-key map (kbd "M-a") 'anything-mark-all)
1509 (when (locate-library "elscreen")
1510 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1511 (delq nil map))
1512 "Keymap for buffer sources in anything.")
1514 (defvar anything-find-files-map
1515 (let ((map (copy-keymap anything-map)))
1516 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1517 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1518 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1519 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1520 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1521 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1522 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1523 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1524 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1525 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1526 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1527 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1528 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1529 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1530 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1531 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1532 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1533 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1534 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1535 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1536 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1537 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1538 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1539 (define-key map (kbd "C-c ?") 'anything-ff-help)
1540 (define-key map (kbd "C-}") 'anything-narrow-window)
1541 (define-key map (kbd "C-{") 'anything-enlarge-window)
1542 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1543 (define-key map (kbd "M-a") 'anything-mark-all)
1544 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1545 (define-key map (kbd "M-u") 'anything-unmark-all)
1546 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1547 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1548 ;; Next 2 have no effect if candidate is not an image file.
1549 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1550 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1551 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1552 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1553 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1554 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1555 (when anything-ff-lynx-style-map
1556 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1557 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1558 (delq nil map))
1559 "Keymap for `anything-find-files'.")
1561 (defvar anything-c-read-file-map
1562 (let ((map (copy-keymap anything-map)))
1563 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1565 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1566 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1567 (when anything-ff-lynx-style-map
1568 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1569 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1570 (define-key map (kbd "<M-left>") 'anything-previous-source)
1571 (define-key map (kbd "<M-right>") 'anything-next-source))
1572 (delq nil map))
1573 "Keymap for `anything-c-read-file-name'.")
1575 (defvar anything-generic-files-map
1576 (let ((map (copy-keymap anything-map)))
1577 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1578 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1579 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1580 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1581 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1582 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1583 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1584 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1585 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1586 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1587 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1588 map)
1589 "Generic Keymap for files.")
1591 (defvar anything-c-grep-map
1592 (let ((map (copy-keymap anything-map)))
1593 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1594 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1595 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1596 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1597 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1598 (when anything-c-grep-use-ioccur-style-keys
1599 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1600 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1601 (define-key map (kbd "C-c ?") 'anything-grep-help)
1602 (delq nil map))
1603 "Keymap used in Grep sources.")
1605 (defvar anything-c-pdfgrep-map
1606 (let ((map (copy-keymap anything-map)))
1607 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1608 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1609 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1610 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1611 map)
1612 "Keymap used in pdfgrep.")
1614 (defvar anything-c-etags-map
1615 (let ((map (copy-keymap anything-map)))
1616 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1617 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1618 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1619 (define-key map (kbd "C-c ?") 'anything-etags-help)
1620 map)
1621 "Keymap used in Etags.")
1623 (defvar anything-eval-expression-map
1624 (let ((map (copy-keymap anything-map)))
1625 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1626 (define-key map (kbd "<tab>") 'lisp-indent-line)
1627 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1628 (define-key map (kbd "C-p") 'previous-line)
1629 (define-key map (kbd "C-n") 'next-line)
1630 (define-key map (kbd "<up>") 'previous-line)
1631 (define-key map (kbd "<down>") 'next-line)
1632 (define-key map (kbd "<right>") 'forward-char)
1633 (define-key map (kbd "<left>") 'backward-char)
1634 map))
1636 (defvar anything-c-ucs-map
1637 (let ((map (copy-keymap anything-map)))
1638 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1639 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1640 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1641 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1642 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1643 map)
1644 "Keymap for `anything-ucs'.")
1648 ;;; Embeded documentation.
1651 (defun anything-c-list-preconfigured-anything ()
1652 "Collect preconfigured anything functions in this file."
1653 (loop with doc
1654 with sym
1655 for entry in (cdr (assoc
1656 (file-truename (locate-library "anything-config"))
1657 load-history))
1658 if (and (consp entry)
1659 (eq (car entry) 'defun)
1660 (string-match "^Preconfigured.+$"
1661 (setq doc (or (documentation (setq sym (cdr entry)))
1662 ""))))
1663 collect (cons sym (match-string 0 doc))))
1665 (defun anything-c-format-preconfigured-anything ()
1666 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1667 (anything-c-list-preconfigured-anything)))
1669 ;;; Global help message - Used by `anything-help'
1672 (setq anything-help-message
1673 (lambda ()
1674 (concat
1675 "\\<anything-map>"
1676 "`anything' is QuickSilver-like candidate-selection framework.
1678 Narrow the list by typing some pattern,
1679 Multiple patterns are allowed by splitting by space.
1680 Select with natural Emacs operations, choose with RET.
1682 If you have any problems, press C-c C-x C-b!!
1683 Feel free to send bug reports. I'll fix them.
1684 The steps are described in the beginning of anything.el file.
1686 == Basic Operations ==
1687 C-p, Up: Previous Line
1688 C-n, Down : Next Line
1689 M-v, PageUp : Previous Page
1690 C-v, PageDown : Next Page
1691 Enter : Execute first (default) action / Select
1692 M-< : First Line
1693 M-> : Last Line
1694 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1695 M-PageDown, C-M-v : Next Page (other-window)
1697 Tab, C-i : Show action list
1698 Left : Previous Source
1699 Right, C-o : Next Source
1700 C-k : Delete pattern
1701 C-z : Persistent Action (Execute action with anything session kept)
1702 C-c C-x C-b: Send a bug report
1704 == Shortcuts For 2nd/3rd Action ==
1705 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1706 \\[anything-select-3rd-action] : Execute 3rd Action
1708 == Visible Marks ==
1709 Visible marks store candidate. Some actions uses marked candidates.
1711 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1712 \\[anything-prev-visible-mark] : Previous Mark
1713 \\[anything-next-visible-mark] : Next Mark
1715 == Miscellaneous Commands ==
1716 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1717 \\[anything-quit-and-find-file] : Drop into `find-file'
1718 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1719 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1720 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1721 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1722 \\[anything-force-update] : Recalculate And Redisplay Candidates
1724 == Global Commands ==
1725 \\<global-map>\\[anything-resume] revives last `anything' session.
1726 It is very useful, so you should bind any key.
1728 Single source is executed by \\[anything-call-source].
1730 == Preconfigured `anything' ==
1731 Preconfigured `anything' is commands that uses `anything' interface.
1732 You can use them without configuration.
1735 (apply 'concat (anything-c-format-preconfigured-anything))
1737 Enjoy!")))
1739 ;;; `anything-buffer-list' help
1742 ;;;###autoload
1743 (defun anything-c-buffer-help ()
1744 "Help command for anything buffers."
1745 (interactive)
1746 (let ((anything-help-message "== Anything Buffer ==
1747 \nTips:
1748 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1749 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1750 \nSpecific commands for `anything-buffers-list':
1751 \\<anything-c-buffer-map>
1752 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1753 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1754 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1755 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1756 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1757 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1758 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1759 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1760 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1761 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1762 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1763 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1764 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1765 \\[anything-mark-all]\t\t->Mark all.
1766 \\[anything-c-buffer-help]\t\t->Display this help.
1767 \n== Anything Map ==
1768 \\{anything-map}
1770 (anything-help)))
1773 ;;; Find files help (`anything-find-files')
1776 ;;;###autoload
1777 (defun anything-ff-help ()
1778 "Help command for `anything-find-files'."
1779 (interactive)
1780 (let ((anything-help-message "== Anything Find Files ==
1781 \nTips:
1782 \n- Enter `~/' at end of pattern to quickly reach home directory.
1783 - Enter `/' at end of pattern to quickly reach root of your file system.
1784 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1785 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1786 - Use `C-u C-z' to watch an image.
1787 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1788 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1790 \nSpecific commands for `anything-find-files':
1791 \\<anything-find-files-map>
1792 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1793 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1794 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1795 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1796 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1797 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1798 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1799 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1800 \\[anything-ff-run-load-file]\t\t->Load File.
1801 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1802 \\[anything-ff-run-delete-file]\t\t->Delete File.
1803 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1804 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1805 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1806 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1807 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1808 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1809 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1810 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1811 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1812 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1813 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1814 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1815 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1816 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1817 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1818 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1819 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1820 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1821 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1822 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1823 \\[anything-narrow-window]\t\t->Narrow anything window.
1824 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1825 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1826 \\[anything-ff-help]\t\t->Display this help info.
1827 \n== Anything Map ==
1828 \\{anything-map}
1830 (anything-help)))
1832 ;;; Help for `anything-c-read-file-name'
1835 ;;;###autoload
1836 (defun anything-read-file-name-help ()
1837 (interactive)
1838 (let ((anything-help-message "== Anything read file name Map ==\
1839 \nSpecific commands for anything-c-read-file-name:
1840 \\<anything-c-read-file-map>
1841 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1842 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1843 \\[anything-next-source]\t\t->Goto next source.
1844 \\[anything-previous-source]\t->Goto previous source.
1845 \\[anything-read-file-name-help]\t\t->Display this help info.
1846 \n== Anything Map ==
1847 \\{anything-map}
1849 (anything-help)))
1851 ;;; Generic file help - Used by locate.
1854 ;;;###autoload
1855 (defun anything-generic-file-help ()
1856 (interactive)
1857 (let ((anything-help-message "== Anything Generic files Map ==\
1858 \nSpecific commands for anything locate and others files sources:
1859 \\<anything-generic-files-map>
1860 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1861 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1862 \\[anything-ff-run-delete-file]\t\t->Delete file.
1863 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1864 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1865 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1866 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1867 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1868 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1869 \nLocate tips:
1870 You can add after writing search pattern any of the locate command line options.
1871 e.g -b, -e, -n <number>...etc.
1872 See Man locate for more infos.
1873 \n== Anything Map ==
1874 \\{anything-map}"))
1875 (anything-help)))
1878 ;;; Grep help
1881 ;;;###autoload
1882 (defun anything-grep-help ()
1883 (interactive)
1884 (let ((anything-help-message "== Anything Grep Map ==\
1885 \nSpecific commands for Grep and Etags:
1886 \\<anything-c-grep-map>
1887 \\[anything-c-goto-next-file]\t->Next File.
1888 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1889 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1890 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1891 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1892 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1893 \\[anything-grep-help]\t\t->Show this help.
1894 \n== Anything Map ==
1895 \\{anything-map}"))
1896 (anything-help)))
1898 ;;; Pdf grep help
1901 ;;;###autoload
1902 (defun anything-pdfgrep-help ()
1903 (interactive)
1904 (let ((anything-help-message "== Anything PdfGrep Map ==\
1905 \nSpecific commands for Pdf Grep:
1906 \\<anything-c-pdfgrep-map>
1907 \\[anything-c-goto-next-file]\t->Next File.
1908 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1909 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1910 \\[anything-pdfgrep-help]\t\t->Show this help.
1911 \n== Anything Map ==
1912 \\{anything-map}"))
1913 (anything-help)))
1915 ;;; Etags help
1918 ;;;###autoload
1919 (defun anything-etags-help ()
1920 "The help function for etags."
1921 (interactive)
1922 (let ((anything-help-message "== Anything Etags Map ==\
1923 \nSpecific commands for Etags:
1924 \\<anything-c-etags-map>
1925 \\[anything-c-goto-next-file]\t->Next File.
1926 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1927 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1928 \\[anything-etags-help]\t\t->Show this help.
1929 \n== Anything Map ==
1930 \\{anything-map}"))
1931 (anything-help)))
1933 ;;; Ucs help
1936 (defun anything-c-ucs-help ()
1937 "Help command for `anything-ucs'."
1938 (interactive)
1939 (let ((anything-help-message "== Anything Ucs ==
1940 \nSpecific commands for `anything-ucs':
1941 \\<anything-c-ucs-map>
1942 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1943 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1944 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1945 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1946 \\[anything-c-ucs-help]\t\t->Show this help.
1948 \n== Anything Map ==
1949 \\{anything-map}
1951 (anything-help)))
1955 ;;; Mode line strings
1958 (defvar anything-buffer-mode-line-string
1959 '("Buffer(s)"
1960 "\\<anything-c-buffer-map>\
1961 \\[anything-c-buffer-help]:Help, \
1962 \\<anything-map>\
1963 \\[anything-select-action]:Acts,\
1964 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1965 \\[anything-select-3rd-action]:NthAct,\
1966 \\[anything-send-bug-report-from-anything]:BugReport."
1967 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1969 (defvar anything-ff-mode-line-string
1970 "\\<anything-find-files-map>\
1971 \\[anything-ff-help]:Help, \
1972 \\[anything-send-bug-report-from-anything]:BugReport, \
1973 \\<anything-map>\
1974 \\[anything-select-action]:Acts, \
1975 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1976 \\[anything-select-3rd-action]:NthAct"
1977 "String displayed in mode-line in `anything-c-source-find-files'")
1979 (defvar anything-read-file-name-mode-line-string
1980 "\\<anything-c-read-file-map>\
1981 \\[anything-read-file-name-help]:Help, \
1982 \\<anything-map>\
1983 \\[anything-select-action]:Acts,\
1984 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1985 \\[anything-select-3rd-action]:NthAct"
1986 "String displayed in mode-line in `anything-c-source-find-files'")
1988 (defvar anything-generic-file-mode-line-string
1989 "\\<anything-generic-files-map>\
1990 \\[anything-generic-file-help]:Help, \
1991 \\<anything-map>\
1992 \\[anything-select-action]:Acts,\
1993 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1994 \\[anything-select-3rd-action]:NthAct,\
1995 \\[anything-send-bug-report-from-anything]:BugReport."
1996 "String displayed in mode-line in Locate.")
1998 (defvar anything-grep-mode-line-string
1999 "\\<anything-c-grep-map>\
2000 \\[anything-grep-help]:Help,\
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 \\[anything-send-bug-report-from-anything]:BugReport."
2006 "String displayed in mode-line in `anything-do-grep'.")
2008 (defvar anything-pdfgrep-mode-line-string
2009 "\\<anything-c-pdfgrep-map>\
2010 \\[anything-pdfgrep-help]:Help,\
2011 \\<anything-map>\
2012 \\[anything-select-action]:Acts,\
2013 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2014 \\[anything-select-3rd-action]:NthAct,\
2015 \\[anything-send-bug-report-from-anything]:BugReport."
2016 "String displayed in mode-line in `anything-do-pdfgrep'.")
2018 (defvar anything-etags-mode-line-string
2019 "\\<anything-c-etags-map>\
2020 \\[anything-etags-help]:Help,\
2021 \\<anything-map>\
2022 \\[anything-select-action]:Acts,\
2023 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2024 \\[anything-select-3rd-action]:NthAct,\
2025 \\[anything-send-bug-report-from-anything]:BugReport."
2026 "String displayed in mode-line in `anything-c-etags-select'.")
2029 (defvar anything-c-ucs-mode-line-string
2030 "\\<anything-c-ucs-map>\
2031 \\[anything-c-ucs-help]:Help, \
2032 \\<anything-map>\
2033 \\[anything-select-action]:Acts,\
2034 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2035 \\[anything-select-3rd-action]:NthAct."
2036 "String displayed in mode-line in `anything-ucs'.")
2040 ;;; Utilities Functions
2043 (defun anything-ff-find-printers ()
2044 "Return a list of available printers on Unix systems."
2045 (let ((printer-list (with-temp-buffer
2046 (call-process "lpstat" nil t nil "-a")
2047 (split-string (buffer-string) "\n"))))
2048 (loop for p in printer-list
2049 for printer = (car (split-string p))
2050 when printer
2051 collect printer)))
2053 ;; Shut up byte compiler in emacs24*.
2054 (defun anything-c-switch-to-buffer (buffer-or-name)
2055 "Same as `switch-to-buffer' whithout warnings at compile time."
2056 (with-no-warnings
2057 (switch-to-buffer buffer-or-name)))
2059 (defsubst* anything-c-position (item seq &key (test 'eq))
2060 "A simple and faster replacement of CL `position'."
2061 (loop for i in seq for index from 0
2062 when (funcall test i item) return index))
2064 (defun anything-c-get-pid-from-process-name (process-name)
2065 "Get pid from running process PROCESS-NAME."
2066 (loop with process-list = (list-system-processes)
2067 for pid in process-list
2068 for process = (assoc-default 'comm (process-attributes pid))
2069 when (and process (string-match process-name process))
2070 return pid))
2072 (defun* anything-current-buffer-narrowed-p (&optional
2073 (buffer anything-current-buffer))
2074 "Check if BUFFER is narrowed.
2075 Default is `anything-current-buffer'."
2076 (with-current-buffer buffer
2077 (let ((beg (point-min))
2078 (end (point-max))
2079 (total (buffer-size)))
2080 (or (/= beg 1) (/= end (1+ total))))))
2082 (defun anything-region-active-p ()
2083 (and transient-mark-mode mark-active (/= (mark) (point))))
2085 (defun anything-goto-line (lineno)
2086 "Goto LINENO opening only outline headline if needed."
2087 (goto-char (point-min)) (forward-line (1- lineno))
2088 (when (or (eq major-mode 'org-mode)
2089 (and (boundp 'outline-minor-mode)
2090 outline-minor-mode))
2091 (require 'org) ; On some old Emacs versions org may not be loaded.
2092 (org-reveal))
2093 (anything-match-line-color-current-line) (sit-for 0.3)
2094 (anything-match-line-cleanup))
2096 (defun anything-show-this-source-only ()
2097 "Show all candidates of this source."
2098 (interactive)
2099 (setq anything-candidate-number-limit nil)
2100 (anything-set-source-filter
2101 (list (assoc-default 'name (anything-get-current-source)))))
2103 ;;;###autoload
2104 (defun anything-test-sources ()
2105 "List all anything sources for test.
2106 The output is sexps which are evaluated by \\[eval-last-sexp]."
2107 (interactive)
2108 (with-output-to-temp-buffer "*Anything Test Sources*"
2109 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2110 (apropos-internal "^anything-c-source" #'boundp))
2111 (pop-to-buffer standard-output)))
2113 (defun anything-nest (&rest same-as-anything)
2114 "Nested `anything'. If you use `anything' within `anything', use it."
2115 (with-selected-window (anything-window)
2116 (let (anything-current-position
2117 anything-current-buffer
2118 (orig-anything-buffer anything-buffer)
2119 anything-pattern
2120 anything-buffer
2121 anything-sources
2122 anything-compiled-sources
2123 anything-buffer-chars-modified-tick
2124 (anything-samewindow t)
2125 (enable-recursive-minibuffers t))
2126 (unwind-protect
2127 (apply #'anything same-as-anything)
2128 (anything-initialize-overlays orig-anything-buffer)
2129 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2131 (defun anything-displaying-source-names ()
2132 "Display sources name."
2133 (with-current-buffer anything-buffer
2134 (goto-char (point-min))
2135 (loop with pos
2136 while (setq pos (next-single-property-change (point) 'anything-header))
2137 do (goto-char pos)
2138 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2139 do (forward-line 1))))
2141 ;; [Obsolete]
2142 (defun anything-select-source ()
2143 "[OBSOLETE] Select source."
2144 (interactive)
2145 (let ((default (assoc-default 'name (anything-get-current-source)))
2146 (source-names (anything-displaying-source-names))
2147 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2148 (anything-get-sources))))
2149 (setq anything-candidate-number-limit 9999)
2150 (anything-aif
2151 (let (anything-source-filter)
2152 (anything-nest '(((name . "Anything Source")
2153 (candidates . source-names)
2154 (action . identity))
2155 ((name . "Anything Source (ALL)")
2156 (candidates . all-source-names)
2157 (action . identity)))
2158 nil "Source: " nil
2159 default "*anything select source*"))
2160 (anything-set-source-filter (list it))
2161 (anything-set-source-filter nil))))
2163 (defun anything-c-match-on-file-name (candidate)
2164 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2165 (string-match anything-pattern (file-name-nondirectory candidate)))
2167 (defun anything-c-match-on-directory-name (candidate)
2168 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2169 (anything-aif (file-name-directory candidate)
2170 (string-match anything-pattern it)))
2172 (defun anything-c-match-on-basename (candidate)
2173 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2174 (string-match anything-pattern (anything-c-basename candidate)))
2176 (defun anything-c-string-match (candidate)
2177 "Return non-nil if `anything-pattern' match CANDIDATE.
2178 The match is done with `string-match'."
2179 (string-match anything-pattern candidate))
2181 (defun anything-c-skip-entries (list regexp)
2182 "Remove entries which matches REGEXP from LIST."
2183 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2184 list))
2186 (defun anything-c-shadow-entries (list regexp)
2187 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2188 (mapcar (lambda (file)
2189 ;; Add shadow face property to boring files.
2190 (let ((face (if (facep 'file-name-shadow)
2191 'file-name-shadow
2192 ;; fall back to default on XEmacs
2193 'default)))
2194 (if (string-match regexp file)
2195 (setq file (propertize file 'face face))))
2196 file)
2197 list))
2199 (defsubst anything-c-stringify (str-or-sym)
2200 "Get string of STR-OR-SYM."
2201 (if (stringp str-or-sym)
2202 str-or-sym
2203 (symbol-name str-or-sym)))
2205 (defsubst anything-c-symbolify (str-or-sym)
2206 "Get symbol of STR-OR-SYM."
2207 (if (symbolp str-or-sym)
2208 str-or-sym
2209 (intern str-or-sym)))
2211 (defun anything-c-describe-function (func)
2212 "FUNC is symbol or string."
2213 (describe-function (anything-c-symbolify func)))
2215 (defun anything-c-describe-variable (var)
2216 "VAR is symbol or string."
2217 (describe-variable (anything-c-symbolify var)))
2219 (defun anything-c-find-function (func)
2220 "FUNC is symbol or string."
2221 (find-function (anything-c-symbolify func)))
2223 (defun anything-c-find-variable (var)
2224 "VAR is symbol or string."
2225 (find-variable (anything-c-symbolify var)))
2227 (defun anything-c-kill-new (candidate &optional replace)
2228 "CANDIDATE is symbol or string.
2229 See `kill-new' for argument REPLACE."
2230 (kill-new (anything-c-stringify candidate) replace))
2232 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2233 "Remove duplicates elements in list SEQ.
2234 This is same as `remove-duplicates' but with memoisation.
2235 It is much faster, especially in large lists.
2236 A test function can be provided with TEST argument key.
2237 Default is `eq'."
2238 (let ((cont (make-hash-table :test test)))
2239 (loop for elm in seq
2240 unless (gethash elm cont)
2241 do (puthash elm elm cont)
2242 finally return
2243 (loop for i being the hash-values in cont collect i))))
2245 (defadvice eval-defun (after anything-source-hack activate)
2246 "Allow immediate execution of anything source when evaling it.
2247 See `anything-c-enable-eval-defun-hack'."
2248 (when anything-c-enable-eval-defun-hack
2249 (let ((varsym (save-excursion
2250 (beginning-of-defun)
2251 (forward-char 1)
2252 (when (memq (read (current-buffer)) '(defvar setq))
2253 (read (current-buffer))))))
2254 (when (string-match "^anything-c-source-" (symbol-name varsym))
2255 (anything varsym)))))
2256 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2259 ;; Move this function from anything.el and redefine here
2260 ;; to avoid an unneeded defadvice.
2261 (defun anything-quit-and-find-file ()
2262 "Drop into `anything-find-files' from `anything'.
2263 If current selection is a buffer or a file, `anything-find-files'
2264 from its directory."
2265 (interactive)
2266 (anything-run-after-quit
2267 (lambda (f)
2268 (if (file-exists-p f)
2269 (anything-find-files-1 (file-name-directory f)
2270 (if anything-ff-transformer-show-only-basename
2271 (anything-c-basename f) f))
2272 (anything-find-files-1 f)))
2273 (anything-aif (get-buffer (anything-get-selection))
2274 (or (buffer-file-name it)
2275 (car (rassoc it dired-buffers))
2276 (and (with-current-buffer it
2277 (eq major-mode 'org-agenda-mode))
2278 org-directory
2279 (expand-file-name org-directory))
2280 default-directory)
2281 (let ((sel (anything-get-selection)))
2282 (if (file-exists-p sel)
2283 (expand-file-name sel)
2284 default-directory)))))
2287 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2288 "Walk through DIRECTORY tree.
2289 PATH can be one of basename, relative, or full.
2290 DIRECTORIES when non--nil (default) return also directories names, otherwise
2291 skip directories names.
2292 MATCH match only filenames matching regexp MATCH."
2293 `(let (result
2294 (fn (case ,path
2295 (basename 'file-name-nondirectory)
2296 (relative 'file-relative-name)
2297 (full 'identity)
2298 (t 'file-name-nondirectory))))
2299 (labels ((ls-R (dir)
2300 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2301 for f in ls
2302 if (file-directory-p f)
2303 do (progn (when ,directories
2304 (push (funcall fn f) result))
2305 ;; Don't recurse in directory symlink.
2306 (unless (file-symlink-p f)
2307 (ls-R f)))
2308 else do
2309 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2310 (push (funcall fn f) result)))))
2311 (ls-R ,directory)
2312 (nreverse result))))
2314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2316 ;;; Anything regexp.
2319 (defun anything-c-query-replace-regexp (candidate)
2320 "Query replace regexp from `anything-regexp'.
2321 With a prefix arg replace only matches surrounded by word boundaries,
2322 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2323 (let ((regexp (funcall (anything-attr 'regexp))))
2324 (apply 'query-replace-regexp
2325 (anything-c-query-replace-args regexp))))
2327 (defun anything-c-kill-regexp-as-sexp (candidate)
2328 "Kill regexp in a format usable in lisp code."
2329 (anything-c-regexp-kill-new
2330 (prin1-to-string (funcall (anything-attr 'regexp)))))
2332 (defun anything-c-kill-regexp (candidate)
2333 "Kill regexp as it is in `anything-pattern'."
2334 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2336 (defun anything-c-query-replace-args (regexp)
2337 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2338 (let ((region-only (anything-region-active-p)))
2339 (list
2340 regexp
2341 (query-replace-read-to regexp
2342 (format "Query replace %sregexp %s"
2343 (if anything-current-prefix-arg "word " "")
2344 (if region-only "in region " ""))
2346 anything-current-prefix-arg
2347 (when region-only (region-beginning))
2348 (when region-only (region-end)))))
2350 (defvar anything-c-source-regexp
2351 '((name . "Regexp Builder")
2352 (init . (lambda ()
2353 (anything-candidate-buffer anything-current-buffer)))
2354 (candidates-in-buffer)
2355 (get-line . anything-c-regexp-get-line)
2356 (persistent-action . anything-c-regexp-persistent-action)
2357 (persistent-help . "Show this line")
2358 (multiline)
2359 (delayed)
2360 (requires-pattern . 2)
2361 (mode-line . "Press TAB to select action.")
2362 (regexp . (lambda () anything-input))
2363 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2364 ("Query Replace Regexp (C-u Not inside word.)"
2365 . anything-c-query-replace-regexp)
2366 ("Kill Regexp" . anything-c-kill-regexp)))))
2368 (defun anything-c-regexp-get-line (s e)
2369 (propertize
2370 (apply 'concat
2371 ;; Line contents
2372 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2373 ;; subexps
2374 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2375 collect (format "\n %s'%s'"
2376 (if (zerop i) "Group 0: " (format "Group %d: " i))
2377 (match-string i))))
2378 ;; match beginning
2379 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2380 ;; It is implementation problem of candidates-in-buffer.
2381 'anything-realvalue
2382 (1- s)))
2384 (defun anything-c-regexp-persistent-action (pt)
2385 (goto-char pt)
2386 (anything-persistent-highlight-point))
2388 (defun anything-c-regexp-kill-new (input)
2389 (kill-new input)
2390 (message "Killed: %s" input))
2394 ;;; Toggle all marks.
2397 ;;;###autoload
2398 (defun anything-mark-all ()
2399 "Mark all visible unmarked candidates in current source."
2400 (interactive)
2401 (with-anything-window
2402 (save-excursion
2403 (goto-char (anything-get-previous-header-pos))
2404 (anything-next-line)
2405 (let* ((next-head (anything-get-next-header-pos))
2406 (end (and next-head
2407 (save-excursion
2408 (goto-char next-head)
2409 (forward-line -1)
2410 (point))))
2411 (maxpoint (or end (point-max))))
2412 (while (< (point) maxpoint)
2413 (anything-mark-current-line)
2414 (let ((prefix (get-text-property (point-at-bol) 'display))
2415 (bn (anything-c-basename (anything-get-selection)))
2416 (src (assoc-default 'name (anything-get-current-source))))
2417 (when (and (not (anything-this-visible-mark))
2418 (not (or (string= prefix "[?]")
2419 (string= prefix "[@]"))))
2420 ;; Don't mark possibles directories ending with . or ..
2421 ;; and also autosave files/links.
2422 (unless
2423 (and (or (anything-file-completion-source-p)
2424 (equal src "Files from Current Directory"))
2425 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2426 (anything-make-visible-mark))))
2427 (forward-line 1) (end-of-line))))
2428 (anything-mark-current-line)
2429 (message "%s candidates marked" (length anything-marked-candidates))))
2431 ;;;###autoload
2432 (defun anything-unmark-all ()
2433 "Unmark all candidates in all sources of current anything session."
2434 (interactive)
2435 (with-anything-window
2436 (let ((len (length anything-marked-candidates)))
2437 (save-excursion
2438 (anything-clear-visible-mark))
2439 (setq anything-marked-candidates nil)
2440 (anything-mark-current-line)
2441 (message "%s candidates unmarked" len))))
2443 ;;;###autoload
2444 (defun anything-toggle-all-marks ()
2445 "Toggle all marks.
2446 Mark all visible candidates of current source or unmark all candidates
2447 visible or invisible in all sources of current anything session"
2448 (interactive)
2449 (let ((marked (anything-marked-candidates)))
2450 (if (and (>= (length marked) 1)
2451 (with-anything-window anything-visible-mark-overlays))
2452 (anything-unmark-all)
2453 (anything-mark-all))))
2457 ;;; Buffers
2460 (defun anything-c-buffer-list ()
2461 "Return the list of names of buffers with boring buffers filtered out.
2462 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2463 The first buffer in the list will be the last recently used
2464 buffer that is not the current buffer."
2465 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2466 (append (cdr buffers) (list (car buffers)))))
2468 (defvar anything-c-source-buffers
2469 '((name . "Buffers")
2470 (candidates . anything-c-buffer-list)
2471 (type . buffer)))
2472 ;; (anything 'anything-c-source-buffers)
2474 (defvar anything-c-source-buffer-not-found
2475 '((name . "Create buffer")
2476 (dummy)
2477 (filtered-candidate-transformer (lambda (cands source)
2478 (list anything-pattern)))
2479 (action . (lambda (candidate)
2480 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2481 ;; (anything 'anything-c-source-buffer-not-found)
2483 ;;; Buffers-list (was buffers+)
2486 (eval-when-compile (require 'dired))
2488 (defun anything-c-highlight-buffers (buffers)
2489 (loop for i in buffers
2490 for buf = (get-buffer i)
2491 for bfname = (buffer-file-name buf)
2492 collect
2493 (cond (;; A dired buffer.
2494 (rassoc buf dired-buffers)
2495 (propertize i 'face 'anything-ff-directory
2496 'help-echo (car (rassoc buf dired-buffers))))
2497 ;; A buffer file modified somewhere outside of emacs.
2498 ((and bfname (not (file-remote-p bfname))
2499 (file-exists-p bfname)
2500 (not (verify-visited-file-modtime buf)))
2501 (propertize i 'face 'anything-buffer-saved-out
2502 'help-echo bfname))
2503 ;; A new buffer file not already saved on disk.
2504 ((and bfname (not (file-remote-p bfname))
2505 (not (verify-visited-file-modtime buf)))
2506 (propertize i 'face 'anything-buffer-not-saved
2507 'help-echo bfname))
2508 ;; A Remote buffer file modified and not saved on disk.
2509 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2510 (let ((prefix (propertize
2511 " " 'display
2512 (propertize "@ " 'face 'anything-ff-prefix))))
2513 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2514 'help-echo bfname)) i)))
2515 ;; A buffer file modified and not saved on disk.
2516 ((and bfname (buffer-modified-p buf))
2517 (propertize i 'face 'anything-ff-symlink
2518 'help-echo bfname))
2519 ;; A remote buffer file not modified and saved on disk.
2520 ((and bfname (file-remote-p bfname))
2521 (let ((prefix (propertize
2522 " " 'display
2523 (propertize "@ " 'face 'anything-ff-prefix))))
2524 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2525 'help-echo bfname)) i)))
2526 ;; A buffer file not modified and saved on disk.
2527 (bfname
2528 (propertize i 'face 'font-lock-type-face
2529 'help-echo bfname))
2530 ;; Any non--file buffer.
2531 (t (propertize i 'face 'italic)))))
2534 (defvar anything-c-source-buffers-list
2535 '((name . "Buffers")
2536 (candidates . anything-c-buffer-list)
2537 (type . buffer)
2538 (match anything-c-buffer-match-major-mode)
2539 (diff-action . anything-buffer-toggle-diff)
2540 (revert-action . anything-buffer-revert-and-update)
2541 (save-action . anything-buffer-save-and-update)
2542 (candidate-transformer anything-c-skip-current-buffer
2543 anything-c-skip-boring-buffers
2544 anything-c-highlight-buffers)
2545 (persistent-action . anything-c-buffers-list-persistent-action)
2546 (volatile)
2547 (mode-line . anything-buffer-mode-line-string)
2548 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2549 ;; (anything 'anything-c-source-buffers-list)
2551 (defun anything-c-buffer-match-major-mode (candidate)
2552 "Match maybe buffer by major-mode.
2553 If you give a major-mode or partial major-mode,
2554 it will list all buffers of this major-mode and/or buffers with name
2555 matching this major-mode.
2556 If you add a space after major-mode and then a space,
2557 it will match all buffers of the major-mode
2558 before space matching pattern after space.
2559 If you give a pattern which doesn't match a major-mode, it will search buffer
2560 with name matching pattern."
2561 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2562 (buf (get-buffer cand)))
2563 (when buf
2564 (with-current-buffer buf
2565 (let ((mjm (symbol-name major-mode))
2566 (split (split-string anything-pattern)))
2567 (cond ((string-match "\\s-$" anything-pattern)
2568 (string-match (car split) mjm))
2569 ((string-match "\\s-" anything-pattern)
2570 (and (string-match (car split) mjm)
2571 (string-match (cadr split) cand)))
2572 (t (or (string-match anything-pattern mjm)
2573 (string-match anything-pattern cand)))))))))
2575 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2576 "Query replace in marked buffers.
2577 If REGEXP-FLAG is given use `query-replace-regexp'."
2578 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2579 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2580 (bufs (anything-marked-candidates)))
2581 (loop
2582 with replace = (query-replace-read-from prompt regexp-flag)
2583 with tostring = (unless (consp replace)
2584 (query-replace-read-to
2585 replace prompt regexp-flag))
2586 for buf in bufs
2588 (save-window-excursion
2589 (anything-c-switch-to-buffer buf)
2590 (save-excursion
2591 (let ((case-fold-search t))
2592 (goto-char (point-min))
2593 (if (consp replace)
2594 (apply fn (list (car replace) (cdr replace)))
2595 (apply fn (list replace tostring)))))))))
2597 (defun anything-c-buffer-query-replace-regexp (candidate)
2598 (anything-c-buffer-query-replace-1 'regexp))
2600 (defun anything-c-buffer-query-replace (candidate)
2601 (anything-c-buffer-query-replace-1))
2603 (defun anything-buffer-toggle-diff (candidate)
2604 "Toggle diff buffer CANDIDATE with it's file."
2605 (if (get-buffer-window "*Diff*")
2606 (kill-buffer "*Diff*")
2607 (diff-buffer-with-file (get-buffer candidate))))
2609 ;;;###autoload
2610 (defun anything-buffer-diff-persistent ()
2611 "Toggle diff buffer without quitting anything."
2612 (interactive)
2613 (anything-execute-persistent-action 'diff-action))
2615 (defun anything-buffer-revert-and-update (candidate)
2616 (let ((marked (anything-marked-candidates)))
2617 (loop for buf in marked do (anything-revert-buffer buf))
2618 (anything-force-update)
2619 (anything-c-recenter-window)))
2621 ;;;###autoload
2622 (defun anything-buffer-revert-persistent ()
2623 "Revert buffer without quitting anything."
2624 (interactive)
2625 (anything-execute-persistent-action 'revert-action 'onewindow))
2627 (defun anything-buffer-save-and-update (candidate)
2628 (let ((marked (anything-marked-candidates))
2629 (enable-recursive-minibuffers t))
2630 (loop for buf in marked do
2631 (with-current-buffer (get-buffer buf)
2632 (save-buffer)))
2633 (anything-force-update)
2634 (anything-c-recenter-window)))
2636 ;;;###autoload
2637 (defun anything-buffer-save-persistent ()
2638 "Save buffer without quitting anything."
2639 (interactive)
2640 (anything-execute-persistent-action 'save-action 'onewindow))
2642 ;;;###autoload
2643 (defun anything-buffer-run-kill-buffers ()
2644 "Run kill buffer action from `anything-c-source-buffers-list'."
2645 (interactive)
2646 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2648 ;;;###autoload
2649 (defun anything-buffer-run-grep ()
2650 "Run Grep action from `anything-c-source-buffers-list'."
2651 (interactive)
2652 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2654 ;;;###autoload
2655 (defun anything-buffer-run-zgrep ()
2656 "Run Grep action from `anything-c-source-buffers-list'."
2657 (interactive)
2658 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2660 ;;;###autoload
2661 (defun anything-buffer-run-query-replace-regexp ()
2662 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2663 (interactive)
2664 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2666 ;;;###autoload
2667 (defun anything-buffer-run-query-replace ()
2668 "Run Query replace action from `anything-c-source-buffers-list'."
2669 (interactive)
2670 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2672 ;;;###autoload
2673 (defun anything-buffer-switch-other-window ()
2674 "Run switch to other window action from `anything-c-source-buffers-list'."
2675 (interactive)
2676 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2678 ;;;###autoload
2679 (defun anything-buffer-switch-other-frame ()
2680 "Run switch to other frame action from `anything-c-source-buffers-list'."
2681 (interactive)
2682 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2684 ;;;###autoload
2685 (defun anything-buffer-switch-to-elscreen ()
2686 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2687 (interactive)
2688 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2690 ;;;###autoload
2691 (defun anything-buffer-run-ediff ()
2692 "Run ediff action from `anything-c-source-buffers-list'."
2693 (interactive)
2694 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2696 (defun anything-buffer-run-ediff-merge ()
2697 "Run ediff action from `anything-c-source-buffers-list'."
2698 (interactive)
2699 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2701 (defun anything-c-buffers-persistent-kill (buffer)
2702 "Persistent action to kill buffer."
2703 (with-current-buffer (get-buffer buffer)
2704 (if (and (buffer-modified-p)
2705 (buffer-file-name (current-buffer)))
2706 (progn
2707 (save-buffer)
2708 (kill-buffer buffer))
2709 (kill-buffer buffer)))
2710 (anything-delete-current-selection))
2712 (defun anything-c-recenter-window ()
2713 "Make visible current selection by recentering anything window."
2714 (with-anything-window (recenter)))
2716 (defun anything-c-buffers-list-persistent-action (candidate)
2717 (if current-prefix-arg
2718 (anything-c-buffers-persistent-kill candidate)
2719 (anything-c-switch-to-buffer candidate)))
2722 ;;;; <File>
2725 ;;; File name history
2726 (defvar anything-c-source-file-name-history
2727 '((name . "File Name History")
2728 (candidates . file-name-history)
2729 (match anything-c-match-on-basename)
2730 (type . file)))
2731 ;; (anything 'anything-c-source-file-name-history)
2733 ;;; Files in current dir
2736 (defvar anything-c-source-files-in-current-dir
2737 '((name . "Files from Current Directory")
2738 (candidates . (lambda ()
2739 (with-anything-current-buffer
2740 (directory-files (anything-c-current-directory)))))
2741 ;; volatile is not needed, I think.
2742 (type . file)))
2743 ;; (anything 'anything-c-source-files-in-current-dir)
2745 (defun anything-c-highlight-files (files)
2746 (loop for i in files
2747 if (file-directory-p i)
2748 collect (propertize (file-name-nondirectory i)
2749 'face 'anything-ff-directory
2750 'help-echo (expand-file-name i))
2751 else
2752 collect (propertize (file-name-nondirectory i)
2753 'face 'anything-ff-file
2754 'help-echo (expand-file-name i))))
2756 (defvar anything-c-source-files-in-current-dir+
2757 '((name . "Files from Current Directory")
2758 (candidates . (lambda ()
2759 (with-anything-current-buffer
2760 (directory-files (anything-c-current-directory) t))))
2761 (candidate-transformer anything-c-highlight-files)
2762 ;; volatile is not needed, I think.
2763 (type . file)))
2764 ;; (anything 'anything-c-source-files-in-current-dir+)
2768 ;;; Anything-find-files - The anything files browser.
2771 ;; Internal.
2772 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2773 "*The doc that is inserted in the Name header of a find-files or dired source.")
2774 (defvar anything-ff-auto-update-flag nil
2775 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2776 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2777 (defvar anything-ff-last-expanded nil
2778 "Store last expanded directory or file.")
2779 (defvar anything-ff-default-directory nil)
2780 (defvar anything-ff-history nil)
2781 (defvar anything-ff-cand-to-mark nil)
2784 (defvar anything-c-source-find-files
2785 `((name . "Find Files")
2786 (header-name . (lambda (name)
2787 (concat name anything-c-find-files-doc-header)))
2788 ;; It is needed for filenames with capital letters
2789 (disable-shortcuts)
2790 (init . (lambda ()
2791 (setq anything-ff-auto-update-flag
2792 anything-ff-auto-update-initial-value)))
2793 (candidates . anything-find-files-get-candidates)
2794 (filtered-candidate-transformer anything-c-find-files-transformer)
2795 (image-action1 . anything-ff-rotate-image-left)
2796 (image-action2 . anything-ff-rotate-image-right)
2797 (toggle-basename . anything-ff-toggle-basename)
2798 (properties-action . anything-ff-properties)
2799 (toggle-auto-update . anything-ff-toggle-auto-update)
2800 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2801 (persistent-action . anything-find-files-persistent-action)
2802 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2803 (mode-line . anything-ff-mode-line-string)
2804 (volatile)
2805 (candidate-number-limit . 9999)
2806 (action-transformer . anything-find-files-action-transformer)
2807 (action
2808 . ,(delq
2810 `(("Find File" . anything-c-find-file-or-marked)
2811 ("Find file in Dired" . anything-c-point-file-in-dired)
2812 ,(and (locate-library "elscreen")
2813 '("Find file in Elscreen" . anything-elscreen-find-file))
2814 ,(and (locate-library "popwin")
2815 '("Find file in popup window" . popwin:find-file))
2816 ("Checksum File" . anything-ff-checksum)
2817 ("Complete at point `M-tab'"
2818 . anything-c-insert-file-name-completion-at-point)
2819 ("Open file externally `C-c C-x, C-u to choose'"
2820 . anything-c-open-file-externally)
2821 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2822 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2823 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2824 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2825 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2826 . anything-find-files-eshell-command-on-file)
2827 ("Find file as root" . anything-find-file-as-root)
2828 ("Find file in hex dump" . hexl-find-file)
2829 ("Ediff File `C-='" . anything-find-files-ediff-files)
2830 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2831 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2832 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2833 ("Copy file(s) Async" . anything-ff-copy-async)
2834 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2835 ("Serial rename files" . anything-ff-serial-rename)
2836 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2837 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2838 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2839 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2840 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2841 ("Find file other window `C-o'" . find-file-other-window)
2842 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2843 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2844 ("Print File `C-c p'" . anything-ff-print)
2845 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2846 ;; (anything 'anything-c-source-find-files)
2848 (defun anything-find-files-set-prompt-for-action (prompt files)
2849 "Set prompt for action in `anything-find-files'."
2850 (let ((len (length files)))
2851 (if (> len 1)
2852 (format "%s * %d Files to: " prompt len)
2853 (format "%s %s to: " prompt (car files)))))
2855 (defun anything-dwim-target-directory ()
2856 "Return value of `default-directory' of buffer in other window.
2857 If there is only one window return the value ot `default-directory'
2858 for current buffer."
2859 (with-anything-current-buffer
2860 (let ((num-windows (length (window-list))))
2861 (if (> num-windows 1)
2862 (save-window-excursion
2863 (other-window 1)
2864 default-directory)
2865 (car anything-ff-history)))))
2867 (defun anything-find-files-do-action (action)
2868 "Generic function for creating action from `anything-c-source-find-files'.
2869 ACTION must be an action supported by `anything-dired-action'."
2870 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2871 (anything-marked-candidates)))
2872 (cand (anything-get-selection)) ; Target
2873 (prompt (anything-find-files-set-prompt-for-action
2874 (capitalize (symbol-name action)) ifiles))
2875 (parg anything-current-prefix-arg)
2876 (dest (anything-c-read-file-name
2877 prompt
2878 :preselect (if anything-ff-transformer-show-only-basename
2879 (anything-c-basename cand) cand)
2880 :initial-input (anything-dwim-target-directory)
2881 :history (anything-find-files-history :comp-read nil)))
2882 (win-conf (current-window-configuration)))
2883 (unwind-protect
2884 (let ((default-directory anything-ff-default-directory))
2885 (anything-dired-action
2886 dest :files ifiles :action action :follow parg))
2887 ;; Don't reset win-conf when following.
2888 (unless parg (set-window-configuration win-conf)))))
2890 (defun anything-find-files-copy (candidate)
2891 "Copy files from `anything-find-files'."
2892 (anything-find-files-do-action 'copy))
2894 (defun anything-find-files-rename (candidate)
2895 "Rename files from `anything-find-files'."
2896 (anything-find-files-do-action 'rename))
2898 (defun anything-find-files-symlink (candidate)
2899 "Symlink files from `anything-find-files'."
2900 (anything-find-files-do-action 'symlink))
2902 (defun anything-find-files-relsymlink (candidate)
2903 "Relsymlink files from `anything-find-files'."
2904 (anything-find-files-do-action 'relsymlink))
2906 (defun anything-find-files-hardlink (candidate)
2907 "Hardlink files from `anything-find-files'."
2908 (anything-find-files-do-action 'hardlink))
2910 (defun anything-find-files-byte-compile (candidate)
2911 "Byte compile elisp files from `anything-find-files'."
2912 (let ((files (anything-marked-candidates))
2913 (parg anything-current-prefix-arg))
2914 (loop for fname in files
2915 do (byte-compile-file fname parg))))
2917 (defun anything-find-files-load-files (candidate)
2918 "Load elisp files from `anything-find-files'."
2919 (let ((files (anything-marked-candidates)))
2920 (loop for fname in files
2921 do (load fname))))
2923 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2924 "Generic function to ediff/merge files in `anything-find-files'."
2925 (let ((bname (anything-c-basename candidate))
2926 (prompt (if merge "Ediff Merge `%s' With File: "
2927 "Ediff `%s' With File: "))
2928 (fun (if merge 'ediff-merge-files 'ediff-files)))
2929 (funcall fun
2930 candidate
2931 (condition-case quit
2932 (anything-c-read-file-name
2933 (format prompt bname))
2934 (quit ;; Hit C-g ask user to fallback to locate.
2935 (if (y-or-n-p "Search file for ediff with locate? ")
2936 (anything-c-locate-read-file-name
2937 (format prompt bname)
2938 ;; Check if -b option is available.
2939 (if (and (eq system-type 'windows-nt)
2940 (string-match "^es" anything-c-locate-command))
2941 bname
2942 (concat bname " -b")))
2943 (error "Error: Ediff Operation aborted")))))))
2945 (defun anything-find-files-ediff-files (candidate)
2946 (anything-find-files-ediff-files-1 candidate))
2948 (defun anything-find-files-ediff-merge-files (candidate)
2949 (anything-find-files-ediff-files-1 candidate 'merge))
2951 (defun anything-find-files-grep (candidate)
2952 "Default action to grep files from `anything-find-files'."
2953 (anything-do-grep-1 (anything-marked-candidates)
2954 anything-current-prefix-arg))
2956 (defun anything-ff-zgrep (candidate)
2957 "Default action to zgrep files from `anything-find-files'."
2958 (let ((prefarg anything-current-prefix-arg)
2959 (ls (anything-marked-candidates)))
2960 (anything-ff-zgrep-1 ls prefarg)))
2962 (defun anything-ff-pdfgrep (candidate)
2963 "Default action to pdfgrep files from `anything-find-files'."
2964 (let ((cands (loop for file in (anything-marked-candidates)
2965 if (or (string= (file-name-extension file) "pdf")
2966 (string= (file-name-extension file) "PDF"))
2967 collect file))
2968 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2969 (when cands
2970 (anything-do-pdfgrep-1 cands))))
2972 (defun anything-ff-etags-select (candidate)
2973 "Default action to jump to etags from `anything-find-files'."
2974 (when (get-buffer anything-action-buffer)
2975 (kill-buffer anything-action-buffer))
2976 (let ((default-directory anything-ff-default-directory))
2977 (anything-c-etags-select anything-current-prefix-arg)))
2979 (defun anything-find-files-switch-to-hist (candidate)
2980 "Switch to anything-find-files history."
2981 (anything-find-files t))
2983 ;;; Asynchronous copy of files.
2986 (defun anything-c-copy-files-async-1 (flist dest)
2987 "Copy a list of Files FLIST to DEST asynchronously.
2988 It use another emacs process to do the job.
2989 Communication with background emacs is done with temp file
2990 `anything-c-copy-files-async-log-file'."
2991 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2992 "-Q" "--batch" "--eval"
2993 (format "(progn
2994 (require 'dired) (require 'cl)
2995 (let ((dired-recursive-copies 'always)
2996 failures success
2997 (ovw-count 0)
2998 (cpf-count 0))
2999 (dolist (f '%S)
3000 (condition-case err
3001 (let ((file-exists (file-exists-p
3002 (expand-file-name
3003 (file-name-nondirectory (directory-file-name f))
3004 (file-name-directory
3005 (file-name-as-directory \"%s\"))))))
3006 (dired-copy-file f \"%s\" t)
3007 (if file-exists
3008 (progn (push (cons \"Overwriting\" f) success)
3009 (incf ovw-count))
3010 (push (cons \"Copying\" f) success)
3011 (incf cpf-count)))
3012 (file-error
3013 (push (dired-make-relative
3014 (expand-file-name
3015 (file-name-nondirectory (directory-file-name f))
3016 (file-name-directory \"%s\")))
3017 failures))))
3018 (with-current-buffer (find-file-noselect \"%s\")
3019 (erase-buffer)
3020 (when failures
3021 (dolist (fail (reverse failures))
3022 (insert (concat \"Failed to copy \" fail \"\n\"))))
3023 (when success
3024 (loop for (a . s) in (reverse success) do
3025 (insert (concat a \" \" s \" to %s done\n\"))))
3026 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3027 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3028 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3029 (save-buffer))))"
3030 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3032 (defun anything-c-copy-async-with-log (flist dest)
3033 "Copy file list FLIST to DEST showing log.
3034 Log is send to `anything-c-copy-files-async-log-file'.
3035 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3036 (declare (special auto-revert-interval))
3037 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3038 (set (make-local-variable 'auto-revert-interval) 1)
3039 (erase-buffer)
3040 (insert "Wait copying files...\n")
3041 (sit-for 0.5) (save-buffer)
3042 (goto-char (point-max))
3043 (auto-revert-mode 1)
3044 (anything-c-copy-files-async-1 flist dest))
3046 (defun anything-ff-copy-async (candidate)
3047 "Anything find files action to copy files async.
3048 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3049 (let ((flist (anything-marked-candidates))
3050 (dest (anything-c-read-file-name
3051 "Copy File(s) async To: "
3052 :preselect candidate
3053 :initial-input (car anything-ff-history)
3054 :history (anything-find-files-history :comp-read nil))))
3055 (anything-c-copy-async-with-log flist dest)))
3057 (defvar eshell-command-aliases-list nil)
3058 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3059 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3061 Basename of CANDIDATE can be a wild-card.
3062 If MAP is given run `eshell-command' on all marked files at once,
3063 Otherwise, run `eshell-command' on each marked files.
3065 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3066 `eshell-command-aliases-list' will not be loaded first time you use this."
3067 (when (or eshell-command-aliases-list
3068 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3069 (and eshell-command-aliases-list (eshell-read-aliases-list))
3070 (let* ((cand-list (anything-marked-candidates))
3071 (default-directory (or anything-ff-default-directory
3072 ;; If candidate is an url *-ff-default-directory is nil
3073 ;; so keep value of default-directory.
3074 default-directory))
3075 (command (anything-comp-read
3076 "Command: "
3077 (loop for (a . c) in eshell-command-aliases-list
3078 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3079 collect (propertize a 'help-echo (car c)) into ls
3080 finally return (sort ls 'string<))))
3081 (com-value (car (assoc-default command eshell-command-aliases-list))))
3082 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3083 (> (length cand-list) 1))
3084 ;; Run eshell-command with ALL marked files as arguments.
3085 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3086 (eshell-command (format "%s %s" command mapfiles)))
3087 ;; Run eshell-command on EACH marked files.
3088 (loop
3089 for i in cand-list
3090 for bn = (anything-c-basename i)
3091 for files = (if (and bn (string-match "^\*" bn))
3092 ;; Assume if fname is a wildcard
3093 ;; cand-list have a length of 1.
3094 (mapconcat
3095 'shell-quote-argument
3096 (file-expand-wildcards i t) " ")
3097 (format "'%s'" i))
3098 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3099 ;; This allow to enter other args AFTER filename
3100 ;; i.e <command %s some_more_args>
3101 (format command files)
3102 (format "%s %s" command files))
3103 do (eshell-command com))))))
3105 (defun anything-find-files-eshell-command-on-file (candidate)
3106 "Run `eshell-command' on CANDIDATE or marked candidates.
3107 See `anything-find-files-eshell-command-on-file-1' for more info."
3108 (anything-find-files-eshell-command-on-file-1
3109 candidate anything-current-prefix-arg))
3111 (defun anything-ff-switch-to-eshell (candidate)
3112 "Switch to eshell and cd to `anything-ff-default-directory'."
3113 (flet ((cd-eshell ()
3114 (goto-char (point-max))
3115 (insert
3116 (format "cd '%s'" anything-ff-default-directory))
3117 (eshell-send-input)))
3118 (if (get-buffer "*eshell*")
3119 (progn
3120 (anything-c-switch-to-buffer "*eshell*")
3121 (cd-eshell))
3122 (call-interactively 'eshell)
3123 (cd-eshell))))
3125 (defun anything-ff-serial-rename-action (method)
3126 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3127 See `anything-ff-serial-rename-1'."
3128 (let* ((cands (anything-marked-candidates))
3129 (name (read-string "NewName: "))
3130 (start (read-number "StartAtNumber: "))
3131 (extension (read-string "Extension: " (file-name-extension (car cands))))
3132 (dir (expand-file-name
3133 (anything-c-read-file-name
3134 "Serial Rename to directory: " :initial-input
3135 (expand-file-name anything-ff-default-directory)))))
3136 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3137 (length cands) dir name))
3138 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3139 (anything-find-files-1 dir))))
3141 (defun anything-ff-member-directory-p (file directory)
3142 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3143 (cur-dir (expand-file-name (file-name-as-directory directory))))
3144 (string= dir-file cur-dir)))
3146 (defun* anything-ff-serial-rename-1
3147 (directory collection new-name start-at-num extension &key (method 'rename))
3148 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3149 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3150 EXTENSION is the file extension to use, in empty prompt,
3151 reuse the original extension of file.
3152 METHOD can be one of rename, copy or symlink.
3153 Files will be renamed if they are files of current directory, otherwise they
3154 will be treated with METHOD.
3155 Default METHOD is rename."
3156 ;; Maybe remove directories selected by error in collection.
3157 (setq collection (remove-if 'file-directory-p collection))
3158 (flet ((symlink-file (file dest)
3159 (let ((flist (list file)))
3160 (anything-dired-action
3161 dest :action 'symlink :files flist))))
3163 (let* ((tmp-dir (file-name-as-directory
3164 (concat (file-name-as-directory directory)
3165 (symbol-name (gensym "tmp")))))
3166 (fn (case method
3167 (copy 'copy-file)
3168 (symlink 'symlink-file)
3169 (rename 'rename-file)
3170 (t (error "Error: Unknow method %s" method)))))
3171 (make-directory tmp-dir)
3172 (loop for i in collection
3173 for count from start-at-num
3174 for fnum = (if (< count 10) "0%s" "%s")
3175 for nname = (concat tmp-dir new-name (format fnum count)
3176 (if (not (string= extension ""))
3177 (format ".%s" (replace-regexp-in-string
3178 "[.]" "" extension))
3179 (file-name-extension i 'dot)))
3180 do (if (anything-ff-member-directory-p i directory)
3181 (rename-file i nname)
3182 (funcall fn i nname)))
3183 (loop with dirlist = (directory-files
3184 tmp-dir t directory-files-no-dot-files-regexp)
3185 for f in dirlist do
3186 (if (file-symlink-p f)
3187 (symlink-file (file-truename f)
3188 (concat (file-name-as-directory directory)
3189 (anything-c-basename f)))
3190 (rename-file f directory)))
3191 (delete-directory tmp-dir t))))
3193 (defun anything-ff-serial-rename (candidate)
3194 "Serial rename all marked files to `anything-ff-default-directory'.
3195 Rename only file of current directory, and symlink files coming from
3196 other directories.
3197 See `anything-ff-serial-rename-1'."
3198 (anything-ff-serial-rename-action 'rename))
3200 (defun anything-ff-serial-rename-by-symlink (candidate)
3201 "Serial rename all marked files to `anything-ff-default-directory'.
3202 Rename only file of current directory, and symlink files coming from
3203 other directories.
3204 See `anything-ff-serial-rename-1'."
3205 (anything-ff-serial-rename-action 'symlink))
3207 (defun anything-ff-serial-rename-by-copying (candidate)
3208 "Serial rename all marked files to `anything-ff-default-directory'.
3209 Rename only file of current directory, and copy files coming from
3210 other directories.
3211 See `anything-ff-serial-rename-1'."
3212 (anything-ff-serial-rename-action 'copy))
3214 (defun anything-c-quit-and-execute-action (action)
3215 "Quit current anything session and execute ACTION."
3216 (setq anything-saved-action action)
3217 (anything-exit-minibuffer))
3219 (defun anything-ff-toggle-auto-update (candidate)
3220 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3221 (message "[Auto expansion %s]"
3222 (if anything-ff-auto-update-flag "enabled" "disabled")))
3224 ;;;###autoload
3225 (defun anything-ff-run-toggle-auto-update ()
3226 (interactive)
3227 (anything-execute-persistent-action 'toggle-auto-update))
3229 ;;;###autoload
3230 (defun anything-ff-run-switch-to-history ()
3231 "Run Switch to history action from `anything-c-source-find-files'."
3232 (interactive)
3233 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3235 ;;;###autoload
3236 (defun anything-ff-run-grep ()
3237 "Run Grep action from `anything-c-source-find-files'."
3238 (interactive)
3239 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3241 ;;;###autoload
3242 (defun anything-ff-run-pdfgrep ()
3243 "Run Pdfgrep action from `anything-c-source-find-files'."
3244 (interactive)
3245 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3247 ;;;###autoload
3248 (defun anything-ff-run-zgrep ()
3249 "Run Grep action from `anything-c-source-find-files'."
3250 (interactive)
3251 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3253 ;;;###autoload
3254 (defun anything-ff-run-copy-file ()
3255 "Run Copy file action from `anything-c-source-find-files'."
3256 (interactive)
3257 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3259 ;;;###autoload
3260 (defun anything-ff-run-rename-file ()
3261 "Run Rename file action from `anything-c-source-find-files'."
3262 (interactive)
3263 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3265 ;;;###autoload
3266 (defun anything-ff-run-byte-compile-file ()
3267 "Run Byte compile file action from `anything-c-source-find-files'."
3268 (interactive)
3269 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3271 ;;;###autoload
3272 (defun anything-ff-run-load-file ()
3273 "Run Load file action from `anything-c-source-find-files'."
3274 (interactive)
3275 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3277 ;;;###autoload
3278 (defun anything-ff-run-eshell-command-on-file ()
3279 "Run eshell command on file action from `anything-c-source-find-files'."
3280 (interactive)
3281 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3283 ;;;###autoload
3284 (defun anything-ff-run-ediff-file ()
3285 "Run Ediff file action from `anything-c-source-find-files'."
3286 (interactive)
3287 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3289 ;;;###autoload
3290 (defun anything-ff-run-ediff-merge-file ()
3291 "Run Ediff merge file action from `anything-c-source-find-files'."
3292 (interactive)
3293 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3295 ;;;###autoload
3296 (defun anything-ff-run-symlink-file ()
3297 "Run Symlink file action from `anything-c-source-find-files'."
3298 (interactive)
3299 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3301 ;;;###autoload
3302 (defun anything-ff-run-delete-file ()
3303 "Run Delete file action from `anything-c-source-find-files'."
3304 (interactive)
3305 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3307 ;;;###autoload
3308 (defun anything-ff-run-complete-fn-at-point ()
3309 "Run complete file name action from `anything-c-source-find-files'."
3310 (interactive)
3311 (anything-c-quit-and-execute-action
3312 'anything-c-insert-file-name-completion-at-point))
3314 ;;;###autoload
3315 (defun anything-ff-run-switch-to-eshell ()
3316 "Run switch to eshell action from `anything-c-source-find-files'."
3317 (interactive)
3318 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3320 ;;;###autoload
3321 (defun anything-ff-run-switch-other-window ()
3322 "Run switch to other window action from `anything-c-source-find-files'."
3323 (interactive)
3324 (anything-c-quit-and-execute-action 'find-file-other-window))
3326 ;;;###autoload
3327 (defun anything-ff-run-switch-other-frame ()
3328 "Run switch to other frame action from `anything-c-source-find-files'."
3329 (interactive)
3330 (anything-c-quit-and-execute-action 'find-file-other-frame))
3332 ;;;###autoload
3333 (defun anything-ff-run-open-file-externally ()
3334 "Run open file externally command action from `anything-c-source-find-files'."
3335 (interactive)
3336 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3338 (defun anything-ff-locate (candidate)
3339 "Locate action function for `anything-find-files'."
3340 (let ((input (concat (anything-c-basename
3341 (expand-file-name
3342 candidate
3343 anything-ff-default-directory))
3344 ;; The locate '-b' option doesn't exists
3345 ;; in everything.
3346 (unless (and (eq system-type 'windows-nt)
3347 (string-match "^es" anything-c-locate-command))
3348 " -b")))
3349 (anything-mp-highlight-delay 0.7))
3350 (anything-locate-1 anything-current-prefix-arg input)))
3352 ;;;###autoload
3353 (defun anything-ff-run-locate ()
3354 "Run locate action from `anything-c-source-find-files'."
3355 (interactive)
3356 (anything-c-quit-and-execute-action 'anything-ff-locate))
3358 ;;;###autoload
3359 (defun anything-ff-run-gnus-attach-files ()
3360 "Run gnus attach files command action from `anything-c-source-find-files'."
3361 (interactive)
3362 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3364 ;;;###autoload
3365 (defun anything-ff-run-etags ()
3366 "Run Etags command action from `anything-c-source-find-files'."
3367 (interactive)
3368 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3371 (defun anything-ff-print (candidate)
3372 "Print marked files.
3373 You have to set in order
3374 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3376 e.g:
3377 \(setq lpr-command \"gtklp\"\)
3378 \(setq lpr-switches '(\"-P\")\)
3379 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3381 Same as `dired-do-print' but for anything."
3382 (let* ((file-list (anything-marked-candidates))
3383 (len (length file-list))
3384 (printer-name (if anything-ff-printer-list
3385 (anything-comp-read
3386 "Printer: " anything-ff-printer-list)
3387 printer-name))
3388 (command (read-string
3389 (format "Print *%s File(s):\n%s with: "
3391 (mapconcat
3392 (lambda (f) (format "- %s\n" f))
3393 file-list ""))
3394 (when (and lpr-command
3395 (or lpr-switches
3396 printer-name))
3397 (mapconcat 'identity
3398 (cons lpr-command
3399 (append (if (stringp lpr-switches)
3400 (list lpr-switches)
3401 lpr-switches)
3402 (list printer-name)))
3403 " "))))
3404 (file-args (mapconcat #'(lambda (x)
3405 (format "'%s'" x))
3406 file-list " "))
3407 (cmd-line (concat command " " file-args)))
3408 (if command
3409 (start-process-shell-command "anything-print" nil cmd-line)
3410 (error "Error: Please verify your printer settings in Emacs."))))
3412 ;;;###autoload
3413 (defun anything-ff-run-print-file ()
3414 "Run Print file action from `anything-c-source-find-files'."
3415 (interactive)
3416 (anything-c-quit-and-execute-action 'anything-ff-print))
3418 (defun anything-ff-checksum (file)
3419 "Calculate the checksum of FILE.
3420 Provide completion on different algorithms to use on Emacs24.
3421 On Emacs23 only 'sha1' is available.
3422 The checksum is copied to kill-ring."
3423 (let ((algo-list (and (fboundp 'secure-hash)
3424 '(md5 sha1 sha224 sha256 sha384 sha512))))
3425 (kill-new
3426 (if algo-list
3427 (secure-hash (intern
3428 (anything-comp-read
3429 "Algorithm: " algo-list))
3430 file)
3431 (sha1 (with-temp-buffer
3432 (insert-file-contents file)
3433 (buffer-string)))))
3434 (message "Checksum copied to kill-ring.")))
3436 (defun anything-ff-toggle-basename (candidate)
3437 (setq anything-ff-transformer-show-only-basename
3438 (not anything-ff-transformer-show-only-basename))
3439 (save-excursion
3440 (anything-force-update)))
3442 (defun anything-ff-run-toggle-basename ()
3443 (interactive)
3444 (anything-execute-persistent-action 'toggle-basename))
3446 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3447 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3448 If LEVEL is positive reduce from end else from beginning.
3449 If UNIX-CLOSE is non--nil close filename with /.
3450 If EXPAND is non--nil expand-file-name."
3451 (let* ((exp-fname (expand-file-name fname))
3452 (fname-list (split-string (if (or (string= fname "~/") expand)
3453 exp-fname fname) "/" t))
3454 (len (length fname-list))
3455 (pop-list (if (< level 0)
3456 (subseq fname-list (* level -1))
3457 (subseq fname-list 0 (- len level))))
3458 (result (mapconcat 'identity pop-list "/"))
3459 (empty (string= result "")))
3460 (when unix-close (setq result (concat result "/")))
3461 (if (string-match "^~" result)
3462 (if (string= result "~/") "~/" result)
3463 (if (< level 0)
3464 (if empty "../" (concat "../" result))
3465 (cond ((eq system-type 'windows-nt)
3466 (if empty "c:/" result))
3467 (empty "/")
3469 (concat "/" result)))))))
3471 ;; Internal
3472 (defvar anything-file-completion-sources
3473 '("Find Files" "find-file" "Copy Files"
3474 "dired-do-copy" "dired-do-rename"
3475 "dired-do-symlink" "dired-do-hardlink"
3476 "write-file" "insert-file" "dired"
3477 "find-alternate-file" "find-alternate-file-other-window"
3478 "find-file-read-only" "list-directory"
3479 "Read File Name History"
3480 "Rename Files" "Symlink Files"
3481 "Hardlink Files" "Write File"
3482 "Insert File" "Read File Name")
3483 "Sources that use the *find-files mechanism can be added here.
3484 You should not modify this yourself and know what you do if you do so.")
3486 (defun anything-file-completion-source-p ()
3487 "Test if current source is a dired or find-files source."
3488 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3489 (loop for i in anything-file-completion-sources
3490 thereis (string= cur-source i))))
3492 (defun anything-find-files-down-one-level (arg)
3493 "Go down one level like unix command `cd ..'.
3494 If prefix numeric arg is given go ARG level down."
3495 (interactive "p")
3496 (when (and (anything-file-completion-source-p)
3497 (not (anything-ff-invalid-tramp-name-p)))
3498 (with-anything-window
3499 (setq anything-follow-mode nil))
3500 ;; When going to precedent level we want to be at the line
3501 ;; corresponding to actual directory, so store this info
3502 ;; in `anything-ff-last-expanded'.
3503 (if (and (not (file-directory-p anything-pattern))
3504 (file-exists-p anything-pattern))
3505 (setq anything-ff-last-expanded anything-pattern)
3506 (setq anything-ff-last-expanded anything-ff-default-directory))
3507 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3508 :unix-close t :expand t)))
3509 (anything-set-pattern new-pattern))))
3511 (defun anything-ff-retrieve-last-expanded ()
3512 "Move overlay to last visited directory `anything-ff-last-expanded'.
3513 This happen after using `anything-find-files-down-one-level',
3514 or hitting C-z on \"..\"."
3515 (when (and anything-ff-last-expanded
3516 (anything-file-completion-source-p))
3517 (let ((dirname (if anything-ff-transformer-show-only-basename
3518 (anything-c-basename
3519 (directory-file-name anything-ff-last-expanded))
3520 (directory-file-name anything-ff-last-expanded))))
3521 (with-anything-window
3522 (when (or (re-search-forward (concat dirname "$") nil t)
3523 (re-search-forward
3524 (concat anything-ff-last-expanded "$") nil t))
3525 (forward-line 0)
3526 (anything-mark-current-line)))
3527 (setq anything-ff-last-expanded nil))))
3528 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3530 ;; Auto-update - anything-find-files auto expansion of directories.
3532 (defun anything-ff-update-when-only-one-matched ()
3533 "Expand to directory when sole completion.
3534 When only one candidate is remaining and it is a directory,
3535 expand to this directory."
3536 (when (and anything-ff-auto-update-flag
3537 (anything-file-completion-source-p)
3538 (not (anything-ff-invalid-tramp-name-p)))
3539 (let* ((history-p (string= (assoc-default
3540 'name (anything-get-current-source))
3541 "Read File Name History"))
3542 (pat (if (string-match tramp-file-name-regexp
3543 anything-pattern)
3544 (anything-create-tramp-name anything-pattern)
3545 anything-pattern))
3546 (completed-p (string= (file-name-as-directory pat)
3547 anything-ff-default-directory)))
3548 (when (and (or
3549 ;; Only one candidate remaining
3550 ;; and at least 2 char in basename.
3551 (and (<= (anything-approximate-candidate-number) 2)
3552 (>= (length (anything-c-basename anything-pattern)) 2))
3553 ;; Already completed.
3554 completed-p)
3555 (not history-p)) ; Don't try to auto complete in history.
3556 (with-anything-window
3557 (let ((cur-cand (prog2
3558 (unless completed-p
3559 ;; Only one non--existing candidate
3560 ;; and one directory candidate, move to it.
3561 (anything-next-line))
3562 (anything-get-selection))))
3563 (when (file-directory-p cur-cand)
3564 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3565 ;; Maybe we are here because completed-p is true
3566 ;; but check this again to be sure. (Windows fix)
3567 (<= (anything-approximate-candidate-number) 2)) ; [2]
3568 ;; If after going to next line the candidate
3569 ;; is not one of "." or ".." [1]
3570 ;; and only one candidate is remaining [2],
3571 ;; assume candidate is a new directory to expand, and do it.
3572 (anything-set-pattern (file-name-as-directory cur-cand))
3573 ;; The candidate is one of "." or ".."
3574 ;; that mean we have entered the last letter of the directory name
3575 ;; in prompt, so expansion is already done, just add the "/" at end
3576 ;; of name unless anything-pattern ends with "."
3577 ;; (i.e we are writing something starting with ".")
3578 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3579 (anything-set-pattern
3580 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3581 (expand-file-name (file-name-as-directory anything-pattern)))))
3582 (anything-check-minibuffer-input-1))))))))
3583 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3585 ;; Allow expanding to home directory or root
3586 ;; when entering respectively "~/" or "//" at end of pattern.
3587 ;; e.g /home/thierry/labo/anything-config-qp/~/
3588 ;; will expand to "~/"
3589 ;; and /home/thierry/labo/anything-config-qp//
3590 ;; will expand to "/"
3591 (defun anything-ff-auto-expand-to-home-or-root ()
3592 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3593 This happen only in function using sources that are
3594 `anything-file-completion-source-p' compliant."
3595 (when (and (anything-file-completion-source-p)
3596 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3597 anything-pattern))
3598 (let ((match (match-string 1 anything-pattern)))
3599 (cond ((string= match "//")
3600 (if (eq system-type 'windows-nt)
3601 (setq anything-pattern "c:/")
3602 (setq anything-pattern "/")))
3603 ((string= match "/~/")
3604 (if (eq system-type 'windows-nt)
3605 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3606 (setq anything-pattern "~/")))
3607 ((string= match "/./")
3608 (setq anything-pattern
3609 (with-anything-current-buffer
3610 (expand-file-name default-directory))))))
3611 (setq anything-ff-default-directory anything-pattern)
3612 ;; For some reasons, i must use here with-current-buffer => mini buffer
3613 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3614 (with-current-buffer (window-buffer (minibuffer-window))
3615 (delete-minibuffer-contents)
3616 (insert anything-pattern))))
3618 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3620 (defun anything-c-point-file-in-dired (file)
3621 "Put point on filename FILE in dired buffer."
3622 (dired (file-name-directory file))
3623 (dired-goto-file file))
3625 (defun anything-create-tramp-name (fname)
3626 "Build filename for `anything-pattern' like /su:: or /sudo::."
3627 (apply #'tramp-make-tramp-file-name
3628 (loop with v = (tramp-dissect-file-name fname)
3629 for i across v collect i)))
3631 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3632 "Get a list of hosts for tramp method found in `anything-pattern'.
3633 Argument PATTERN default to `anything-pattern', it is here only for debugging
3634 purpose."
3635 (when (string-match tramp-file-name-regexp pattern)
3636 (let ((method (match-string 1 pattern))
3637 (tn (match-string 0 pattern))
3638 (all-methods (mapcar 'car tramp-methods)))
3639 (remove-duplicates
3640 (loop for (f . h) in (tramp-get-completion-function method)
3641 append (loop for e in (funcall f (car h))
3642 for host = (and (consp e) (cadr e))
3643 when (and host (not (member host all-methods)))
3644 collect (concat tn host)))
3645 :test 'equal))))
3647 (defun anything-ff-before-action-hook-fn ()
3648 "Exit anything when user try to execute action on an invalid tramp fname."
3649 (let ((cand (anything-get-selection)))
3650 (when (and (anything-file-completion-source-p)
3651 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3652 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3653 (error "Error: Unknow file or directory `%s'" cand))))
3654 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3656 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3657 "Return non--nil when PATTERN is an invalid tramp filename."
3658 (string= (anything-ff-set-pattern pattern)
3659 "Invalid tramp file name"))
3661 (defun anything-ff-set-pattern (pattern)
3662 "Handle tramp filenames in `anything-pattern'."
3663 (let ((methods (mapcar 'car tramp-methods))
3664 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3665 cur-method tramp-name)
3666 (cond ((string= pattern "") "")
3667 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3668 (with-anything-current-buffer
3669 (expand-file-name default-directory)))
3670 ((string-match ".*\\(~//\\|//\\)$" pattern)
3671 (if (eq system-type 'windows-nt) "c:/" "/"))
3672 ((string-match "^~\\|.*/~/$" pattern)
3673 (let* ((home (expand-file-name (getenv "HOME"))))
3674 (replace-match home nil t pattern)))
3675 ;; Match "/method:maybe_hostname:"
3676 ((and (string-match reg pattern)
3677 (setq cur-method (match-string 1 pattern))
3678 (member cur-method methods))
3679 (setq tramp-name (anything-create-tramp-name
3680 (match-string 0 pattern)))
3681 (replace-match tramp-name nil t pattern))
3682 ;; Match "/hostname:"
3683 ((and (string-match tramp-file-name-regexp pattern)
3684 (setq cur-method (match-string 1 pattern))
3685 (and cur-method (not (member cur-method methods))))
3686 (setq tramp-name (anything-create-tramp-name
3687 (match-string 0 pattern)))
3688 (replace-match tramp-name nil t pattern))
3689 ;; Match "/method:" in this case don't try to connect.
3690 ((and (not (string-match reg pattern))
3691 (string-match tramp-file-name-regexp pattern)
3692 (member (match-string 1 pattern) methods))
3693 "Invalid tramp file name") ; Write in anything-buffer.
3694 ;; PATTERN is a directory, end it with "/".
3695 ;; This will make PATTERN not ending yet with "/"
3696 ;; candidate for `anything-ff-default-directory',
3697 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3698 ;; when descending level.
3699 ((file-directory-p pattern)
3700 (file-name-as-directory pattern))
3701 ;; Return PATTERN unchanged.
3702 (t pattern))))
3704 (defun anything-find-files-get-candidates ()
3705 "Create candidate list for `anything-c-source-find-files'."
3706 (let* ((path (anything-ff-set-pattern anything-pattern))
3707 (path-name-dir (if (file-directory-p path)
3708 (file-name-as-directory path)
3709 (file-name-directory path)))
3710 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3711 (set-text-properties 0 (length path) nil path)
3712 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3713 ;; like that the actual value (e.g /ssh:) is passed to
3714 ;; `anything-ff-tramp-hostnames'.
3715 (unless (string= path "Invalid tramp file name")
3716 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3717 (setq anything-ff-default-directory
3718 (if (string= anything-pattern "")
3719 (if (eq system-type 'windows-nt) "c:/" "/")
3720 (unless (string-match ffap-url-regexp path)
3721 ;; If path is an url *default-directory have to be nil.
3722 path-name-dir)))
3723 (cond ((string= path "Invalid tramp file name")
3724 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3725 (prog2
3726 ;; `anything-pattern' have not been modified yet.
3727 ;; Set it here to the value of `path' that should be now
3728 ;; "Invalid tramp file name" and set the candidates list
3729 ;; to ("Invalid tramp file name") to make `anything-pattern'
3730 ;; match single candidate "Invalid tramp file name".
3731 (setq anything-pattern path)
3732 ;; "Invalid tramp file name" is now printed
3733 ;; in `anything-buffer'.
3734 (list path))))
3735 ((or (file-regular-p path)
3736 (and (not (file-exists-p path)) (string-match "/$" path))
3737 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3738 (list path))
3739 ((string= path "") (directory-files "/" t))
3740 ((and (file-directory-p path) (not (file-readable-p path)))
3741 (list (format "Opening directory: access denied, `%s'" path)))
3742 ((file-directory-p path) (directory-files path t))
3744 (append (list path) (directory-files path-name-dir t))))))
3746 (defun anything-ff-transform-fname-for-completion (fname)
3747 "Return FNAME with it's basename modified as a regexp.
3748 e.g foo => f.*o.*o .
3749 If basename contain one or more space or FNAME is a valid directory name
3750 return FNAME unchanged."
3751 (let ((bn (anything-c-basename fname)))
3752 (if (or (not anything-ff-smart-completion)
3753 (string-match "\\s-" bn)
3754 (string-match "/$" fname) ; Allow mkdir.
3755 (file-directory-p fname))
3756 fname ; Fall back to match-plugin.
3757 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3758 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3759 (concat (file-name-directory fname) bn))))
3761 (defun anything-ff-save-history ()
3762 "Store the last value of `anything-ff-default-directory' \
3763 in `anything-ff-history'."
3764 (when (and anything-ff-default-directory
3765 (anything-file-completion-source-p))
3766 (push anything-ff-default-directory anything-ff-history)))
3767 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3769 (defun anything-ff-valid-symlink-p (file)
3770 (file-exists-p (file-truename file)))
3772 (defun anything-ff-properties (candidate)
3773 "Show file properties of CANDIDATE in a tooltip or message."
3774 (let ((type (anything-ff-attributes candidate :type t))
3775 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3776 (if (window-system)
3777 (tooltip-show
3778 (concat
3779 (anything-c-basename candidate) ": \n"
3780 "Type: " type "\n"
3781 (when (string= type "symlink")
3782 (format "True name: '%s'\n"
3783 (cond ((string-match "^\.#" (anything-c-basename candidate))
3784 "Autosave symlink")
3785 ((anything-ff-valid-symlink-p candidate)
3786 (file-truename candidate))
3787 (t "Invalid Symlink"))))
3788 dired-line))
3789 (message dired-line) (sit-for 5))))
3791 ;;;###autoload
3792 (defun anything-ff-properties-persistent ()
3793 "Show properties without quitting anything."
3794 (interactive)
3795 (anything-execute-persistent-action 'properties-action))
3797 (defun anything-ff-kill-buffer-fname (candidate)
3798 (let* ((buf (get-file-buffer candidate))
3799 (buf-name (buffer-name buf)))
3800 (if buf
3801 (progn
3802 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3803 (message "No buffer to kill"))))
3805 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3806 "Find file CANDIDATE or kill it's buffer if it is visible.
3807 Never kill `anything-current-buffer'.
3808 Never kill buffer modified.
3809 This is called normally on third hit of \
3810 \\<anything-map>\\[anything-execute-persistent-action]
3811 in `anything-find-files-persistent-action'."
3812 (let* ((buf (get-file-buffer candidate))
3813 (buf-name (buffer-name buf)))
3814 (if (and buf (get-buffer-window buf)
3815 (not (eq buf (get-buffer anything-current-buffer)))
3816 (not (buffer-modified-p buf)))
3817 (progn
3818 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3819 (find-file candidate))))
3821 ;;;###autoload
3822 (defun anything-ff-run-kill-buffer-persistent ()
3823 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3824 (interactive)
3825 (anything-execute-persistent-action 'kill-buffer-fname))
3827 (defun anything-ff-human-size (size)
3828 "Return a string showing SIZE of a file in human readable form.
3829 SIZE can be an integer or a float depending it's value.
3830 `file-attributes' will take care of that to avoid overflow error.
3831 KBSIZE if a floating point number, default value is 1024.0."
3832 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3833 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3834 (K (cons "K" (/ size anything-ff-default-kbsize)))
3835 (B (cons "B" size)))
3836 (loop with result = B
3837 for (a . b) in
3838 (loop for (x . y) in (list M G K B)
3839 unless (< y 1) collect (cons x y))
3840 when (< b (cdr result)) do (setq result (cons a b))
3841 finally return (if (string= (car result) "B")
3842 (format "%s" size)
3843 (format "%.1f%s" (cdr result) (car result))))))
3845 (defun* anything-ff-attributes
3846 (file &key type links uid gid access-time modif-time
3847 status size mode gid-change inode device-num dired human-size)
3848 "Easy interface for `file-attributes'."
3849 (let ((all (destructuring-bind
3850 (type links uid gid access-time modif-time
3851 status size mode gid-change inode device-num)
3852 (file-attributes file 'string)
3853 (list :type type
3854 :links links
3855 :uid uid
3856 :gid gid
3857 :access-time access-time
3858 :modif-time modif-time
3859 :status status
3860 :size size
3861 :mode mode
3862 :gid-change gid-change
3863 :inode inode
3864 :device-num device-num))))
3865 (cond (type
3866 (let ((result (getf all :type)))
3867 (cond ((stringp result)
3868 "symlink")
3869 (result "directory")
3870 (t "file"))))
3871 (links (getf all :links))
3872 (uid (getf all :uid))
3873 (gid (getf all :gid))
3874 (access-time
3875 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3876 (modif-time
3877 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3878 (status
3879 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3880 (size (if human-size (anything-ff-human-size (getf all :size))
3881 (getf all :size)))
3882 (mode (getf all :mode))
3883 (gid-change (getf all :gid-change))
3884 (inode (getf all :inode))
3885 (device-num (getf all :device-num))
3886 (dired
3887 (concat
3888 (getf all :mode) " "
3889 (number-to-string (getf all :links)) " "
3890 (getf all :uid) ":"
3891 (getf all :gid) " "
3892 (if human-size (anything-ff-human-size (getf all :size))
3893 (int-to-string (getf all :size))) " "
3894 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3895 (t all))))
3897 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3898 "Return filename FNAME maybe prefixed with [?] or [@].
3899 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3900 existing filename or valid symlink and there is no need to test it.
3901 NEW-FILE when non--nil mean FNAME is a non existing file and
3902 return FNAME prefixed with [?]."
3903 (let* ((prefix-new (propertize
3904 " " 'display
3905 (propertize "[?]" 'face 'anything-ff-prefix)))
3906 (prefix-url (propertize
3907 " " 'display
3908 (propertize "[@]" 'face 'anything-ff-prefix))))
3909 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3910 ((string-match ffap-url-regexp fname)
3911 (concat prefix-url " " fname))
3912 ((or new-file (not (file-exists-p fname)))
3913 (concat prefix-new " " fname)))))
3915 (defun anything-c-find-files-transformer (files sources)
3916 "Transformer for `anything-c-source-find-files'.
3917 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3918 is non--nil."
3919 (if (and (string-match tramp-file-name-regexp anything-pattern)
3920 anything-ff-tramp-not-fancy)
3921 (if anything-ff-transformer-show-only-basename
3922 (loop for i in files collect
3923 (if (string-match "[.]\\{1,2\\}$" i)
3924 i (cons (anything-c-basename i) i)))
3925 files)
3926 (anything-ff-highlight-files files sources)))
3928 (defun anything-ff-highlight-files (files sources)
3929 "Candidate transformer for `anything-c-source-find-files' without icons."
3930 (loop for i in files
3931 for disp = (if (and anything-ff-transformer-show-only-basename
3932 (not (string-match "[.]\\{1,2\\}$" i))
3933 (not (string-match ffap-url-regexp i)))
3934 (anything-c-basename i) i)
3935 collect
3936 (cond ((and (stringp (car (file-attributes i)))
3937 (not (anything-ff-valid-symlink-p i))
3938 (not (string-match "^\.#" (anything-c-basename i))))
3939 (cons (anything-ff-prefix-filename
3940 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3942 ((stringp (car (file-attributes i)))
3943 (cons (anything-ff-prefix-filename
3944 (propertize disp 'face 'anything-ff-symlink) t)
3946 ((eq t (car (file-attributes i)))
3947 (cons (anything-ff-prefix-filename
3948 (propertize disp 'face 'anything-ff-directory) t)
3950 ((file-executable-p i)
3951 (cons (anything-ff-prefix-filename
3952 (propertize disp 'face 'anything-ff-executable) t)
3954 ((file-exists-p i)
3955 (cons (anything-ff-prefix-filename
3956 (propertize disp 'face 'anything-ff-file) t)
3959 (cons (anything-ff-prefix-filename
3960 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3961 i)))))
3963 (defun anything-find-files-action-transformer (actions candidate)
3964 "Action transformer for `anything-c-source-find-files'."
3965 (cond ((with-anything-current-buffer
3966 (eq major-mode 'message-mode))
3967 (append (subseq actions 0 4)
3968 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3969 (subseq actions 4)))
3970 ((string-match (image-file-name-regexp) candidate)
3971 (append (subseq actions 0 4)
3972 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3973 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3974 (subseq actions 4)))
3975 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3976 (car it) candidate))
3977 (append (subseq actions 0 4)
3978 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3979 . anything-find-files-byte-compile)
3980 ("Load File(s) `M-L'" . anything-find-files-load-files))
3981 (subseq actions 4)))
3982 ((and (string-match "\.html?$" candidate)
3983 (file-exists-p candidate))
3984 (append (subseq actions 0 4)
3985 '(("Browse url file" . browse-url-of-file))
3986 (subseq actions 5)))
3987 ((or (string= (file-name-extension candidate) "pdf")
3988 (string= (file-name-extension candidate) "PDF"))
3989 (append (subseq actions 0 4)
3990 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3991 (subseq actions 5)))
3992 (t actions)))
3994 (defun anything-ff-gnus-attach-files (candidate)
3995 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3996 (let ((flist (anything-marked-candidates)))
3997 (gnus-dired-attach flist)))
3999 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4000 "Rotate current image at NUM-ARG degrees.
4001 This is a destructive operation on FILE made by external tool mogrify."
4002 (declare (special image-dired-display-image-buffer))
4003 (setq file (file-truename file)) ; For symlinked images.
4004 ;; When FILE is not an image-file, do nothing.
4005 (when (string-match (image-file-name-regexp) file)
4006 (if (executable-find "mogrify")
4007 (progn
4008 (shell-command (format "mogrify -rotate %s %s"
4009 (or num-arg 90)
4010 (shell-quote-argument file)))
4011 (when (buffer-live-p image-dired-display-image-buffer)
4012 (kill-buffer image-dired-display-image-buffer))
4013 (image-dired-display-image file)
4014 (message nil)
4015 (display-buffer (get-buffer image-dired-display-image-buffer)))
4016 (error "mogrify not found"))))
4018 (defun anything-ff-rotate-image-left (candidate)
4019 "Rotate image file CANDIDATE left.
4020 This affect directly file CANDIDATE."
4021 (anything-ff-rotate-current-image-1 candidate -90))
4023 (defun anything-ff-rotate-image-right (candidate)
4024 "Rotate image file CANDIDATE right.
4025 This affect directly file CANDIDATE."
4026 (anything-ff-rotate-current-image-1 candidate))
4028 (defun anything-ff-rotate-left-persistent ()
4029 "Rotate image left without quitting anything."
4030 (interactive)
4031 (anything-execute-persistent-action 'image-action1))
4033 (defun anything-ff-rotate-right-persistent ()
4034 "Rotate image right without quitting anything."
4035 (interactive)
4036 (anything-execute-persistent-action 'image-action2))
4038 (defun anything-ff-exif-data (candidate)
4039 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4040 (if (and anything-ff-exif-data-program
4041 (executable-find anything-ff-exif-data-program))
4042 (shell-command-to-string (format "%s %s %s"
4043 anything-ff-exif-data-program
4044 anything-ff-exif-data-program-args
4045 candidate))
4046 (format "No program %s found to extract exif"
4047 anything-ff-exif-data-program)))
4049 (defun anything-find-files-persistent-action (candidate)
4050 "Open subtree CANDIDATE without quitting anything.
4051 If CANDIDATE is not a directory expand CANDIDATE filename.
4052 If CANDIDATE is alone, open file CANDIDATE filename.
4053 That's mean:
4054 First hit on C-z expand CANDIDATE second hit open file.
4055 If a prefix arg is given or `anything-follow-mode' is on open file."
4056 (let ((follow (buffer-local-value
4057 'anything-follow-mode
4058 (get-buffer-create anything-buffer)))
4059 (new-pattern (anything-get-selection))
4060 (num-lines-buf (with-current-buffer anything-buffer
4061 (count-lines (point-min) (point-max)))))
4062 (flet ((insert-in-minibuffer (fname)
4063 (with-selected-window (minibuffer-window)
4064 (unless follow
4065 (delete-minibuffer-contents)
4066 (set-text-properties 0 (length fname) nil fname)
4067 (insert fname)))))
4068 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4069 "Invalid tramp file name")
4070 (string-match tramp-file-name-regexp candidate))
4071 (insert-in-minibuffer candidate))
4072 (;; A symlink directory, expand it's truename.
4073 (and (file-directory-p candidate) (file-symlink-p candidate))
4074 (insert-in-minibuffer (file-name-as-directory
4075 (file-truename
4076 (expand-file-name candidate)))))
4077 ;; A directory, open it.
4078 ((file-directory-p candidate)
4079 (when (string= (anything-c-basename candidate) "..")
4080 (setq anything-ff-last-expanded anything-ff-default-directory))
4081 (insert-in-minibuffer (file-name-as-directory
4082 (expand-file-name candidate))))
4083 ;; A symlink file, expand to it's true name. (first hit)
4084 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4085 (insert-in-minibuffer (file-truename candidate)))
4086 ;; A regular file, expand it, (first hit)
4087 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4088 (insert-in-minibuffer new-pattern))
4089 ;; An image file and it is the second hit on C-z,
4090 ;; show the file in `image-dired'.
4091 ((string-match (image-file-name-regexp) candidate)
4092 (when (buffer-live-p image-dired-display-image-buffer)
4093 (kill-buffer image-dired-display-image-buffer))
4094 (image-dired-display-image candidate)
4095 (message nil)
4096 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4097 (with-current-buffer image-dired-display-image-buffer
4098 (let ((exif-data (anything-ff-exif-data candidate)))
4099 (image-dired-update-property 'help-echo exif-data))))
4100 ;; Allow browsing archive on avfs fs.
4101 ;; Assume volume is already mounted with mountavfs.
4102 ((and anything-ff-avfs-directory
4103 (string-match
4104 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4105 (file-name-directory candidate))
4106 (anything-ff-file-compressed-p candidate))
4107 (insert-in-minibuffer (concat candidate "#")))
4108 ;; On second hit we open file.
4109 ;; On Third hit we kill it's buffer maybe.
4111 (anything-ff-kill-or-find-buffer-fname candidate))))))
4113 (defun anything-ff-file-compressed-p (candidate)
4114 "Whether CANDIDATE is a compressed file or not."
4115 (member (file-name-extension candidate)
4116 anything-ff-file-compressed-list))
4118 (defun anything-c-insert-file-name-completion-at-point (candidate)
4119 "Insert file name completion at point."
4120 (with-anything-current-buffer
4121 (if buffer-read-only
4122 (error "Error: Buffer `%s' is read-only" (buffer-name))
4123 (let* ((end (point))
4124 (guess (substring-no-properties (thing-at-point 'filename)))
4125 (beg (- (point) (length guess)))
4126 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4127 (string-match-p "^[^\~]" guess))))
4128 (set-text-properties 0 (length candidate) nil candidate)
4129 (if (and guess (not (string= guess ""))
4130 (string-match-p "^~\\|/.*" guess))
4131 (progn
4132 (delete-region beg end)
4133 (insert (if full-path-p
4134 (expand-file-name candidate)
4135 (abbreviate-file-name candidate))))
4136 (error "Aborting completion: No valid file name at point"))))))
4138 (defun* anything-find-files-history (&key (comp-read t))
4139 "The `anything-find-files' history.
4140 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4141 in an `anything-comp-read'."
4142 (let ((history (when anything-ff-history
4143 (loop with dup for i in anything-ff-history
4144 ;; Remove duplicate and not existing files.
4145 ;; Keep remote files.
4146 unless (or (member i dup)
4147 (and (not (file-remote-p i))
4148 (not (file-exists-p i))))
4149 collect i into dup
4150 finally return dup)))) ; Remove dups.
4151 (when history
4152 (setq anything-ff-history
4153 (if (>= (length history) anything-ff-history-max-length)
4154 (subseq history 0 anything-ff-history-max-length)
4155 history))
4156 (if comp-read
4157 (anything-comp-read
4158 "Switch to Directory: "
4159 anything-ff-history
4160 :name "Anything Find Files History"
4161 :must-match t)
4162 anything-ff-history))))
4164 (defun anything-find-files-1 (fname &optional preselect)
4165 "Find FNAME with `anything' completion.
4166 Like `find-file' but with `anything' support.
4167 Use it for non--interactive calls of `anything-find-files'."
4168 (when (get-buffer anything-action-buffer)
4169 (kill-buffer anything-action-buffer))
4170 (let ((anything-mp-highlight-delay nil)
4171 ;; Be sure we don't erase the precedent minibuffer if some.
4172 (anything-ff-auto-update-initial-value
4173 (not (minibuffer-window-active-p (minibuffer-window))))
4174 anything-samewindow)
4175 (anything :sources 'anything-c-source-find-files
4176 :input fname
4177 :preselect preselect
4178 :keymap anything-find-files-map
4179 :prompt "Find Files or Url: "
4180 :buffer "*Anything Find Files*")))
4183 (defun anything-find-files-initial-input (&optional input)
4184 "Return INPUT if present, otherwise try to guess it."
4185 (or (and input (expand-file-name input))
4186 (anything-find-files-input
4187 (ffap-guesser)
4188 (thing-at-point 'filename))))
4190 (defun anything-find-files-input (fap tap)
4191 "Default input of `anything-find-files'."
4192 (let* ((def-dir (anything-c-current-directory))
4193 (lib (anything-find-library-at-point))
4194 (url (anything-ff-find-url-at-point))
4195 (file-p (and fap (not (string= fap ""))
4196 (file-exists-p fap)
4197 tap (not (string= tap ""))
4198 (file-exists-p
4199 (file-name-directory (expand-file-name tap def-dir))))))
4200 (cond (lib) ; e.g we are inside a require sexp.
4201 (url) ; String at point is an hyperlink.
4202 (file-p (expand-file-name tap def-dir))
4203 (t (and (not (string= fap "")) fap)))))
4205 (defun anything-c-current-directory ()
4206 "Return current-directory name at point.
4207 Useful in dired buffers when there is inserted subdirs."
4208 (if (eq major-mode 'dired-mode)
4209 (dired-current-directory)
4210 default-directory))
4212 (defun anything-ff-find-url-at-point ()
4213 "Try to find link to an url in text-property at point."
4214 (let* ((he (get-text-property (point) 'help-echo))
4215 (ov (overlays-at (point)))
4216 (ov-he (and ov (overlay-get
4217 (car (overlays-at (point))) 'help-echo)))
4218 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4219 (nt-prop (get-text-property (point) 'nt-link)))
4220 ;; Org link.
4221 (when (and (stringp he) (string-match "^LINK: " he))
4222 (setq he (replace-match "" t t he)))
4223 (loop for i in (list he ov-he w3m-l nt-prop)
4224 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4226 (defun anything-find-library-at-point ()
4227 "Try to find library path at point.
4228 Find inside `require' and `declare-function' sexp."
4229 (require 'find-func)
4230 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4231 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4232 (sexp (and beg-sexp end-sexp
4233 (buffer-substring-no-properties
4234 (1+ beg-sexp) (1- end-sexp)))))
4235 (ignore-errors
4236 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4237 (find-library-name
4238 (replace-regexp-in-string
4239 "'\\|\)\\|\(" ""
4240 ;; If require use third arg, ignore it,
4241 ;; always use library path found in `load-path'.
4242 (second (split-string (match-string 0 sexp))))))
4243 ((and sexp (string-match-p "^declare-function" sexp))
4244 (find-library-name
4245 (replace-regexp-in-string
4246 "\"\\|ext:" ""
4247 (third (split-string sexp)))))
4248 (t nil)))))
4250 ;;; Anything completion for `write-file'.==> C-x C-w
4251 (defvar anything-c-source-write-file
4252 `((name . "Write File")
4253 (header-name . (lambda (name)
4254 (concat name anything-c-find-files-doc-header)))
4255 ;; It is needed for filenames with capital letters
4256 (disable-shortcuts)
4257 (candidates . anything-find-files-get-candidates)
4258 (filtered-candidate-transformer anything-c-find-files-transformer)
4259 (persistent-action . anything-find-files-persistent-action)
4260 (persistent-help . "Expand Candidate")
4261 (volatile)
4262 (action .
4263 (("Write File" . (lambda (candidate)
4264 (write-file candidate 'confirm)))))))
4266 ;;; Anything completion for `insert-file'.==> C-x i
4267 (defvar anything-c-source-insert-file
4268 `((name . "Insert File")
4269 (header-name . (lambda (name)
4270 (concat name anything-c-find-files-doc-header)))
4271 ;; It is needed for filenames with capital letters
4272 (disable-shortcuts)
4273 (candidates . anything-find-files-get-candidates)
4274 (filtered-candidate-transformer anything-c-find-files-transformer)
4275 (persistent-action . anything-find-files-persistent-action)
4276 (persistent-help . "Expand Candidate")
4277 (volatile)
4278 (action .
4279 (("Insert File" . (lambda (candidate)
4280 (when (y-or-n-p (format "Really insert %s in %s "
4281 candidate anything-current-buffer))
4282 (insert-file-contents candidate))))))))
4284 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4285 (defvar anything-c-source-copy-files
4286 `((name . "Copy Files")
4287 (header-name . (lambda (name)
4288 (concat name anything-c-find-files-doc-header)))
4289 ;; It is needed for filenames with capital letters
4290 (disable-shortcuts)
4291 (candidates . anything-find-files-get-candidates)
4292 (filtered-candidate-transformer anything-c-find-files-transformer)
4293 (persistent-action . anything-find-files-persistent-action)
4294 (persistent-help . "Expand Candidate")
4295 (volatile)
4296 (action .
4297 (("Copy File"
4298 . (lambda (candidate)
4299 (anything-dired-action candidate :action 'copy)))
4300 ("Copy and Follow"
4301 . (lambda (candidate)
4302 (anything-dired-action candidate :action 'copy :follow t)))))))
4305 (defvar anything-c-source-rename-files
4306 `((name . "Rename Files")
4307 (header-name . (lambda (name)
4308 (concat name anything-c-find-files-doc-header)))
4309 ;; It is needed for filenames with capital letters
4310 (disable-shortcuts)
4311 (candidates . anything-find-files-get-candidates)
4312 (filtered-candidate-transformer anything-c-find-files-transformer)
4313 (persistent-action . anything-find-files-persistent-action)
4314 (persistent-help . "Expand Candidate")
4315 (volatile)
4316 (action .
4317 (("Rename File"
4318 . (lambda (candidate)
4319 (anything-dired-action candidate :action 'rename)))
4320 ("Rename and Follow"
4321 . (lambda (candidate)
4322 (anything-dired-action candidate :action 'rename :follow t)))))))
4324 (defvar anything-c-source-symlink-files
4325 `((name . "Symlink Files")
4326 (header-name . (lambda (name)
4327 (concat name anything-c-find-files-doc-header)))
4328 ;; It is needed for filenames with capital letters
4329 (disable-shortcuts)
4330 (candidates . anything-find-files-get-candidates)
4331 (filtered-candidate-transformer anything-c-find-files-transformer)
4332 (persistent-action . anything-find-files-persistent-action)
4333 (persistent-help . "Expand Candidate")
4334 (volatile)
4335 (action
4336 . (("Symlink File"
4337 . (lambda (candidate)
4338 (anything-dired-action candidate :action 'symlink)))
4339 ("RelSymlink File"
4340 . (lambda (candidate)
4341 (anything-dired-action candidate :action 'relsymlink)))))))
4344 (defvar anything-c-source-hardlink-files
4345 `((name . "Hardlink Files")
4346 (header-name . (lambda (name)
4347 (concat name anything-c-find-files-doc-header)))
4348 ;; It is needed for filenames with capital letters
4349 (disable-shortcuts)
4350 (candidates . anything-find-files-get-candidates)
4351 (filtered-candidate-transformer anything-c-find-files-transformer)
4352 (persistent-action . anything-find-files-persistent-action)
4353 (persistent-help . "Expand Candidate")
4354 (volatile)
4355 (action
4356 . (("Hardlink File"
4357 . (lambda (candidate)
4358 (anything-dired-action candidate :action 'hardlink)))))))
4360 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4361 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4362 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4363 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4364 (let ((fn (case action
4365 ('copy 'dired-copy-file)
4366 ('rename 'dired-rename-file)
4367 ('symlink 'make-symbolic-link)
4368 ('relsymlink 'dired-make-relative-symlink)
4369 ('hardlink 'dired-hardlink)))
4370 (marker (case action
4371 ((copy rename) dired-keep-marker-copy)
4372 ('symlink dired-keep-marker-symlink)
4373 ('relsymlink dired-keep-marker-relsymlink)
4374 ('hardlink dired-keep-marker-hardlink)))
4375 (dirflag (and (= (length files) 1)
4376 (file-directory-p (car files))
4377 (not (file-directory-p candidate)))))
4378 (dired-create-files
4379 fn (symbol-name action) files
4380 ;; CANDIDATE is the destination.
4381 (if (file-directory-p candidate)
4382 ;; When CANDIDATE is a directory, build file-name in this directory.
4383 ;; Else we use CANDIDATE.
4384 #'(lambda (from)
4385 (expand-file-name (file-name-nondirectory from) candidate))
4386 #'(lambda (from) candidate))
4387 marker)
4388 (when (and follow (not (get-buffer dired-log-buffer)))
4389 (let ((target (directory-file-name candidate)))
4390 (unwind-protect
4391 (progn
4392 (setq anything-ff-cand-to-mark
4393 (anything-get-dest-fnames-from-list files candidate dirflag))
4394 (if (and dirflag (eq action 'rename))
4395 (anything-find-files-1 (file-name-directory target)
4396 (if anything-ff-transformer-show-only-basename
4397 (anything-c-basename target) target))
4398 (anything-find-files-1 (expand-file-name candidate))))
4399 (setq anything-ff-cand-to-mark nil))))))
4402 (defun anything-c-basename (fname)
4403 "Resolve basename of file or directory named FNAME."
4404 (file-name-nondirectory (directory-file-name fname)))
4406 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4407 "Transform filenames of FLIST to abs of DEST-CAND.
4408 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4409 members of FLIST."
4410 ;; At this point files have been renamed/copied at destination.
4411 ;; That's mean DEST-CAND exists.
4412 (loop
4413 with dest = (expand-file-name dest-cand)
4414 for src in flist
4415 for basename-src = (anything-c-basename src)
4416 for fname = (cond (rename-dir-flag (directory-file-name dest))
4417 ((file-directory-p dest)
4418 (concat (file-name-as-directory dest) basename-src))
4419 (t dest))
4420 when (file-exists-p fname)
4421 collect fname into tmp-list
4422 finally return (sort tmp-list 'string<)))
4424 (defun anything-ff-maybe-mark-candidates ()
4425 "Mark all candidates of list `anything-ff-cand-to-mark'."
4426 (when (and (string= (assoc-default 'name (anything-get-current-source))
4427 (assoc-default 'name anything-c-source-find-files))
4428 anything-ff-cand-to-mark)
4429 (with-anything-window
4430 (while anything-ff-cand-to-mark
4431 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4432 (progn
4433 (anything-make-visible-mark)
4434 (anything-next-line)
4435 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4436 (anything-next-line)))
4437 (unless (anything-this-visible-mark)
4438 (anything-prev-visible-mark)))))
4440 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4442 (defun* anything-dired-do-action-on-file (&key action)
4443 (let* ((files (dired-get-marked-files))
4444 (len (length files))
4445 (fname (if (> len 1)
4446 (format "* %d Files" len)
4447 (car files)))
4448 (source (case action
4449 ('copy 'anything-c-source-copy-files)
4450 ('rename 'anything-c-source-rename-files)
4451 ('symlink 'anything-c-source-symlink-files)
4452 ('hardlink 'anything-c-source-hardlink-files)))
4453 (prompt-fm (case action
4454 ('copy "Copy %s to: ")
4455 ('rename "Rename %s to: ")
4456 ('symlink "Symlink %s to: ")
4457 ('hardlink "Hardlink %s to: ")))
4458 (buffer (case action
4459 ('copy "*Anything Copy Files*")
4460 ('rename "*Anything Rename Files*")
4461 ('symlink "*Anything Symlink Files*")
4462 ('hardlink "*Anything Hardlink Files*")))
4463 (anything-mp-highlight-delay nil))
4464 (anything :sources source
4465 :input (or (dired-dwim-target-directory)
4466 (expand-file-name (anything-c-current-directory)))
4467 :preselect (dired-get-filename)
4468 :prompt (format prompt-fm fname)
4469 :keymap anything-c-read-file-map
4470 :buffer buffer)))
4472 ;;;###autoload
4473 (define-minor-mode anything-dired-mode ()
4474 "Enable anything completion in Dired functions.
4475 Bindings affected are C, R, S, H.
4476 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4477 :group 'anything-config
4478 :global t
4479 (if anything-dired-mode
4480 (progn
4481 (substitute-key-definition
4482 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4483 (substitute-key-definition
4484 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4485 (substitute-key-definition
4486 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4487 (substitute-key-definition
4488 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4489 (substitute-key-definition
4490 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4491 (substitute-key-definition
4492 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4493 (substitute-key-definition
4494 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4495 (substitute-key-definition
4496 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4498 (defalias 'anything-dired-bindings 'anything-dired-mode)
4500 (defun* anything-c-read-file-name (prompt
4501 &key
4502 (name "Read File Name")
4503 (initial-input (expand-file-name default-directory))
4504 (buffer "*Anything Completions*")
4505 test
4506 (preselect nil)
4507 (history nil)
4508 (marked-candidates nil)
4509 (alistp t)
4510 (persistent-action 'anything-find-files-persistent-action)
4511 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4512 "Anything `read-file-name' emulation.
4513 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4514 (when (get-buffer anything-action-buffer)
4515 (kill-buffer anything-action-buffer))
4516 (let ((anything-mp-highlight-delay nil)
4517 ;; Be sure we don't erase the underlying minibuffer if some.
4518 (anything-ff-auto-update-initial-value
4519 (not (minibuffer-window-active-p (minibuffer-window))))
4520 anything-same-window)
4521 (flet ((action-fn (candidate)
4522 (if marked-candidates
4523 (anything-marked-candidates)
4524 (identity candidate))))
4525 (or (anything
4526 :sources
4527 `(((name . ,(format "%s History" name))
4528 (header-name . (lambda (name)
4529 (concat name anything-c-find-files-doc-header)))
4530 (disable-shortcuts)
4531 (mode-line . anything-read-file-name-mode-line-string)
4532 (candidates . (lambda ()
4533 (anything-comp-read-get-candidates history nil nil alistp)))
4534 (persistent-action . ,persistent-action)
4535 (persistent-help . ,persistent-help)
4536 (action . ,'action-fn))
4537 ((name . ,name)
4538 (header-name . (lambda (name)
4539 (concat name anything-c-find-files-doc-header)))
4540 ;; It is needed for filenames with capital letters
4541 (disable-shortcuts)
4542 (mode-line . anything-read-file-name-mode-line-string)
4543 (candidates . (lambda ()
4544 (let ((seq (anything-find-files-get-candidates)))
4545 (if test
4546 (loop for fname in seq
4547 when (funcall test fname) collect fname)
4548 seq))))
4549 (filtered-candidate-transformer anything-c-find-files-transformer)
4550 (persistent-action . ,persistent-action)
4551 (candidate-number-limit . 9999)
4552 (toggle-auto-update . anything-ff-toggle-auto-update)
4553 (persistent-help . ,persistent-help)
4554 (volatile)
4555 (action . ,'action-fn)))
4556 :input initial-input
4557 :prompt prompt
4558 :keymap anything-c-read-file-map
4559 :resume 'noresume
4560 :buffer buffer
4561 :preselect preselect)
4562 (keyboard-quit)))))
4565 ;;; File Cache
4566 (defvar anything-c-file-cache-initialized-p nil)
4568 (defvar anything-c-file-cache-files nil)
4570 (defvar anything-c-source-file-cache
4571 '((name . "File Cache")
4572 (init
4573 . (lambda ()
4574 (require 'filecache nil t)
4575 (unless anything-c-file-cache-initialized-p
4576 (setq anything-c-file-cache-files
4577 (loop for item in file-cache-alist append
4578 (destructuring-bind (base &rest dirs) item
4579 (loop for dir in dirs collect
4580 (concat dir base)))))
4581 (defadvice file-cache-add-file (after file-cache-list activate)
4582 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4583 (setq anything-c-file-cache-initialized-p t))))
4584 (candidates . anything-c-file-cache-files)
4585 (match anything-c-match-on-basename)
4586 (type . file)))
4587 ;; (anything 'anything-c-source-file-cache)
4590 ;;; Locate
4593 ;; NOTE for WINDOZE users:
4594 ;; You have to install Everything with his command line interface here:
4595 ;; http://www.voidtools.com/download.php
4597 (defun anything-locate-1 (&optional localdb init)
4598 "Generic function to run Locate.
4599 if LOCALDB is non--nil search and use a local locate db file.
4600 INIT is a string to use as initial input in prompt.
4601 See `anything-locate-with-db' and `anything-locate'."
4602 (anything-locate-with-db
4603 (and localdb
4604 (anything-c-read-file-name
4605 "LocateDBFiles: "
4606 :marked-candidates t
4607 :preselect anything-locate-db-file-regexp
4608 :test #'(lambda (x)
4609 (if anything-locate-db-file-regexp
4610 ;; Select only locate db files and directories
4611 ;; to allow navigation.
4612 (or (string-match
4613 anything-locate-db-file-regexp x)
4614 (file-directory-p x))
4615 x))))
4616 init))
4617 ;; (anything-locate-1 t)
4619 (defun anything-locate-with-db (&optional db initial-input)
4620 "Run locate -d DB.
4621 If DB is not given or nil use locate without -d option.
4622 Argument DB can be given as a string or list of db files.
4623 Argument INITIAL-INPUT is a string to use as initial-input.
4624 See also `anything-locate'."
4625 (when (and db (stringp db)) (setq db (list db)))
4626 (let ((anything-c-locate-command
4627 (if db
4628 (replace-regexp-in-string
4629 "locate"
4630 (format "locate -d %s"
4631 (mapconcat 'identity
4632 ;; Remove eventually
4633 ;; marked directories by error.
4634 (loop for i in db
4635 unless (file-directory-p i)
4636 collect i) ":"))
4637 anything-c-locate-command)
4638 anything-c-locate-command)))
4639 (anything :sources 'anything-c-source-locate
4640 :buffer "*anything locate*"
4641 :input initial-input
4642 :keymap anything-generic-files-map)))
4643 ;; (anything-locate-with-db "~/locate.db")
4645 (defun anything-c-locate-init ()
4646 "Initialize async locate process for `anything-c-source-locate'."
4647 (setq mode-line-format
4648 '(" " mode-line-buffer-identification " "
4649 (line-number-mode "%l") " "
4650 (:eval (propertize "(Locate Process Running) "
4651 'face '((:foreground "red"))))))
4652 (prog1
4653 (start-process-shell-command "locate-process" nil
4654 (format anything-c-locate-command
4655 anything-pattern))
4656 (set-process-sentinel (get-process "locate-process")
4657 #'(lambda (process event)
4658 (when (string= event "finished\n")
4659 (with-anything-window
4660 (force-mode-line-update nil)
4661 (anything-update-move-first-line)))))))
4663 (defvar anything-c-source-locate
4664 '((name . "Locate")
4665 (candidates . anything-c-locate-init)
4666 (type . file)
4667 (properties-action . anything-ff-properties)
4668 (requires-pattern . 3)
4669 (candidate-number-limit . 9999)
4670 (mode-line . anything-generic-file-mode-line-string)
4671 (delayed))
4672 "Find files matching the current input pattern with locate.")
4673 ;; (anything 'anything-c-source-locate)
4675 (defun anything-c-locate-read-file-name (prompt &optional init)
4676 "Search a file with locate and return it's filename.
4677 Use argument PROMPT and INIT for `anything' arguments
4678 prompt and input."
4679 (anything :sources
4680 '((name . "Locate")
4681 (candidates . anything-c-locate-init)
4682 (action . identity)
4683 (properties-action . anything-ff-properties)
4684 (requires-pattern . 3)
4685 (candidate-number-limit . 9999)
4686 (mode-line . anything-generic-file-mode-line-string)
4687 (delayed))
4688 :prompt prompt
4689 :input init
4690 :buffer "*anything locate rfn*"))
4694 ;;; Anything Incremental Grep.
4697 ;; Allow to grep incrementally with anything interface.
4698 ;; It allow also to Grep files recursively without using 'find' shell command.
4699 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4700 (defvar anything-c-grep-default-command
4701 "grep -d skip %e -niH -e %p %f"
4702 "Default grep format command for `anything-do-grep-1'.
4703 Where:
4704 '%e' format spec is for --exclude or --include grep options.
4705 '%p' format spec is for pattern.
4706 '%f' format spec is for filenames.")
4708 (defvar anything-c-grep-default-recurse-command
4709 "grep -d recurse %e -niH -e %p %f"
4710 "Default recursive grep format command for `anything-do-grep-1'.
4711 See `anything-c-grep-default-command' for format specs.")
4713 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4715 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4717 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4719 (defvar anything-c-grep-debug-command-line nil
4720 "Turn on anything grep command-line debugging when non--nil.")
4722 (defvar anything-c-zgrep-recurse-flag nil)
4724 (defvar anything-c-grep-history nil)
4726 (defvar anything-c-grep-max-length-history 100
4727 "*Max number of elements to save in `anything-c-grep-history'.")
4729 (defun anything-c-grep-prepare-candidates (candidates)
4730 "Prepare filenames and directories CANDIDATES for grep command line."
4731 ;; If one or more candidate is a directory, search in all files
4732 ;; of this candidate (e.g /home/user/directory/*).
4733 ;; If r option is enabled search also in subdidrectories.
4734 ;; We need here to expand wildcards to support crap windows filenames
4735 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4736 (if anything-c-zgrep-recurse-flag
4737 (mapconcat 'shell-quote-argument candidates " ")
4738 (loop for i in candidates append
4739 (cond ( ;; Candidate is a directory and we use recursion.
4740 (and (file-directory-p i)
4741 (anything-c-grep-recurse-p))
4742 (list (expand-file-name i)))
4743 ;; Candidate is a directory, search in all files.
4744 ((file-directory-p i)
4745 (file-expand-wildcards
4746 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4747 ;; Candidate is a file or wildcard and we use recursion, use the
4748 ;; current directory instead of candidate.
4749 ((and (or (file-exists-p i) (string-match "\*" i))
4750 (anything-c-grep-recurse-p))
4751 (list (expand-file-name
4752 (directory-file-name ; Needed for windoze.
4753 (file-name-directory (directory-file-name i))))))
4754 ;; Candidate use wildcard.
4755 ((string-match "^\*" (anything-c-basename i))
4756 (file-expand-wildcards i t))
4757 ;; Else should be one or more file.
4758 (t (list i))) into all-files
4759 finally return
4760 (mapconcat 'shell-quote-argument all-files " "))))
4762 (defun anything-c-grep-recurse-p ()
4763 "Check if `anything-do-grep-1' have switched to recursive."
4764 (let ((args (replace-regexp-in-string
4765 "grep" "" anything-c-grep-default-command)))
4766 (string-match-p "r\\|recurse" args)))
4768 (defun anything-c-grep-init (only-files &optional include zgrep)
4769 "Start an asynchronous grep process in ONLY-FILES list."
4770 (let* ((fnargs (anything-c-grep-prepare-candidates
4771 (if (file-remote-p anything-ff-default-directory)
4772 (mapcar #'(lambda (x)
4773 (file-remote-p x 'localname))
4774 only-files)
4775 only-files)))
4776 (ignored-files (mapconcat
4777 #'(lambda (x)
4778 (concat "--exclude=" (shell-quote-argument x)))
4779 grep-find-ignored-files " "))
4780 (ignored-dirs (mapconcat
4781 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4782 #'(lambda (x)
4783 (concat "--exclude-dir=" (shell-quote-argument x)))
4784 grep-find-ignored-directories " "))
4785 (exclude (if (anything-c-grep-recurse-p)
4786 (concat (or include ignored-files) " " ignored-dirs)
4787 ignored-files))
4788 (cmd-line (format-spec
4789 anything-c-grep-default-command
4790 (delq nil
4791 (list (unless zgrep (cons ?e exclude))
4792 (cons ?p (shell-quote-argument anything-pattern))
4793 (cons ?f fnargs))))))
4794 (when anything-c-grep-debug-command-line
4795 (with-current-buffer (get-buffer-create "*any grep debug*")
4796 (goto-char (point-max))
4797 (insert (concat ">>> " cmd-line "\n\n"))))
4798 (setq mode-line-format
4799 '(" " mode-line-buffer-identification " "
4800 (line-number-mode "%l") " "
4801 (:eval (when (get-process "grep-process")
4802 (propertize "[Grep Process Running] "
4803 'face 'anything-grep-running)))))
4804 (force-mode-line-update nil)
4805 (prog1
4806 (let ((default-directory anything-ff-default-directory))
4807 (start-file-process-shell-command "grep-process" nil cmd-line))
4808 (message nil)
4809 (set-process-sentinel
4810 (get-process "grep-process")
4811 #'(lambda (process event)
4812 (when (string= event "finished\n")
4813 (with-anything-window
4814 (anything-update-move-first-line)
4815 (setq mode-line-format
4816 '(" " mode-line-buffer-identification " "
4817 (line-number-mode "%l") " "
4818 (:eval (propertize
4819 (format "[Grep Process Finished - (%s results)] "
4820 (let ((nlines (1- (count-lines
4821 (point-min)
4822 (point-max)))))
4823 (if (> nlines 0) nlines 0)))
4824 'face 'anything-grep-finish))))
4825 (force-mode-line-update nil))))))))
4827 (defun anything-c-grep-action (candidate &optional where mark)
4828 "Define a default action for `anything-do-grep' on CANDIDATE.
4829 WHERE can be one of other-window, elscreen, other-frame."
4830 (let* ((split (anything-c-grep-split-line candidate))
4831 (lineno (string-to-number (nth 1 split)))
4832 (loc-fname (car split))
4833 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4834 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4835 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4836 (fname (if tramp-host
4837 (concat tramp-prefix loc-fname) loc-fname)))
4838 (case where
4839 (other-window (find-file-other-window fname))
4840 (elscreen (anything-elscreen-find-file fname))
4841 (other-frame (find-file-other-frame fname))
4842 (t (find-file fname)))
4843 (anything-goto-line lineno)
4844 (when mark
4845 (set-marker (mark-marker) (point))
4846 (push-mark (point) 'nomsg))
4847 ;; Save history
4848 (unless (or anything-in-persistent-action
4849 (string= anything-pattern ""))
4850 (setq anything-c-grep-history
4851 (cons anything-pattern
4852 (delete anything-pattern anything-c-grep-history)))
4853 (when (> (length anything-c-grep-history)
4854 anything-c-grep-max-length-history)
4855 (setq anything-c-grep-history
4856 (delete (car (last anything-c-grep-history))
4857 anything-c-grep-history))))))
4859 (defun anything-c-grep-other-window (candidate)
4860 "Jump to result in other window from anything grep."
4861 (anything-c-grep-action candidate 'other-window))
4863 (defun anything-c-grep-other-frame (candidate)
4864 "Jump to result in other frame from anything grep."
4865 (anything-c-grep-action candidate 'other-frame))
4867 (defun anything-c-grep-jump-elscreen (candidate)
4868 "Jump to result in elscreen from anything grep."
4869 (anything-c-grep-action candidate 'elscreen))
4871 (defun anything-c-grep-save-results (candidate)
4872 "Save anything grep result in a `grep-mode' buffer."
4873 (let ((buf "*grep*")
4874 new-buf)
4875 (when (get-buffer buf)
4876 (setq new-buf (read-string "GrepBufferName: " buf))
4877 (loop for b in (anything-c-buffer-list)
4878 when (and (string= new-buf b)
4879 (not (y-or-n-p
4880 (format "Buffer `%s' already exists overwrite? "
4881 new-buf))))
4882 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4883 (setq buf new-buf))
4884 (with-current-buffer (get-buffer-create buf)
4885 (let ((inhibit-read-only t))
4886 (erase-buffer)
4887 (insert "-*- mode: grep -*-\n\n"
4888 (format "Grep Results for `%s':\n\n" anything-pattern))
4889 (save-excursion
4890 (insert (with-current-buffer anything-buffer
4891 (forward-line 1)
4892 (buffer-substring (point) (point-max))))
4893 (grep-mode))))
4894 (message "Anything Grep Results saved in `%s' buffer" buf)))
4896 (defun anything-c-grep-persistent-action (candidate)
4897 "Persistent action for `anything-do-grep'.
4898 With a prefix arg record CANDIDATE in `mark-ring'."
4899 (if current-prefix-arg
4900 (anything-c-grep-action candidate nil 'mark)
4901 (anything-c-grep-action candidate))
4902 (anything-match-line-color-current-line))
4904 (defun anything-c-grep-guess-extensions (files)
4905 "Try to guess file extensions in FILES list when using grep recurse.
4906 These extensions will be added to command line with --include arg of grep."
4907 (loop
4908 with glob-list = nil
4909 with lst = (if (file-directory-p (car files))
4910 (directory-files
4911 (car files) nil
4912 directory-files-no-dot-files-regexp)
4913 files)
4914 for i in lst
4915 for ext = (file-name-extension i t)
4916 for glob = (and ext (not (string= ext ""))
4917 (concat "*" ext))
4918 unless (or (not glob)
4919 (member glob glob-list)
4920 (member glob grep-find-ignored-files))
4921 collect glob into glob-list
4922 finally return glob-list))
4924 (defun anything-do-grep-1 (only &optional recurse zgrep)
4925 "Launch grep with a list of ONLY files.
4926 When RECURSE is given use -r option of grep and prompt user
4927 to set the --include args of grep.
4928 You can give more than one arg separated by space.
4929 e.g *.el *.py *.tex.
4930 If it's empty --exclude `grep-find-ignored-files' is used instead."
4931 (let* ((anything-compile-source-functions
4932 ;; rule out anything-match-plugin because the input is one regexp.
4933 (delq 'anything-compile-source--match-plugin
4934 (copy-sequence anything-compile-source-functions)))
4935 (exts (anything-c-grep-guess-extensions only))
4936 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4937 (include-files (and recurse (not zgrep)
4938 (read-string "OnlyExt(*.[ext]): "
4939 globs)))
4940 ;; Set `minibuffer-history' AFTER includes-files
4941 ;; to avoid storing wild-cards here.
4942 (minibuffer-history anything-c-grep-history)
4943 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4944 (recurse anything-c-grep-default-recurse-command)
4945 (zgrep anything-c-default-zgrep-command)
4946 (t anything-c-grep-default-command)))
4947 ;; Disable match-plugin and use here own highlighting.
4948 (anything-mp-highlight-delay nil))
4949 (when include-files
4950 (setq include-files
4951 (and (not (string= include-files ""))
4952 (mapconcat #'(lambda (x)
4953 (concat "--include=" (shell-quote-argument x)))
4954 (split-string include-files) " "))))
4955 ;; When called as action from an other source e.g *-find-files
4956 ;; we have to kill action buffer.
4957 (when (get-buffer anything-action-buffer)
4958 (kill-buffer anything-action-buffer))
4959 ;; `anything-find-files' haven't already started,
4960 ;; give a default value to `anything-ff-default-directory'.
4961 (setq anything-ff-default-directory (or anything-ff-default-directory
4962 default-directory))
4963 (anything
4964 :sources
4965 `(((name . "Grep (C-c ? Help)")
4966 (candidates
4967 . (lambda ()
4968 (funcall anything-c-grep-default-function only include-files zgrep)))
4969 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4970 (candidate-number-limit . 9999)
4971 (mode-line . anything-grep-mode-line-string)
4972 (jump-persistent . anything-c-grep-persistent-action)
4973 (action . ,(delq
4975 `(("Find File" . anything-c-grep-action)
4976 ("Find file other frame" . anything-c-grep-other-frame)
4977 ,(and (locate-library "elscreen")
4978 '("Find file in Elscreen"
4979 . anything-c-grep-jump-elscreen))
4980 ("Save results in grep buffer" . anything-c-grep-save-results)
4981 ("Find file other window" . anything-c-grep-other-window))))
4982 (persistent-action . anything-c-grep-persistent-action)
4983 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4984 (requires-pattern . 3)
4985 (delayed)))
4986 :keymap anything-c-grep-map
4987 :buffer "*anything grep*")))
4989 (defun anything-ff-zgrep-1 (flist recursive)
4990 (unwind-protect
4991 (let* ((def-dir (or anything-ff-default-directory
4992 default-directory))
4993 (only (if recursive
4994 (or (gethash def-dir anything-c-rzgrep-cache)
4995 (puthash
4996 def-dir
4997 (anything-c-walk-directory
4998 def-dir
4999 :directories nil
5000 :path 'full
5001 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5002 anything-c-rzgrep-cache))
5003 flist)))
5004 (when recursive (setq anything-c-zgrep-recurse-flag t))
5005 (anything-do-grep-1 only recursive 'zgrep))
5006 (setq anything-c-zgrep-recurse-flag nil)))
5008 (defun anything-c-grep-split-line (line)
5009 "Split a grep output line."
5010 (let (beg fname lineno str)
5011 ;; Don't print until grep line is valid.
5012 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5013 (with-temp-buffer
5014 (insert line)
5015 (goto-char (point-min))
5016 (setq beg (point))
5017 (forward-char 2)
5018 (re-search-forward ":" nil t)
5019 (setq fname (buffer-substring-no-properties beg (1- (point))))
5020 (setq beg (point))
5021 (re-search-forward ":" nil t)
5022 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5023 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5024 (list fname lineno str))))
5026 (defun anything-c-grep-cand-transformer (candidates sources)
5027 "Filtered candidate transformer function for `anything-do-grep'."
5028 (loop for i in candidates
5029 for split = (and i (anything-c-grep-split-line i))
5030 for fname = (car split)
5031 for lineno = (nth 1 split)
5032 for str = (nth 2 split)
5033 when (and fname lineno str)
5034 collect
5035 (cons (concat (propertize (file-name-nondirectory fname)
5036 'face 'anything-grep-file
5037 'help-echo fname) ":"
5038 (propertize lineno 'face 'anything-grep-lineno) ":"
5039 (anything-c-grep-highlight-match str))
5040 i)))
5042 (defun anything-c-grep-highlight-match (str)
5043 "Highlight in string STR all occurences matching `anything-pattern'."
5044 (condition-case nil
5045 (with-temp-buffer
5046 (insert str)
5047 (goto-char (point-min))
5048 (while (and (re-search-forward anything-pattern nil t)
5049 (> (- (match-end 0) (match-beginning 0)) 0))
5050 (add-text-properties
5051 (match-beginning 0) (match-end 0)
5052 '(face anything-grep-match)))
5053 (buffer-string))
5054 (error nil)))
5056 ;; Go to next or precedent file (common to etags and grep).
5057 (defun anything-c-goto-next-or-prec-file (n)
5058 "Go to next or precedent candidate file in anything grep/etags buffers.
5059 If N is positive go forward otherwise go backward."
5060 (with-anything-window
5061 (let* ((current-line-list (split-string
5062 (buffer-substring
5063 (point-at-bol)
5064 (point-at-eol)) ":"))
5065 (current-fname (nth 0 current-line-list))
5066 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5067 (catch 'break
5068 (while (not (funcall fn-b-o-f))
5069 (forward-line n) ; Go forward or backward depending of n value.
5070 (unless (search-forward current-fname (point-at-eol) t)
5071 (anything-mark-current-line)
5072 (throw 'break nil))))
5073 (cond ((and (eq n 1) (eobp))
5074 (re-search-backward ".")
5075 (forward-line 0)
5076 (anything-mark-current-line))
5077 ((and (< n 1) (bobp))
5078 (forward-line 1)
5079 (anything-mark-current-line))))))
5081 ;;;###autoload
5082 (defun anything-c-goto-precedent-file ()
5083 "Go to precedent file in anything grep/etags buffers."
5084 (interactive)
5085 (anything-c-goto-next-or-prec-file -1))
5087 ;;;###autoload
5088 (defun anything-c-goto-next-file ()
5089 "Go to precedent file in anything grep/etags buffers."
5090 (interactive)
5091 (anything-c-goto-next-or-prec-file 1))
5093 ;;;###autoload
5094 (defun anything-c-grep-run-persistent-action ()
5095 "Run grep persistent action from `anything-do-grep-1'."
5096 (interactive)
5097 (anything-execute-persistent-action 'jump-persistent))
5099 ;;;###autoload
5100 (defun anything-c-grep-run-default-action ()
5101 "Run grep default action from `anything-do-grep-1'."
5102 (interactive)
5103 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5105 ;;;###autoload
5106 (defun anything-c-grep-run-other-window-action ()
5107 "Run grep goto other window action from `anything-do-grep-1'."
5108 (interactive)
5109 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5111 ;;;###autoload
5112 (defun anything-c-grep-run-save-buffer ()
5113 "Run grep save results action from `anything-do-grep-1'."
5114 (interactive)
5115 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5117 ;; Grep buffers
5118 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5119 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5120 If one of selected buffers is not a file--buffer,
5121 it is ignored and grep will run on all others file--buffers.
5122 If only one candidate is selected and it is not a file--buffer,
5123 switch to this buffer and run `anything-occur'.
5124 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5125 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5126 (cands (if prefarg
5127 (buffer-list)
5128 (anything-marked-candidates)))
5129 (win-conf (current-window-configuration))
5130 ;; Non--fname buffers are ignored.
5131 (bufs (loop for buf in cands
5132 for fname = (buffer-file-name (get-buffer buf))
5133 when fname
5134 collect (expand-file-name fname))))
5135 (if bufs
5136 (if zgrep
5137 (anything-do-grep-1 bufs nil 'zgrep)
5138 (anything-do-grep-1 bufs))
5139 ;; bufs is empty, thats mean we have only CANDIDATE
5140 ;; and it is not a buffer-filename, fallback to occur.
5141 (anything-c-switch-to-buffer candidate)
5142 (when (get-buffer anything-action-buffer)
5143 (kill-buffer anything-action-buffer))
5144 (anything-occur)
5145 (when (eq anything-exit-status 1)
5146 (set-window-configuration win-conf)))))
5148 (defun anything-c-grep-buffers (candidate)
5149 "Action to grep buffers."
5150 (anything-c-grep-buffers-1 candidate))
5152 (defun anything-c-zgrep-buffers (candidate)
5153 "Action to zgrep buffers."
5154 (anything-c-grep-buffers-1 candidate 'zgrep))
5157 ;;; Anything interface for pdfgrep
5158 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5159 ;; and a pdf-reader (e.g xpdf) are needed.
5161 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5162 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5163 (defvar anything-c-pdfgrep-debug-command-line nil)
5165 (defun anything-c-pdfgrep-init (only-files)
5166 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5167 (let* ((fnargs (anything-c-grep-prepare-candidates
5168 (if (file-remote-p anything-ff-default-directory)
5169 (mapcar #'(lambda (x)
5170 (file-remote-p x 'localname))
5171 only-files)
5172 only-files)))
5173 (cmd-line (format anything-c-pdfgrep-default-command
5174 anything-pattern
5175 fnargs)))
5176 (when anything-c-pdfgrep-debug-command-line
5177 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5178 (goto-char (point-max))
5179 (insert (concat ">>> " cmd-line "\n\n"))))
5180 (setq mode-line-format
5181 '(" " mode-line-buffer-identification " "
5182 (line-number-mode "%l") " "
5183 (:eval (propertize "(Pdfgrep Process Running) "
5184 'face '((:foreground "red"))))))
5185 (prog1
5186 (let ((default-directory anything-ff-default-directory))
5187 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5188 (message nil)
5189 (set-process-sentinel
5190 (get-process "pdfgrep-process")
5191 #'(lambda (process event)
5192 (when (string= event "finished\n")
5193 (with-anything-window
5194 (anything-update-move-first-line))
5195 (force-mode-line-update nil)))))))
5198 (defun anything-do-pdfgrep-1 (only)
5199 "Launch pdfgrep with a list of ONLY files."
5200 (unless (executable-find "pdfgrep")
5201 (error "Error: No such program `pdfgrep'."))
5202 (let* ((anything-compile-source-functions
5203 ;; rule out anything-match-plugin because the input is one regexp.
5204 (delq 'anything-compile-source--match-plugin
5205 (copy-sequence anything-compile-source-functions)))
5206 ;; Disable match-plugin and use here own highlighting.
5207 (anything-mp-highlight-delay nil))
5208 ;; When called as action from an other source e.g *-find-files
5209 ;; we have to kill action buffer.
5210 (when (get-buffer anything-action-buffer)
5211 (kill-buffer anything-action-buffer))
5212 ;; If `anything-find-files' haven't already started,
5213 ;; give a default value to `anything-ff-default-directory'.
5214 (setq anything-ff-default-directory (or anything-ff-default-directory
5215 default-directory))
5216 (anything
5217 :sources
5218 `(((name . "PdfGrep")
5219 (candidates
5220 . (lambda ()
5221 (funcall anything-c-pdfgrep-default-function only)))
5222 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5223 (candidate-number-limit . 9999)
5224 (mode-line . anything-pdfgrep-mode-line-string)
5225 (action . anything-c-pdfgrep-action)
5226 (persistent-help . "Jump to PDF Page")
5227 (requires-pattern . 3)
5228 (delayed)))
5229 :keymap anything-c-pdfgrep-map
5230 :buffer "*anything grep*")))
5233 (defun anything-c-pdfgrep-action (candidate)
5234 (let* ((split (anything-c-grep-split-line candidate))
5235 (pageno (nth 1 split))
5236 (fname (car split)))
5237 (start-file-process-shell-command
5238 "pdf-reader" nil
5239 (format-spec anything-c-pdfgrep-default-read-command
5240 (list (cons ?f fname) (cons ?p pageno))))))
5242 (defun anything-do-pdfgrep ()
5243 (interactive)
5244 (let ((only (anything-c-read-file-name
5245 "Search in file(s): "
5246 :marked-candidates t
5247 :test #'(lambda (file)
5248 (or (string= (file-name-extension file) "pdf")
5249 (string= (file-name-extension file) "PDF")
5250 (file-directory-p file)))
5251 :preselect (or (dired-get-filename nil t)
5252 (buffer-file-name (current-buffer)))))
5253 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5254 (anything-do-pdfgrep-1 only)))
5257 ;; Yank text at point.
5260 ;; Internal
5261 (defvar anything-yank-point nil)
5263 ;;;###autoload
5264 (defun anything-yank-text-at-point ()
5265 "Yank text at point in minibuffer."
5266 (interactive)
5267 (let (input)
5268 (flet ((insert-in-minibuffer (word)
5269 (with-selected-window (minibuffer-window)
5270 (let ((str anything-pattern))
5271 (delete-minibuffer-contents)
5272 (set-text-properties 0 (length word) nil word)
5273 (insert (concat str word))))))
5274 (with-anything-current-buffer
5275 ;; Start to initial point if C-w have never been hit.
5276 (unless anything-yank-point (setq anything-yank-point (point)))
5277 (and anything-yank-point (goto-char anything-yank-point))
5278 (forward-word 1)
5279 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5280 (setq anything-yank-point (point))) ; End of last forward-word
5281 (insert-in-minibuffer input))))
5283 (defun anything-reset-yank-point ()
5284 (setq anything-yank-point nil))
5286 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5287 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5290 ;;; Recentf files
5293 (defvar anything-c-source-recentf
5294 '((name . "Recentf")
5295 (init . (lambda ()
5296 (require 'recentf)
5297 (or recentf-mode (recentf-mode 1))))
5298 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5299 (candidates . recentf-list)
5300 (match anything-c-match-on-basename)
5301 (type . file))
5302 "See (info \"(emacs)File Conveniences\").
5303 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5304 ;; (anything 'anything-c-source-recentf)
5306 ;;; ffap
5307 (eval-when-compile (require 'ffap))
5308 (defvar anything-c-source-ffap-guesser
5309 '((name . "File at point")
5310 (init . (lambda () (require 'ffap)))
5311 (candidates . (lambda ()
5312 (anything-aif
5313 (with-anything-current-buffer
5314 (ffap-guesser))
5315 (list it))))
5316 (type . file)))
5317 ;; (anything 'anything-c-source-ffap-guesser)
5319 ;;; ffap with line number
5320 (defun anything-c-ffap-file-line-at-point ()
5321 "Get (FILENAME . LINENO) at point."
5322 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5323 (save-excursion
5324 (beginning-of-line)
5325 (when (and (search-forward it nil t)
5326 (looking-at ":\\([0-9]+\\)"))
5327 (cons it (string-to-number (match-string 1)))))))
5329 (defvar anything-c-ffap-line-location nil
5330 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5331 It is cleared after jumping line.")
5333 (defun anything-c-ffap-line-candidates ()
5334 (with-anything-current-buffer
5335 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5336 (when anything-c-ffap-line-location
5337 (destructuring-bind (file . line) anything-c-ffap-line-location
5338 (list (cons (format "%s (line %d)" file line) file)))))
5340 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5341 (defun anything-c-ffap-line-goto-line ()
5342 (when (car anything-c-ffap-line-location)
5343 (unwind-protect
5344 (ignore-errors
5345 (with-selected-window
5346 (get-buffer-window
5347 (get-file-buffer (car anything-c-ffap-line-location)))
5348 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5349 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5350 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5352 (defvar anything-c-source-ffap-line
5353 '((name . "File/Lineno at point")
5354 (init . (lambda () (require 'ffap)))
5355 (candidates . anything-c-ffap-line-candidates)
5356 (type . file)))
5357 ;; (anything 'anything-c-source-ffap-line)
5359 ;;; list of files gleaned from every dired buffer
5360 (defun anything-c-files-in-all-dired-candidates ()
5361 (save-excursion
5362 (mapcan
5363 (lambda (dir)
5364 (cond ((listp dir) ;filelist
5365 dir)
5366 ((equal "" (file-name-nondirectory dir)) ;dir
5367 (directory-files dir t))
5368 (t ;wildcard
5369 (file-expand-wildcards dir t))))
5370 (delq nil
5371 (mapcar (lambda (buf)
5372 (set-buffer buf)
5373 (when (eq major-mode 'dired-mode)
5374 (if (consp dired-directory)
5375 (cdr dired-directory) ;filelist
5376 dired-directory))) ;dir or wildcard
5377 (buffer-list))))))
5378 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5380 (defvar anything-c-source-files-in-all-dired
5381 '((name . "Files in all dired buffer.")
5382 (candidates . anything-c-files-in-all-dired-candidates)
5383 (type . file)))
5384 ;; (anything 'anything-c-source-files-in-all-dired)
5386 (defvar anything-c-source-filelist
5387 '((name . "FileList")
5388 (grep-candidates . anything-c-filelist-file-name)
5389 (candidate-number-limit . 200)
5390 (requires-pattern . 4)
5391 (type . file))
5392 "Source to find files instantly.
5393 See `anything-c-filelist-file-name' docstring for usage.")
5396 ;;;; <info>
5397 ;;; Info pages
5398 (defvar anything-c-info-pages nil
5399 "All info pages on system.
5400 Will be calculated the first time you invoke anything with this
5401 source.")
5403 (defun anything-c-info-pages-init ()
5404 "Collect candidates for initial Info node Top."
5405 (if anything-c-info-pages
5406 anything-c-info-pages
5407 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5408 topics)
5409 (require 'info)
5410 (with-temp-buffer
5411 (Info-find-node "dir" "top")
5412 (goto-char (point-min))
5413 (while (re-search-forward info-topic-regexp nil t)
5414 (push (match-string-no-properties 1) topics))
5415 (kill-buffer))
5416 (setq anything-c-info-pages topics))))
5418 (defvar anything-c-source-info-pages
5419 `((name . "Info Pages")
5420 (init . anything-c-info-pages-init)
5421 (candidates . anything-c-info-pages)
5422 (action . (("Show with Info" .(lambda (node-str)
5423 (info (replace-regexp-in-string
5424 "^[^:]+: " "" node-str))))))
5425 (requires-pattern . 2)))
5426 ;; (anything 'anything-c-source-info-pages)
5429 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5430 (defun anything-c-describe-attributes (anything-attribute)
5431 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5432 Same as `anything-describe-anything-attribute' but with anything completion."
5433 (interactive (list (intern
5434 (anything-comp-read
5435 "Describe anything attribute: "
5436 (mapcar 'symbol-name anything-additional-attributes)
5437 :must-match t
5438 :persistent-action
5439 #'(lambda (candidate)
5440 (with-output-to-temp-buffer "*Help*"
5441 (princ (get (intern candidate) 'anything-attrdoc))))))))
5442 (with-output-to-temp-buffer "*Help*"
5443 (princ (get anything-attribute 'anything-attrdoc))))
5446 ;;; Use info-index plug-in.
5449 ;; Note that `name' attribute is not needed since
5450 ;; `anything-c-insert-summary' have been removed.
5451 ;; Info Elisp
5452 (defvar anything-c-source-info-elisp
5453 '((name . "Info index: elisp")
5454 (info-index . "elisp")))
5455 ;; (anything 'anything-c-source-info-elisp)
5457 ;; Info-Common-Lisp
5458 (defvar anything-c-source-info-cl
5459 '((name . "Info index: cl")
5460 (info-index . "cl")))
5461 ;; (anything 'anything-c-source-info-cl)
5463 ;; Info Index org
5464 (defvar anything-c-source-info-org
5465 '((name . "Info index: org")
5466 (info-index . "org")))
5467 ;; (anything 'anything-c-source-info-org)
5469 ;; Info Index gnus
5470 (defvar anything-c-source-info-gnus
5471 '((name . "Info index: Gnus")
5472 (info-index . "gnus")))
5474 ;; Info Index ratpoison
5475 (defvar anything-c-source-info-ratpoison
5476 '((name . "Info index: ratpoison")
5477 (info-index . "ratpoison")))
5478 ;; (anything 'anything-c-source-info-ratpoison)
5480 ;; Info Index zsh
5481 (defvar anything-c-source-info-zsh
5482 '((name . "Info index: zsh")
5483 (info-index . "zsh")))
5484 ;; (anything 'anything-c-source-info-zsh)
5486 ;; Info Index bash
5487 (defvar anything-c-source-info-bash
5488 '((name . "Info index: bash")
5489 (info-index . "bash")))
5490 ;; (anything 'anything-c-source-info-bash)
5492 ;; Info Index coreutils
5493 (defvar anything-c-source-info-coreutils
5494 '((name . "Info index: coreutils")
5495 (info-index . "coreutils")))
5496 ;; (anything 'anything-c-source-info-coreutils)
5498 ;; Info Index fileutils
5499 (defvar anything-c-source-info-fileutils
5500 '((name . "Info index: fileutils")
5501 (info-index . "fileutils")))
5502 ;; (anything 'anything-c-source-info-fileutils)
5504 ;; Info Index find
5505 (defvar anything-c-source-info-find
5506 '((name . "Info index: find")
5507 (info-index . "find")))
5508 ;; (anything 'anything-c-source-info-find)
5510 ;; Info Index sh-utils
5511 (defvar anything-c-source-info-sh-utils
5512 '((name . "Info index: sh-utils")
5513 (info-index . "sh-utils")))
5514 ;; (anything 'anything-c-source-info-sh-utils)
5516 ;; Info Index textutils
5517 (defvar anything-c-source-info-textutils
5518 '((name . "Info index: textutils")
5519 (info-index . "textutils")))
5520 ;; (anything 'anything-c-source-info-textutils)
5522 ;; Info Index libc
5523 (defvar anything-c-source-info-libc
5524 '((name . "Info index: libc")
5525 (info-index . "libc")))
5526 ;; (anything 'anything-c-source-info-libc)
5528 ;; Info Index make
5529 (defvar anything-c-source-info-make
5530 '((name . "Info index: make")
5531 (info-index . "make")))
5532 ;; (anything 'anything-c-source-info-make)
5534 ;; Info Index automake
5535 (defvar anything-c-source-info-automake
5536 '((name . "Info index: automake")
5537 (info-index . "automake")))
5538 ;; (anything 'anything-c-source-info-automake)
5540 ;; Info Index autoconf
5541 (defvar anything-c-source-info-autoconf
5542 '((name . "Info index: autoconf")
5543 (info-index . "autoconf")))
5544 ;; (anything 'anything-c-source-info-autoconf)
5546 ;; Info Index emacs-lisp-intro
5547 (defvar anything-c-source-info-emacs-lisp-intro
5548 '((name . "Info index: emacs-lisp-intro")
5549 (info-index . "emacs-lisp-intro")))
5550 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5552 ;; Info Index emacs
5553 (defvar anything-c-source-info-emacs
5554 '((name . "Info index: emacs")
5555 (info-index . "emacs")))
5556 ;; (anything 'anything-c-source-info-emacs)
5558 ;; Info Index elib
5559 (defvar anything-c-source-info-elib
5560 '((name . "Info index: elib")
5561 (info-index . "elib")))
5562 ;; (anything 'anything-c-source-info-elib)
5564 ;; Info Index eieio
5565 (defvar anything-c-source-info-eieio
5566 '((name . "Info index: eieio")
5567 (info-index . "eieio")))
5568 ;; (anything 'anything-c-source-info-eieio)
5570 ;; Info Index gauche-refe
5571 (defvar anything-c-source-info-gauche-refe
5572 '((name . "Info index: gauche")
5573 (info-index . "gauche-refe")))
5574 ;; (anything 'anything-c-source-info-gauche-refe)
5576 ;; Info Index guile
5577 (defvar anything-c-source-info-guile
5578 '((name . "Info index: guile")
5579 (info-index . "guile")))
5580 ;; (anything 'anything-c-source-info-guile)
5582 ;; Info Index guile-tut
5583 (defvar anything-c-source-info-guile-tut
5584 '((name . "Info index: guile-tut")
5585 (info-index . "guile-tut")))
5586 ;; (anything 'anything-c-source-info-guile-tut)
5588 ;; Info Index goops
5589 (defvar anything-c-source-info-goops
5590 '((name . "Info index: goops")
5591 (info-index . "goops")))
5592 ;; (anything 'anything-c-source-info-goops)
5594 ;; Info Index screen
5595 (defvar anything-c-source-info-screen
5596 '((name . "Info index: screen")
5597 (info-index . "screen")
5598 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5599 ;; (anything 'anything-c-source-info-screen)
5601 ;; Info Index latex
5602 (defvar anything-c-source-info-latex
5603 '((name . "Info index: latex")
5604 (info-index . "latex")))
5605 ;; (anything 'anything-c-source-info-latex)
5607 ;; Info Index gawk
5608 (defvar anything-c-source-info-gawk
5609 '((name . "Info index: gawk")
5610 (info-index . "gawk")))
5611 ;; (anything 'anything-c-source-info-gawk)
5613 ;; Info Index sed
5614 (defvar anything-c-source-info-sed
5615 '((name . "Info index: sed")
5616 (info-index . "sed")))
5617 ;; (anything 'anything-c-source-info-sed)
5619 ;; Info Index m4
5620 (defvar anything-c-source-info-m4
5621 '((name . "Info index: m4")
5622 (info-index . "m4")))
5623 ;; (anything 'anything-c-source-info-m4)
5625 ;; Info Index wget
5626 (defvar anything-c-source-info-wget
5627 '((name . "Info index: wget")
5628 (info-index . "wget")))
5629 ;; (anything 'anything-c-source-info-wget)
5631 ;; Info Index binutils
5632 (defvar anything-c-source-info-binutils
5633 '((name . "Info index: binutils")
5634 (info-index . "binutils")))
5635 ;; (anything 'anything-c-source-info-binutils)
5637 ;; Info Index as
5638 (defvar anything-c-source-info-as
5639 '((name . "Info index: as")
5640 (info-index . "as")))
5641 ;; (anything 'anything-c-source-info-as)
5643 ;; Info Index bfd
5644 (defvar anything-c-source-info-bfd
5645 '((name . "Info index: bfd")
5646 (info-index . "bfd")))
5647 ;; (anything 'anything-c-source-info-bfd)
5649 ;; Info Index gprof
5650 (defvar anything-c-source-info-gprof
5651 '((name . "Info index: gprof")
5652 (info-index . "gprof")))
5653 ;; (anything 'anything-c-source-info-gprof)
5655 ;; Info Index ld
5656 (defvar anything-c-source-info-ld
5657 '((name . "Info index: ld")
5658 (info-index . "ld")))
5659 ;; (anything 'anything-c-source-info-ld)
5661 ;; Info Index diff
5662 (defvar anything-c-source-info-diff
5663 '((name . "Info index: diff")
5664 (info-index . "diff")))
5665 ;; (anything 'anything-c-source-info-diff)
5667 ;; Info Index flex
5668 (defvar anything-c-source-info-flex
5669 '((name . "Info index: flex")
5670 (info-index . "flex")))
5671 ;; (anything 'anything-c-source-info-flex)
5673 ;; Info Index grep
5674 (defvar anything-c-source-info-grep
5675 '((name . "Info index: grep")
5676 (info-index . "grep")))
5677 ;; (anything 'anything-c-source-info-grep)
5679 ;; Info Index gzip
5680 (defvar anything-c-source-info-gzip
5681 '((name . "Info index: gzip")
5682 (info-index . "gzip")))
5683 ;; (anything 'anything-c-source-info-gzip)
5685 ;; Info Index libtool
5686 (defvar anything-c-source-info-libtool
5687 '((name . "Info index: libtool")
5688 (info-index . "libtool")))
5689 ;; (anything 'anything-c-source-info-libtool)
5691 ;; Info Index texinfo
5692 (defvar anything-c-source-info-texinfo
5693 '((name . "Info index: texinfo")
5694 (info-index . "texinfo")))
5695 ;; (anything 'anything-c-source-info-texinfo)
5697 ;; Info Index info
5698 (defvar anything-c-source-info-info
5699 '((name . "Info index: info")
5700 (info-index . "info")))
5701 ;; (anything 'anything-c-source-info-info)
5703 ;; Info Index gdb
5704 (defvar anything-c-source-info-gdb
5705 '((name . "Info index: gdb")
5706 (info-index . "gdb")))
5707 ;; (anything 'anything-c-source-info-gdb)
5709 ;; Info Index stabs
5710 (defvar anything-c-source-info-stabs
5711 '((name . "Info index: stabs")
5712 (info-index . "stabs")))
5713 ;; (anything 'anything-c-source-info-stabs)
5715 ;; Info Index cvsbook
5716 (defvar anything-c-source-info-cvsbook
5717 '((name . "Info index: cvsbook")
5718 (info-index . "cvsbook")))
5719 ;; (anything 'anything-c-source-info-cvsbook)
5721 ;; Info Index cvs
5722 (defvar anything-c-source-info-cvs
5723 '((name . "Info index: cvs")
5724 (info-index . "cvs")))
5725 ;; (anything 'anything-c-source-info-cvs)
5727 ;; Info Index bison
5728 (defvar anything-c-source-info-bison
5729 '((name . "Info index: bison")
5730 (info-index . "bison")))
5731 ;; (anything 'anything-c-source-info-bison)
5733 ;; Info Index id-utils
5734 (defvar anything-c-source-info-id-utils
5735 '((name . "Info index: id-utils")
5736 (info-index . "id-utils")))
5737 ;; (anything 'anything-c-source-info-id-utils)
5739 ;; Info Index global
5740 (defvar anything-c-source-info-global
5741 '((name . "Info index: global")
5742 (info-index . "global")))
5743 ;; (anything 'anything-c-source-info-global)
5746 ;;; Man and woman UI
5749 (defvar anything-c-man-pages nil
5750 "All man pages on system.
5751 Will be calculated the first time you invoke anything with this
5752 source.")
5754 (defun anything-c-man-default-action (candidate)
5755 "Default action for jumping to a woman or man page from anything."
5756 (let ((wfiles (woman-file-name-all-completions candidate)))
5757 (condition-case err
5758 (if (> (length wfiles) 1)
5759 (woman-find-file
5760 (anything-comp-read
5761 "ManFile: " wfiles :must-match t))
5762 (woman candidate))
5763 ;; If woman is unable to format correctly
5764 ;; use man instead.
5765 (error (kill-buffer) ; Kill woman buffer.
5766 (let ((Man-notify-method 'meek))
5767 (Man-getpage-in-background candidate))))))
5769 (defvar anything-c-source-man-pages
5770 `((name . "Manual Pages")
5771 (candidates . (lambda ()
5772 (if anything-c-man-pages
5773 anything-c-man-pages
5774 ;; XEmacs doesn't have a woman :)
5775 (setq anything-c-man-pages
5776 (ignore-errors
5777 (require 'woman)
5778 (woman-file-name "")
5779 (sort (mapcar 'car woman-topic-all-completions)
5780 'string-lessp))))))
5781 (action ("Show with Woman" . anything-c-man-default-action))
5782 ;; Woman does not work OS X
5783 ;; http://xahlee.org/emacs/modernization_man_page.html
5784 (action-transformer . (lambda (actions candidate)
5785 (if (eq system-type 'darwin)
5786 '(("Show with Man" . man))
5787 actions)))
5788 (requires-pattern . 2)))
5789 ;; (anything 'anything-c-source-man-pages)
5792 ;;;; <Command>
5793 ;;; Anything M-x - Enhanced M-x UI
5796 ;; Another replacement of `M-x' that act exactly like the
5797 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5798 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5799 ;; anything invocation.
5800 ;; Documentation of commands available without quitting,
5801 ;; Show keybindings of commands.
5802 ;; Show history.
5803 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5804 "Return alist of MODE-MAP."
5805 (loop for key being the key-seqs of mode-map using (key-bindings com)
5806 for str-key = (key-description key)
5807 for ismenu = (string-match "<menu-bar>" str-key)
5808 unless ismenu collect (cons str-key com)))
5810 (defun anything-get-mode-map-from-mode (mode)
5811 "Guess the mode-map name according to MODE.
5812 Some modes don't use conventional mode-map name
5813 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5814 Return nil if no mode-map found."
5815 (loop
5816 ;; Start with a conventional mode-map name.
5817 with mode-map = (intern-soft (format "%s-map" mode))
5818 with mode-string = (symbol-name mode)
5819 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5820 while (not mode-map)
5821 for count downfrom (length mode-name)
5822 ;; Return when no result after parsing entire string.
5823 when (eq count 0) return nil
5824 for sub-name = (substring mode-name 0 count)
5825 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5826 finally return mode-map))
5828 (defun anything-M-x-current-mode-map-alist ()
5829 "Return mode-map alist of current `major-mode'."
5830 (let ((map (anything-get-mode-map-from-mode major-mode)))
5831 (when (and map (boundp map))
5832 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5835 (defun anything-M-x-transformer (candidates sources)
5836 "filtered-candidate-transformer to show bindings in emacs commands.
5837 Show global bindings and local bindings according to current `major-mode'."
5838 (with-anything-current-buffer
5839 (loop
5840 with local-map = (anything-M-x-current-mode-map-alist)
5841 for cand in candidates
5842 for local-key = (car (rassq cand local-map))
5843 for key = (substitute-command-keys (format "\\[%s]" cand))
5844 collect
5845 (cons (cond ((and (string-match "^M-x" key) local-key)
5846 (format "%s (%s)"
5847 cand (propertize
5848 local-key
5849 'face 'anything-M-x-key-face)))
5850 ((string-match "^M-x" key) cand)
5851 (t (format "%s (%s)"
5852 cand (propertize
5854 'face 'anything-M-x-key-face))))
5855 cand) into ls
5856 finally return
5857 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5860 ;;; Complex command history
5863 (defvar anything-c-source-complex-command-history
5864 '((name . "Complex Command History")
5865 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5866 (type . sexp)))
5867 ;; (anything 'anything-c-source-complex-command-history)
5869 ;;; M-x history (not related to `anything-M-x')
5872 (defvar anything-c-source-extended-command-history
5873 '((name . "Emacs Commands History")
5874 (candidates . extended-command-history)
5875 (type . command)))
5876 ;; (anything 'anything-c-source-extended-command-history)
5878 ;;; Emacs commands (Basic source for emacs commands)
5881 (defvar anything-c-source-emacs-commands
5882 '((name . "Emacs Commands")
5883 (candidates . (lambda ()
5884 (let (commands)
5885 (mapatoms (lambda (a)
5886 (if (commandp a)
5887 (push (symbol-name a)
5888 commands))))
5889 (sort commands 'string-lessp))))
5890 (type . command)
5891 (requires-pattern . 2))
5892 "Source for completing and invoking Emacs commands.
5893 A command is a function with interactive spec that can
5894 be invoked with `M-x'.
5896 To get non-interactive functions listed, use
5897 `anything-c-source-emacs-functions'.")
5898 ;; (anything 'anything-c-source-emacs-commands)
5901 ;;;; <Function>
5902 ;;; Emacs functions
5905 (defvar anything-c-source-emacs-functions
5906 '((name . "Emacs Functions")
5907 (candidates . (lambda ()
5908 (let (commands)
5909 (mapatoms (lambda (a)
5910 (if (functionp a)
5911 (push (symbol-name a) commands))))
5912 (sort commands 'string-lessp))))
5913 (type . function)
5914 (requires-pattern . 2))
5915 "Source for completing Emacs functions.")
5916 ;; (anything 'anything-c-source-emacs-functions)
5918 ;;; With abbrev expansion
5919 ;;; Similar to my exec-abbrev-cmd.el
5920 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5921 (defvar anything-c-function-abbrev-regexp nil
5922 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5923 Regexp built from the current `anything-pattern' interpreting it
5924 as abbreviation.
5925 Only for internal use.")
5927 (defun anything-c-match-function-by-abbrev (candidate)
5928 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5930 Abbreviations are made by taking the first character from each
5931 word in the function's name, e.g. \"bb\" is an abbrev for
5932 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5933 (string-match anything-c-function-abbrev-regexp candidate))
5935 (defvar anything-c-source-emacs-functions-with-abbrevs
5936 (append anything-c-source-emacs-functions
5937 '((match anything-c-match-function-by-abbrev
5938 anything-c-string-match))
5939 '((init
5940 . (lambda ()
5941 (defadvice anything-update
5942 (before anything-c-update-function-abbrev-regexp activate)
5943 (let ((char-list (append anything-pattern nil))
5944 (str "^"))
5945 (dolist (c char-list)
5946 (setq str (concat str (list c) "[^-]*-")))
5947 (setq str (concat (substring str 0 (1- (length str))) "$"))
5948 (setq anything-c-function-abbrev-regexp str))))))))
5949 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5951 (defvar anything-c-source-advice
5952 '((name . "Function Advice")
5953 (candidates . anything-c-advice-candidates)
5954 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5955 ;; (real-to-display . anything-c-advice-real-to-display)
5956 (persistent-action . anything-c-advice-persistent-action)
5957 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5958 ;; (anything 'anything-c-source-advice)
5959 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5960 ;; (testadvice)
5962 (defun anything-c-advice-candidates ()
5963 (require 'advice)
5964 (loop for (fname) in ad-advised-functions
5965 for function = (intern fname)
5966 append
5967 (loop for class in ad-advice-classes append
5968 (loop for advice in (ad-get-advice-info-field function class)
5969 for enabled = (ad-advice-enabled advice)
5970 collect
5971 (cons (format
5972 "%s %s %s"
5973 (if enabled "Enabled " "Disabled")
5974 (propertize fname 'face 'font-lock-function-name-face)
5975 (ad-make-single-advice-docstring advice class nil))
5976 (list function class advice))))))
5978 (defun anything-c-advice-persistent-action (func-class-advice)
5979 (if current-prefix-arg
5980 (anything-c-advice-toggle func-class-advice)
5981 (describe-function (car func-class-advice))))
5983 (defun anything-c-advice-toggle (func-class-advice)
5984 (destructuring-bind (function class advice) func-class-advice
5985 (cond ((ad-advice-enabled advice)
5986 (ad-advice-set-enabled advice nil)
5987 (message "Disabled"))
5988 (t ;disabled
5989 (ad-advice-set-enabled advice t)
5990 (message "Enabled")))
5991 (ad-activate function)
5992 (and anything-in-persistent-action
5993 (anything-c-advice-update-current-display-string))))
5995 (defun anything-c-advice-update-current-display-string ()
5996 (anything-edit-current-selection
5997 (let ((newword (cond ((looking-at "Disabled") "Enabled")
5998 ((looking-at "Enabled") "Disabled")))
5999 realvalue)
6000 (when newword
6001 (delete-region (point) (progn (forward-word 1) (point)))
6002 (insert newword)))))
6005 ;;;; <Variable>
6006 ;;; Emacs variables
6009 (defvar anything-c-source-emacs-variables
6010 '((name . "Emacs Variables")
6011 (candidates . (lambda ()
6012 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6013 (type . variable)
6014 (requires-pattern . 2))
6015 "Source for completing Emacs variables.")
6016 ;; (anything 'anything-c-source-emacs-variables)
6019 ;;; LaCarte
6020 (defvar anything-c-source-lacarte
6021 '((name . "Lacarte")
6022 (init . (lambda () (require 'lacarte )))
6023 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6024 (candidate-number-limit . 9999)
6025 (action . anything-c-call-interactively))
6026 "Needs lacarte.el.
6028 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6029 ;; (anything 'anything-c-source-lacarte)
6032 ;;; Bookmarks
6035 ;; Bind some faces for bookmarks.
6036 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6037 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6038 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6040 (eval-when-compile (require 'bookmark))
6041 (defvar anything-c-source-bookmarks
6042 '((name . "Bookmarks")
6043 (init . (lambda ()
6044 (require 'bookmark)))
6045 (candidates . bookmark-all-names)
6046 (type . bookmark))
6047 "See (info \"(emacs)Bookmarks\").")
6048 ;; (anything 'anything-c-source-bookmarks)
6050 ;;; bookmark-set
6051 (defvar anything-c-source-bookmark-set
6052 '((name . "Set Bookmark")
6053 (dummy)
6054 (action . bookmark-set))
6055 "See (info \"(emacs)Bookmarks\").")
6056 ;; (anything 'anything-c-source-bookmark-set)
6058 ;;; Visible Bookmarks
6059 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6062 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6063 (defvar anything-c-source-bm
6064 '((name . "Visible Bookmarks")
6065 (init . anything-c-bm-init)
6066 (candidates-in-buffer)
6067 (type . line))
6068 "Needs bm.el.
6070 http://www.nongnu.org/bm/")
6072 (defun anything-c-bm-init ()
6073 "Init function for `anything-c-source-bm'."
6074 (when (require 'bm nil t)
6075 (with-no-warnings
6076 (let ((bookmarks (bm-lists))
6077 (buf (anything-candidate-buffer 'global)))
6078 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6079 '< :key 'overlay-start))
6080 (let ((start (overlay-start bm))
6081 (end (overlay-end bm))
6082 (annotation (or (overlay-get bm 'annotation) "")))
6083 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6084 (let ((str (format "%5d: [%s]: %s\n"
6085 (line-number-at-pos start)
6086 annotation
6087 (buffer-substring start (1- end)))))
6088 (with-current-buffer buf (insert str))))))))))
6090 ;;; Special bookmarks
6091 (defvar anything-c-source-bookmarks-ssh
6092 '((name . "Bookmarks-ssh")
6093 (init . (lambda ()
6094 (require 'bookmark)))
6095 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6096 (type . bookmark))
6097 "See (info \"(emacs)Bookmarks\").")
6098 ;; (anything 'anything-c-source-bookmarks-ssh)
6100 (defvar anything-c-source-bookmarks-su
6101 '((name . "Bookmarks-root")
6102 (init . (lambda ()
6103 (require 'bookmark)))
6104 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6105 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6107 (type . bookmark))
6108 "See (info \"(emacs)Bookmarks\").")
6109 ;; (anything 'anything-c-source-bookmarks-su)
6111 (defvar anything-c-source-bookmarks-local
6112 '((name . "Bookmarks-Local")
6113 (init . (lambda ()
6114 (require 'bookmark)))
6115 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6116 (filtered-candidate-transformer
6117 anything-c-adaptive-sort
6118 anything-c-highlight-bookmark)
6119 (type . bookmark))
6120 "See (info \"(emacs)Bookmarks\").")
6121 ;; (anything 'anything-c-source-bookmarks-local)
6123 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6124 (let* ((lis-all (bookmark-all-names))
6125 (lis-loc (cond (local (loop for i in lis-all
6126 unless (string-match "^(ssh)\\|^(su)" i)
6127 collect i))
6128 (su (loop for i in lis-all
6129 when (string-match "^(su)" i)
6130 collect i))
6131 (sudo (loop for i in lis-all
6132 when (string-match "^(sudo)" i)
6133 collect i))
6134 (ssh (loop for i in lis-all
6135 when (string-match "^(ssh)" i)
6136 collect i)))))
6137 (sort lis-loc 'string-lessp)))
6139 (defun anything-c-bookmark-root-logged-p ()
6140 (catch 'break
6141 (dolist (i (mapcar #'buffer-name (buffer-list)))
6142 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6143 (throw 'break t)))))
6145 (defun anything-c-highlight-bookmark-su (files source)
6146 (if (anything-c-bookmark-root-logged-p)
6147 (anything-c-highlight-bookmark files source)
6148 (anything-c-highlight-not-logged files source)))
6150 (defun anything-c-highlight-not-logged (files source)
6151 (loop for i in files
6152 collect (propertize i 'face anything-c-bookmarks-face3)))
6154 (defun anything-c-highlight-bookmark (bookmarks source)
6155 "Used as `candidate-transformer' to colorize bookmarks.
6156 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6157 (loop for i in bookmarks
6158 for isfile = (bookmark-get-filename i)
6159 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6160 (bmkext-get-buffer-name i))
6161 for handlerp = (and (fboundp 'bookmark-get-handler)
6162 (bookmark-get-handler i))
6163 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6164 (bmkext-w3m-bookmark-p i))
6165 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6166 (bmkext-gnus-bookmark-p i))
6167 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6168 (bmkext-man-bookmark-p i))
6169 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6170 (bmkext-woman-bookmark-p i))
6171 for handlerp = (bookmark-get-handler i)
6172 for isannotation = (bookmark-get-annotation i)
6173 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6174 for isinfo = (eq handlerp 'Info-bookmark-jump)
6175 ;; Add a * if bookmark have annotation
6176 if (and isannotation (not (string-equal isannotation "")))
6177 do (setq i (concat "*" i))
6178 collect (cond (;; info buffers
6179 isinfo
6180 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6181 (;; w3m buffers
6182 isw3m
6183 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6184 (;; gnus buffers
6185 isgnus
6186 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6187 (;; Man Woman
6188 (or iswoman isman)
6189 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6190 (;; Addressbook
6191 isabook
6192 (propertize i 'face '((:foreground "Tomato"))))
6193 (;; directories
6194 (and isfile (file-directory-p isfile))
6195 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6196 (;; regular files
6198 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6202 ;;; Sources to filter bookmark-extensions bookmarks.
6205 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6206 ;; If you want to enable google-maps in addressbook you will need
6207 ;; Julien Danjou google-maps-el package available here:
6208 ;; http://julien.danjou.info/google-maps-el.html
6210 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6211 "Return a filtered `bookmark-alist' sorted alphabetically."
6212 (loop
6213 with alist = (if args
6214 (apply #'(lambda (x) (funcall fn x)) args)
6215 (funcall fn))
6216 for i in alist
6217 for b = (car i)
6218 collect b into sa
6219 finally return (sort sa 'string-lessp)))
6221 ;;; Addressbook.
6224 (defvar anything-c-source-bmkext-addressbook
6225 '((name . "Bookmark Addressbook")
6226 (init . (lambda ()
6227 (require 'bookmark-extensions)
6228 (bookmark-maybe-load-default-file)))
6229 (candidates . anything-c-bmkext-addressbook-setup-alist)
6230 (persistent-action
6231 . (lambda (candidate)
6232 (let ((bmk (anything-bookmark-get-bookmark-from-name
6233 candidate)))
6234 (bookmark--jump-via bmk 'pop-to-buffer))))
6235 (persistent-help . "Show contact - Prefix with C-u to append")
6236 (filtered-candidate-transformer
6237 anything-c-adaptive-sort
6238 anything-c-highlight-bookmark)
6239 (action . (("Show Contact(s)"
6240 . (lambda (candidate)
6241 (let* ((contacts (anything-marked-candidates))
6242 (current-prefix-arg (or anything-current-prefix-arg
6243 (> (length contacts) 1))))
6244 (bookmark-jump
6245 (anything-bookmark-get-bookmark-from-name (car contacts)))
6246 (anything-aif (cdr contacts)
6247 (loop for bmk in it do
6248 (bookmark-jump
6249 (anything-bookmark-get-bookmark-from-name bmk)))))))
6250 ("Send Mail"
6251 . (lambda (candidate)
6252 (let* ((contacts (anything-marked-candidates))
6253 (bmk (anything-bookmark-get-bookmark-from-name
6254 (car contacts)))
6255 (append (message-buffers)))
6256 (if append
6257 (addressbook-set-mail-buffer1 bmk 'append)
6258 (addressbook-set-mail-buffer1 bmk))
6259 (setq contacts (cdr contacts))
6260 (when contacts
6261 (loop for bmk in contacts do
6262 (addressbook-set-mail-buffer1 bmk 'append))))))
6263 ("Edit Bookmark"
6264 . (lambda (candidate)
6265 (let ((bmk (anything-bookmark-get-bookmark-from-name
6266 candidate)))
6267 (addressbook-bookmark-edit
6268 (assoc bmk bookmark-alist)))))
6269 ("Insert Email at point"
6270 . (lambda (candidate)
6271 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6272 candidate))
6273 (mlist (split-string
6274 (assoc-default
6275 'email (assoc bmk bookmark-alist))
6276 ", ")))
6277 (insert
6278 (if (> (length mlist) 1)
6279 (anything-comp-read
6280 "Insert Mail Address: " mlist :must-match t)
6281 (car mlist))))))
6282 ("Show annotation"
6283 . (lambda (candidate)
6284 (let ((bmk (anything-bookmark-get-bookmark-from-name
6285 candidate)))
6286 (bookmark-show-annotation bmk))))
6287 ("Edit annotation"
6288 . (lambda (candidate)
6289 (let ((bmk (anything-bookmark-get-bookmark-from-name
6290 candidate)))
6291 (bookmark-edit-annotation bmk))))
6292 ("Show Google map"
6293 . (lambda (candidate)
6294 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6295 candidate))
6296 (full-bmk (assoc bmk bookmark-alist)))
6297 (addressbook-google-map full-bmk))))))))
6300 (defun anything-c-bmkext-addressbook-setup-alist ()
6301 "Specialized filter function for bookmarks w3m."
6302 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6304 ;; W3m bookmarks from bookmark-extensions.
6305 (defvar anything-c-source-bookmark-w3m
6306 '((name . "Bookmark W3m")
6307 (init . (lambda ()
6308 (require 'bookmark-extensions)
6309 (bookmark-maybe-load-default-file)))
6310 (candidates . anything-c-bookmark-w3m-setup-alist)
6311 (filtered-candidate-transformer
6312 anything-c-adaptive-sort
6313 anything-c-highlight-bookmark)
6314 (type . bookmark)))
6315 ;; (anything 'anything-c-source-bookmark-w3m)
6317 (defun anything-c-bookmark-w3m-setup-alist ()
6318 "Specialized filter function for bookmarks w3m."
6319 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6321 ;; Images
6322 (defvar anything-c-source-bookmark-images
6323 '((name . "Bookmark Images")
6324 (init . (lambda ()
6325 (require 'bookmark-extensions)
6326 (bookmark-maybe-load-default-file)))
6327 (candidates . anything-c-bookmark-images-setup-alist)
6328 (filtered-candidate-transformer
6329 anything-c-adaptive-sort
6330 anything-c-highlight-bookmark)
6331 (type . bookmark)))
6332 ;; (anything 'anything-c-source-bookmark-images)
6334 (defun anything-c-bookmark-images-setup-alist ()
6335 "Specialized filter function for images bookmarks."
6336 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6338 ;; Woman Man
6339 (defvar anything-c-source-bookmark-man
6340 '((name . "Bookmark Woman&Man")
6341 (init . (lambda ()
6342 (require 'bookmark-extensions)
6343 (bookmark-maybe-load-default-file)))
6344 (candidates . anything-c-bookmark-man-setup-alist)
6345 (filtered-candidate-transformer
6346 anything-c-adaptive-sort
6347 anything-c-highlight-bookmark)
6348 (type . bookmark)))
6349 ;; (anything 'anything-c-source-bookmark-man)
6351 (defun anything-c-bookmark-man-setup-alist ()
6352 "Specialized filter function for bookmarks w3m."
6353 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6354 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6356 ;; Gnus
6357 (defvar anything-c-source-bookmark-gnus
6358 '((name . "Bookmark Gnus")
6359 (init . (lambda ()
6360 (require 'bookmark-extensions)
6361 (bookmark-maybe-load-default-file)))
6362 (candidates . anything-c-bookmark-gnus-setup-alist)
6363 (filtered-candidate-transformer
6364 anything-c-adaptive-sort
6365 anything-c-highlight-bookmark)
6366 (type . bookmark)))
6367 ;; (anything 'anything-c-source-bookmark-gnus)
6369 (defun anything-c-bookmark-gnus-setup-alist ()
6370 "Specialized filter function for bookmarks gnus."
6371 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6373 ;; Info
6374 (defvar anything-c-source-bookmark-info
6375 '((name . "Bookmark Info")
6376 (init . (lambda ()
6377 (require 'bookmark-extensions)
6378 (bookmark-maybe-load-default-file)))
6379 (candidates . anything-c-bookmark-info-setup-alist)
6380 (filtered-candidate-transformer
6381 anything-c-adaptive-sort
6382 anything-c-highlight-bookmark)
6383 (type . bookmark)))
6384 ;; (anything 'anything-c-source-bookmark-info)
6386 (defun anything-c-bookmark-info-setup-alist ()
6387 "Specialized filter function for bookmarks info."
6388 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6390 ;; Local Files&directories
6391 (defvar anything-c-source-bookmark-files&dirs
6392 '((name . "Bookmark Files&Directories")
6393 (init . (lambda ()
6394 (require 'bookmark-extensions)
6395 (bookmark-maybe-load-default-file)))
6396 (candidates . anything-c-bookmark-local-files-setup-alist)
6397 (filtered-candidate-transformer
6398 anything-c-adaptive-sort
6399 anything-c-highlight-bookmark)
6400 (type . bookmark)))
6401 ;; (anything 'anything-c-source-bookmark-files&dirs)
6403 (defun anything-c-bookmark-local-files-setup-alist ()
6404 "Specialized filter function for bookmarks locals files."
6405 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6407 ;; Su Files&directories
6408 (defvar anything-c-source-bookmark-su-files&dirs
6409 '((name . "Bookmark Root-Files&Directories")
6410 (init . (lambda ()
6411 (require 'bookmark-extensions)
6412 (bookmark-maybe-load-default-file)))
6413 (candidates . anything-c-bookmark-su-files-setup-alist)
6414 (filtered-candidate-transformer
6415 anything-c-adaptive-sort
6416 anything-c-highlight-bookmark-su)
6417 (type . bookmark)))
6418 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6420 (defun anything-c-bookmark-su-files-setup-alist ()
6421 "Specialized filter function for bookmarks su/sudo files."
6422 (declare (special bmkext-su-or-sudo-regexp))
6423 (loop
6424 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6425 for i in l
6426 for isfile = (bookmark-get-filename i)
6427 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6428 (save-match-data
6429 (string-match tramp-file-name-regexp isfile)))
6430 for issu = (and istramp
6431 (string-match bmkext-su-or-sudo-regexp isfile))
6432 if issu
6433 collect i))
6435 ;; Ssh Files&directories
6436 (defvar anything-c-source-bookmark-ssh-files&dirs
6437 '((name . "Bookmark Ssh-Files&Directories")
6438 (init . (lambda ()
6439 (require 'bookmark-extensions)
6440 (bookmark-maybe-load-default-file)))
6441 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6442 (filtered-candidate-transformer . anything-c-adaptive-sort)
6443 (type . bookmark)))
6444 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6446 (defun anything-c-bookmark-ssh-files-setup-alist ()
6447 "Specialized filter function for bookmarks ssh files."
6448 (loop
6449 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6450 for i in l
6451 for isfile = (bookmark-get-filename i)
6452 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6453 (save-match-data
6454 (string-match tramp-file-name-regexp isfile)))
6455 for isssh = (and istramp
6456 (string-match "/ssh:" isfile))
6457 if isssh
6458 collect i))
6462 ;;; Firefox bookmarks
6465 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6466 ;; (only for firefox versions >=3)
6467 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6468 ;; to true:
6469 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6470 ;; You should have now:
6471 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6473 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6474 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6476 (defun anything-get-firefox-user-init-dir ()
6477 "Guess the default Firefox user directory name."
6478 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6479 (moz-user-dir
6480 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6481 (goto-char (point-min))
6482 (prog1
6483 (when (search-forward "Path=" nil t)
6484 (buffer-substring-no-properties (point) (point-at-eol)))
6485 (kill-buffer)))))
6486 (file-name-as-directory (concat moz-dir moz-user-dir))))
6488 (defun anything-guess-firefox-bookmark-file ()
6489 "Return the path of the Firefox bookmarks file."
6490 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6492 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6493 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6494 (let (bookmarks-alist url title)
6495 (with-temp-buffer
6496 (insert-file-contents file)
6497 (goto-char (point-min))
6498 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6499 (forward-line 0)
6500 (when (re-search-forward url-regexp nil t)
6501 (setq url (match-string 0)))
6502 (when (re-search-forward bmk-regexp nil t)
6503 (setq title (match-string 1)))
6504 (push (cons title url) bookmarks-alist)
6505 (forward-line)))
6506 (nreverse bookmarks-alist)))
6508 (defvar anything-c-firefox-bookmarks-alist nil)
6509 (defvar anything-c-source-firefox-bookmarks
6510 '((name . "Firefox Bookmarks")
6511 (init . (lambda ()
6512 (setq anything-c-firefox-bookmarks-alist
6513 (anything-html-bookmarks-to-alist
6514 (anything-guess-firefox-bookmark-file)
6515 anything-firefox-bookmark-url-regexp
6516 anything-firefox-bookmarks-regexp))))
6517 (candidates . (lambda ()
6518 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6519 (filtered-candidate-transformer
6520 anything-c-adaptive-sort
6521 anything-c-highlight-firefox-bookmarks)
6522 (action . (("Browse Url Firefox"
6523 . (lambda (candidate)
6524 (browse-url-firefox
6525 (anything-c-firefox-bookmarks-get-value candidate))))
6526 ("Browse Url w3m"
6527 . (lambda (candidate)
6528 (w3m-browse-url
6529 (anything-c-firefox-bookmarks-get-value candidate))))
6530 ("Copy Url"
6531 . (lambda (elm)
6532 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6534 ;; (anything 'anything-c-source-firefox-bookmarks)
6536 (defun anything-c-firefox-bookmarks-get-value (elm)
6537 (assoc-default elm anything-c-firefox-bookmarks-alist))
6539 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6540 (loop for i in bookmarks
6541 collect (propertize
6542 i 'face '((:foreground "YellowGreen"))
6543 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6547 ;;; W3m bookmark - anything interface.
6550 ;; Some users have the emacs-w3m library in load-path
6551 ;; without having the w3m executable :-;
6552 ;; So check if w3m program is present before trying to load
6553 ;; emacs-w3m.
6554 (eval-when-compile
6555 (when (executable-find "w3m")
6556 (require 'w3m-bookmark nil t)))
6558 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6559 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6560 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6561 (defvar anything-c-w3m-bookmarks-alist nil)
6562 (defvar anything-c-source-w3m-bookmarks
6563 '((name . "W3m Bookmarks")
6564 (init . (lambda ()
6565 (setq anything-c-w3m-bookmarks-alist
6566 (anything-html-bookmarks-to-alist
6567 w3m-bookmark-file
6568 anything-w3m-bookmark-url-regexp
6569 anything-w3m-bookmarks-regexp))))
6570 (candidates . (lambda ()
6571 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6572 (filtered-candidate-transformer
6573 anything-c-adaptive-sort
6574 anything-c-highlight-w3m-bookmarks)
6575 (action . (("Browse Url"
6576 . (lambda (candidate)
6577 (anything-c-w3m-browse-bookmark candidate)))
6578 ("Copy Url"
6579 . (lambda (elm)
6580 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6581 ("Browse Url Firefox"
6582 . (lambda (candidate)
6583 (anything-c-w3m-browse-bookmark candidate t)))
6584 ("Delete Bookmark"
6585 . (lambda (candidate)
6586 (anything-c-w3m-delete-bookmark candidate)))
6587 ("Rename Bookmark"
6588 . (lambda (candidate)
6589 (anything-c-w3m-rename-bookmark candidate)))))
6590 (persistent-action . (lambda (candidate)
6591 (if current-prefix-arg
6592 (anything-c-w3m-browse-bookmark candidate t)
6593 (anything-c-w3m-browse-bookmark candidate nil t))))
6594 (persistent-help . "Open URL with emacs-w3m in new tab / \
6595 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6596 "Needs w3m and emacs-w3m.
6598 http://w3m.sourceforge.net/
6599 http://emacs-w3m.namazu.org/")
6601 ;; (anything 'anything-c-source-w3m-bookmarks)
6603 (defun anything-c-w3m-bookmarks-get-value (elm)
6604 (replace-regexp-in-string
6605 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6607 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6608 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6609 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6610 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6612 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6613 (loop for i in bookmarks
6614 collect (propertize
6615 i 'face 'anything-w3m-bookmarks-face
6616 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6619 (defun anything-c-w3m-delete-bookmark (elm)
6620 "Delete w3m bookmark from `w3m-bookmark-file'."
6621 (with-current-buffer
6622 (find-file-literally w3m-bookmark-file)
6623 (goto-char (point-min))
6624 (when (re-search-forward elm nil t)
6625 (beginning-of-line)
6626 (delete-region (point)
6627 (line-end-position))
6628 (delete-blank-lines))
6629 (save-buffer)
6630 (kill-buffer)))
6632 (defun anything-c-w3m-rename-bookmark (elm)
6633 "Rename w3m bookmark in `w3m-bookmark-file'."
6634 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6635 (new-title (read-string "NewTitle: " old-title)))
6636 (with-current-buffer
6637 (find-file-literally w3m-bookmark-file)
6638 (goto-char (point-min))
6639 (when (re-search-forward (concat elm "<") nil t)
6640 (goto-char (1- (point)))
6641 (delete-char (- (length old-title)))
6642 (insert new-title))
6643 (save-buffer)
6644 (kill-buffer))))
6647 ;;;; <Library>
6648 ;;; Elisp library scan
6651 (defvar anything-c-source-elisp-library-scan
6652 '((name . "Elisp libraries (Scan)")
6653 (init . (anything-c-elisp-library-scan-init))
6654 (candidates-in-buffer)
6655 (action ("Find library"
6656 . (lambda (candidate) (find-file (find-library-name candidate))))
6657 ("Find library other window"
6658 . (lambda (candidate)
6659 (find-file-other-window (find-library-name candidate))))
6660 ("Load library"
6661 . (lambda (candidate) (load-library candidate))))))
6662 ;; (anything 'anything-c-source-elisp-library-scan)
6664 (defun anything-c-elisp-library-scan-init ()
6665 "Init anything buffer status."
6666 (let ((anything-buffer (anything-candidate-buffer 'global))
6667 (library-list (anything-c-elisp-library-scan-list)))
6668 (with-current-buffer anything-buffer
6669 (dolist (library library-list)
6670 (insert (format "%s\n" library))))))
6672 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6673 "Do completion for file names passed to `locate-file'.
6674 DIRS is directory to search path.
6675 STRING is string to match."
6676 ;; Use `load-path' as path when ignore `dirs'.
6677 (or dirs (setq dirs load-path))
6678 ;; Init with blank when ignore `string'.
6679 (or string (setq string ""))
6680 ;; Get library list.
6681 (let ((string-dir (file-name-directory string))
6682 ;; File regexp that suffix match `load-file-rep-suffixes'.
6683 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6684 name
6685 names)
6686 (dolist (dir dirs)
6687 (unless dir
6688 (setq dir default-directory))
6689 (if string-dir
6690 (setq dir (expand-file-name string-dir dir)))
6691 (when (file-directory-p dir)
6692 (dolist (file (file-name-all-completions
6693 (file-name-nondirectory string) dir))
6694 ;; Suffixes match `load-file-rep-suffixes'.
6695 (setq name (if string-dir (concat string-dir file) file))
6696 (if (string-match match-regexp name)
6697 (add-to-list 'names name)))))
6698 names))
6701 ;;;; <Programming>
6705 ;;; Imenu
6708 (defvar anything-c-imenu-delimiter " / ")
6710 (defvar anything-c-imenu-index-filter nil)
6711 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6713 (defvar anything-c-cached-imenu-alist nil)
6714 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6716 (defvar anything-c-cached-imenu-candidates nil)
6717 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6719 (defvar anything-c-cached-imenu-tick nil)
6720 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6722 (eval-when-compile (require 'imenu))
6723 (setq imenu-auto-rescan t)
6725 (defun anything-imenu-create-candidates (entry)
6726 "Create candidates with ENTRY."
6727 (if (listp (cdr entry))
6728 (mapcan
6729 (lambda (sub)
6730 (if (consp (cdr sub))
6731 (mapcar
6732 (lambda (subentry)
6733 (concat (car entry) anything-c-imenu-delimiter subentry))
6734 (anything-imenu-create-candidates sub))
6735 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6736 (cdr entry))
6737 (list entry)))
6739 (defvar anything-c-source-imenu
6740 '((name . "Imenu")
6741 (init . (lambda () (require 'imenu)))
6742 (candidates . anything-c-imenu-candidates)
6743 (persistent-action . (lambda (elm)
6744 (anything-c-imenu-default-action elm)
6745 (unless (fboundp 'semantic-imenu-tag-overlay)
6746 (anything-match-line-color-current-line))))
6747 (persistent-help . "Show this entry")
6748 (action . anything-c-imenu-default-action))
6749 "See (info \"(emacs)Imenu\")")
6751 ;; (anything 'anything-c-source-imenu)
6753 (defun anything-c-imenu-candidates ()
6754 (with-anything-current-buffer
6755 (let ((tick (buffer-modified-tick)))
6756 (if (eq anything-c-cached-imenu-tick tick)
6757 anything-c-cached-imenu-candidates
6758 (setq imenu--index-alist nil)
6759 (setq anything-c-cached-imenu-tick tick
6760 anything-c-cached-imenu-candidates
6761 (ignore-errors
6762 (mapcan
6763 'anything-imenu-create-candidates
6764 (setq anything-c-cached-imenu-alist
6765 (let ((index (imenu--make-index-alist)))
6766 (if anything-c-imenu-index-filter
6767 (funcall anything-c-imenu-index-filter index)
6768 index))))))
6769 (setq anything-c-cached-imenu-candidates
6770 (mapcar #'(lambda (x)
6771 (if (stringp x)
6773 (car x)))
6774 anything-c-cached-imenu-candidates))))))
6776 (setq imenu-default-goto-function 'imenu-default-goto-function)
6777 (defun anything-c-imenu-default-action (elm)
6778 "The default action for `anything-c-source-imenu'."
6779 (let ((path (split-string elm anything-c-imenu-delimiter))
6780 (alist anything-c-cached-imenu-alist))
6781 (dolist (elm path)
6782 (setq alist (assoc elm alist)))
6783 (imenu alist)))
6787 ;;; Ctags
6790 (defvar anything-c-ctags-modes
6791 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6792 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6793 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6795 (defun anything-c-source-ctags-init ()
6796 (when (and buffer-file-name
6797 (memq major-mode anything-c-ctags-modes)
6798 (anything-current-buffer-is-modified))
6799 (with-current-buffer (anything-candidate-buffer 'local)
6800 (call-process-shell-command
6801 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6802 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6803 anything-buffer-file-name)
6804 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6805 nil (current-buffer))
6806 (goto-char (point-min))
6807 (forward-line 2)
6808 (delete-region (point-min) (point))
6809 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6810 for lineno-start = (point)
6811 for lineno = (buffer-substring
6812 lineno-start
6813 (1- (search-forward "," (point-at-eol) t)))
6815 (beginning-of-line)
6816 (insert (format "%5s:" lineno))
6817 (search-forward "\177" (point-at-eol) t)
6818 (delete-region (1- (point)) (point-at-eol))
6819 (forward-line 1)))))
6821 (defvar anything-c-source-ctags
6822 '((name . "Exuberant ctags")
6823 (init . anything-c-source-ctags-init)
6824 (candidates-in-buffer)
6825 (adjust)
6826 (type . line))
6827 "Needs Exuberant Ctags.
6829 http://ctags.sourceforge.net/")
6830 ;; (anything 'anything-c-source-ctags)
6833 ;;; Etags
6836 ;; anything-etags.el is deprecated, if this file is found,
6837 ;; warn user at compile time.
6838 (eval-when-compile
6839 (when (locate-library "anything-etags.el")
6840 (display-warning
6841 '(anything-config)
6842 "You are using obsolete library `anything-etags.el' and should remove it."
6843 :warning)))
6845 (defvar anything-c-etags-tag-file-dir nil
6846 "Etags file directory.")
6847 (defvar anything-c-etags-mtime-alist nil
6848 "Store the last modification time of etags files here.")
6849 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6850 "Cache content of etags files used here for faster access.")
6852 (defun anything-c-etags-get-tag-file (&optional directory)
6853 "Return the path of etags file if found."
6854 ;; Get tag file from `default-directory' or upper directory.
6855 (let ((current-dir (anything-c-etags-find-tag-file-directory
6856 (or directory default-directory))))
6857 ;; Return nil if not find tag file.
6858 (when current-dir
6859 ;; Set tag file directory.
6860 (setq anything-c-etags-tag-file-dir current-dir)
6861 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6863 (defun anything-c-etags-find-tag-file-directory (current-dir)
6864 "Try to find the directory containing tag file.
6865 If not found in CURRENT-DIR search in upper directory."
6866 (flet ((file-exists? (dir)
6867 (let ((tag-path (expand-file-name
6868 anything-c-etags-tag-file-name dir)))
6869 (and (stringp tag-path)
6870 (file-exists-p tag-path)
6871 (file-readable-p tag-path)))))
6872 (loop with count = 0
6873 until (file-exists? current-dir)
6874 ;; Return nil if outside the value of
6875 ;; `anything-c-etags-tag-file-search-limit'.
6876 if (= count anything-c-etags-tag-file-search-limit)
6877 do (return nil)
6878 ;; Or search upper directories.
6879 else
6880 do (incf count)
6881 (setq current-dir (expand-file-name (concat current-dir "../")))
6882 finally return current-dir)))
6884 (defun anything-c-source-etags-header-name (x)
6885 "Create header name for this anything etags session."
6886 (concat "Etags in "
6887 (with-anything-current-buffer
6888 (anything-c-etags-get-tag-file))))
6890 (defmacro anything-c-etags-create-buffer (file)
6891 "Create the `anything-buffer' based on contents of etags tag FILE."
6892 `(let* ((tag-fname ,file)
6894 (split (with-current-buffer (find-file-noselect tag-fname)
6895 (prog1
6896 (split-string (buffer-string) "\n" 'omit-nulls)
6897 (setq max (line-number-at-pos (point-max)))
6898 (kill-buffer))))
6899 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6900 (loop
6901 with fname
6902 with cand
6903 for i in split for count from 0
6904 for elm = (unless (string-match "^\x0c" i)
6905 (anything-aif (string-match "\177" i)
6906 (substring i 0 it)
6908 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6909 (setq fname (match-string 1 elm)))
6910 (elm (setq cand (concat fname ": " elm)))
6911 (t (setq cand nil)))
6912 when cand do (progn
6913 (insert (concat cand "\n"))
6914 (progress-reporter-update progress-reporter count)))))
6916 (defun anything-c-etags-init ()
6917 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6918 If no entry in cache, create one."
6919 (let ((tagfile (anything-c-etags-get-tag-file)))
6920 (when tagfile
6921 (with-current-buffer (anything-candidate-buffer 'global)
6922 (anything-aif (gethash tagfile anything-c-etags-cache)
6923 ;; An entry is present in cache, insert it.
6924 (insert it)
6925 ;; No entry, create a new buffer using content of tag file (slower).
6926 (anything-c-etags-create-buffer tagfile)
6927 ;; Store content of buffer in cache.
6928 (puthash tagfile (buffer-string) anything-c-etags-cache)
6929 ;; Store or set the last modification of tag file.
6930 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6931 ;; If an entry exists modify it.
6932 (setcdr it (anything-c-etags-mtime tagfile))
6933 ;; No entry create a new one.
6934 (add-to-list 'anything-c-etags-mtime-alist
6935 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6937 (defvar anything-c-source-etags-select
6938 '((name . "Etags")
6939 (header-name . anything-c-source-etags-header-name)
6940 (init . anything-c-etags-init)
6941 (candidates-in-buffer)
6942 (search . (anything-c-etags-search-fn))
6943 (mode-line . anything-etags-mode-line-string)
6944 (action . anything-c-etags-default-action)
6945 (persistent-action . (lambda (candidate)
6946 (anything-c-etags-default-action candidate)
6947 (anything-match-line-color-current-line))))
6948 "Anything source for Etags.")
6950 (defun anything-c-etags-search-fn (pattern bound noerror)
6951 "Search function for `anything-c-source-etags-select'."
6952 (re-search-forward
6953 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6954 bound noerror))
6956 (defun anything-c-etags-default-action (candidate)
6957 "Anything default action to jump to an etags entry."
6958 (let* ((split (split-string candidate ": "))
6959 (fname (expand-file-name
6960 (car split) anything-c-etags-tag-file-dir))
6961 (elm (cadr split)))
6962 (find-file fname)
6963 (goto-char (point-min))
6964 (search-forward elm nil t)
6965 (goto-char (match-beginning 0))))
6967 (defun anything-c-etags-mtime (file)
6968 "Last modification time of etags tag FILE."
6969 (cadr (nth 5 (file-attributes file))))
6971 (defun anything-c-etags-file-modified-p (file)
6972 "Check if tag FILE have been modified in this session.
6973 If FILE is nil return nil."
6974 (let ((last-modif (and file
6975 (assoc-default file anything-c-etags-mtime-alist))))
6976 (and last-modif
6977 (/= last-modif (anything-c-etags-mtime file)))))
6981 ;;; Semantic
6984 (defvar anything-semantic-candidates nil)
6986 (defun anything-semantic-construct-candidates (tags depth)
6987 (when (require 'semantic nil t)
6988 (apply
6989 'append
6990 (mapcar
6991 (lambda (tag)
6992 (if (listp tag)
6993 (let ((type (semantic-tag-type tag))
6994 (class (semantic-tag-class tag)))
6995 (if (or (and (stringp type)
6996 (or (string= type "class")
6997 (string= type "namespace")))
6998 (eq class 'function)
6999 (eq class 'variable))
7000 (cons (cons (concat (make-string (* depth 2) ?\s)
7001 (semantic-format-tag-summarize tag nil t))
7002 tag)
7003 (anything-semantic-construct-candidates
7004 (semantic-tag-components tag) (1+ depth)))))))
7005 tags))))
7007 (defun anything-semantic-default-action (candidate)
7008 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7009 (semantic-go-to-tag tag)))
7011 (defvar anything-c-source-semantic
7012 '((name . "Semantic Tags")
7013 (init . (lambda ()
7014 (setq anything-semantic-candidates
7015 (ignore-errors (anything-semantic-construct-candidates
7016 (semantic-fetch-tags) 0)))))
7017 (candidates . (lambda ()
7018 (if anything-semantic-candidates
7019 (mapcar 'car anything-semantic-candidates))))
7020 (persistent-action . (lambda (elm)
7021 (anything-semantic-default-action elm)
7022 (anything-match-line-color-current-line)))
7023 (persistent-help . "Show this entry")
7024 (action . anything-semantic-default-action)
7025 "Needs semantic in CEDET.
7027 http://cedet.sourceforge.net/semantic.shtml
7028 http://cedet.sourceforge.net/"))
7030 ;; (anything 'anything-c-source-semantic)
7033 ;;; Anything interface of `simple-call-tree.el'.
7035 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7037 ;; Function is called by
7038 (defvar anything-c-source-simple-call-tree-functions-callers
7039 '((name . "Function is called by")
7040 (init . anything-c-simple-call-tree-functions-callers-init)
7041 (multiline)
7042 (candidates . anything-c-simple-call-tree-candidates)
7043 (persistent-action . anything-c-simple-call-tree-persistent-action)
7044 (persistent-help . "Show function definitions by rotation")
7045 (action ("Find definition selected by persistent-action" .
7046 anything-c-simple-call-tree-find-definition)))
7047 "Needs simple-call-tree.el.
7048 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7050 (defvar anything-c-simple-call-tree-tick nil)
7051 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7052 (defun anything-c-simple-call-tree-analyze-maybe ()
7053 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7054 (simple-call-tree-analyze)
7055 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7057 (defun anything-c-simple-call-tree-init-base (function message)
7058 (require 'simple-call-tree)
7059 (with-no-warnings
7060 (when (anything-current-buffer-is-modified)
7061 (anything-c-simple-call-tree-analyze-maybe)
7062 (let ((list (funcall function simple-call-tree-alist)))
7063 (with-current-buffer (anything-candidate-buffer 'local)
7064 (dolist (entry list)
7065 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7066 (insert (car entry) message
7067 (if (string= funcs " ")
7068 " no functions."
7069 funcs)
7070 "\n\n"))))))))
7072 (defun anything-c-simple-call-tree-functions-callers-init ()
7073 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7074 " is called by\n"))
7076 (defun anything-c-simple-call-tree-candidates ()
7077 (with-current-buffer (anything-candidate-buffer)
7078 (split-string (buffer-string) "\n\n")))
7080 (defvar anything-c-simple-call-tree-related-functions nil)
7081 (defvar anything-c-simple-call-tree-function-index 0)
7082 (defun anything-c-simple-call-tree-persistent-action (candidate)
7083 (unless (eq last-command 'anything-execute-persistent-action)
7084 (setq anything-c-simple-call-tree-related-functions
7085 (delete "no functions."
7086 (split-string
7087 (replace-regexp-in-string " \\| is called by\\| calls "
7088 "" candidate)
7089 "\n")))
7090 (setq anything-c-simple-call-tree-function-index -1))
7091 (incf anything-c-simple-call-tree-function-index)
7092 (anything-c-simple-call-tree-find-definition candidate))
7094 (defun anything-c-simple-call-tree-find-definition (candidate)
7095 (find-function
7096 (intern
7097 (nth (mod anything-c-simple-call-tree-function-index
7098 (length anything-c-simple-call-tree-related-functions))
7099 anything-c-simple-call-tree-related-functions))))
7101 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7103 ;;; Function calls
7104 (defvar anything-c-source-simple-call-tree-callers-functions
7105 '((name . "Function calls")
7106 (init . anything-c-simple-call-tree-callers-functions-init)
7107 (multiline)
7108 (candidates . anything-c-simple-call-tree-candidates)
7109 (persistent-action . anything-c-simple-call-tree-persistent-action)
7110 (persistent-help . "Show function definitions by rotation")
7111 (action ("Find definition selected by persistent-action" .
7112 anything-c-simple-call-tree-find-definition)))
7113 "Needs simple-call-tree.el.
7114 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7116 (defun anything-c-simple-call-tree-callers-functions-init ()
7117 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7119 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7123 ;;; Anything UI of auto-document.el
7125 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7127 ;; Commands/Options with doc
7128 (defvar anything-c-auto-document-data nil)
7129 (make-variable-buffer-local 'anything-c-auto-document-data)
7130 (defvar anything-c-source-commands-and-options-in-file
7131 '((name . "Commands/Options in file")
7132 (header-name
7133 . (lambda (x) (format "Commands/Options in %s"
7134 (buffer-local-value 'buffer-file-name
7135 anything-current-buffer))))
7136 (candidates . anything-command-and-options-candidates)
7137 (multiline)
7138 (action . imenu))
7139 "List Commands and Options with doc. It needs auto-document.el .
7141 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7143 (eval-when-compile (require 'auto-document nil t))
7144 (defun anything-command-and-options-candidates ()
7145 (with-anything-current-buffer
7146 (when (and (require 'auto-document nil t)
7147 (eq major-mode 'emacs-lisp-mode)
7148 (or (anything-current-buffer-is-modified)
7149 (not anything-c-auto-document-data)))
7150 (or imenu--index-alist (imenu--make-index-alist t))
7151 (setq anything-c-auto-document-data
7152 (destructuring-bind (commands options)
7153 (adoc-construct anything-current-buffer)
7154 (append
7155 (loop for (command . doc) in commands
7156 for cmdname = (symbol-name command)
7157 collect
7158 (cons
7159 (format "Command: %s\n %s"
7160 (propertize cmdname 'face font-lock-function-name-face)
7161 (adoc-first-line doc))
7162 (assoc cmdname imenu--index-alist)))
7163 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7164 for (option doc default) in options
7165 for optname = (symbol-name option)
7166 collect
7167 (cons
7168 (format "Option: %s\n %s\n default = %s"
7169 (propertize optname 'face font-lock-variable-name-face)
7170 (adoc-first-line doc)
7171 (adoc-prin1-to-string default))
7172 (assoc optname
7173 var-alist)))))))
7174 anything-c-auto-document-data))
7176 ;; (anything 'anything-c-source-commands-and-options-in-file)
7179 ;;;; <Color and Face>
7182 ;;; Customize Face
7185 (defvar anything-c-source-customize-face
7186 '((name . "Customize Face")
7187 (init . (lambda ()
7188 (unless (anything-candidate-buffer)
7189 (save-window-excursion (list-faces-display))
7190 (anything-candidate-buffer (get-buffer "*Faces*")))))
7191 (candidates-in-buffer)
7192 (get-line . buffer-substring)
7193 (action . (lambda (line)
7194 (customize-face (intern (car (split-string line))))))
7195 (requires-pattern . 3))
7196 "See (info \"(emacs)Faces\")")
7197 ;; (anything 'anything-c-source-customize-face)
7199 ;;; Colors browser
7202 (defvar anything-c-source-colors
7203 '((name . "Colors")
7204 (init . (lambda () (unless (anything-candidate-buffer)
7205 (save-window-excursion (list-colors-display))
7206 (anything-candidate-buffer (get-buffer "*Colors*")))))
7207 (candidates-in-buffer)
7208 (get-line . buffer-substring)
7209 (action
7210 ("Copy Name" . (lambda (candidate)
7211 (kill-new (anything-c-colors-get-name candidate))))
7212 ("Copy RGB" . (lambda (candidate)
7213 (kill-new (anything-c-colors-get-rgb candidate))))
7214 ("Insert Name" . (lambda (candidate)
7215 (with-anything-current-buffer
7216 (insert (anything-c-colors-get-name candidate)))))
7217 ("Insert RGB" . (lambda (candidate)
7218 (with-anything-current-buffer
7219 (insert (anything-c-colors-get-rgb candidate))))))))
7220 ;; (anything 'anything-c-source-colors)
7222 (defun anything-c-colors-get-name (candidate)
7223 "Get color name."
7224 (replace-regexp-in-string
7225 " " ""
7226 (with-temp-buffer
7227 (insert (capitalize candidate))
7228 (goto-char (point-min))
7229 (search-forward-regexp "\\s-\\{2,\\}")
7230 (delete-region (point) (point-max))
7231 (buffer-string))))
7233 (defun anything-c-colors-get-rgb (candidate)
7234 "Get color RGB."
7235 (replace-regexp-in-string
7236 " " ""
7237 (with-temp-buffer
7238 (insert (capitalize candidate))
7239 (goto-char (point-max))
7240 (search-backward-regexp "\\s-\\{2,\\}")
7241 (delete-region (point) (point-min))
7242 (buffer-string))))
7245 ;;;; <Search Engine>
7246 ;;; Tracker desktop search
7247 (defvar anything-c-source-tracker-search
7248 '((name . "Tracker Search")
7249 (candidates . (lambda ()
7250 (start-process "tracker-search-process" nil
7251 "tracker-search"
7252 anything-pattern)))
7253 (type . file)
7254 (requires-pattern . 3)
7255 (delayed))
7256 "Source for retrieving files matching the current input pattern
7257 with the tracker desktop search.")
7258 ;; (anything 'anything-c-source-tracker-search)
7260 ;;; Spotlight (MacOS X desktop search)
7261 (defvar anything-c-source-mac-spotlight
7262 '((name . "mdfind")
7263 (candidates
7264 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7265 (type . file)
7266 (requires-pattern . 3)
7267 (delayed))
7268 "Source for retrieving files via Spotlight's command line
7269 utility mdfind.")
7270 ;; (anything 'anything-c-source-mac-spotlight)
7272 ;;; Picklist
7273 (defvar anything-c-source-picklist
7274 '((name . "Picklist")
7275 (candidates . (lambda () (mapcar 'car picklist-list)))
7276 (type . file)))
7277 ;; (anything 'anything-c-source-picklist)
7281 ;;; Kill ring
7284 (defvar anything-c-source-kill-ring
7285 '((name . "Kill Ring")
7286 (init . (lambda () (anything-attrset 'last-command last-command)))
7287 (candidates . anything-c-kill-ring-candidates)
7288 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7289 (action . anything-c-kill-ring-action)
7290 (last-command)
7291 (migemo)
7292 (multiline))
7293 "Source for browse and insert contents of kill-ring.")
7295 (defun anything-c-kill-ring-candidates ()
7296 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7297 unless (or (< (length kill) anything-kill-ring-threshold)
7298 (string-match "^[\\s\\t]+$" kill))
7299 collect kill))
7301 (defun anything-c-kill-ring-transformer (candidates source)
7302 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7303 (loop for i in candidates
7304 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7305 if (and anything-c-kill-ring-max-lines-number
7306 (> nlines anything-c-kill-ring-max-lines-number))
7307 collect (cons
7308 (with-temp-buffer
7309 (insert i)
7310 (goto-char (point-min))
7311 (concat
7312 (buffer-substring
7313 (point-min)
7314 (save-excursion
7315 (forward-line anything-c-kill-ring-max-lines-number)
7316 (point)))
7317 "[...]")) i)
7318 else collect i))
7320 (defun anything-c-kill-ring-action (str)
7321 "Insert STR in `kill-ring' and set STR to the head.
7322 If this action is executed just after `yank',
7323 replace with STR as yanked string."
7324 (setq kill-ring (delete str kill-ring))
7325 (if (not (eq (anything-attr 'last-command) 'yank))
7326 (insert-for-yank str)
7327 ;; from `yank-pop'
7328 (let ((inhibit-read-only t)
7329 (before (< (point) (mark t))))
7330 (if before
7331 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7332 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7333 (setq yank-undo-function nil)
7334 (set-marker (mark-marker) (point) (current-buffer))
7335 (insert-for-yank str)
7336 ;; Set the window start back where it was in the yank command,
7337 ;; if possible.
7338 (set-window-start (selected-window) yank-window-start t)
7339 (if before
7340 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7341 ;; It is cleaner to avoid activation, even though the command
7342 ;; loop would deactivate the mark because we inserted text.
7343 (goto-char (prog1 (mark t)
7344 (set-marker (mark-marker) (point) (current-buffer)))))))
7345 (kill-new str))
7347 ;; (anything 'anything-c-source-kill-ring)
7350 ;;;; <Mark ring>
7351 ;; DO NOT include these sources in `anything-sources' use
7352 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7353 ;; `anything-all-mark-rings' instead.
7355 (defun anything-c-source-mark-ring-candidates ()
7356 (flet ((get-marks (pos)
7357 (save-excursion
7358 (goto-char pos)
7359 (beginning-of-line)
7360 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7361 (when (string= "" line)
7362 (setq line "<EMPTY LINE>"))
7363 (format "%7d: %s" (line-number-at-pos) line)))))
7364 (with-anything-current-buffer
7365 (loop
7366 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7367 with recip = nil
7368 for i in marks
7369 for m = (get-marks i)
7370 unless (member m recip)
7371 collect m into recip
7372 finally return recip))))
7374 (defvar anything-mark-ring-cache nil)
7375 (defvar anything-c-source-mark-ring
7376 '((name . "mark-ring")
7377 (init . (lambda ()
7378 (setq anything-mark-ring-cache
7379 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7380 (candidates . (lambda ()
7381 (anything-aif anything-mark-ring-cache
7382 it)))
7383 (action . (("Goto line"
7384 . (lambda (candidate)
7385 (anything-goto-line (string-to-number candidate))))))
7386 (persistent-action . (lambda (candidate)
7387 (anything-goto-line (string-to-number candidate))
7388 (anything-match-line-color-current-line)))
7389 (persistent-help . "Show this line")))
7391 ;; (anything 'anything-c-source-mark-ring)
7393 ;;; Global-mark-ring
7394 (defvar anything-c-source-global-mark-ring
7395 '((name . "global-mark-ring")
7396 (candidates . anything-c-source-global-mark-ring-candidates)
7397 (action . (("Goto line"
7398 . (lambda (candidate)
7399 (let ((items (split-string candidate ":")))
7400 (anything-c-switch-to-buffer (second items))
7401 (anything-goto-line (string-to-number (car items))))))))
7402 (persistent-action . (lambda (candidate)
7403 (let ((items (split-string candidate ":")))
7404 (anything-c-switch-to-buffer (second items))
7405 (anything-goto-line (string-to-number (car items)))
7406 (anything-match-line-color-current-line))))
7407 (persistent-help . "Show this line")))
7409 (defun anything-c-source-global-mark-ring-candidates ()
7410 (flet ((buf-fn (m)
7411 (with-current-buffer (marker-buffer m)
7412 (goto-char m)
7413 (beginning-of-line)
7414 (let (line)
7415 (if (string= "" line)
7416 (setq line "<EMPTY LINE>")
7417 (setq line (car (split-string (thing-at-point 'line)
7418 "[\n\r]"))))
7419 (format "%7d:%s: %s"
7420 (line-number-at-pos) (marker-buffer m) line)))))
7421 (loop
7422 with marks = global-mark-ring
7423 with recip = nil
7424 for i in marks
7425 for gm = (unless (or (string-match
7426 "^ " (format "%s" (marker-buffer i)))
7427 (null (marker-buffer i)))
7428 (buf-fn i))
7429 when (and gm (not (member gm recip)))
7430 collect gm into recip
7431 finally return recip)))
7433 ;; (anything 'anything-c-source-global-mark-ring)
7436 ;;;; <Register>
7437 ;;; Insert from register
7438 (defvar anything-c-source-register
7439 '((name . "Registers")
7440 (candidates . anything-c-register-candidates)
7441 (action-transformer . anything-c-register-action-transformer)
7442 (multiline)
7443 (action))
7444 "See (info \"(emacs)Registers\")")
7446 (defun anything-c-register-candidates ()
7447 "Collecting register contents and appropriate commands."
7448 (loop for (char . val) in register-alist
7449 for key = (single-key-description char)
7450 for string-actions =
7451 (cond
7452 ((numberp val)
7453 (list (int-to-string val)
7454 'insert-register
7455 'increment-register))
7456 ((markerp val)
7457 (let ((buf (marker-buffer val)))
7458 (if (null buf)
7459 (list "a marker in no buffer")
7460 (list (concat
7461 "a buffer position:"
7462 (buffer-name buf)
7463 ", position "
7464 (int-to-string (marker-position val)))
7465 'jump-to-register
7466 'insert-register))))
7467 ((and (consp val) (window-configuration-p (car val)))
7468 (list "window configuration."
7469 'jump-to-register))
7470 ((and (consp val) (frame-configuration-p (car val)))
7471 (list "frame configuration."
7472 'jump-to-register))
7473 ((and (consp val) (eq (car val) 'file))
7474 (list (concat "file:"
7475 (prin1-to-string (cdr val))
7476 ".")
7477 'jump-to-register))
7478 ((and (consp val) (eq (car val) 'file-query))
7479 (list (concat "file:a file-query reference: file "
7480 (car (cdr val))
7481 ", position "
7482 (int-to-string (car (cdr (cdr val))))
7483 ".")
7484 'jump-to-register))
7485 ((consp val)
7486 (let ((lines (format "%4d" (length val))))
7487 (list (format "%s: %s\n" lines
7488 (truncate-string-to-width
7489 (mapconcat 'identity (list (car val))
7490 ;; (mapconcat (lambda (y) y) val
7491 "^J") (- (window-width) 15)))
7492 'insert-register)))
7493 ((stringp val)
7494 (list ;; without properties
7495 (substring-no-properties val)
7496 'insert-register
7497 'append-to-register
7498 'prepend-to-register))
7500 "GARBAGE!"))
7501 collect (cons (format "register %3s: %s" key (car string-actions))
7502 (cons char (cdr string-actions)))))
7504 (defun anything-c-register-action-transformer (actions register-and-functions)
7505 "Decide actions by the contents of register."
7506 (loop with func-actions =
7507 '((insert-register
7508 "Insert Register" .
7509 (lambda (c) (insert-register (car c))))
7510 (jump-to-register
7511 "Jump to Register" .
7512 (lambda (c) (jump-to-register (car c))))
7513 (append-to-register
7514 "Append Region to Register" .
7515 (lambda (c) (append-to-register
7516 (car c) (region-beginning) (region-end))))
7517 (prepend-to-register
7518 "Prepend Region to Register" .
7519 (lambda (c) (prepend-to-register
7520 (car c) (region-beginning) (region-end))))
7521 (increment-register
7522 "Increment Prefix Arg to Register" .
7523 (lambda (c) (increment-register
7524 anything-current-prefix-arg (car c)))))
7525 for func in (cdr register-and-functions)
7526 for cell = (assq func func-actions)
7527 when cell
7528 collect (cdr cell)))
7530 ;; (anything 'anything-c-source-register)
7533 ;;; Latex completion
7534 (defun anything-c-latex-math-candidates ()
7535 "Collect candidates for latex math completion."
7536 (declare (special LaTeX-math-menu))
7537 (loop for i in (cddr LaTeX-math-menu)
7538 for elm = (loop for s in i when (vectorp s)
7539 collect (cons (aref s 0) (aref s 1)))
7540 append elm))
7542 (defvar anything-c-source-latex-math
7543 '((name . "Latex Math Menu")
7544 (init . (lambda ()
7545 (with-anything-current-buffer
7546 (LaTeX-math-mode 1))))
7547 (candidate-number-limit . 9999)
7548 (candidates . anything-c-latex-math-candidates)
7549 (action . (lambda (candidate)
7550 (call-interactively candidate)))))
7553 ;;;; <Headline Extraction>
7554 (defvar anything-c-source-fixme
7555 '((name . "TODO/FIXME/DRY comments")
7556 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7557 (adjust)
7558 (recenter))
7559 "Show TODO/FIXME/DRY comments in current file.")
7560 ;; (anything 'anything-c-source-fixme)
7562 (defvar anything-c-source-rd-headline
7563 '((name . "RD HeadLine")
7564 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7565 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7566 (migemo)
7567 (subexp . 1))
7568 "Show RD headlines.
7570 RD is Ruby's POD.
7571 http://en.wikipedia.org/wiki/Ruby_Document_format")
7572 ;; (anything 'anything-c-source-rd-headline)
7574 (defvar anything-c-source-oddmuse-headline
7575 '((name . "Oddmuse HeadLine")
7576 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7577 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7578 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7579 (migemo)
7580 (subexp . 1))
7581 "Show Oddmuse headlines, such as EmacsWiki.")
7582 ;; (anything 'anything-c-source-oddmuse-headline)
7584 (defvar anything-c-source-emacs-source-defun
7585 '((name . "Emacs Source DEFUN")
7586 (headline . "DEFUN\\|DEFVAR")
7587 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7588 (or buffer-file-name ""))))
7589 "Show DEFUN/DEFVAR in Emacs C source file.")
7590 ;; (anything 'anything-c-source-emacs-source-defun)
7592 (defvar anything-c-source-emacs-lisp-expectations
7593 '((name . "Emacs Lisp Expectations")
7594 (headline . "(desc[ ]\\|(expectations")
7595 (condition . (eq major-mode 'emacs-lisp-mode)))
7596 "Show descriptions (desc) in Emacs Lisp Expectations.
7598 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7599 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7601 (defvar anything-c-source-emacs-lisp-toplevels
7602 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7603 (headline . "^(\\|(@\\*\\|^;;;;")
7604 (get-line . buffer-substring)
7605 (condition . (eq major-mode 'emacs-lisp-mode))
7606 (adjust))
7607 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7608 linkd.el is optional because linkd stars are extracted by regexp.
7609 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7610 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7613 ;;; Anything yaoddmuse
7615 ;; Be sure to have yaoddmuse.el installed
7616 ;; install-elisp may be required if you want to install elisp file from here.
7617 (defvar anything-yaoddmuse-use-cache-file nil)
7618 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7619 (defvar anything-c-yaoddmuse-ew-cache nil)
7621 (defun anything-yaoddmuse-get-candidates ()
7622 (declare (special yaoddmuse-pages-hash))
7623 (if anything-yaoddmuse-use-cache-file
7624 (ignore-errors
7625 (unless anything-c-yaoddmuse-ew-cache
7626 (load anything-c-yaoddmuse-cache-file)
7627 (setq anything-c-yaoddmuse-ew-cache
7628 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7629 anything-c-yaoddmuse-ew-cache)
7630 (yaoddmuse-update-pagename t)
7631 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7633 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7634 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7635 (candidates . anything-yaoddmuse-get-candidates)
7636 (action . (("Edit page" . (lambda (candidate)
7637 (yaoddmuse-edit "EmacsWiki" candidate)))
7638 ("Browse page"
7639 . (lambda (candidate)
7640 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7641 ("Browse page other window"
7642 . (lambda (candidate)
7643 (if (one-window-p)
7644 (split-window-vertically))
7645 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7646 ("Browse diff"
7647 . (lambda (candidate)
7648 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7649 ("Copy URL"
7650 . (lambda (candidate)
7651 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7652 (message "Have copy page %s's URL to yank." candidate)))
7653 ("Create page"
7654 . (lambda (candidate)
7655 (yaoddmuse-edit "EmacsWiki" anything-input)))
7656 ("Update cache"
7657 . (lambda (candidate)
7658 (if anything-yaoddmuse-use-cache-file
7659 (progn
7660 (anything-yaoddmuse-cache-pages t)
7661 (setq anything-c-yaoddmuse-ew-cache
7662 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7663 (yaoddmuse-update-pagename))))))
7664 (action-transformer anything-c-yaoddmuse-action-transformer))
7665 "Needs yaoddmuse.el.
7667 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7669 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7671 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7672 '((name . "Yaoddmuse Post library (EmacsWiki)")
7673 (init . (anything-yaoddmuse-init))
7674 (candidates-in-buffer)
7675 (action . (("Post library and Browse"
7676 . (lambda (candidate)
7677 (yaoddmuse-post-file
7678 (find-library-name candidate)
7679 "EmacsWiki"
7680 (file-name-nondirectory (find-library-name candidate))
7681 nil t)))
7682 ("Post library"
7683 . (lambda (candidate)
7684 (yaoddmuse-post-file
7685 (find-library-name candidate)
7686 "EmacsWiki"
7687 (file-name-nondirectory
7688 (find-library-name candidate))))))))
7689 "Needs yaoddmuse.el.
7691 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7693 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7695 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7696 "Allow the use of `install-elisp' only on elisp files."
7697 (if (string-match "\.el$" candidate)
7698 (append actions '(("Install Elisp"
7699 . (lambda (elm)
7700 (install-elisp-from-emacswiki elm)))))
7701 actions))
7703 ;;;###autoload
7704 (defun anything-yaoddmuse-cache-pages (&optional load)
7705 "Fetch the list of files on emacswiki and create cache file.
7706 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7707 (interactive)
7708 (declare (special yaoddmuse-pages-hash))
7709 (yaoddmuse-update-pagename)
7710 (save-excursion
7711 (find-file anything-c-yaoddmuse-cache-file)
7712 (erase-buffer)
7713 (insert "(puthash \"EmacsWiki\" '(")
7714 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7716 (insert (concat "(\"" (car i) "\") ")))
7717 (insert ") yaoddmuse-pages-hash)\n")
7718 (save-buffer)
7719 (kill-buffer (current-buffer))
7720 (when (or current-prefix-arg
7721 load)
7722 (load anything-c-yaoddmuse-cache-file))))
7724 (defun anything-yaoddmuse-init ()
7725 "Init anything buffer status."
7726 (let ((anything-buffer (anything-candidate-buffer 'global))
7727 (library-list (yaoddmuse-get-library-list)))
7728 (with-current-buffer anything-buffer
7729 ;; Insert library name.
7730 (dolist (library library-list)
7731 (insert (format "%s\n" library)))
7732 ;; Sort lines.
7733 (sort-lines nil (point-min) (point-max)))))
7736 ;;; Eev anchors
7737 (defvar anything-c-source-eev-anchor
7738 '((name . "Anchors")
7739 (candidates
7740 . (lambda ()
7741 (ignore-errors
7742 (with-anything-current-buffer
7743 (loop initially (goto-char (point-min))
7744 while (re-search-forward
7745 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7746 for anchor = (match-string-no-properties 1)
7747 collect (cons (format "%5d:%s"
7748 (line-number-at-pos (match-beginning 0))
7749 (format ee-anchor-format anchor))
7750 anchor))))))
7751 (persistent-action . (lambda (item)
7752 (ee-to item)
7753 (anything-match-line-color-current-line)))
7754 (persistent-help . "Show this entry")
7755 (action . (("Goto link" . ee-to)))))
7756 ;; (anything 'anything-c-source-eev-anchor)
7759 ;;; Org headlines
7762 (defvar anything-c-source-org-headline
7763 `((name . "Org HeadLine")
7764 (headline
7765 ,@(mapcar
7766 (lambda (num)
7767 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7768 num))
7769 (number-sequence 1 8)))
7770 (condition . (eq major-mode 'org-mode))
7771 (migemo)
7772 (subexp . 1)
7773 (persistent-action . (lambda (elm)
7774 (anything-c-action-line-goto elm)
7775 (org-cycle)))
7776 (action-transformer
7777 . (lambda (actions candidate)
7778 '(("Go to Line" . anything-c-action-line-goto)
7779 ("Refile to this Headline" . anything-c-org-headline-refile)
7780 ("Insert Link to This Headline"
7781 . anything-c-org-headline-insert-link-to-headline)))))
7782 "Show Org headlines.
7783 org-mode is very very much extended text-mode/outline-mode.
7785 See (find-library \"org.el\")
7786 See http://orgmode.org for the latest version.")
7787 ;; (anything 'anything-c-source-org-headline)
7789 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7790 (insert
7791 (save-excursion
7792 (anything-goto-line (car lineno-and-content))
7793 (and (looking-at org-complex-heading-regexp)
7794 (org-make-link-string (concat "*" (match-string 4)))))))
7796 (defun anything-c-org-headline-refile (lineno-and-content)
7797 "Refile current org entry to LINENO-AND-CONTENT."
7798 (with-anything-current-buffer
7799 (org-cut-subtree)
7800 (anything-goto-line (car lineno-and-content))
7801 (org-end-of-subtree t t)
7802 (let ((org-yank-adjusted-subtrees t))
7803 (org-yank))))
7806 ;;; Org keywords
7809 (defvar anything-c-source-org-keywords
7810 '((name . "Org Keywords")
7811 (init . anything-c-org-keywords-init)
7812 (candidates . anything-c-org-keywords-candidates)
7813 (action . anything-c-org-keywords-insert)
7814 (persistent-action . anything-c-org-keywords-show-help)
7815 (persistent-help . "Show an example and info page to describe this keyword.")
7816 (keywords-examples)
7817 (keywords)))
7818 ;; (anything 'anything-c-source-org-keywords)
7820 (defvar anything-c-org-keywords-info-location
7821 '(("#+TITLE:" . "(org)Export options")
7822 ("#+AUTHOR:" . "(org)Export options")
7823 ("#+DATE:" . "(org)Export options")
7824 ("#+EMAIL:" . "(org)Export options")
7825 ("#+DESCRIPTION:" . "(org)Export options")
7826 ("#+KEYWORDS:" . "(org)Export options")
7827 ("#+LANGUAGE:" . "(org)Export options")
7828 ("#+TEXT:" . "(org)Export options")
7829 ("#+TEXT:" . "(org)Export options")
7830 ("#+OPTIONS:" . "(org)Export options")
7831 ("#+BIND:" . "(org)Export options")
7832 ("#+LINK_UP:" . "(org)Export options")
7833 ("#+LINK_HOME:" . "(org)Export options")
7834 ("#+LATEX_HEADER:" . "(org)Export options")
7835 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7836 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7837 ("#+INFOJS_OPT" . "(org)Javascript support")
7838 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7839 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7840 ("#+ORGTBL" . "(org)Radio tables")
7841 ("#+HTML:" . "(org)Quoting HTML tags")
7842 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7843 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7844 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7845 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7846 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7847 ("#+BEGIN_SRC" . "(org)Literal examples")
7848 ("#+CAPTION" . "(org)Tables in HTML export")
7849 ("#+LABEL" . "(org)Tables in LaTeX export")
7850 ("#+ATTR_HTML" . "(org)Links")
7851 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7853 (defun anything-c-org-keywords-init ()
7854 (unless (anything-attr 'keywords-examples)
7855 (require 'org)
7856 (anything-attrset 'keywords-examples
7857 (append
7858 (mapcar
7859 (lambda (x)
7860 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7861 (cons (match-string 2 x) (match-string 1 x)))
7862 (org-split-string (org-get-current-options) "\n"))
7863 (mapcar 'list org-additional-option-like-keywords)))
7864 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7866 (defun anything-c-org-keywords-candidates ()
7867 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7868 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7869 (anything-attr 'keywords)))
7871 (defun anything-c-org-keywords-insert (keyword)
7872 (cond ((and (string-match "BEGIN" keyword)
7873 (anything-region-active-p))
7874 (let ((beg (region-beginning))
7875 (end (region-end)))
7876 (goto-char end)
7877 (insert "\n#+" (replace-regexp-in-string
7878 "BEGIN" "END" keyword) "\n")
7879 (goto-char beg)
7880 (insert "#+" keyword " ")
7881 (save-excursion (insert "\n"))))
7882 ((string-match "BEGIN" keyword)
7883 (insert "#+" keyword " ")
7884 (save-excursion
7885 (insert "\n#+" (replace-regexp-in-string
7886 "BEGIN" "END" keyword) "\n")))
7887 (t (insert "#+" keyword " "))))
7889 (defun anything-c-org-keywords-show-help (keyword)
7890 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7891 "(org)In-buffer settings"))
7892 (search-forward (concat "#+" keyword) nil t)
7893 (anything-persistent-highlight-point)
7894 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7898 ;;; bbdb
7901 (defvar bbdb-records)
7902 (defvar bbdb-buffer-name)
7904 (defun anything-c-bbdb-candidates ()
7905 "Return a list of all names in the bbdb database. The format
7906 is \"Firstname Lastname\"."
7907 (mapcar (lambda (bbdb-record)
7908 (replace-regexp-in-string
7909 "\\s-+$" ""
7910 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7911 (bbdb-records)))
7913 (defun anything-c-bbdb-create-contact (actions candidate)
7914 "Action transformer that returns only an entry to add the
7915 current `anything-pattern' as new contact. All other actions are
7916 removed."
7917 (if (string= candidate "*Add to contacts*")
7918 '(("Add to contacts" . (lambda (actions)
7919 (bbdb-create-internal
7920 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7921 (read-from-minibuffer "Company: ")
7922 (read-from-minibuffer "Email: ")
7925 (read-from-minibuffer "Note: ")))))
7926 actions))
7928 (defun anything-c-bbdb-get-record (candidate)
7929 "Return record that match CANDIDATE."
7930 (bbdb candidate nil)
7931 (set-buffer "*BBDB*")
7932 (bbdb-current-record))
7934 (defvar anything-c-bbdb-name nil
7935 "Only for internal use.")
7937 (defvar anything-c-source-bbdb
7938 '((name . "BBDB")
7939 (candidates . anything-c-bbdb-candidates)
7940 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7941 ("View person's data" . anything-c-bbdb-view-person-action))
7942 (filtered-candidate-transformer . (lambda (candidates source)
7943 (setq anything-c-bbdb-name anything-pattern)
7944 (if (not candidates)
7945 (list "*Add to contacts*")
7946 candidates)))
7947 (action-transformer . (lambda (actions candidate)
7948 (anything-c-bbdb-create-contact actions candidate))))
7949 "Needs BBDB.
7951 http://bbdb.sourceforge.net/")
7952 ;; (anything 'anything-c-source-bbdb)
7954 (defun anything-c-bbdb-view-person-action (candidate)
7955 "View BBDB data of single CANDIDATE or marked candidates."
7956 (anything-aif (anything-marked-candidates)
7957 (let ((bbdb-append-records (length it)))
7958 (dolist (i it)
7959 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7960 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7962 (defun anything-c-bbdb-collect-mail-addresses ()
7963 "Return a list of all mail addresses of records in bbdb buffer."
7964 (with-current-buffer bbdb-buffer-name
7965 (loop for i in bbdb-records
7966 if (bbdb-record-net (car i))
7967 collect (bbdb-dwim-net-address (car i)))))
7969 (defun anything-c-bbdb-compose-mail (candidate)
7970 "Compose a mail with all records of bbdb buffer."
7971 (anything-c-bbdb-view-person-action candidate)
7972 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7973 (address-str (mapconcat 'identity address-list ",\n ")))
7974 (compose-mail address-str)))
7977 ;;; Evaluation Result
7980 ;; Internal
7981 (defvar anything-eldoc-active-minibuffers-list nil)
7983 (defvar anything-c-source-evaluation-result
7984 '((name . "Evaluation Result")
7985 (disable-shortcuts)
7986 (dummy)
7987 (multiline)
7988 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7989 (filtered-candidate-transformer . (lambda (candidates source)
7990 (list
7991 (condition-case nil
7992 (with-anything-current-buffer
7993 (pp-to-string
7994 (eval (read anything-pattern))))
7995 (error "Error")))))
7996 (action . (("Copy result to kill-ring" . (lambda (candidate)
7997 (with-current-buffer anything-buffer
7998 (let ((end (save-excursion
7999 (goto-char (point-max))
8000 (search-backward "\n")
8001 (point))))
8002 (kill-region (point) end)))))
8003 ("copy sexp to kill-ring" . (lambda (candidate)
8004 (kill-new anything-input)))))))
8005 ;; (anything 'anything-c-source-evaluation-result)
8007 (defun anything-eval-new-line-and-indent ()
8008 (interactive)
8009 (newline) (lisp-indent-line))
8011 (defun anything-eldoc-store-minibuffer ()
8012 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8013 (with-selected-window (minibuffer-window)
8014 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8016 (defun anything-eldoc-show-in-eval ()
8017 "Return eldoc in mode-line for current minibuffer input."
8018 (let ((buf (with-selected-window (minibuffer-window)
8019 (buffer-name))))
8020 (when (member buf anything-eldoc-active-minibuffers-list)
8021 (let* ((str-all (with-current-buffer buf
8022 (minibuffer-completion-contents)))
8023 (sym (when str-all
8024 (with-temp-buffer
8025 (insert str-all)
8026 (goto-char (point-max))
8027 (unless (looking-back ")\\|\"") (forward-char -1))
8028 (eldoc-current-symbol))))
8029 (info-fn (eldoc-fnsym-in-current-sexp))
8030 (doc (or (eldoc-get-var-docstring sym)
8031 (eldoc-get-fnsym-args-string
8032 (car info-fn) (cadr info-fn)))))
8033 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8035 (defun anything-c-eldoc-show-in-mode-line (str)
8036 "Show string STR in mode-line."
8037 (save-window-excursion
8038 (with-current-buffer anything-buffer
8039 (let ((mode-line-format (concat " " str)))
8040 (force-mode-line-update)
8041 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8042 (force-mode-line-update))))
8044 ;;; Calculation Result
8047 (defvar anything-c-source-calculation-result
8048 '((name . "Calculation Result")
8049 (dummy)
8050 (filtered-candidate-transformer . (lambda (candidates source)
8051 (list
8052 (condition-case nil
8053 (calc-eval anything-pattern)
8054 (error "error")))))
8055 (action ("Copy result to kill-ring" . kill-new))))
8056 ;; (anything 'anything-c-source-calculation-result)
8059 ;;; Google Suggestions
8062 ;; Internal
8063 (defvar anything-ggs-max-length-real-flag 0)
8064 (defvar anything-ggs-max-length-num-flag 0)
8066 (defun anything-c-google-suggest-fetch (input)
8067 "Fetch suggestions for INPUT from XML buffer.
8068 Return an alist with elements like (data . number_results)."
8069 (setq anything-ggs-max-length-real-flag 0
8070 anything-ggs-max-length-num-flag 0)
8071 (let ((request (concat anything-c-google-suggest-url
8072 (url-hexify-string input))))
8073 (flet ((fetch ()
8074 (loop
8075 with result-alist = (xml-get-children
8076 (car (xml-parse-region
8077 (point-min) (point-max)))
8078 'CompleteSuggestion)
8079 for i in result-alist
8080 for data = (cdr (caadr (assoc 'suggestion i)))
8081 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8082 for lqueries = (length (anything-c-ggs-set-number-result
8083 nqueries))
8084 for ldata = (length data)
8086 (progn
8087 (when (> ldata anything-ggs-max-length-real-flag)
8088 (setq anything-ggs-max-length-real-flag ldata))
8089 (when (> lqueries anything-ggs-max-length-num-flag)
8090 (setq anything-ggs-max-length-num-flag lqueries)))
8091 collect (cons data nqueries) into cont
8092 finally return cont)))
8093 (if anything-google-suggest-use-curl-p
8094 (with-temp-buffer
8095 (call-process "curl" nil t nil request)
8096 (fetch))
8097 (with-current-buffer
8098 (url-retrieve-synchronously request)
8099 (fetch))))))
8101 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8102 "Set candidates with result and number of google results found."
8103 (let ((suggestions
8104 (loop with suggested-results = (anything-c-google-suggest-fetch
8105 (or (and request-prefix
8106 (concat request-prefix " " anything-pattern))
8107 anything-pattern))
8108 for (real . numresult) in suggested-results
8109 ;; Prepare number of results with ","
8110 for fnumresult = (anything-c-ggs-set-number-result numresult)
8111 ;; Calculate number of spaces to add before fnumresult
8112 ;; if it is smaller than longest result
8113 ;; `anything-ggs-max-length-num-flag'.
8114 ;; e.g 1,234,567
8115 ;; 345,678
8116 ;; To be sure it is aligned properly.
8117 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8118 (- anything-ggs-max-length-num-flag (length fnumresult))
8120 ;; Add now the spaces before fnumresult.
8121 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8122 for interval = (- anything-ggs-max-length-real-flag (length real))
8123 for spaces = (make-string (+ 2 interval) ? )
8124 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8125 collect (cons display real))))
8126 (if (loop for (disp . dat) in suggestions
8127 thereis (equal dat anything-pattern))
8128 suggestions
8129 ;; if there is no suggestion exactly matching the input then
8130 ;; prepend a Search on Google item to the list
8131 (append
8132 suggestions
8133 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8134 anything-input))))))
8136 (defun anything-c-ggs-set-number-result (num)
8137 (if num
8138 (progn
8139 (and (numberp num) (setq num (number-to-string num)))
8140 (loop for i in (reverse (split-string num "" t))
8141 for count from 1
8142 append (list i) into C
8143 when (= count 3)
8144 append (list ",") into C
8145 and do (setq count 0)
8146 finally return
8147 (replace-regexp-in-string
8148 "^," "" (mapconcat 'identity (reverse C) ""))))
8149 "?"))
8151 (defvar anything-c-google-suggest-default-browser-function nil
8152 "*The browse url function you prefer to use with google suggest.
8153 When nil, use the first browser function available
8154 See `anything-browse-url-default-browser-alist'.")
8156 (defun anything-c-google-suggest-action (candidate)
8157 "Default action to jump to a google suggested candidate."
8158 (let ((arg (concat anything-c-google-suggest-search-url
8159 (url-hexify-string candidate))))
8160 (anything-aif anything-c-google-suggest-default-browser-function
8161 (funcall it arg)
8162 (anything-c-browse-url arg))))
8164 (defvar anything-c-google-suggest-default-function
8165 'anything-c-google-suggest-set-candidates
8166 "Default function to use in anything google suggest.")
8168 (defvar anything-c-source-google-suggest
8169 '((name . "Google Suggest")
8170 (candidates . (lambda ()
8171 (funcall anything-c-google-suggest-default-function)))
8172 (action . (("Google Search" . anything-c-google-suggest-action)))
8173 (volatile)
8174 (requires-pattern . 3)
8175 (delayed)))
8177 (defun anything-c-google-suggest-emacs-lisp ()
8178 "Try to emacs lisp complete with google suggestions."
8179 (anything-c-google-suggest-set-candidates "emacs lisp"))
8181 ;; (anything 'anything-c-source-google-suggest)
8183 ;;; Yahoo suggestions
8186 (defun anything-c-yahoo-suggest-fetch (input)
8187 "Fetch Yahoo suggestions for INPUT from XML buffer.
8188 Return an alist with elements like (data . number_results)."
8189 (let ((request (concat anything-c-yahoo-suggest-url
8190 (url-hexify-string input))))
8191 (flet ((fetch ()
8192 (loop
8193 with result-alist = (xml-get-children
8194 (car (xml-parse-region (point-min) (point-max)))
8195 'Result)
8196 for i in result-alist
8197 collect (caddr i))))
8198 (with-current-buffer
8199 (url-retrieve-synchronously request)
8200 (fetch)))))
8202 (defun anything-c-yahoo-suggest-set-candidates ()
8203 "Set candidates with Yahoo results found."
8204 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8205 (or suggestions
8206 (append
8207 suggestions
8208 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8209 anything-input))))))
8211 (defun anything-c-yahoo-suggest-action (candidate)
8212 "Default action to jump to a Yahoo suggested candidate."
8213 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8214 (url-hexify-string candidate))))
8216 (defvar anything-c-source-yahoo-suggest
8217 '((name . "Yahoo Suggest")
8218 (candidates . anything-c-yahoo-suggest-set-candidates)
8219 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8220 (volatile)
8221 (requires-pattern . 3)
8222 (delayed)))
8224 ;; (anything 'anything-c-source-yahoo-suggest)
8227 ;;; Web browser functions.
8230 (require 'browse-url)
8231 ;; If default setting of `w3m-command' is not
8232 ;; what you want you and you modify it, you will have to reeval
8233 ;; also `anything-browse-url-default-browser-alist'.
8234 (defvar w3m-command "/usr/bin/w3m")
8235 (defvar anything-c-home-url "http://www.google.fr"
8236 "*Default url to use as home url.")
8238 (defvar ac-browse-url-chromium-program "chromium-browser")
8239 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8240 (defvar anything-browse-url-default-browser-alist
8241 `((,w3m-command . w3m-browse-url)
8242 (,browse-url-firefox-program . browse-url-firefox)
8243 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8244 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8245 (,browse-url-kde-program . browse-url-kde)
8246 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8247 (,browse-url-mozilla-program . browse-url-mozilla)
8248 (,browse-url-galeon-program . browse-url-galeon)
8249 (,browse-url-netscape-program . browse-url-netscape)
8250 (,browse-url-mosaic-program . browse-url-mosaic)
8251 (,browse-url-xterm-program . browse-url-text-xterm))
8252 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8254 (defun* anything-c-generic-browser (url name &rest args)
8255 "Browse URL with NAME browser."
8256 (let ((proc (concat name " " url)))
8257 (message "Starting %s..." name)
8258 (apply 'start-process proc nil name
8259 (append args (list url)))
8260 (set-process-sentinel
8261 (get-process proc)
8262 #'(lambda (process event)
8263 (when (string= event "finished\n")
8264 (message "%s process %s" process event))))))
8266 (defun ac-browse-url-chromium (url)
8267 "Browse URL with google chrome browser."
8268 (interactive "sURL: ")
8269 (anything-c-generic-browser
8270 url ac-browse-url-chromium-program))
8272 (defun ac-browse-url-uzbl (url &optional ignore)
8273 "Browse URL with uzbl browser."
8274 (interactive "sURL: ")
8275 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8277 (defun anything-browse-url-default-browser (url &rest args)
8278 "Find the first available browser and ask it to load URL."
8279 (let ((default-browser-fn
8280 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8281 thereis (and exe (executable-find exe) fn))))
8282 (if default-browser-fn
8283 (apply default-browser-fn url args)
8284 (error "No usable browser found"))))
8286 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8287 "Default command to browse URL."
8288 (if browse-url-browser-function
8289 (browse-url url)
8290 (anything-browse-url-default-browser url)))
8293 ;;; Surfraw
8295 ;; Need external program surfraw.
8296 ;; <http://surfraw.alioth.debian.org/>
8298 (defvar anything-surfraw-default-browser-function nil
8299 "*The browse url function you prefer to use with surfraw.
8300 When nil, fallback to `browse-url-browser-function'.")
8302 ;; Internal
8303 (defvar anything-surfraw-engines-history nil)
8305 (defun anything-c-build-elvi-list ()
8306 "Return list of all engines and descriptions handled by surfraw."
8307 (cdr
8308 (with-temp-buffer
8309 (call-process "surfraw" nil t nil
8310 "-elvi")
8311 (split-string (buffer-string) "\n"))))
8314 ;;; Emms
8317 (defun anything-emms-stream-edit-bookmark (elm)
8318 "Change the information of current emms-stream bookmark from anything."
8319 (declare (special emms-stream-list))
8320 (let* ((cur-buf anything-current-buffer)
8321 (bookmark (assoc elm emms-stream-list))
8322 (name (read-from-minibuffer "Description: "
8323 (nth 0 bookmark)))
8324 (url (read-from-minibuffer "URL: "
8325 (nth 1 bookmark)))
8326 (fd (read-from-minibuffer "Feed Descriptor: "
8327 (int-to-string (nth 2 bookmark))))
8328 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8329 (format "%s" (car (last bookmark))))))
8330 (save-excursion
8331 (emms-streams)
8332 (when (re-search-forward (concat "^" name) nil t)
8333 (beginning-of-line)
8334 (emms-stream-delete-bookmark)
8335 (emms-stream-add-bookmark name url (string-to-number fd) type)
8336 (emms-stream-save-bookmarks-file)
8337 (emms-stream-quit)
8338 (anything-c-switch-to-buffer cur-buf)))))
8340 (defun anything-emms-stream-delete-bookmark (elm)
8341 "Delete an emms-stream bookmark from anything."
8342 (let* ((cur-buf anything-current-buffer)
8343 (bookmark (assoc elm emms-stream-list))
8344 (name (nth 0 bookmark)))
8345 (save-excursion
8346 (emms-streams)
8347 (when (re-search-forward (concat "^" name) nil t)
8348 (beginning-of-line)
8349 (emms-stream-delete-bookmark)
8350 (emms-stream-save-bookmarks-file)
8351 (emms-stream-quit)
8352 (anything-c-switch-to-buffer cur-buf)))))
8354 (defvar anything-c-source-emms-streams
8355 '((name . "Emms Streams")
8356 (init . (lambda ()
8357 (emms-stream-init)))
8358 (candidates . (lambda ()
8359 (declare (special emms-stream-list))
8360 (mapcar 'car emms-stream-list)))
8361 (action . (("Play" . (lambda (elm)
8362 (declare (special emms-stream-list))
8363 (let* ((stream (assoc elm emms-stream-list))
8364 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8365 (url (second stream)))
8366 (funcall fn url))))
8367 ("Delete" . anything-emms-stream-delete-bookmark)
8368 ("Edit" . anything-emms-stream-edit-bookmark)))
8369 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8370 ;; (anything 'anything-c-source-emms-streams)
8372 ;; Don't forget to set `emms-source-file-default-directory'
8373 (defvar anything-c-source-emms-dired
8374 '((name . "Music Directory")
8375 (candidates . (lambda ()
8376 (cddr (directory-files emms-source-file-default-directory))))
8377 (action .
8378 (("Play Directory" . (lambda (item)
8379 (emms-play-directory
8380 (expand-file-name
8381 item
8382 emms-source-file-default-directory))))
8383 ("Open dired in file's directory" . (lambda (item)
8384 (anything-c-open-dired
8385 (expand-file-name
8386 item
8387 emms-source-file-default-directory))))))
8388 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8389 ;; (anything 'anything-c-source-emms-dired)
8392 (defun anything-c-emms-files-modifier (candidates source)
8393 (let ((current-playlist (with-current-emms-playlist
8394 (loop
8395 with cur-list = (emms-playlist-tracks-in-region
8396 (point-min) (point-max))
8397 for i in cur-list
8398 collect (assoc-default 'name i)))))
8399 (loop for i in candidates
8400 if (member (cdr i) current-playlist)
8401 collect (cons (propertize (car i)
8402 'face 'anything-emms-playlist)
8403 (cdr i)) into lis
8404 else collect i into lis
8405 finally return lis)))
8407 (defun anything-c-emms-play-current-playlist ()
8408 "Play current playlist."
8409 (with-current-emms-playlist
8410 (emms-playlist-first)
8411 (emms-playlist-mode-play-smart)))
8413 (defvar anything-c-source-emms-files
8414 '((name . "Emms files")
8415 (candidates . (lambda ()
8416 (loop for v being the hash-values in emms-cache-db
8417 for name = (assoc-default 'name v)
8418 for artist = (or (assoc-default 'info-artist v) "unknown")
8419 for genre = (or (assoc-default 'info-genre v) "unknown")
8420 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8421 for song = (or (assoc-default 'info-title v) "unknown")
8422 for info = (concat artist " - " genre " - " tracknum ": " song)
8423 unless (string-match "^http:" name) collect (cons info name))))
8424 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8425 (action . (("Play file" . emms-play-file)
8426 ("Add to Playlist and play (C-u clear current)"
8427 . (lambda (candidate)
8428 (when anything-current-prefix-arg
8429 (emms-playlist-current-clear))
8430 (emms-playlist-new)
8431 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8432 (unless emms-player-playing-p
8433 (anything-c-emms-play-current-playlist))))))))
8435 ;; (anything 'anything-c-source-emms-files)
8438 ;;; Jabber Contacts (jabber.el)
8439 (defun anything-c-jabber-online-contacts ()
8440 "List online Jabber contacts."
8441 (with-no-warnings
8442 (let (jids)
8443 (dolist (item (jabber-concat-rosters) jids)
8444 (when (get item 'connected)
8445 (push (if (get item 'name)
8446 (cons (get item 'name) item)
8447 (cons (symbol-name item) item)) jids))))))
8449 (defvar anything-c-source-jabber-contacts
8450 '((name . "Jabber Contacts")
8451 (init . (lambda () (require 'jabber)))
8452 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8453 (action . (lambda (x)
8454 (jabber-chat-with
8455 (jabber-read-account)
8456 (symbol-name
8457 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8458 ;; (anything 'anything-c-source-jabber-contacts)
8462 ;;; Call source.
8463 (defvar anything-source-select-buffer "*anything source select*")
8464 (defvar anything-c-source-call-source
8465 `((name . "Call anything source")
8466 (candidate-number-limit)
8467 (candidates
8468 . (lambda ()
8469 (loop for vname in (all-completions "anything-c-source-" obarray)
8470 for var = (intern vname)
8471 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8472 if name collect
8473 (cons (format "%s `%s'"
8474 name (propertize vname 'face 'font-lock-variable-name-face))
8475 var))))
8476 (action
8477 . (("Invoke anything with selected source"
8479 (lambda (candidate)
8480 (setq anything-candidate-number-limit 9999)
8481 (anything candidate nil nil nil nil
8482 anything-source-select-buffer)))
8483 ("Describe variable" . describe-variable)
8484 ("Find variable" . find-variable)))
8485 (persistent-action . describe-variable)
8486 (persistent-help . "Show description of this source")))
8487 ;; (anything 'anything-c-source-call-source)
8489 (defun anything-call-source-from-anything ()
8490 "Call anything source within `anything' session."
8491 (interactive)
8492 (setq anything-input-idle-delay 0)
8493 (anything-set-sources '(anything-c-source-call-source)))
8495 ;;; Execute Preconfigured anything.
8496 (defvar anything-c-source-anything-commands
8497 '((name . "Preconfigured Anything")
8498 (candidates . anything-c-anything-commands-candidates)
8499 (type . command)
8500 (candidate-number-limit)))
8501 ;; (anything 'anything-c-source-anything-commands)
8503 (defun anything-c-anything-commands-candidates ()
8504 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8505 collect (cons (if (where-is-internal cmd nil t)
8506 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8507 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8508 cmd)))
8511 ;;; Occur
8514 (defun anything-c-occur-init ()
8515 "Create the initial anything occur buffer.
8516 If region is active use region as buffer contents
8517 instead of whole buffer."
8518 (with-current-buffer (anything-candidate-buffer 'global)
8519 (erase-buffer)
8520 (let ((buf-contents
8521 (with-anything-current-buffer
8522 (if (anything-region-active-p)
8523 (buffer-substring (region-beginning) (region-end))
8524 (buffer-substring (point-min) (point-max))))))
8525 (insert buf-contents))))
8527 (defun anything-c-occur-get-line (s e)
8528 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8530 (defun anything-c-occur-query-replace-regexp (candidate)
8531 "Query replace regexp starting from CANDIDATE.
8532 If region is active ignore CANDIDATE and replace only in region.
8533 With a prefix arg replace only matches surrounded by word boundaries,
8534 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8535 (let ((regexp anything-input))
8536 (unless (anything-region-active-p)
8537 (anything-c-action-line-goto candidate))
8538 (apply 'query-replace-regexp
8539 (anything-c-query-replace-args regexp))))
8541 (defvar anything-c-source-occur
8542 '((name . "Occur")
8543 (init . anything-c-occur-init)
8544 (candidates-in-buffer)
8545 (migemo)
8546 (get-line . anything-c-occur-get-line)
8547 (display-to-real . anything-c-display-to-real-line)
8548 (action . (("Go to Line" . anything-c-action-line-goto)
8549 ("Query replace regexp (C-u Not inside word.)"
8550 . anything-c-occur-query-replace-regexp)))
8551 (recenter)
8552 (requires-pattern . 1)
8553 (delayed)
8554 (volatile)))
8555 ;; (anything 'anything-c-source-occur)
8558 ;;; Anything browse code.
8559 (defun anything-c-browse-code-get-line (beg end)
8560 "Select line if it match the regexp corresponding to current `major-mode'.
8561 Line is parsed for BEG position to END position."
8562 (let ((str-line (buffer-substring beg end))
8563 (regexp (assoc-default major-mode
8564 anything-c-browse-code-regexp-alist))
8565 (num-line (if (string= anything-pattern "") beg (1- beg))))
8566 (when (and regexp (string-match regexp str-line))
8567 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8570 (defvar anything-c-source-browse-code
8571 '((name . "Browse code")
8572 (init . (lambda ()
8573 (anything-candidate-buffer anything-current-buffer)
8574 (with-anything-current-buffer
8575 (jit-lock-fontify-now))))
8576 (candidate-number-limit . 9999)
8577 (candidates-in-buffer)
8578 (get-line . anything-c-browse-code-get-line)
8579 (type . line)
8580 (recenter)))
8583 ;; Do many actions for input
8584 (defvar anything-c-source-create
8585 '((name . "Create")
8586 (dummy)
8587 (action)
8588 (action-transformer . anything-create--actions))
8589 "Do many create actions from `anything-pattern'.
8590 See also `anything-create--actions'.")
8591 ;; (anything 'anything-c-source-create)
8593 (defun anything-create-from-anything ()
8594 "Run `anything-create' from `anything' as a fallback."
8595 (interactive)
8596 (anything-run-after-quit 'anything-create nil anything-pattern))
8598 (defun anything-create--actions (&rest ignored)
8599 "Default actions for `anything-create' / `anything-c-source-create'."
8600 (remove-if-not
8601 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8602 (append anything-create--actions-private
8603 '(("find-file" . find-file)
8604 ("find-file other window" . find-file-other-window)
8605 ("New buffer" . anything-c-switch-to-buffer)
8606 ("New buffer other window" . switch-to-buffer-other-window)
8607 ("Bookmark Set" . bookmark-set)
8608 ("Set Register" .
8609 (lambda (x) (set-register (read-char "Register: ") x)))
8610 ("Insert Linkd star" . linkd-insert-star)
8611 ("Insert Linkd Tag" . linkd-insert-tag)
8612 ("Insert Linkd Link" . linkd-insert-link)
8613 ("Insert Linkd Lisp" . linkd-insert-lisp)
8614 ("Insert Linkd Wiki" . linkd-insert-wiki)
8615 ("Google Search" . google)))))
8618 ;; Minibuffer History
8621 (defvar anything-c-source-minibuffer-history
8622 '((name . "Minibuffer History")
8623 (header-name . (lambda (name)
8624 (format "%s (%s)" name minibuffer-history-variable)))
8625 (candidates
8626 . (lambda ()
8627 (let ((history (loop
8628 for i in (symbol-value minibuffer-history-variable)
8629 unless (string= "" i) collect i)))
8630 (if (consp (car history))
8631 (mapcar 'prin1-to-string history)
8632 history))))
8633 (migemo)
8634 (action . insert)))
8635 ;; (anything 'anything-c-source-minibuffer-history)
8638 ;;; Elscreen
8641 (defvar anything-c-source-elscreen
8642 '((name . "Elscreen")
8643 (candidates . (lambda ()
8644 (if (cdr (elscreen-get-screen-to-name-alist))
8645 (sort
8646 (loop for sname in (elscreen-get-screen-to-name-alist)
8647 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8648 finally (return lst))
8649 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8650 (action . (("Change Screen".
8651 (lambda (candidate)
8652 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8653 ("Kill Screen(s)".
8654 (lambda (candidate)
8655 (dolist (i (anything-marked-candidates))
8656 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8657 (elscreen-kill))))
8658 ("Only Screen".
8659 (lambda (candidate)
8660 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8661 (elscreen-kill-others)))))))
8662 ;; (anything 'anything-c-source-elscreen)
8665 ;;;; <System>
8667 ;;; Top (process)
8668 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8669 "Top command (batch mode). %s is replaced with `frame-width'.")
8670 (defvar anything-c-source-top
8671 '((name . "Top (Press C-c C-u to refresh)")
8672 (init . anything-c-top-init)
8673 (candidates-in-buffer)
8674 (display-to-real . anything-c-top-display-to-real)
8675 (update . anything-c-top-update)
8676 (persistent-action . anything-c-top-sh-persistent-action)
8677 (persistent-help . "SIGTERM")
8678 (action
8679 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8680 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8681 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8682 ;; (anything 'anything-c-source-top)
8684 (defun anything-c-top-sh (cmd)
8685 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8687 (defun anything-c-top-sh-persistent-action (pid)
8688 (delete-other-windows)
8689 (anything-c-top-sh (format "kill -TERM %s" pid))
8690 (anything-force-update))
8692 (defun anything-c-top-init ()
8693 (with-current-buffer (anything-candidate-buffer 'global)
8694 (call-process-shell-command
8695 (format anything-c-top-command
8696 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8697 nil (current-buffer))))
8699 (defun anything-c-top-display-to-real (line)
8700 (car (split-string line)))
8702 (defun anything-c-top-update ()
8703 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8704 (anything-c-top-init)))
8706 ;;; Timers
8707 (defvar anything-c-source-absolute-time-timers
8708 '((name . "Absolute Time Timers")
8709 (candidates . timer-list)
8710 (type . timer)))
8711 ;; (anything 'anything-c-source-absolute-time-timers)
8713 (defvar anything-c-source-idle-time-timers
8714 '((name . "Idle Time Timers")
8715 (candidates . timer-idle-list)
8716 (type . timer)))
8717 ;; (anything 'anything-c-source-idle-time-timers)
8719 (defun anything-c-timer-real-to-display (timer)
8720 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8721 (append timer nil) ;use `append' to convert vector->list
8722 (format "%s repeat=%5S %s(%s)"
8723 (let ((time (list t1 t2 t3)))
8724 (if idle-delay
8725 (format-time-string "idle-for=%5s" time)
8726 (format-time-string "%m/%d %T" time)))
8727 repeat-delay
8728 func
8729 (mapconcat 'prin1-to-string args " "))))
8731 ;;; X RandR resolution change
8732 ;;; FIXME I do not care multi-display.
8733 (defvar anything-c-xrandr-output "VGA")
8734 (defvar anything-c-xrandr-screen "0")
8735 (defvar anything-c-source-xrandr-change-resolution
8736 '((name . "Change Resolution")
8737 (candidates
8738 . (lambda ()
8739 (with-temp-buffer
8740 (call-process "xrandr" nil (current-buffer) nil
8741 "--screen" anything-c-xrandr-screen "-q")
8742 (goto-char 1)
8743 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8744 collect (match-string 1)))))
8745 (action
8746 ("Change Resolution" . (lambda (mode)
8747 (call-process "xrandr" nil nil nil
8748 "--screen" anything-c-xrandr-screen
8749 "--output" anything-c-xrandr-output
8750 "--mode" mode))))))
8751 ;; (anything 'anything-c-source-xrandr-change-resolution)
8753 ;;; Xfont selection
8756 (defun anything-c-persistent-xfont-action (elm)
8757 "Show current font temporarily"
8758 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8759 (default-font elm))
8760 (unwind-protect
8761 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8762 (set-frame-font current-font))))
8764 (defvar anything-c-xfonts-cache nil)
8765 (defvar anything-c-source-xfonts
8766 '((name . "X Fonts")
8767 (init . (lambda ()
8768 (unless anything-c-xfonts-cache
8769 (setq anything-c-xfonts-cache
8770 (x-list-fonts "*")))))
8771 (candidates . anything-c-xfonts-cache)
8772 (action . (("Copy to kill ring" . (lambda (elm)
8773 (kill-new elm)))
8774 ("Set Font" . (lambda (elm)
8775 (kill-new elm)
8776 (set-frame-font elm 'keep-size)
8777 (message "New font have been copied to kill ring")))))
8778 (persistent-action . anything-c-persistent-xfont-action)
8779 (persistent-help . "Switch to this font temporarily")))
8780 ;; (anything 'anything-c-source-xfonts)
8782 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8785 (defvar anything-c-ucs-max-len 0)
8786 (defun anything-c-calculate-ucs-max-len ()
8787 "Calculate the length of longest `ucs-names' candidate."
8788 (loop with count = 0
8789 for (n . v) in (ucs-names)
8790 for len = (length n)
8791 if (> len count)
8792 do (setq count len)
8793 finally return count))
8795 (defun anything-c-ucs-init ()
8796 "Initialize an anything buffer with ucs symbols.
8797 Only math* symbols are collected."
8798 (unless (> anything-c-ucs-max-len 0)
8799 (setq anything-c-ucs-max-len
8800 (anything-c-calculate-ucs-max-len)))
8801 (with-current-buffer (anything-candidate-buffer
8802 (get-buffer-create "*anything ucs*"))
8803 ;; `ucs-names' fn will not run again, data is cached in
8804 ;; var `ucs-names'.
8805 (loop for (n . v) in (ucs-names)
8806 for len = (length n)
8807 for diff = (+ (- anything-c-ucs-max-len len) 2)
8808 unless (string= "" n)
8809 do (progn (insert (concat
8810 n ":"
8811 (make-string
8812 diff ? )))
8813 (ucs-insert v)
8814 (insert "\n")))))
8816 (defun anything-c-ucs-forward-char (candidate)
8817 (with-anything-current-buffer
8818 (forward-char 1)))
8820 (defun anything-c-ucs-backward-char (candidate)
8821 (with-anything-current-buffer
8822 (forward-char -1)))
8824 (defun anything-c-ucs-delete-backward (candidate)
8825 (with-anything-current-buffer
8826 (delete-char -1)))
8828 (defun anything-c-ucs-insert-char (candidate)
8829 (with-anything-current-buffer
8830 (insert
8831 (replace-regexp-in-string
8832 " " ""
8833 (cadr (split-string candidate ":"))))))
8835 (defun anything-c-ucs-persistent-insert ()
8836 (interactive)
8837 (anything-execute-persistent-action 'action-insert))
8839 (defun anything-c-ucs-persistent-forward ()
8840 (interactive)
8841 (anything-execute-persistent-action 'action-forward))
8843 (defun anything-c-ucs-persistent-backward ()
8844 (interactive)
8845 (anything-execute-persistent-action 'action-back))
8847 (defun anything-c-ucs-persistent-delete ()
8848 (interactive)
8849 (anything-execute-persistent-action 'action-delete))
8851 (defvar anything-c-source-ucs
8852 '((name . "Ucs names")
8853 (init . anything-c-ucs-init)
8854 (candidate-number-limit . 9999)
8855 (candidates-in-buffer)
8856 (mode-line . anything-c-ucs-mode-line-string)
8857 (action-insert . anything-c-ucs-insert-char)
8858 (action-forward . anything-c-ucs-forward-char)
8859 (action-back . anything-c-ucs-backward-char)
8860 (action-delete . anything-c-ucs-delete-backward)
8861 (action . (("Insert" . anything-c-ucs-insert-char)
8862 ("Forward char" . anything-c-ucs-forward-char)
8863 ("Backward char" . anything-c-ucs-backward-char)
8864 ("Delete char backward" . anything-c-ucs-delete-backward))))
8865 "Source for collecting `ucs-names' math symbols.")
8868 ;;; Emacs process
8871 (defvar anything-c-source-emacs-process
8872 '((name . "Emacs Process")
8873 (candidates . (lambda () (mapcar #'process-name (process-list))))
8874 (persistent-action . (lambda (elm)
8875 (delete-process (get-process elm))
8876 (anything-delete-current-selection)))
8877 (persistent-help . "Kill Process")
8878 (action ("Kill Process" . (lambda (elm)
8879 (delete-process (get-process elm)))))))
8880 ;; (anything 'anything-c-source-emacs-process)
8882 ;;; World time
8885 (defvar anything-c-source-time-world
8886 '((name . "Time World List")
8887 (init . (lambda ()
8888 (let ((anything-buffer (anything-candidate-buffer 'global)))
8889 (with-current-buffer anything-buffer
8890 (display-time-world-display display-time-world-list)))))
8891 (candidates-in-buffer)))
8895 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8898 (defvar anything-c-source-apt
8899 '((name . "APT")
8900 (init . anything-c-apt-init)
8901 (candidates-in-buffer)
8902 (candidate-transformer anything-c-apt-candidate-transformer)
8903 (display-to-real . anything-c-apt-display-to-real)
8904 (requires-pattern . 2)
8905 (delayed)
8906 (action
8907 ("Show package description" . anything-c-apt-cache-show)
8908 ("Install package" . anything-c-apt-install)
8909 ("Remove package" . anything-c-apt-uninstall)
8910 ("Purge package" . anything-c-apt-purge))
8911 (persistent-action . anything-c-apt-persistent-action)
8912 (persistent-help . "Show - C-u Refresh")))
8913 ;; (anything 'anything-c-source-apt)
8915 (defvar anything-c-apt-query "emacs")
8916 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8917 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8918 (defvar anything-c-apt-installed-packages nil)
8919 (defvar anything-c-apt-all-packages nil)
8922 (defun anything-c-apt-refresh ()
8923 "Refresh installed candidates list."
8924 (setq anything-c-apt-installed-packages nil)
8925 (setq anything-c-apt-all-packages nil)
8926 (anything-force-update))
8928 (defun anything-c-apt-persistent-action (candidate)
8929 "Persistent action for APT source."
8930 (if current-prefix-arg
8931 (anything-c-apt-refresh)
8932 (anything-c-apt-cache-show candidate)))
8934 (defun anything-c-apt-candidate-transformer (candidates)
8935 "Show installed candidates in a different color."
8936 (loop
8937 with all
8938 for cand in candidates
8939 for name = (anything-c-apt-display-to-real cand)
8940 if (member name anything-c-apt-installed-packages)
8941 collect (propertize cand 'face 'anything-apt-installed) into all
8942 else collect cand into all finally return all))
8944 (defun anything-c-apt-init ()
8945 "Initialize list of debian packages."
8946 (let ((query ""))
8947 (unless (and anything-c-apt-installed-packages
8948 anything-c-apt-all-packages)
8949 (message "Loading package list...")
8950 (setq anything-c-apt-installed-packages
8951 (with-temp-buffer
8952 (call-process-shell-command "dpkg --get-selections"
8953 nil (current-buffer))
8954 (loop for i in (split-string (buffer-string) "\n" t)
8955 collect (car (split-string i)))))
8956 (setq anything-c-apt-all-packages
8957 (with-current-buffer
8958 (anything-candidate-buffer
8959 (get-buffer-create (format "*anything-apt*")))
8960 (erase-buffer)
8961 (call-process-shell-command
8962 (format anything-c-apt-search-command query)
8963 nil (current-buffer))))
8964 (message "Loading package list done")
8965 (sit-for 0.5))))
8967 (defun anything-c-apt-display-to-real (line)
8968 "Return only name of a debian package.
8969 LINE is displayed like:
8970 package name - description."
8971 (car (split-string line " - ")))
8973 (defun anything-c-shell-command-if-needed (command)
8974 "Run shell command COMMAND to describe package.
8975 If a buffer named COMMAND already exists, just switch to it."
8976 (let ((buf (get-buffer command)))
8977 (anything-c-switch-to-buffer (get-buffer-create command))
8978 (unless buf (insert (shell-command-to-string command)))))
8980 (defun anything-c-apt-cache-show (package)
8981 "Show information on apt package PACKAGE."
8982 (anything-c-shell-command-if-needed
8983 (format anything-c-apt-show-command package)))
8985 (defun anything-c-apt-install (package)
8986 "Run 'apt-get install' shell command on PACKAGE."
8987 (anything-c-apt-generic-action :action 'install))
8989 (defun anything-c-apt-uninstall (package)
8990 "Run 'apt-get remove' shell command on PACKAGE."
8991 (anything-c-apt-generic-action :action 'uninstall))
8993 (defun anything-c-apt-purge (package)
8994 "Run 'apt-get purge' shell command on PACKAGE."
8995 (anything-c-apt-generic-action :action 'purge))
8997 (defun* anything-c-apt-generic-action (&key action)
8998 "Run 'apt-get ACTION'.
8999 Support install, remove and purge actions."
9000 (ansi-term (getenv "SHELL") "anything apt")
9001 (term-line-mode)
9002 (let ((command (case action
9003 ('install "sudo apt-get install ")
9004 ('uninstall "sudo apt-get remove ")
9005 ('purge "sudo apt-get purge ")
9006 (t (error "Unknow action"))))
9007 (beg (point))
9009 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9010 (anything-marked-candidates) " ")))
9011 (goto-char (point-max))
9012 (insert (concat command cand-list))
9013 (setq end (point))
9014 (if (y-or-n-p (format "%s package" (symbol-name action)))
9015 (progn
9016 (setq anything-c-external-commands-list nil)
9017 (setq anything-c-apt-installed-packages nil)
9018 (term-char-mode) (term-send-input))
9019 (delete-region beg end) (term-send-eof) (kill-buffer))))
9021 ;; (anything-c-apt-install "jed")
9024 ;;; Anything UI for gentoo portage.
9027 (defvar anything-c-gentoo-use-flags nil)
9028 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9029 (defvar anything-c-cache-gentoo nil)
9030 (defvar anything-c-cache-world nil)
9031 (defvar anything-c-source-gentoo
9032 '((name . "Portage sources")
9033 (init . (lambda ()
9034 (get-buffer-create anything-c-gentoo-buffer)
9035 (unless anything-c-cache-gentoo
9036 (anything-c-gentoo-setup-cache))
9037 (unless anything-c-cache-world
9038 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9039 (anything-c-gentoo-init-list)))
9040 (candidates-in-buffer)
9041 (match . identity)
9042 (candidate-transformer anything-c-highlight-world)
9043 (action . (("Show package" . (lambda (elm)
9044 (anything-c-gentoo-eshell-action elm "eix")))
9045 ("Show history" . (lambda (elm)
9046 (if (member elm anything-c-cache-world)
9047 (anything-c-gentoo-eshell-action elm "genlop -qe")
9048 (message "No infos on packages not yet installed"))))
9049 ("Copy in kill-ring" . kill-new)
9050 ("insert at point" . insert)
9051 ("Browse HomePage" . (lambda (elm)
9052 (let ((urls (anything-c-gentoo-get-url elm)))
9053 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9054 ("Show extra infos" . (lambda (elm)
9055 (if (member elm anything-c-cache-world)
9056 (anything-c-gentoo-eshell-action elm "genlop -qi")
9057 (message "No infos on packages not yet installed"))))
9058 ("Show use flags" . (lambda (elm)
9059 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9060 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9061 (font-lock-mode 1)))
9062 ("Run emerge pretend" . (lambda (elm)
9063 (anything-c-gentoo-eshell-action elm "emerge -p")))
9064 ("Emerge" . (lambda (elm)
9065 (anything-gentoo-install elm :action 'install)))
9066 ("Unmerge" . (lambda (elm)
9067 (anything-gentoo-install elm :action 'uninstall)))
9068 ("Show dependencies" . (lambda (elm)
9069 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9070 ("Show related files" . (lambda (elm)
9071 (anything-c-gentoo-default-action elm "equery" "files")))
9072 ("Refresh" . (lambda (elm)
9073 (anything-c-gentoo-setup-cache)
9074 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9076 ;; (anything 'anything-c-source-gentoo)
9078 (defun* anything-gentoo-install (candidate &key action)
9079 (setq anything-c-external-commands-list nil)
9080 (ansi-term (getenv "SHELL") "Gentoo emerge")
9081 (term-line-mode)
9082 (let ((command (case action
9083 ('install "sudo emerge -av ")
9084 ('uninstall "sudo emerge -avC ")
9085 (t (error "Unknow action"))))
9086 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9087 (beg (point)) end)
9088 (goto-char (point-max))
9089 (insert (concat command elms))
9090 (setq end (point))
9091 (term-char-mode) (term-send-input)))
9093 (defun anything-c-gentoo-default-action (elm command &rest args)
9094 "Gentoo default action that use `anything-c-gentoo-buffer'."
9095 (if (member elm anything-c-cache-world)
9096 (progn
9097 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9098 (erase-buffer)
9099 (let ((com-list (append args (list elm))))
9100 (apply #'call-process command nil t nil
9101 com-list)))
9102 (message "No infos on packages not yet installed")))
9104 (defvar anything-c-source-use-flags
9105 '((name . "Use Flags")
9106 (init . (lambda ()
9107 (unless anything-c-gentoo-use-flags
9108 (anything-c-gentoo-setup-use-flags-cache))
9109 (anything-c-gentoo-get-use)))
9110 (candidates-in-buffer)
9111 (match . identity)
9112 (candidate-transformer anything-c-highlight-local-use)
9113 (action . (("Description"
9114 . (lambda (elm)
9115 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9116 (erase-buffer)
9117 (apply #'call-process "euse" nil t nil
9118 `("-i"
9119 ,elm))
9120 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9121 (font-lock-mode 1)))
9122 ("Enable"
9123 . (lambda (elm)
9124 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9125 ("Disable"
9126 . (lambda (elm)
9127 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9128 ("Remove"
9129 . (lambda (elm)
9130 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9131 ("Show which dep use this flag"
9132 . (lambda (elm)
9133 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9134 (erase-buffer)
9135 (apply #'call-process "equery" nil t nil
9136 `("-C"
9138 ,elm))))))))
9141 ;; (anything 'anything-c-source-use-flags)
9143 (defun anything-c-gentoo-init-list ()
9144 "Initialize buffer with all packages in Portage."
9145 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9146 (buf (anything-candidate-buffer 'portage-buf)))
9147 (with-current-buffer buf
9148 (dolist (i anything-c-cache-gentoo)
9149 (insert (concat i "\n"))))))
9151 (defun anything-c-gentoo-setup-cache ()
9152 "Set up `anything-c-cache-gentoo'"
9153 (setq anything-c-cache-gentoo
9154 (split-string (with-temp-buffer
9155 (call-process "eix" nil t nil
9156 "--only-names")
9157 (buffer-string)))))
9159 (defun anything-c-gentoo-eshell-action (elm command)
9160 (when (get-buffer "*EShell Command Output*")
9161 (kill-buffer "*EShell Command Output*"))
9162 (message "Wait searching...")
9163 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9164 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9165 (progn
9166 (save-window-excursion
9167 (pop-to-buffer "*scratch*")
9168 (eshell-command (format "%s %s" command elm)))
9169 (pop-to-buffer "*EShell Command Output*"))
9170 (eshell-command (format "%s %s" command elm)))))
9172 (defun anything-c-gentoo-get-use ()
9173 "Initialize buffer with all use flags."
9174 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9175 (buf (anything-candidate-buffer 'use-buf)))
9176 (with-current-buffer buf
9177 (dolist (i anything-c-gentoo-use-flags)
9178 (insert (concat i "\n"))))))
9181 (defun anything-c-gentoo-setup-use-flags-cache ()
9182 "Setup `anything-c-gentoo-use-flags'"
9183 (setq anything-c-gentoo-use-flags
9184 (split-string (with-temp-buffer
9185 (call-process "eix" nil t nil
9186 "--print-all-useflags")
9187 (buffer-string)))))
9189 (defun anything-c-gentoo-get-url (elm)
9190 "Return a list of urls from eix output."
9191 (loop
9192 with url-list = (split-string
9193 (with-temp-buffer
9194 (call-process "eix" nil t nil
9195 elm "--format" "<homepage>\n")
9196 (buffer-string)))
9197 with all
9198 for i in url-list
9199 when (and (string-match "^http://.*" i)
9200 (not (member i all)))
9201 collect i into all
9202 finally return all))
9204 (defun anything-c-gentoo-get-world ()
9205 "Return list of all installed package on your system."
9206 (split-string (with-temp-buffer
9207 (call-process "qlist" nil t nil
9208 "-I")
9209 (buffer-string))))
9211 (defun anything-c-gentoo-get-local-use ()
9212 (split-string (with-temp-buffer
9213 (call-process "portageq" nil t nil
9214 "envvar"
9215 "USE")
9216 (buffer-string))))
9219 (defun anything-c-highlight-world (eix)
9220 "Highlight all installed package."
9221 (loop for i in eix
9222 if (member i anything-c-cache-world)
9223 collect (propertize i 'face 'anything-gentoo-match-face)
9224 else
9225 collect i))
9227 (defun anything-c-highlight-local-use (use-flags)
9228 (let ((local-uses (anything-c-gentoo-get-local-use)))
9229 (loop for i in use-flags
9230 if (member i local-uses)
9231 collect (propertize i 'face 'anything-gentoo-match-face)
9232 else
9233 collect i)))
9237 ;;; Anything ratpoison UI
9240 (defvar anything-c-source-ratpoison-commands
9241 '((name . "Ratpoison Commands")
9242 (init . anything-c-ratpoison-commands-init)
9243 (candidates-in-buffer)
9244 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9245 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9246 (candidate-number-limit)))
9247 ;; (anything 'anything-c-source-ratpoison-commands)
9249 (defun anything-c-ratpoison-commands-init ()
9250 (unless (anything-candidate-buffer)
9251 (with-current-buffer (anything-candidate-buffer 'global)
9252 ;; with ratpoison prefix key
9253 (save-excursion
9254 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9255 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9256 (replace-match "<ratpoison> \\1: \\2"))
9257 (goto-char (point-max))
9258 ;; direct binding
9259 (save-excursion
9260 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9261 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9262 (replace-match "\\1: \\2")))))
9264 (defun anything-c-ratpoison-commands-display-to-real (display)
9265 (and (string-match ": " display)
9266 (substring display (match-end 0))))
9268 (defun anything-c-ratpoison-commands-execute (candidate)
9269 (call-process "ratpoison" nil nil nil "-ic" candidate))
9273 ;;; Anything `completing-read' replacement
9276 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9277 "Convert COLLECTION to list removing elements that don't match TEST.
9278 See `anything-comp-read' about supported COLLECTION arguments.
9280 SORT-FN is a predicate to sort COLLECTION.
9282 ALISTP when non--nil will not use `all-completions' to collect
9283 candidates because it doesn't handle alists correctly for anything.
9284 i.e In `all-completions' the keys \(cars of elements\)
9285 are the possible completions. In anything we want to use the cdr instead
9286 like \(display . real\).
9287 See docstring of `all-completions' for more info.
9289 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9290 (let ((cands
9291 (cond ((and (eq collection obarray) test)
9292 (all-completions "" collection test))
9293 ((and (vectorp collection) test)
9294 (loop for i across collection when (funcall test i) collect i))
9295 ((vectorp collection)
9296 (loop for i across collection collect i))
9297 ((and alistp test)
9298 (loop for i in collection when (funcall test i) collect i))
9299 (alistp collection)
9300 ((and collection test)
9301 (all-completions "" collection test))
9302 (t (all-completions "" collection)))))
9303 (if sort-fn (sort cands sort-fn) cands)))
9305 (defun anything-cr-default-transformer (candidates source)
9306 "Default filter candidate function for `anything-comp-read'.
9307 Do nothing, just return candidate list unmodified."
9308 candidates)
9310 (defun* anything-comp-read (prompt collection
9311 &key
9312 test
9313 initial-input
9314 default
9315 preselect
9316 (buffer "*Anything Completions*")
9317 must-match
9318 (requires-pattern 0)
9319 (history nil)
9320 (persistent-action nil)
9321 (persistent-help "DoNothing")
9322 (name "Anything Completions")
9323 (volatile t)
9324 sort
9325 (fc-transformer 'anything-cr-default-transformer)
9326 (marked-candidates nil)
9327 (alistp t))
9328 "Anything `completing-read' emulation.
9329 PROMPT is the prompt name to use.
9330 COLLECTION can be a list, vector, obarray or hash-table.
9331 It can be also a function that receives three arguments:
9332 the values string, predicate and t. See `all-completions' for more details.
9334 Keys description:
9336 TEST: A predicate called with one arg i.e candidate.
9337 INITIAL-INPUT: Same as initial-input arg in `anything'.
9338 PRESELECT: See preselect arg of `anything'.
9339 DEFAULT: This option is used only for compatibility with regular
9340 Emacs `completing-read'.
9341 BUFFER: Name of anything-buffer.
9342 MUST-MATCH: Candidate selected must be one of COLLECTION.
9343 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9344 HISTORY: A list containing specific history, default is nil.
9345 When it is non--nil, all elements of HISTORY are displayed in
9346 a special source before COLLECTION.
9347 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9348 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9349 NAME: The name related to this local source.
9350 VOLATILE: Use volatile attribute \(enabled by default\).
9351 SORT: A predicate to give to `sort' e.g `string-lessp'.
9352 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9353 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9354 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9356 Any prefix args passed during `anything-comp-read' invocation will be recorded
9357 in `anything-current-prefix-arg', otherwise if prefix args where given before
9358 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9359 That's mean you can pass prefix args before or after calling a command
9360 that use `anything-comp-read' See `anything-M-x' for example."
9361 (when (get-buffer anything-action-buffer)
9362 (kill-buffer anything-action-buffer))
9363 (flet ((action-fn (candidate)
9364 (if marked-candidates
9365 (anything-marked-candidates)
9366 (identity candidate))))
9367 (let ((hist `((name . ,(format "%s History" name))
9368 (candidates
9369 . (lambda ()
9370 (let ((all (anything-comp-read-get-candidates
9371 history nil nil ,alistp)))
9372 (anything-fast-remove-dups
9373 (if (and default (not (string= default "")))
9374 (delq nil (cons default (delete default all)))
9375 all)
9376 :test 'equal))))
9377 (filtered-candidate-transformer
9378 . (lambda (candidates sources)
9379 (loop for i in candidates
9380 do (set-text-properties 0 (length i) nil i)
9381 collect i)))
9382 (persistent-action . ,persistent-action)
9383 (persistent-help . ,persistent-help)
9384 (action . ,'action-fn)))
9385 (src `((name . ,name)
9386 (candidates
9387 . (lambda ()
9388 (let ((cands (anything-comp-read-get-candidates
9389 collection test sort alistp)))
9390 (unless (or must-match (string= anything-pattern ""))
9391 (setq cands (append (list anything-pattern) cands)))
9392 (if (and default (not (string= default "")))
9393 (delq nil (cons default (delete default cands)))
9394 cands))))
9395 (filtered-candidate-transformer ,fc-transformer)
9396 (requires-pattern . ,requires-pattern)
9397 (persistent-action . ,persistent-action)
9398 (persistent-help . ,persistent-help)
9399 (action . ,'action-fn))))
9400 (when volatile (setq src (append src '((volatile)))))
9401 (or (anything
9402 :sources `(,hist ,src)
9403 :input initial-input
9404 :default default
9405 :preselect preselect
9406 :prompt prompt
9407 :resume 'noresume
9408 :buffer buffer)
9409 (keyboard-quit)))))
9411 ;; Generic completing-read
9413 ;; Support also function as collection.
9414 ;; e.g M-x man is supported.
9415 ;; Support hash-table and vectors as collection.
9416 ;; NOTE:
9417 ;; Some crap emacs functions may not be supported
9418 ;; like ffap-alternate-file (bad use of completing-read)
9419 ;; and maybe others.
9420 ;; Provide a mode `anything-completion-mode' which turn on
9421 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9423 (defvar anything-completion-mode-string " AC")
9425 (defvar anything-completion-mode-quit-message
9426 "Anything completion disabled")
9428 (defvar anything-completion-mode-start-message
9429 "Anything completion enabled")
9431 ;;; Specialized handlers
9434 (defun anything-completing-read-symbols
9435 (prompt collection test require-match init
9436 hist default inherit-input-method name buffer)
9437 "Specialized function for fast symbols completion in `ac-mode'."
9439 (anything
9440 :sources `((name . ,name)
9441 (init . (lambda ()
9442 (with-current-buffer (anything-candidate-buffer 'global)
9443 (goto-char (point-min))
9444 (when (and default (stringp default)
9445 ;; Some defaults args result as
9446 ;; (symbol-name nil) == "nil".
9447 ;; e.g debug-on-entry.
9448 (not (string= default "nil")))
9449 (insert (concat default "\n")))
9450 (loop with all = (all-completions "" collection test)
9451 for sym in all
9452 unless (and default (eq sym default))
9453 do (insert (concat sym "\n"))))))
9454 (persistent-action . anything-lisp-completion-persistent-action)
9455 (persistent-help . "Show brief doc in mode-line")
9456 (candidates-in-buffer)
9457 (action . identity))
9458 :prompt prompt
9459 :buffer buffer
9460 :input init
9461 :resume 'noresume
9462 :default (or default ""))
9463 (keyboard-quit)))
9466 ;;; Generic completing read
9469 (defun anything-completing-read-default-1
9470 (prompt collection test require-match
9471 init hist default inherit-input-method
9472 name buffer)
9473 (anything-comp-read
9474 prompt collection
9475 :test test
9476 :fc-transformer #'(lambda (candidates source)
9477 ;; In regular `completing-read'
9478 ;; when a candidate is a cons cell
9479 ;; the car is used. Anything use
9480 ;; normally the cdr, so modify that
9481 ;; to fit `completing-read'.
9482 (loop for i in candidates
9483 for cand = (if (consp i) (car i) i)
9484 do (set-text-properties 0 (length cand) nil cand)
9485 collect cand))
9486 :history (eval (or (car-safe hist) hist))
9487 :must-match require-match
9488 :alistp nil
9489 :name name
9490 :buffer buffer
9491 ;; If DEF is not provided, fallback to empty string
9492 ;; to avoid `thing-at-point' to be appended on top of list
9493 :default (or default "")
9494 :initial-input init))
9496 (defun* anything-completing-read-default
9497 (prompt collection &optional
9498 predicate require-match
9499 initial-input hist def
9500 inherit-input-method)
9501 "An anything replacement of `completing-read'.
9502 This function should be used only as a `completing-read-function'.
9504 Don't use it directly, use instead `anything-comp-read' in your programs \
9505 which is more powerful.
9507 See documentation of `completing-read' and `all-completions' for details."
9508 (declare (special anything-completion-mode))
9509 (let* ((current-command this-command)
9510 (str-command (symbol-name current-command))
9511 (buf-name (format "*ac-mode-%s*" str-command))
9512 (entry (assq current-command
9513 anything-completing-read-handlers-alist))
9514 (def-com (cdr-safe entry))
9515 (str-defcom (and def-com (symbol-name def-com)))
9516 (def-args (list prompt collection predicate require-match
9517 initial-input hist def inherit-input-method))
9518 ;; Append the two extra args needed to set the buffer and source name
9519 ;; in anything specialized functions.
9520 (any-args (append def-args (list str-command buf-name)))
9521 anything-completion-mode-start-message ; Be quiet
9522 anything-completion-mode-quit-message)
9523 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9524 (unless (or (not entry) def-com)
9525 ;; An entry in *read-handlers-alist exists but have
9526 ;; a nil value, so we exit from here, disable `ac-mode'
9527 ;; and run the command again with it original behavior.
9528 ;; `ac-mode' will be restored on exit.
9529 (return-from anything-completing-read-default
9530 (unwind-protect
9531 (progn
9532 (ac-mode -1)
9533 (call-interactively current-command))
9534 (ac-mode 1))))
9535 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9536 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9537 (when (or (eq def-com 'completing-read)
9538 ;; All specialized functions are prefixed by "anything"
9539 (and (stringp str-defcom)
9540 (not (string-match "^anything" str-defcom))))
9541 (ac-mode -1))
9542 (unwind-protect
9543 (cond (;; An anything specialized function exists, run it.
9544 (and def-com anything-completion-mode)
9545 (apply def-com any-args))
9546 (;; Try to handle `ido-completing-read' everywhere.
9547 (and def-com (eq def-com 'ido-completing-read))
9548 (setcar (memq collection def-args)
9549 (all-completions "" collection predicate))
9550 (apply def-com def-args))
9551 (;; User set explicitely `completing-read' or something similar
9552 ;; in *read-handlers-alist, use this with exactly the same
9553 ;; args as in `completing-read'.
9554 ;; If we are here `anything-completion-mode' is now disabled.
9555 def-com
9556 (apply def-com def-args))
9557 (t ; Fall back to classic `anything-comp-read'.
9558 (anything-completing-read-default-1
9559 prompt collection predicate require-match
9560 initial-input hist def inherit-input-method str-command buf-name)))
9561 (ac-mode 1))))
9563 (defun* anything-generic-read-file-name
9564 (prompt &optional dir default-filename mustmatch initial predicate)
9565 "An anything replacement of `read-file-name'."
9566 (declare (special anything-completion-mode))
9567 (let* ((default (and default-filename
9568 (if (listp default-filename)
9569 (car default-filename)
9570 default-filename)))
9571 (init (or default initial dir default-directory))
9572 (ini-input (and init (expand-file-name init)))
9573 (current-command this-command)
9574 (str-command (symbol-name current-command))
9575 (buf-name (format "*ac-mode-%s*" str-command))
9576 (entry (assq current-command
9577 anything-completing-read-handlers-alist))
9578 (def-com (cdr-safe entry))
9579 (str-defcom (symbol-name def-com))
9580 (def-args (list prompt dir default-filename mustmatch initial predicate))
9581 ;; Append the two extra args needed to set the buffer and source name
9582 ;; in anything specialized functions.
9583 (any-args (append def-args (list str-command buf-name)))
9584 (ido-state ido-mode)
9585 anything-completion-mode-start-message ; Be quiet
9586 anything-completion-mode-quit-message ; Same here
9587 fname)
9588 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9589 (unless (or (not entry) def-com)
9590 (return-from anything-completing-read-default
9591 (unwind-protect
9592 (progn
9593 (ac-mode -1)
9594 (call-interactively current-command))
9595 (ac-mode 1))))
9596 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9597 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9598 (when (or (eq def-com 'read-file-name)
9599 (eq def-com 'ido-read-file-name)
9600 (and (stringp str-defcom)
9601 (not (string-match "^anything" str-defcom))))
9602 (ac-mode -1))
9603 (unwind-protect
9604 (setq fname
9605 (cond (;; A specialized function exists, run it
9606 ;; with the two extra args specific to anything..
9607 (and def-com anything-completion-mode
9608 (not (eq def-com 'ido-read-file-name)))
9609 (apply def-com any-args))
9610 (;; Def-com value is `ido-read-file-name'
9611 ;; run it with default args.
9612 (and def-com (eq def-com 'ido-read-file-name))
9613 (ido-mode 1)
9614 (apply def-com def-args))
9615 (;; Def-com value is `read-file-name'
9616 ;; run it with default args.
9617 def-com
9618 (apply def-com def-args))
9619 (t ; Fall back to classic `anything-c-read-file-name'.
9620 (anything-c-read-file-name
9621 prompt
9622 :name str-command
9623 :buffer buf-name
9624 :initial-input (expand-file-name init dir)
9625 :alistp nil
9626 :test predicate))))
9627 (ac-mode 1)
9628 (ido-mode (if ido-state 1 -1)))
9629 (if (and mustmatch (not (file-exists-p fname)))
9630 (if (y-or-n-p "File does not exists, create buffer?")
9631 fname (error "Abort file does not exists"))
9632 fname)))
9634 ;;;###autoload
9635 (define-minor-mode anything-completion-mode
9636 "Toggle generic anything completion.
9638 All functions in Emacs that use `completing-read'
9639 or `read-file-name' and friends will use anything interface
9640 when this mode is turned on.
9641 However you can modify this behavior for functions of your choice
9642 with `anything-completing-read-handlers-alist'.
9644 Called with a positive arg, turn on inconditionnaly, with a
9645 negative arg turn off.
9646 You can turn it on with `ac-mode'.
9648 Some crap emacs functions may not be supported,
9649 e.g `ffap-alternate-file' and maybe others
9650 You can add such functions to `anything-completing-read-handlers-alist'
9651 with a nil value.
9653 Note: This mode will work only partially on Emacs23."
9654 :group 'anything
9655 :global t
9656 :lighter anything-completion-mode-string
9657 (declare (special completing-read-function))
9658 (if anything-completion-mode
9659 (progn
9660 (setq completing-read-function 'anything-completing-read-default
9661 read-file-name-function 'anything-generic-read-file-name)
9662 (message anything-completion-mode-start-message))
9663 (setq completing-read-function (and (fboundp 'completing-read-default)
9664 'completing-read-default)
9665 read-file-name-function (and (fboundp 'read-file-name-default)
9666 'read-file-name-default))
9667 (message anything-completion-mode-quit-message)))
9669 (defalias 'ac-mode 'anything-completion-mode)
9673 ;;; Eshell completion.
9675 ;; Enable like this in .emacs:
9677 ;; (add-hook 'eshell-mode-hook
9678 ;; #'(lambda ()
9679 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9681 (defvar anything-c-source-esh
9682 '((name . "Eshell completions")
9683 (init . (lambda ()
9684 (setq pcomplete-current-completions nil
9685 pcomplete-last-completion-raw nil)
9686 ;; Eshell-command add this hook in all minibuffers
9687 ;; Remove it for the anything one.
9688 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9689 (candidates . anything-esh-get-candidates)
9690 (action . anything-ec-insert))
9691 "Anything source for Eshell completion.")
9693 ;; Internal.
9694 (defvar anything-ec-target "")
9695 (defun anything-ec-insert (candidate)
9696 "Insert CANDIDATE at point.
9697 This is the same as `ac-insert', just inlined here for compatibility."
9698 (let ((pt (point)))
9699 (when (and anything-ec-target
9700 (search-backward anything-ec-target nil t)
9701 (string= (buffer-substring (point) pt) anything-ec-target))
9702 (delete-region (point) pt)))
9703 (insert candidate))
9705 (defun anything-esh-get-candidates ()
9706 "Get candidates for eshell completion using `pcomplete'."
9707 (catch 'pcompleted
9708 (let* ((pcomplete-stub)
9709 pcomplete-seen pcomplete-norm-func
9710 pcomplete-args pcomplete-last pcomplete-index
9711 (pcomplete-autolist pcomplete-autolist)
9712 (pcomplete-suffix-list pcomplete-suffix-list))
9713 (with-anything-current-buffer
9714 (loop
9715 with table = (pcomplete-completions)
9716 with entry = (condition-case nil
9717 ;; For Emacs24
9718 (try-completion anything-pattern (pcomplete-entries))
9719 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9720 (error
9722 (let ((fc (car (last (pcomplete-parse-arguments)))))
9723 ;; Check if last arg require fname completion.
9724 (and (file-name-directory fc) fc))))
9725 for i in (if (listp table) table ; Emacs23 or commands.
9726 (all-completions pcomplete-stub table)) ; Emacs24
9727 for file-cand = (and entry
9728 (if (file-remote-p i) i
9729 (expand-file-name i (file-name-directory entry))))
9730 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9731 collect file-cand into ls
9732 else collect i into ls
9733 finally return
9734 (if (and entry (not (string= entry "")) (file-exists-p entry))
9735 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9737 ;;; Eshell history.
9740 (defvar anything-c-source-eshell-history
9741 '((name . "Eshell history")
9742 (init . (lambda ()
9743 (let (eshell-hist-ignoredups)
9744 ;; Dump the content's of hist file
9745 ;; to `eshell-history-ring'.
9746 (eshell-read-history eshell-history-file-name)
9747 ;; And now write the content's of ring to file.
9748 (eshell-write-history eshell-history-file-name t)
9749 (with-current-buffer (anything-candidate-buffer 'global)
9750 (insert-file-contents eshell-history-file-name)))
9751 ;; Same comment as in `anything-c-source-esh'
9752 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9753 (candidates-in-buffer)
9754 (filtered-candidate-transformer . (lambda (candidates sources)
9755 (reverse candidates)))
9756 (candidate-number-limit . 9999)
9757 (action . (lambda (candidate)
9758 (eshell-kill-input)
9759 (insert candidate))))
9760 "Anything source for Eshell history.")
9763 ;;; Show completion - an alternative of anything-show-completion.el.
9765 ;; Provide show completion with macro `with-anything-show-completion'.
9768 ;; Called each time cursor move in anything-buffer.
9769 (defun anything-c-show-completion ()
9770 (with-anything-current-buffer
9771 (overlay-put anything-c-show-completion-overlay
9772 'display (anything-get-selection))))
9774 (defun anything-c-show-completion-init-overlay (beg end)
9775 (and anything-c-turn-on-show-completion
9776 (setq anything-c-show-completion-overlay (make-overlay beg end))
9777 (overlay-put anything-c-show-completion-overlay
9778 'face 'anything-lisp-show-completion)))
9780 (defmacro with-anything-show-completion (beg end &rest body)
9781 "Show anything candidate in an overlay at point.
9782 BEG and END are the beginning and end position of the current completion
9783 in `anything-current-buffer'.
9784 BODY is an anything call where we want to enable show completion.
9785 If `anything-c-turn-on-show-completion' is nil just do nothing."
9786 (declare (indent 2) (debug t))
9787 `(let ((anything-move-selection-after-hook
9788 (and anything-c-turn-on-show-completion
9789 (append (list 'anything-c-show-completion)
9790 anything-move-selection-after-hook))))
9791 (unwind-protect
9792 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9793 ,@body)
9794 (and anything-c-turn-on-show-completion
9795 (delete-overlay anything-c-show-completion-overlay)))))
9798 ;;; Lisp symbol completion.
9801 ;;;###autoload
9802 (defun anything-lisp-completion-at-point ()
9803 "Anything lisp symbol completion at point."
9804 (interactive)
9805 (let* ((data (lisp-completion-at-point))
9806 (beg (car data))
9807 (end (point)) ; 'cadr data' is wrong when no space after point.
9808 (plist (nthcdr 3 data))
9809 (pred (plist-get plist :predicate))
9810 (lgst-len 0)
9811 (target (and beg end (buffer-substring-no-properties beg end)))
9812 (candidates (all-completions target (nth 2 data) pred))
9813 (anything-quit-if-no-candidate t)
9814 (anything-execute-action-at-once-if-one t)
9815 (anything-match-plugin-enabled
9816 (member 'anything-compile-source--match-plugin
9817 anything-compile-source-functions)))
9818 (if candidates
9819 (with-anything-show-completion beg end
9820 ;; Overlay is initialized now in anything-current-buffer.
9821 (anything
9822 :sources
9823 '((name . "Lisp completion")
9824 (init . (lambda ()
9825 (with-current-buffer (anything-candidate-buffer 'global)
9826 (loop for sym in candidates
9827 for len = (length sym)
9828 when (> len lgst-len) do (setq lgst-len len)
9829 do (insert (concat sym "\n"))))))
9830 (candidates-in-buffer)
9831 (persistent-action . anything-lisp-completion-persistent-action)
9832 (persistent-help . "Show brief doc in mode-line")
9833 (filtered-candidate-transformer anything-lisp-completion-transformer)
9834 (action . (lambda (candidate)
9835 (delete-region beg end)
9836 (insert candidate))))
9837 :input (if anything-match-plugin-enabled (concat target " ") target)))
9838 (message "[No Match]"))))
9840 (defun anything-lisp-completion-persistent-action (candidate)
9841 (let ((cursor-in-echo-area t)
9842 mode-line-in-non-selected-windows)
9843 (anything-c-eldoc-show-in-mode-line
9844 (propertize
9845 (anything-c-get-first-line-documentation
9846 (intern candidate))
9847 'face 'anything-lisp-completion-info))))
9849 (defun anything-lisp-completion-transformer (candidates source)
9850 "Anything candidates transformer for lisp completion."
9851 (declare (special lgst-len))
9852 (loop for c in candidates
9853 for sym = (intern c)
9854 for annot = (cond ((commandp sym) " (Com)")
9855 ((fboundp sym) " (Fun)")
9856 ((boundp sym) " (Var)")
9857 ((facep sym) " (Face)"))
9858 for spaces = (make-string (- lgst-len (length c)) ? )
9859 collect (cons (concat c spaces annot) c)))
9861 (defun anything-c-get-first-line-documentation (sym)
9862 "Return first line documentation of symbol SYM.
9863 If SYM is not documented, return \"Not documented\"."
9864 (let ((doc (cond ((fboundp sym)
9865 (documentation sym t))
9866 ((boundp sym)
9867 (documentation-property sym 'variable-documentation t))
9868 ((facep sym)
9869 (face-documentation sym))
9870 (t nil))))
9871 (if (and doc (not (string= doc ""))
9872 ;; `documentation' return "\n\n(args...)"
9873 ;; for CL-style functions.
9874 (not (string-match-p "^\n\n" doc)))
9875 (car (split-string doc "\n"))
9876 "Not documented")))
9878 ;;; File completion.
9880 ;; Complete file name at point.
9881 (defun anything-c-thing-before-point ()
9882 "Get symbol name before point.
9883 Borrowed from anything-complete.el, inlined here for compatibility."
9884 (save-excursion
9885 (let ((beg (point)))
9886 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9887 (when (re-search-backward
9888 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9889 (buffer-substring-no-properties beg (match-end 0))))))
9891 ;;;###autoload
9892 (defun anything-c-complete-file-name-at-point ()
9893 "Complete file name at point."
9894 (interactive)
9895 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9896 (end (point))
9897 (beg (- (point) (length init)))
9898 (anything-quit-if-no-candidate t)
9899 (anything-execute-action-at-once-if-one t)
9900 completion)
9901 (with-anything-show-completion beg end
9902 (setq completion (anything-c-read-file-name "FileName: "
9903 :initial-input init)))
9904 (anything-c-insert-file-name-completion-at-point completion)))
9906 ;; Internal
9907 (defvar anything-lisp-completion-counter 0)
9908 ;;;###autoload
9909 (defun anything-lisp-completion-at-point-or-indent (arg)
9910 "First call indent and second call complete lisp symbol.
9911 The second call should happen before `anything-lisp-completion-or-indent-delay',
9912 after this delay, next call will indent again.
9913 After completion, next call is always indent.
9914 See that like click and double mouse click.
9915 One hit indent, two quick hits maybe indent and complete."
9916 (interactive "P")
9917 ;; Be sure `indent-for-tab-command' will not try
9918 ;; to use `completion-at-point'.
9919 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9920 t tab-always-indent)))
9921 (incf anything-lisp-completion-counter)
9922 (unwind-protect
9923 (if (> anything-lisp-completion-counter 1)
9924 (anything-lisp-completion-or-file-name-at-point)
9925 (indent-for-tab-command arg))
9926 ;; After `anything-lisp-completion-or-indent-delay' seconds
9927 ;; reset to 0.
9928 (run-with-timer anything-lisp-completion-or-indent-delay nil
9929 #'(lambda ()
9930 (setq anything-lisp-completion-counter 0)))
9931 ;; Always reset to 0 at second hit.
9932 (when (eq anything-lisp-completion-counter 2)
9933 (setq anything-lisp-completion-counter 0)))))
9935 ;;;###autoload
9936 (defun anything-lisp-completion-or-file-name-at-point ()
9937 "Complete lisp symbol or filename at point.
9938 Filename completion happen if filename is started in
9939 or between double quotes."
9940 (interactive)
9941 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9942 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9943 (save-excursion (search-backward "\"" (point-at-bol) t)))
9944 (anything-c-complete-file-name-at-point)
9945 (anything-lisp-completion-at-point))))
9949 ;;; Run Externals commands within Emacs with anything completion
9952 (defvar anything-external-command-history nil)
9954 (defun anything-c-external-commands-list-1 (&optional sort)
9955 "Returns a list of all external commands the user can execute.
9956 If `anything-c-external-commands-list' is non-nil it will
9957 return its contents. Else it calculates all external commands
9958 and sets `anything-c-external-commands-list'."
9959 (if anything-c-external-commands-list
9960 anything-c-external-commands-list
9961 (setq anything-c-external-commands-list
9962 (loop
9963 with paths = (split-string (getenv "PATH") path-separator)
9964 with completions = ()
9965 for dir in paths
9966 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9967 for lsdir = (loop for i in (directory-files dir t)
9968 for bn = (file-name-nondirectory i)
9969 when (and (not (member bn completions))
9970 (not (file-directory-p i))
9971 (file-executable-p i))
9972 collect bn)
9973 append lsdir into completions
9974 finally return (if sort (sort completions 'string-lessp) completions)))))
9976 (defun anything-run-or-raise (exe &optional file)
9977 "Generic command that run asynchronously EXE.
9978 If EXE is already running just jump to his window if `anything-raise-command'
9979 is non--nil.
9980 When FILE argument is provided run EXE with FILE.
9981 In this case EXE must be provided as \"EXE %s\"."
9982 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
9983 "'%s'" "" exe))))
9984 (proc (if file (concat real-com " " file) real-com)))
9985 (if (get-process proc)
9986 (if anything-raise-command
9987 (shell-command (format anything-raise-command real-com))
9988 (error "Error: %s is already running" real-com))
9989 (when (loop for i in anything-c-external-commands-list thereis real-com)
9990 (message "Starting %s..." real-com)
9991 (if file
9992 (start-process-shell-command proc nil (format exe file))
9993 (start-process-shell-command proc nil real-com))
9994 (set-process-sentinel
9995 (get-process proc)
9996 #'(lambda (process event)
9997 (when (and (string= event "finished\n")
9998 anything-raise-command
9999 (not (anything-c-get-pid-from-process-name real-com)))
10000 (shell-command (format anything-raise-command "emacs")))
10001 (message "%s process...Finished." process))))
10002 (setq anything-c-external-commands-list
10003 (cons real-com
10004 (delete real-com anything-c-external-commands-list))))))
10008 ;;; Generic action functions
10011 (defun anything-c-file-buffers (filename)
10012 "Returns a list of buffer names corresponding to FILENAME."
10013 (let ((name (expand-file-name filename))
10014 (buf-list ()))
10015 (dolist (buf (buffer-list) buf-list)
10016 (let ((bfn (buffer-file-name buf)))
10017 (when (and bfn (string= name bfn))
10018 (push (buffer-name buf) buf-list))))))
10020 (defun anything-revert-buffer (candidate)
10021 (with-current-buffer candidate
10022 (when (or (buffer-modified-p)
10023 (not (verify-visited-file-modtime
10024 (get-buffer candidate))))
10025 (revert-buffer t t))))
10027 (defun anything-revert-marked-buffers (ignore)
10028 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10030 (defun anything-kill-marked-buffers (ignore)
10031 (mapc 'kill-buffer (anything-marked-candidates)))
10033 (defun anything-c-delete-file (file)
10034 "Delete the given file after querying the user.
10035 Ask to kill buffers associated with that file, too."
10036 (let ((buffers (anything-c-file-buffers file)))
10037 (if (< emacs-major-version 24)
10038 ;; `dired-delete-file' in Emacs versions < 24
10039 ;; doesn't support delete-by-moving-to-trash
10040 ;; so use `delete-directory' and `delete-file'
10041 ;; that handle it.
10042 (cond ((and (not (file-symlink-p file))
10043 (file-directory-p file)
10044 (directory-files file t dired-re-no-dot))
10045 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10046 (delete-directory file 'recursive)))
10047 ((and (not (file-symlink-p file))
10048 (file-directory-p file))
10049 (delete-directory file))
10050 (t (delete-file file)))
10051 (dired-delete-file
10052 file 'dired-recursive-deletes delete-by-moving-to-trash))
10053 (when buffers
10054 (dolist (buf buffers)
10055 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10056 (kill-buffer buf))))))
10058 (defun anything-get-mailcap-for-file (filename)
10059 "Get the command to use for FILENAME from mailcap files.
10060 The command is like <command %s> and is meant to use with `format'."
10061 (mailcap-parse-mailcaps)
10062 (let* ((ext (file-name-extension filename))
10063 (mime (when ext (mailcap-extension-to-mime ext)))
10064 (result (when mime (mailcap-mime-info mime))))
10065 ;; If elisp file have no associations in .mailcap
10066 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10067 (when (stringp result) result)))
10069 (defun anything-get-default-program-for-file (filename)
10070 "Try to find a default program to open FILENAME.
10071 Try first in `anything-c-external-programs-associations' and then in mailcap file
10072 if nothing found return nil."
10073 (let* ((ext (file-name-extension filename))
10074 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10075 (cond ((and def-prog (not (string= def-prog "")))
10076 (concat def-prog " %s"))
10077 ((and anything-c-default-external-file-browser
10078 (file-directory-p filename))
10079 (concat anything-c-default-external-file-browser " %s"))
10080 (t (anything-get-mailcap-for-file filename)))))
10082 (defun anything-c-open-file-externally (file)
10083 "Open FILE with an external program.
10084 Try to guess which program to use with `anything-get-default-program-for-file'.
10085 If not found or a prefix arg is given query the user which tool to use."
10086 (let* ((fname (expand-file-name file))
10087 (collection (anything-c-external-commands-list-1 'sort))
10088 (def-prog (anything-get-default-program-for-file fname))
10089 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10090 ;; Prefix arg or no default program.
10091 (prog1
10092 (anything-comp-read
10093 "Program: " collection
10094 :must-match t
10095 :name "Open file Externally"
10096 :history anything-external-command-history)
10097 ;; Always prompt to set this program as default.
10098 (setq def-prog nil))
10099 ;; No prefix arg or default program exists.
10100 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10101 (program (concat real-prog-name " '%s'")))
10102 (unless (or def-prog ; Association exists, no need to record it.
10103 ;; Don't try to record non--filenames associations (e.g urls).
10104 (not (file-exists-p fname)))
10105 (when
10106 (y-or-n-p
10107 (format
10108 "Do you want to make `%s' the default program for this kind of files? "
10109 real-prog-name))
10110 (anything-aif (assoc (file-name-extension fname)
10111 anything-c-external-programs-associations)
10112 (setq anything-c-external-programs-associations
10113 (delete it anything-c-external-programs-associations)))
10114 (push (cons (file-name-extension fname)
10115 (read-string
10116 "Program (Add args maybe and confirm): " real-prog-name))
10117 anything-c-external-programs-associations)
10118 (customize-save-variable 'anything-c-external-programs-associations
10119 anything-c-external-programs-associations)))
10120 (anything-run-or-raise program file)
10121 (setq anything-external-command-history
10122 (cons real-prog-name
10123 (delete real-prog-name
10124 (loop for i in anything-external-command-history
10125 when (executable-find i) collect i))))))
10128 (defun anything-c-find-file-or-marked (candidate)
10129 "Open file CANDIDATE or open anything marked files in background."
10130 (let ((marked (anything-marked-candidates))
10131 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10132 (find-file-wildcards nil))
10133 (if (> (length marked) 1)
10134 ;; Open all marked files in background and display
10135 ;; the first one.
10136 (progn (mapc 'find-file-noselect (cdr marked))
10137 (find-file (car marked)))
10138 (if (and (not (file-exists-p candidate))
10139 (and ffap-url-regexp
10140 (not (string-match ffap-url-regexp candidate)))
10141 (string-match "/$" candidate))
10142 ;; A a non--existing filename ending with /
10143 ;; Create a directory and jump to it.
10144 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10145 (let ((dirfname (directory-file-name candidate)))
10146 (if (file-exists-p dirfname)
10147 (error "Mkdir: Unable to create directory `%s': file exists."
10148 (anything-c-basename dirfname))
10149 (make-directory candidate 'parent)))
10150 (anything-find-files-1 candidate))
10151 ;; A non--existing filename NOT ending with / or
10152 ;; an existing filename, create or jump to it.
10153 (find-file-at-point (car marked))))))
10155 (defun anything-delete-marked-files (ignore)
10156 (let* ((files (anything-marked-candidates))
10157 (len (length files)))
10158 (if (not (y-or-n-p
10159 (format "Delete *%s File(s):\n%s"
10161 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10162 (message "(No deletions performed)")
10163 (dolist (i files)
10164 (set-text-properties 0 (length i) nil i)
10165 (anything-c-delete-file i))
10166 (message "%s File(s) deleted" len))))
10168 (defun anything-ediff-marked-buffers (candidate &optional merge)
10169 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10170 With optional arg MERGE call `ediff-merge-buffers'."
10171 (let ((lg-lst (length (anything-marked-candidates)))
10172 buf1 buf2)
10173 (case lg-lst
10175 (error "Error:You have to mark at least 1 buffer"))
10177 (setq buf1 anything-current-buffer
10178 buf2 (first (anything-marked-candidates))))
10180 (setq buf1 (first (anything-marked-candidates))
10181 buf2 (second (anything-marked-candidates))))
10183 (error "Error:To much buffers marked!")))
10184 (if merge
10185 (ediff-merge-buffers buf1 buf2)
10186 (ediff-buffers buf1 buf2))))
10188 (defun anything-ediff-marked-buffers-merge (candidate)
10189 "Ediff merge `anything-current-buffer' with CANDIDATE.
10190 See `anything-ediff-marked-buffers'."
10191 (anything-ediff-marked-buffers candidate t))
10193 (defun anything-bookmark-get-bookmark-from-name (bmk)
10194 "Return bookmark name even if it is a bookmark with annotation.
10195 e.g prepended with *.
10196 Return nil if bmk is not a valid bookmark."
10197 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10198 (if (assoc bookmark bookmark-alist)
10199 bookmark
10200 (when (assoc bmk bookmark-alist)
10201 bmk))))
10203 (defun anything-delete-marked-bookmarks (ignore)
10204 "Delete this bookmark or all marked bookmarks."
10205 (dolist (i (anything-marked-candidates))
10206 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10207 'batch)))
10209 (defun anything-require-or-error (feature function)
10210 (or (require feature nil t)
10211 (error "Need %s to use `%s'." feature function)))
10213 (defun anything-find-buffer-on-elscreen (candidate)
10214 "Open buffer in new screen, if marked buffers open all in elscreens."
10215 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10216 (anything-aif (anything-marked-candidates)
10217 (dolist (i it)
10218 (let ((target-screen (elscreen-find-screen-by-buffer
10219 (get-buffer i) 'create)))
10220 (elscreen-goto target-screen)))
10221 (let ((target-screen (elscreen-find-screen-by-buffer
10222 (get-buffer candidate) 'create)))
10223 (elscreen-goto target-screen))))
10225 (defun anything-elscreen-find-file (file)
10226 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10227 (elscreen-find-file file))
10229 ;;;###autoload
10230 (defun w32-shell-execute-open-file (file)
10231 (interactive "fOpen file:")
10232 (with-no-warnings
10233 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10234 "/" "\\"
10235 (replace-regexp-in-string ; strip cygdrive paths
10236 "/cygdrive/\\(.\\)" "\\1:"
10237 file nil nil) nil t))))
10239 (defun anything-c-open-file-with-default-tool (file)
10240 "Open FILE with the default tool on this platform."
10241 (if (eq system-type 'windows-nt)
10242 (w32-shell-execute-open-file file)
10243 (start-process "anything-c-open-file-with-default-tool"
10245 (cond ((eq system-type 'gnu/linux)
10246 "xdg-open")
10247 ((or (eq system-type 'darwin) ;; Mac OS X
10248 (eq system-type 'macos)) ;; Mac OS 9
10249 "open"))
10250 file)))
10252 (defun anything-c-open-dired (file)
10253 "Opens a dired buffer in FILE's directory. If FILE is a
10254 directory, open this directory."
10255 (if (file-directory-p file)
10256 (dired file)
10257 (dired (file-name-directory file))
10258 (dired-goto-file file)))
10260 (defun anything-c-display-to-real-line (candidate)
10261 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10262 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10263 (error "Line number not found")))
10265 (defun anything-c-action-line-goto (lineno-and-content)
10266 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10267 (append lineno-and-content
10268 (list (if (and (anything-attr-defined 'target-file)
10269 (not anything-in-persistent-action))
10270 'find-file-other-window
10271 'find-file)))))
10273 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10274 (apply #'anything-goto-file-line
10275 (if (stringp file-line-content)
10276 ;; Case: filtered-candidate-transformer is skipped
10277 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10278 file-line-content)))
10280 (require 'compile)
10281 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10282 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10284 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10285 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10286 (let ((filename (match-string 1 candidate))
10287 (lineno (match-string 2 candidate))
10288 (content (match-string 3 candidate)))
10289 (cons (format "%s:%s\n %s"
10290 (propertize filename 'face compilation-info-face)
10291 (propertize lineno 'face compilation-line-face)
10292 content)
10293 (list (expand-file-name
10294 filename
10295 (or (anything-interpret-value (anything-attr 'default-directory))
10296 (and (anything-candidate-buffer)
10297 (buffer-local-value
10298 'default-directory (anything-candidate-buffer)))))
10299 (string-to-number lineno) content)))))
10301 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10302 (anything-aif (anything-attr 'before-jump-hook)
10303 (funcall it))
10304 (when file (funcall find-file-function file))
10305 (if (anything-attr-defined 'adjust)
10306 (anything-c-goto-line-with-adjustment lineno content)
10307 (anything-goto-line lineno))
10308 (unless (anything-attr-defined 'recenter)
10309 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10310 (anything-aif (anything-attr 'after-jump-hook)
10311 (funcall it))
10312 (when anything-in-persistent-action
10313 (anything-match-line-color-current-line)))
10315 (defun anything-find-file-as-root (candidate)
10316 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10318 (defun anything-find-many-files (ignore)
10319 (mapc 'find-file (anything-marked-candidates)))
10321 ;; borrowed from etags.el
10322 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10323 (defun anything-c-goto-line-with-adjustment (line line-content)
10324 (let ((startpos)
10325 offset found pat)
10326 ;; This constant is 1/2 the initial search window.
10327 ;; There is no sense in making it too small,
10328 ;; since just going around the loop once probably
10329 ;; costs about as much as searching 2000 chars.
10330 (setq offset 1000
10331 found nil
10332 pat (concat (if (eq selective-display t)
10333 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10334 (regexp-quote line-content)))
10335 ;; If no char pos was given, try the given line number.
10336 (setq startpos (progn (anything-goto-line line) (point)))
10337 (or startpos (setq startpos (point-min)))
10338 ;; First see if the tag is right at the specified location.
10339 (goto-char startpos)
10340 (setq found (looking-at pat))
10341 (while (and (not found)
10342 (progn
10343 (goto-char (- startpos offset))
10344 (not (bobp))))
10345 (setq found
10346 (re-search-forward pat (+ startpos offset) t)
10347 offset (* 3 offset))) ; expand search window
10348 (or found
10349 (re-search-forward pat nil t)
10350 (error "not found")))
10351 ;; Position point at the right place
10352 ;; if the search string matched an extra Ctrl-m at the beginning.
10353 (and (eq selective-display t)
10354 (looking-at "\^m")
10355 (forward-char 1))
10356 (beginning-of-line))
10358 (anything-document-attribute 'default-directory "type . file-line"
10359 "`default-directory' to interpret file.")
10360 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10361 "Function to call before jumping to the target location.")
10362 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10363 "Function to call after jumping to the target location.")
10364 (anything-document-attribute 'adjust "type . file-line"
10365 "Search around line matching line contents.")
10366 (anything-document-attribute 'recenter "type . file-line / line"
10367 "`recenter' after jumping.")
10368 (anything-document-attribute 'target-file "type . line"
10369 "Goto line of target-file.")
10371 ;;;###autoload
10372 (defun anything-c-call-interactively (cmd-or-name)
10373 "Execute CMD-OR-NAME as Emacs command.
10374 It is added to `extended-command-history'.
10375 `anything-current-prefix-arg' is used as the command's prefix argument."
10376 (setq extended-command-history
10377 (cons (anything-c-stringify cmd-or-name)
10378 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10379 (let ((current-prefix-arg anything-current-prefix-arg)
10380 (cmd (anything-c-symbolify cmd-or-name)))
10381 (if (stringp (symbol-function cmd))
10382 (execute-kbd-macro (symbol-function cmd))
10383 (setq this-command cmd)
10384 (call-interactively cmd))))
10386 ;;;###autoload
10387 (defun anything-c-set-variable (var)
10388 "Set value to VAR interactively."
10389 (interactive)
10390 (let ((sym (anything-c-symbolify var)))
10391 (set sym (eval-minibuffer (format "Set %s: " var)
10392 (prin1-to-string (symbol-value sym))))))
10393 ;; (setq hh 12)
10394 ;; (anything-c-set-variable 'hh)
10398 ;;; Persistent Action Helpers
10401 (defvar anything-match-line-overlay-face nil)
10402 (defvar anything-match-line-overlay nil)
10404 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10405 "Highlight and underline current position"
10406 (let ((args (list (or start (line-beginning-position))
10407 (or end (1+ (line-end-position)))
10408 buf)))
10409 (if (not anything-match-line-overlay)
10410 (setq anything-match-line-overlay (apply 'make-overlay args))
10411 (apply 'move-overlay anything-match-line-overlay args)))
10412 (overlay-put anything-match-line-overlay
10413 'face (or face anything-match-line-overlay-face))
10414 (when rec
10415 (goto-char start)
10416 (recenter)))
10418 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10421 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10423 (defun anything-match-line-cleanup ()
10424 (when anything-match-line-overlay
10425 (delete-overlay anything-match-line-overlay)
10426 (setq anything-match-line-overlay nil)))
10428 (defun anything-match-line-update ()
10429 (when anything-match-line-overlay
10430 (delete-overlay anything-match-line-overlay)
10431 (anything-match-line-color-current-line)))
10433 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10434 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10437 ;;; Actions Transformers
10440 ;;; Files
10441 (defun anything-c-transform-file-load-el (actions candidate)
10442 "Add action to load the file CANDIDATE if it is an emacs lisp
10443 file. Else return ACTIONS unmodified."
10444 (if (member (file-name-extension candidate) '("el" "elc"))
10445 (append actions '(("Load Emacs Lisp File" . load-file)))
10446 actions))
10448 (defun anything-c-transform-file-browse-url (actions candidate)
10449 "Add an action to browse the file CANDIDATE if it in a html
10450 file or URL. Else return ACTIONS unmodified."
10451 (let ((browse-action '("Browse with Browser" . browse-url)))
10452 (cond ((string-match "^http\\|^ftp" candidate)
10453 (cons browse-action actions))
10454 ((string-match "\\.html?$" candidate)
10455 (append actions (list browse-action)))
10456 (t actions))))
10458 ;;; Function
10459 (defun anything-c-transform-function-call-interactively (actions candidate)
10460 "Add an action to call the function CANDIDATE interactively if
10461 it is a command. Else return ACTIONS unmodified."
10462 (if (commandp (intern-soft candidate))
10463 (append actions '(("Call Interactively"
10465 anything-c-call-interactively)))
10466 actions))
10468 ;;;; S-Expressions
10469 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10470 "If CANDIDATE's `car' is a command, then add an action to
10471 evaluate it and put it onto the `command-history'."
10472 (if (commandp (car (read candidate)))
10473 ;; Make it first entry
10474 (cons '("Eval and put onto command-history" .
10475 (lambda (sexp)
10476 (let ((sym (read sexp)))
10477 (eval sym)
10478 (setq command-history
10479 (cons sym command-history)))))
10480 actions)
10481 actions))
10484 ;;; Candidate Transformers
10487 ;;; Buffers
10488 (defun anything-c-skip-boring-buffers (buffers)
10489 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10491 (defun anything-c-skip-current-buffer (buffers)
10492 (if anything-allow-skipping-current-buffer
10493 (remove (buffer-name anything-current-buffer) buffers)
10494 buffers))
10496 (defun anything-c-shadow-boring-buffers (buffers)
10497 "Buffers matching `anything-c-boring-buffer-regexp' will be
10498 displayed with the `file-name-shadow' face if available."
10499 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10501 (defvar anything-c-buffer-display-string-functions
10502 '(anything-c-buffer-display-string--compilation
10503 anything-c-buffer-display-string--shell
10504 anything-c-buffer-display-string--eshell)
10505 "Functions to setup display string for buffer.
10507 Function has one argument, buffer name.
10508 If it returns string, use it.
10509 If it returns nil, display buffer name.
10510 See `anything-c-buffer-display-string--compilation' for example.")
10512 (defun anything-c-transform-buffer-display-string (buffers)
10513 "Setup display string for buffer candidates
10514 using `anything-c-buffer-display-string-functions'."
10515 (loop for buf in buffers
10516 if (consp buf)
10517 collect buf
10518 else
10519 for disp = (progn (set-buffer buf)
10520 (run-hook-with-args-until-success
10521 'anything-c-buffer-display-string-functions buf))
10522 collect (if disp (cons disp buf) buf)))
10524 (defun anything-c-buffer-display-string--compilation (buf)
10525 (anything-aif (car compilation-arguments)
10526 (format "%s: %s [%s]" buf it default-directory)))
10528 (defun anything-c-buffer-display-string--eshell (buf)
10529 (declare (special eshell-history-ring))
10530 (when (eq major-mode 'eshell-mode)
10531 (format "%s: %s [%s]" buf
10532 (ignore-errors (ring-ref eshell-history-ring 0))
10533 default-directory)))
10535 (defun anything-c-buffer-display-string--shell (buf)
10536 (when (eq major-mode 'shell-mode)
10537 (format "%s: %s [%s]" buf
10538 (ignore-errors (ring-ref comint-input-ring 0))
10539 default-directory)))
10541 ;;; Files
10542 (defun anything-c-shadow-boring-files (files)
10543 "Files matching `anything-c-boring-file-regexp' will be
10544 displayed with the `file-name-shadow' face if available."
10545 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10547 (defun anything-c-skip-boring-files (files)
10548 "Files matching `anything-c-boring-file-regexp' will be skipped."
10549 (anything-c-skip-entries files anything-c-boring-file-regexp))
10550 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10552 (defun anything-c-skip-current-file (files)
10553 "Current file will be skipped."
10554 (remove (buffer-file-name anything-current-buffer) files))
10556 (defun anything-c-w32-pathname-transformer (args)
10557 "Change undesirable features of windows pathnames to ones more acceptable to
10558 other candidate transformers."
10559 (if (eq system-type 'windows-nt)
10560 (mapcar (lambda (x)
10561 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10562 (mapcar (lambda (y)
10563 (replace-regexp-in-string "\\\\" "/" y)) args))
10564 args))
10566 (defun anything-c-shorten-home-path (files)
10567 "Replaces /home/user with ~."
10568 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10569 (getenv "HOME"))))
10570 (mapcar (lambda (file)
10571 (if (and (stringp file) (string-match home file))
10572 (cons (replace-match "~" nil nil file) file)
10573 file))
10574 files)))
10576 ;;; Functions
10577 (defun anything-c-mark-interactive-functions (functions)
10578 "Mark interactive functions (commands) with (i) after the function name."
10579 (let (list)
10580 (loop for function in functions
10581 do (push (cons (concat function
10582 (when (commandp (intern-soft function)) " (i)"))
10583 function)
10584 list)
10585 finally (return (nreverse list)))))
10588 ;;; Adaptive Sorting of Candidates
10591 ;; Internal
10592 (defvar anything-c-adaptive-done nil
10593 "nil if history information is not yet stored for the current
10594 selection.")
10596 (defvar anything-c-adaptive-history nil
10597 "Contains the stored history information.
10598 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10600 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10601 "Reset `anything-c-adaptive-done' when anything is started."
10602 (when anything-c-use-adaptative-sorting
10603 (setq anything-c-adaptive-done nil)))
10605 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10606 "Store history information when action is executed on selected candidate."
10607 (when anything-c-use-adaptative-sorting
10608 (anything-c-adaptive-store-selection)))
10610 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10611 "Store history information when the user goes to the action buffer."
10612 (when anything-c-use-adaptative-sorting
10613 (anything-c-adaptive-store-selection)))
10615 (defun anything-c-source-use-adaptative-p (&optional source-name)
10616 "Return current source only if it use adaptative history, nil otherwise."
10617 (when anything-c-use-adaptative-sorting
10618 (let* ((source (or source-name (anything-get-current-source)))
10619 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10620 (assoc (assoc-default 'type source)
10621 anything-type-attributes))
10622 (assoc-default 'candidate-transformer
10623 (assoc (assoc-default 'type source)
10624 anything-type-attributes))
10625 (assoc-default 'filtered-candidate-transformer source)
10626 (assoc-default 'candidate-transformer source))))
10627 (if (listp adapt-source)
10628 (when (member 'anything-c-adaptive-sort adapt-source) source)
10629 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10631 (defun anything-c-adaptive-store-selection ()
10632 "Store history information for the selected candidate."
10633 (unless anything-c-adaptive-done
10634 (setq anything-c-adaptive-done t)
10635 (let ((source (anything-c-source-use-adaptative-p)))
10636 (when source
10637 (let* ((source-name (or (assoc-default 'type source)
10638 (assoc-default 'name source)))
10639 (source-info (or (assoc source-name anything-c-adaptive-history)
10640 (progn
10641 (push (list source-name) anything-c-adaptive-history)
10642 (car anything-c-adaptive-history))))
10643 (selection (anything-get-selection))
10644 (selection-info (progn
10645 (setcdr source-info
10646 (cons
10647 (let ((found (assoc selection (cdr source-info))))
10648 (if (not found)
10649 ;; new entry
10650 (list selection)
10652 ;; move entry to the beginning of the
10653 ;; list, so that it doesn't get
10654 ;; trimmed when the history is
10655 ;; truncated
10656 (setcdr source-info
10657 (delete found (cdr source-info)))
10658 found))
10659 (cdr source-info)))
10660 (cadr source-info)))
10661 (pattern-info (progn
10662 (setcdr selection-info
10663 (cons
10664 (let ((found (assoc anything-pattern (cdr selection-info))))
10665 (if (not found)
10666 ;; new entry
10667 (cons anything-pattern 0)
10669 ;; move entry to the beginning of the
10670 ;; list, so if two patterns used the
10671 ;; same number of times then the one
10672 ;; used last appears first in the list
10673 (setcdr selection-info
10674 (delete found (cdr selection-info)))
10675 found))
10676 (cdr selection-info)))
10677 (cadr selection-info))))
10679 ;; increase usage count
10680 (setcdr pattern-info (1+ (cdr pattern-info)))
10682 ;; truncate history if needed
10683 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10684 (setcdr selection-info
10685 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10687 (defun anything-c-adaptative-maybe-load-history ()
10688 (when (and anything-c-use-adaptative-sorting
10689 (file-readable-p anything-c-adaptive-history-file))
10690 (load-file anything-c-adaptive-history-file)))
10692 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10693 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10695 (defun anything-c-adaptive-save-history (&optional arg)
10696 "Save history information to file given by `anything-c-adaptive-history-file'."
10697 (interactive "p")
10698 (when anything-c-use-adaptative-sorting
10699 (with-temp-buffer
10700 (insert
10701 ";; -*- mode: emacs-lisp -*-\n"
10702 ";; History entries used for anything adaptive display.\n")
10703 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10704 (current-buffer))
10705 (insert ?\n)
10706 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10707 (unless arg 'quiet)))))
10709 (defun anything-c-adaptive-sort (candidates source)
10710 "Sort the CANDIDATES for SOURCE by usage frequency.
10711 This is a filtered candidate transformer you can use for the
10712 attribute `filtered-candidate-transformer' of a source in
10713 `anything-sources' or a type in `anything-type-attributes'."
10714 (let* ((source-name (or (assoc-default 'type source)
10715 (assoc-default 'name source)))
10716 (source-info (assoc source-name anything-c-adaptive-history)))
10717 (if source-info
10718 (let ((usage
10719 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10720 ;; pairs
10721 (mapcar (lambda (candidate-info)
10722 (let ((count 0))
10723 (dolist (pattern-info (cdr candidate-info))
10724 (if (not (equal (car pattern-info)
10725 anything-pattern))
10726 (incf count (cdr pattern-info))
10728 ;; if current pattern is equal to the previously
10729 ;; used one then this candidate has priority
10730 ;; (that's why its count is boosted by 10000) and
10731 ;; it only has to compete with other candidates
10732 ;; which were also selected with the same pattern
10733 (setq count (+ 10000 (cdr pattern-info)))
10734 (return)))
10735 (cons (car candidate-info) count)))
10736 (cdr source-info)))
10737 sorted)
10738 (if (and usage (consp usage))
10739 ;; sort the list in descending order, so candidates with highest
10740 ;; priorty come first
10741 (progn
10742 (setq usage (sort usage (lambda (first second)
10743 (> (cdr first) (cdr second)))))
10745 ;; put those candidates first which have the highest usage count
10746 (dolist (info usage)
10747 (when (member* (car info) candidates
10748 :test 'anything-c-adaptive-compare)
10749 (push (car info) sorted)
10750 (setq candidates (remove* (car info) candidates
10751 :test 'anything-c-adaptive-compare))))
10753 ;; and append the rest
10754 (append (reverse sorted) candidates nil))
10755 (message "Your `%s' is maybe corrupted or too old, \
10756 you should reinitialize it with `anything-c-reset-adaptative-history'"
10757 anything-c-adaptive-history-file)
10758 (sit-for 1)
10759 candidates))
10760 ;; if there is no information stored for this source then do nothing
10761 candidates)))
10763 ;;;###autoload
10764 (defun anything-c-reset-adaptative-history ()
10765 "Delete all `anything-c-adaptive-history' and his file.
10766 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10767 (interactive)
10768 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10769 (setq anything-c-adaptive-history nil)
10770 (delete-file anything-c-adaptive-history-file)))
10772 (defun anything-c-adaptive-compare (x y)
10773 "Compare candidates X and Y taking into account that the
10774 candidate can be in (DISPLAY . REAL) format."
10775 (equal (if (listp x)
10776 (cdr x)
10778 (if (listp y)
10779 (cdr y)
10780 y)))
10784 ;;; Outliner
10787 (defvar anything-outline-goto-near-line-flag t)
10788 (defvar anything-outline-using nil)
10789 (defun anything-after-update-hook--outline ()
10790 (if (and (eq anything-outline-using t)
10791 (eq anything-outline-goto-near-line-flag t))
10792 (anything-outline-goto-near-line)))
10793 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10795 (defun anything-outline-goto-near-line ()
10796 (with-anything-window
10797 ;; TODO need consideration whether to update position by every input.
10798 (when t ; (equal anything-pattern "")
10799 (anything-goto-line 2)
10800 (let ((lineno (with-anything-current-buffer
10801 (line-number-at-pos (car anything-current-position)))))
10802 (block exit
10803 (while (<= (progn (skip-chars-forward " ")
10804 (or (number-at-point) lineno))
10805 lineno)
10806 (forward-line 1)
10807 (when (eobp)
10808 (forward-line -1)
10809 (return-from exit))))
10810 (forward-line -1)
10811 (and (bobp) (forward-line 1))
10812 (and (anything-pos-header-line-p) (forward-line -2))
10813 (anything-mark-current-line)))))
10817 ;;; Plug-in
10820 ;; Plug-in: info-index
10821 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10822 (let (result)
10823 (unless (anything-candidate-buffer)
10824 (save-window-excursion
10825 (info file)
10826 (let (Info-history
10827 (tobuf (anything-candidate-buffer 'global))
10828 (infobuf (current-buffer))
10829 s e)
10830 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10831 (Info-goto-node node)
10832 (goto-char (point-min))
10833 (while (search-forward "\n* " nil t)
10834 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10835 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10836 (setq s (point-at-bol)
10837 e (point-at-eol))
10838 (with-current-buffer tobuf
10839 (insert-buffer-substring infobuf s e)
10840 (insert "\n"))))))))))
10842 (defun anything-c-info-goto (node-line)
10843 (Info-goto-node (car node-line))
10844 (anything-goto-line (cdr node-line)))
10846 (defun anything-c-info-display-to-real (line)
10847 (and (string-match
10848 ;; This regexp is stolen from Info-apropos-matches
10849 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10850 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10851 (string-to-number (or (match-string 3 line) "1")))))
10853 (defun anything-c-make-info-source (source file)
10854 `(,@source
10855 (name . ,(concat "Info Index: " file))
10856 (info-file . ,file)
10857 (init . anything-c-info-init)
10858 (display-to-real . anything-c-info-display-to-real)
10859 (get-line . buffer-substring)
10860 (candidates-in-buffer)
10861 (action ("Goto node" . anything-c-info-goto))))
10863 (defun anything-compile-source--info-index (source)
10864 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10865 (anything-c-make-info-source source it)
10866 source))
10867 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10869 (anything-document-attribute 'info-index "info-index plugin"
10870 "Create a source of info index very easily.
10872 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10874 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10875 "Index nodes of info file.
10877 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10878 Some info files are missing index specification.
10880 ex. See `anything-c-source-info-screen'.")
10882 ;; Plug-in: candidates-file
10883 (defun anything-compile-source--candidates-file (source)
10884 (if (assoc-default 'candidates-file source)
10885 `((init anything-p-candidats-file-init
10886 ,@(let ((orig-init (assoc-default 'init source)))
10887 (cond ((null orig-init) nil)
10888 ((functionp orig-init) (list orig-init))
10889 (t orig-init))))
10890 (candidates-in-buffer)
10891 ,@source)
10892 source))
10893 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10895 (defun anything-p-candidats-file-init ()
10896 (destructuring-bind (file &optional updating)
10897 (anything-mklist (anything-attr 'candidates-file))
10898 (setq file (anything-interpret-value file))
10899 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10900 (when updating
10901 (buffer-disable-undo)
10902 (font-lock-mode -1)
10903 (auto-revert-mode 1)))))
10905 (anything-document-attribute 'candidates-file "candidates-file plugin"
10906 "Use a file as the candidates buffer.
10908 1st argument is a filename, string or function name or variable name.
10909 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10911 ;; Plug-in: headline
10912 (defun anything-compile-source--anything-headline (source)
10913 (if (assoc-default 'headline source)
10914 (append '((init . anything-headline-init)
10915 (get-line . buffer-substring)
10916 (type . line))
10917 source
10918 '((candidates-in-buffer)
10919 (persistent-help . "Show this line")))
10920 source))
10921 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10923 (defun anything-headline-init ()
10924 (when (and (anything-current-buffer-is-modified)
10925 (with-anything-current-buffer
10926 (eval (or (anything-attr 'condition) t))))
10927 (anything-headline-make-candidate-buffer
10928 (anything-interpret-value (anything-attr 'headline))
10929 (anything-interpret-value (anything-attr 'subexp)))))
10931 (anything-document-attribute 'headline "Headline plug-in"
10932 "Regexp string for anything-headline to scan.")
10933 (anything-document-attribute 'condition "Headline plug-in"
10934 "A sexp representing the condition to use anything-headline.")
10935 (anything-document-attribute 'subexp "Headline plug-in"
10936 "Display (match-string-no-properties subexp).")
10938 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10939 ;; of regexps.
10941 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10942 ;; 2. Sort this list by start-of-match.
10943 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10945 ;; It's quite brilliantly written.
10949 (defun anything-headline-get-candidates (regexp subexp)
10950 (with-anything-current-buffer
10951 (save-excursion
10952 (goto-char (point-min))
10953 (if (functionp regexp) (setq regexp (funcall regexp)))
10954 (let (hierarchy curhead)
10955 (flet ((matched ()
10956 (if (numberp subexp)
10957 (cons (match-string-no-properties subexp) (match-beginning subexp))
10958 (cons (buffer-substring (point-at-bol) (point-at-eol))
10959 (point-at-bol))))
10960 (hierarchies (headlines)
10961 (1+ (loop for (_ . hierarchy) in headlines
10962 maximize hierarchy)))
10963 (vector-0-n (v n)
10964 (loop for i from 0 to hierarchy
10965 collecting (aref curhead i)))
10966 (arrange (headlines)
10967 (unless (null headlines) ; FIX headlines empty bug!
10968 (loop with curhead = (make-vector (hierarchies headlines) "")
10969 for ((str . pt) . hierarchy) in headlines
10970 do (aset curhead hierarchy str)
10971 collecting
10972 (cons
10973 (format "H%d:%s" (1+ hierarchy)
10974 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
10975 pt)))))
10976 (if (listp regexp)
10977 (arrange
10978 (sort
10979 (loop for re in regexp
10980 for hierarchy from 0
10981 do (goto-char (point-min))
10982 appending
10983 (loop
10984 while (re-search-forward re nil t)
10985 collect (cons (matched) hierarchy)))
10986 (lambda (a b) (> (cdar b) (cdar a)))))
10987 (loop while (re-search-forward regexp nil t)
10988 collect (matched))))))))
10991 (defun anything-headline-make-candidate-buffer (regexp subexp)
10992 (with-current-buffer (anything-candidate-buffer 'local)
10993 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
10994 do (insert
10995 (format "%5d:%s\n"
10996 (with-anything-current-buffer
10997 (line-number-at-pos pos))
10998 content)))))
11000 (defun anything-headline-goto-position (pos recenter)
11001 (goto-char pos)
11002 (unless recenter
11003 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11006 ;; Plug-in: persistent-help
11007 (defun anything-compile-source--persistent-help (source)
11008 (append source '((header-line . anything-persistent-help-string))))
11009 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11011 (defun anything-persistent-help-string ()
11012 (substitute-command-keys
11013 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11014 (or (anything-interpret-value (anything-attr 'persistent-help))
11015 (anything-aif (or (assoc-default 'persistent-action
11016 (anything-get-current-source))
11017 (assoc-default 'action
11018 (anything-get-current-source)))
11019 (cond ((symbolp it) (symbol-name it))
11020 ((listp it) (or (ignore-errors (caar it)) ""))))
11022 " (keeping session)")))
11024 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11025 "A string to explain persistent-action of this source.
11026 It also accepts a function or a variable name.")
11028 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11030 ;; Plug-in: Type customize
11031 (defun anything-c-uniq-list (lst)
11032 "Like `remove-duplicates' in CL.
11033 But cut deeper duplicates and test by `equal'. "
11034 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11035 (defvar anything-additional-type-attributes nil)
11036 (defun anything-c-arrange-type-attribute (type spec)
11037 "Override type attributes by `define-anything-type-attribute'.
11039 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11041 Example: Set `play-sound-file' as default action
11042 (anything-c-arrange-type-attribute 'file
11043 '((action (\"Play sound\" . play-sound-file)
11044 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11047 (add-to-list 'anything-additional-type-attributes
11048 (cons type
11049 (loop with typeattr = (assoc-default type anything-type-attributes)
11050 for (attr . value) in spec
11051 if (listp value)
11052 collect (cons attr
11053 (anything-c-uniq-list
11054 (loop for v in value
11055 if (eq v 'REST)
11056 append (assoc-default attr typeattr)
11057 else
11058 collect v)))
11059 else
11060 collect (cons attr value)))))
11061 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11063 (defun anything-compile-source--type-customize (source)
11064 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11065 (append it source)
11066 source))
11067 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11069 ;; Plug-in: default-action
11070 (defun anything-compile-source--default-action (source)
11071 (anything-aif (assoc-default 'default-action source)
11072 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11073 source)
11074 source))
11075 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11076 (anything-document-attribute 'default-action "default-action plug-in"
11077 "Default action.")
11080 ;;; Toggle anything-match-plugin
11083 (defvar anything-mp-initial-highlight-delay nil)
11085 ;;;###autoload
11086 (defun anything-c-toggle-match-plugin ()
11087 "Toggle anything-match-plugin."
11088 (interactive)
11089 (let ((anything-match-plugin-enabled
11090 (member 'anything-compile-source--match-plugin
11091 anything-compile-source-functions)))
11092 (flet ((disable-match-plugin ()
11093 (setq anything-compile-source-functions
11094 (delq 'anything-compile-source--match-plugin
11095 anything-compile-source-functions))
11096 (setq anything-mp-initial-highlight-delay
11097 anything-mp-highlight-delay)
11098 (setq anything-mp-highlight-delay nil))
11099 (enable-match-plugin ()
11100 (require 'anything-match-plugin)
11101 (unless anything-mp-initial-highlight-delay
11102 (setq anything-mp-initial-highlight-delay
11103 anything-mp-highlight-delay))
11104 (setq anything-compile-source-functions
11105 (cons 'anything-compile-source--match-plugin
11106 anything-compile-source-functions))
11107 (unless anything-mp-highlight-delay
11108 (setq anything-mp-highlight-delay
11109 anything-mp-initial-highlight-delay))))
11110 (if anything-match-plugin-enabled
11111 (when (y-or-n-p "Really disable match-plugin? ")
11112 (disable-match-plugin)
11113 (message "Anything-match-plugin disabled"))
11114 (when (y-or-n-p "Really enable match-plugin? ")
11115 (enable-match-plugin)
11116 (message "Anything-match-plugin enabled"))))))
11120 ;;; Type Attributes
11123 (define-anything-type-attribute 'buffer
11124 `((action
11125 ("Switch to buffer" . anything-c-switch-to-buffer)
11126 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11127 ("Switch to buffer other window" . switch-to-buffer-other-window)
11128 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11129 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11130 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11131 ("Query replace" . anything-c-buffer-query-replace)
11132 ("View buffer" . view-buffer)
11133 ("Display buffer" . display-buffer)
11134 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11135 ("Revert buffer(s)" . anything-revert-marked-buffers)
11136 ("Insert buffer" . insert-buffer)
11137 ("Kill buffer(s)" . anything-kill-marked-buffers)
11138 ("Diff with file" . diff-buffer-with-file)
11139 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11140 ("Ediff Merge marked buffers" . (lambda (candidate)
11141 (anything-ediff-marked-buffers candidate t))))
11142 (persistent-help . "Show this buffer")
11143 (candidate-transformer anything-c-skip-current-buffer
11144 anything-c-skip-boring-buffers
11145 anything-c-transform-buffer-display-string))
11146 "Buffer or buffer name.")
11148 (define-anything-type-attribute 'file
11149 `((action
11150 ("Find file" . anything-find-many-files)
11151 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11152 ("Find file as root" . anything-find-file-as-root)
11153 ("Find file other window" . find-file-other-window)
11154 ("Find file other frame" . find-file-other-frame)
11155 ("Open dired in file's directory" . anything-c-open-dired)
11156 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11157 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11158 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11159 ("Checksum File" . anything-ff-checksum)
11160 ("Ediff File" . anything-find-files-ediff-files)
11161 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11162 ("View file" . view-file)
11163 ("Insert file" . insert-file)
11164 ("Delete file(s)" . anything-delete-marked-files)
11165 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11166 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11167 ("Find file in hex dump" . hexl-find-file))
11168 (persistent-help . "Show this file")
11169 (action-transformer anything-c-transform-file-load-el
11170 anything-c-transform-file-browse-url)
11171 (candidate-transformer anything-c-w32-pathname-transformer
11172 anything-c-skip-current-file
11173 anything-c-skip-boring-files
11174 anything-c-shorten-home-path))
11175 "File name.")
11177 (let ((actions '(("Describe command" . describe-function)
11178 ("Add command to kill ring" . anything-c-kill-new)
11179 ("Go to command's definition" . find-function)
11180 ("Debug on entry" . debug-on-entry)
11181 ("Cancel debug on entry" . cancel-debug-on-entry)
11182 ("Trace function" . trace-function)
11183 ("Trace function (background)" . trace-function-background)
11184 ("Untrace function" . untrace-function))))
11185 (define-anything-type-attribute 'command
11186 `((action ("Call interactively" . anything-c-call-interactively)
11187 ,@actions)
11188 ;; Sort commands according to their usage count.
11189 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11190 (coerce . anything-c-symbolify)
11191 (persistent-action . describe-function))
11192 "Command. (string or symbol)")
11194 (define-anything-type-attribute 'function
11195 `((action . ,actions)
11196 (action-transformer anything-c-transform-function-call-interactively)
11197 (candidate-transformer anything-c-mark-interactive-functions)
11198 (coerce . anything-c-symbolify))
11199 "Function. (string or symbol)"))
11201 (define-anything-type-attribute 'variable
11202 '((action ("Describe variable" . describe-variable)
11203 ("Add variable to kill ring" . anything-c-kill-new)
11204 ("Go to variable's definition" . find-variable)
11205 ("Set variable" . anything-c-set-variable))
11206 (coerce . anything-c-symbolify))
11207 "Variable.")
11209 (define-anything-type-attribute 'sexp
11210 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11211 ("Add s-expression to kill ring" . kill-new))
11212 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11213 "String representing S-Expressions.")
11215 (define-anything-type-attribute 'bookmark
11216 `((coerce . anything-bookmark-get-bookmark-from-name)
11217 (action
11218 ("Jump to bookmark" . (lambda (bookmark)
11219 (let ((current-prefix-arg anything-current-prefix-arg))
11220 (bookmark-jump bookmark))
11221 (anything-update)))
11222 ("Jump to BM other window" . (lambda (bookmark)
11223 (bookmark-jump-other-window bookmark)
11224 (anything-update)))
11225 ("Bookmark edit annotation" . bookmark-edit-annotation)
11226 ("Bookmark show annotation" . bookmark-show-annotation)
11227 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11228 ,@(and (locate-library "bookmark-extensions")
11229 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11230 ("Rename bookmark" . bookmark-rename)
11231 ("Relocate bookmark" . bookmark-relocate)))
11232 "Bookmark name.")
11234 (define-anything-type-attribute 'line
11235 '((display-to-real . anything-c-display-to-real-line)
11236 (action ("Go to Line" . anything-c-action-line-goto)))
11237 "LINENO:CONTENT string, eg. \" 16:foo\".
11239 Optional `target-file' attribute is a name of target file.
11241 Optional `before-jump-hook' attribute is a function with no
11242 arguments which is called before jumping to position.
11244 Optional `after-jump-hook' attribute is a function with no
11245 arguments which is called after jumping to position.
11247 If `adjust' attribute is specified, searches the line whose
11248 content is CONTENT near the LINENO.
11250 If `recenter' attribute is specified, the line is displayed at
11251 the center of window, otherwise at the top of window.
11254 (define-anything-type-attribute 'file-line
11255 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11256 (multiline)
11257 (action ("Go to" . anything-c-action-file-line-goto)))
11258 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11260 Optional `default-directory' attribute is a default-directory
11261 FILENAME is interpreted.
11263 Optional `before-jump-hook' attribute is a function with no
11264 arguments which is called before jumping to position.
11266 Optional `after-jump-hook' attribute is a function with no
11267 arguments which is called after jumping to position.
11269 If `adjust' attribute is specified, searches the line whose
11270 content is CONTENT near the LINENO.
11272 If `recenter' attribute is specified, the line is displayed at
11273 the center of window, otherwise at the top of window.
11276 (define-anything-type-attribute 'timer
11277 '((real-to-display . anything-c-timer-real-to-display)
11278 (action ("Cancel Timer" . cancel-timer)
11279 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11280 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11281 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11282 (persistent-help . "Describe Function"))
11283 "Timer.")
11286 ;;; Default `anything-sources'
11287 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11288 ;; tend to invoke M-x anything directly. So I offer default setting.
11289 (setq anything-sources
11290 '(anything-c-source-buffers-list
11291 anything-c-source-recentf
11292 anything-c-source-files-in-current-dir+))
11295 ;;; Preconfigured Anything
11298 ;;;###autoload
11299 (defun anything-mini ()
11300 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11301 (interactive)
11302 (anything-other-buffer '(anything-c-source-buffers-list
11303 anything-c-source-recentf
11304 anything-c-source-buffer-not-found)
11305 "*anything mini*"))
11306 ;;;###autoload
11307 (defun anything-for-files ()
11308 "Preconfigured `anything' for opening files.
11309 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11310 (interactive)
11311 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11313 ;;;###autoload
11314 (defun anything-recentf ()
11315 "Preconfigured `anything' for `recentf'."
11316 (interactive)
11317 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11319 ;;;###autoload
11320 (defun anything-info-at-point (arg)
11321 "Preconfigured `anything' for searching info at point.
11322 With a prefix-arg insert symbol at point."
11323 (interactive "P")
11324 (let ((anything-c-google-suggest-default-function
11325 'anything-c-google-suggest-emacs-lisp))
11326 (anything :sources '(anything-c-source-info-elisp
11327 anything-c-source-info-cl
11328 anything-c-source-info-pages
11329 anything-c-source-google-suggest)
11330 :input (and arg (thing-at-point 'symbol))
11331 :buffer "*anything info*")))
11333 ;;;###autoload
11334 (defun anything-info-emacs ()
11335 "Preconfigured anything for Emacs manual index."
11336 (interactive)
11337 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11339 ;;;###autoload
11340 (defun anything-show-kill-ring ()
11341 "Preconfigured `anything' for `kill-ring'.
11342 It is drop-in replacement of `yank-pop'.
11343 You may bind this command to M-y.
11344 First call open the kill-ring browser, next calls move to next line."
11345 (interactive)
11346 (let ((buf "*anything kill-ring*"))
11347 (if (get-buffer-window buf)
11348 (with-anything-window
11349 (if (eq (overlay-end anything-selection-overlay) (point-max))
11350 (anything-beginning-of-buffer)
11351 (anything-next-line)))
11352 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11354 ;;;###autoload
11355 (defun anything-minibuffer-history ()
11356 "Preconfigured `anything' for `minibuffer-history'."
11357 (interactive)
11358 (let ((enable-recursive-minibuffers t))
11359 (anything-other-buffer 'anything-c-source-minibuffer-history
11360 "*anything minibuffer-history*")))
11362 ;;;###autoload
11363 (defun anything-gentoo ()
11364 "Preconfigured `anything' for gentoo linux."
11365 (interactive)
11366 (anything-other-buffer '(anything-c-source-gentoo
11367 anything-c-source-use-flags)
11368 "*anything gentoo*"))
11370 ;;;###autoload
11371 (defun anything-imenu ()
11372 "Preconfigured `anything' for `imenu'."
11373 (interactive)
11374 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11376 ;;;###autoload
11377 (defun anything-google-suggest ()
11378 "Preconfigured `anything' for google search with google suggest."
11379 (interactive)
11380 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11382 ;;;###autoload
11383 (defun anything-yahoo-suggest ()
11384 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11385 (interactive)
11386 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11388 ;;; Converted from anything-show-*-only
11389 ;;;###autoload
11390 (defun anything-for-buffers ()
11391 "Preconfigured `anything' for buffer."
11392 (interactive)
11393 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11395 ;;;###autoload
11396 (defun anything-buffers-list ()
11397 "Enhanced preconfigured `anything' for buffer."
11398 (interactive)
11399 (anything :sources '(anything-c-source-buffers-list
11400 anything-c-source-buffer-not-found)
11401 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11403 ;;;###autoload
11404 (defun anything-bbdb ()
11405 "Preconfigured `anything' for BBDB.
11407 Needs BBDB.
11409 http://bbdb.sourceforge.net/"
11410 (interactive)
11411 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11413 ;;;###autoload
11414 (defun anything-locate (arg)
11415 "Preconfigured `anything' for Locate.
11416 Note: you can add locate options after entering pattern.
11417 See 'man locate' for valid options.
11419 You can specify a specific database with prefix argument ARG \(C-u\).
11420 Many databases can be used: navigate and mark them.
11421 See also `anything-locate-with-db'.
11423 To create a user specific db, use
11424 \"updatedb -l 0 -o db_path -U directory\".
11425 Where db_path is a filename matched by
11426 `anything-locate-db-file-regexp'."
11427 (interactive "P")
11428 (anything-locate-1 arg))
11430 ;;;###autoload
11431 (defun anything-w3m-bookmarks ()
11432 "Preconfigured `anything' for w3m bookmark.
11434 Needs w3m and emacs-w3m.
11436 http://w3m.sourceforge.net/
11437 http://emacs-w3m.namazu.org/"
11438 (interactive)
11439 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11440 "*anything w3m bookmarks*"))
11442 ;;;###autoload
11443 (defun anything-firefox-bookmarks ()
11444 "Preconfigured `anything' for firefox bookmark.
11445 You will have to enable html bookmarks in firefox:
11446 open about:config in firefox and double click on this line to enable value \
11447 to true:
11449 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11451 You should have now:
11453 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11455 After closing firefox, you will be able to browse you bookmarks.
11457 (interactive)
11458 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11459 "*Anything Firefox*"))
11461 ;;;###autoload
11462 (defun anything-colors ()
11463 "Preconfigured `anything' for color."
11464 (interactive)
11465 (anything-other-buffer
11466 '(anything-c-source-colors anything-c-source-customize-face)
11467 "*anything colors*"))
11469 ;;;###autoload
11470 (defun anything-bookmarks ()
11471 "Preconfigured `anything' for bookmarks."
11472 (interactive)
11473 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11475 ;;;###autoload
11476 (defun anything-c-pp-bookmarks ()
11477 "Preconfigured `anything' for bookmarks (pretty-printed)."
11478 (interactive)
11479 (anything-other-buffer '(anything-c-source-bookmarks-local
11480 anything-c-source-bookmarks-su
11481 anything-c-source-bookmarks-ssh)
11482 "*anything pp bookmarks*"))
11484 ;;;###autoload
11485 (defun anything-c-insert-latex-math ()
11486 "Preconfigured anything for latex math symbols completion."
11487 (interactive)
11488 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11490 ;;;###autoload
11491 (defun anything-register ()
11492 "Preconfigured `anything' for Emacs registers."
11493 (interactive)
11494 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11496 ;;;###autoload
11497 (defun anything-man-woman ()
11498 "Preconfigured `anything' for Man and Woman pages."
11499 (interactive)
11500 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11502 ;;;###autoload
11503 (defun anything-org-keywords ()
11504 "Preconfigured `anything' for org keywords."
11505 (interactive)
11506 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11508 ;;;###autoload
11509 (defun anything-emms ()
11510 "Preconfigured `anything' for emms sources."
11511 (interactive)
11512 (anything '(anything-c-source-emms-streams
11513 anything-c-source-emms-files
11514 anything-c-source-emms-dired)
11515 nil nil nil nil
11516 "*Anything Emms*"))
11518 ;;;###autoload
11519 (defun anything-eev-anchors ()
11520 "Preconfigured `anything' for eev anchors."
11521 (interactive)
11522 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11524 ;;;###autoload
11525 (defun anything-bm-list ()
11526 "Preconfigured `anything' for visible bookmarks.
11528 Needs bm.el
11530 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11531 (interactive)
11532 (let ((anything-outline-using t))
11533 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11535 ;;;###autoload
11536 (defun anything-timers ()
11537 "Preconfigured `anything' for timers."
11538 (interactive)
11539 (anything-other-buffer '(anything-c-source-absolute-time-timers
11540 anything-c-source-idle-time-timers)
11541 "*anything timers*"))
11543 ;;;###autoload
11544 (defun anything-list-emacs-process ()
11545 "Preconfigured `anything' for emacs process."
11546 (interactive)
11547 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11549 ;;;###autoload
11550 (defun anything-occur ()
11551 "Preconfigured Anything for Occur source.
11552 If region is active, search only in region,
11553 otherwise search in whole buffer."
11554 (interactive)
11555 (let ((anything-compile-source-functions
11556 ;; rule out anything-match-plugin because the input is one regexp.
11557 (delq 'anything-compile-source--match-plugin
11558 (copy-sequence anything-compile-source-functions))))
11559 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11561 ;;;###autoload
11562 (defun anything-browse-code ()
11563 "Preconfigured anything to browse code."
11564 (interactive)
11565 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11567 ;;;###autoload
11568 (defun anything-org-headlines ()
11569 "Preconfigured anything to show org headlines."
11570 (interactive)
11571 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11573 ;;;###autoload
11574 (defun anything-info-gnus ()
11575 "Preconfigured anything to browse Gnus Manual."
11576 (interactive)
11577 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11579 ;;;###autoload
11580 (defun anything-regexp ()
11581 "Preconfigured anything to build regexps and run query-replace-regexp \
11582 against."
11583 (interactive)
11584 (save-restriction
11585 (let ((anything-compile-source-functions
11586 ;; rule out anything-match-plugin because the input is one regexp.
11587 (delq 'anything-compile-source--match-plugin
11588 (copy-sequence anything-compile-source-functions))))
11589 (when (and (anything-region-active-p)
11590 ;; Don't narrow to region if buffer is already narrowed.
11591 (not (anything-current-buffer-narrowed-p)))
11592 (narrow-to-region (region-beginning) (region-end)))
11593 (anything :sources
11594 anything-c-source-regexp
11595 :buffer "*anything regexp*"
11596 :prompt "Regexp: "))))
11598 (defun anything-c-copy-files-async ()
11599 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11600 (interactive)
11601 (let* ((flist (anything-c-read-file-name
11602 "Copy File async: "
11603 :marked-candidates t))
11604 (dest (anything-c-read-file-name
11605 "Copy File async To: "
11606 :preselect (car flist)
11607 :initial-input (car anything-ff-history)
11608 :history (anything-find-files-history :comp-read nil))))
11609 (anything-c-copy-async-with-log flist dest)))
11611 ;;;###autoload
11612 (defun anything-find-files (arg)
11613 "Preconfigured `anything' for anything implementation of `find-file'.
11614 Called with a prefix arg show history if some.
11615 Don't call it from programs, use `anything-find-files-1' instead.
11616 This is the starting point for nearly all actions you can do on files."
11617 (interactive "P")
11618 (let ((any-input (if (and arg anything-ff-history)
11619 (anything-find-files-history)
11620 (anything-find-files-initial-input)))
11621 (presel (buffer-file-name (current-buffer))))
11622 (when (and (eq major-mode 'org-agenda-mode)
11623 org-directory
11624 (not any-input))
11625 (setq any-input (expand-file-name org-directory)))
11626 (set-text-properties 0 (length any-input) nil any-input)
11627 (if any-input
11628 (anything-find-files-1 any-input)
11629 (setq any-input (expand-file-name (anything-c-current-directory)))
11630 (anything-find-files-1
11631 any-input (if anything-ff-transformer-show-only-basename
11632 (and presel (anything-c-basename presel))
11633 presel)))))
11635 ;;;###autoload
11636 (defun anything-write-file ()
11637 "Preconfigured `anything' providing completion for `write-file'."
11638 (interactive)
11639 (let ((anything-mp-highlight-delay nil))
11640 (anything :sources 'anything-c-source-write-file
11641 :input (expand-file-name default-directory)
11642 :prompt "Write buffer to file: "
11643 :buffer "*Anything write file*")))
11645 ;;;###autoload
11646 (defun anything-insert-file ()
11647 "Preconfigured `anything' providing completion for `insert-file'."
11648 (interactive)
11649 (let ((anything-mp-highlight-delay nil))
11650 (anything :sources 'anything-c-source-insert-file
11651 :input (expand-file-name default-directory)
11652 :prompt "Insert file: "
11653 :buffer "*Anything insert file*")))
11655 ;;;###autoload
11656 (defun anything-dired-rename-file ()
11657 "Preconfigured `anything' to rename files from dired."
11658 (interactive)
11659 (anything-dired-do-action-on-file :action 'rename))
11661 ;;;###autoload
11662 (defun anything-dired-copy-file ()
11663 "Preconfigured `anything' to copy files from dired."
11664 (interactive)
11665 (anything-dired-do-action-on-file :action 'copy))
11667 ;;;###autoload
11668 (defun anything-dired-symlink-file ()
11669 "Preconfigured `anything' to symlink files from dired."
11670 (interactive)
11671 (anything-dired-do-action-on-file :action 'symlink))
11673 ;;;###autoload
11674 (defun anything-dired-hardlink-file ()
11675 "Preconfigured `anything' to hardlink files from dired."
11676 (interactive)
11677 (anything-dired-do-action-on-file :action 'hardlink))
11679 ;;;###autoload
11680 (defun anything-do-grep ()
11681 "Preconfigured anything for grep.
11682 Contrarily to Emacs `grep' no default directory is given, but
11683 the full path of candidates in ONLY.
11684 That allow to grep different files not only in `default-directory' but anywhere
11685 by marking them (C-<SPACE>). If one or more directory is selected
11686 grep will search in all files of these directories.
11687 You can use also wildcard in the base name of candidate.
11688 If a prefix arg is given use the -r option of grep.
11689 The prefix arg can be passed before or after start.
11690 See also `anything-do-grep-1'."
11691 (interactive)
11692 (let ((only (anything-c-read-file-name
11693 "Search in file(s): "
11694 :marked-candidates t
11695 :preselect (or (dired-get-filename nil t)
11696 (buffer-file-name (current-buffer)))))
11697 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11698 (anything-do-grep-1 only prefarg)))
11700 ;;;###autoload
11701 (defun anything-do-zgrep (candidate)
11702 "Preconfigured anything for zgrep."
11703 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11704 (ls (anything-c-read-file-name
11705 "Search in file(s): "
11706 :marked-candidates t
11707 :preselect (or (dired-get-filename nil t)
11708 (buffer-file-name (current-buffer))))))
11709 (anything-ff-zgrep-1 ls prefarg)))
11711 (defun anything-c-etags-select (arg)
11712 "Preconfigured anything for etags.
11713 Called with one prefix arg use symbol at point as initial input.
11714 Called with two prefix arg reinitialize cache.
11715 If tag file have been modified reinitialize cache."
11716 (interactive "P")
11717 (let ((tag (anything-c-etags-get-tag-file))
11718 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11719 (anything-quit-if-no-candidate t)
11720 (anything-execute-action-at-once-if-one t)
11721 (anything-compile-source-functions
11722 (if anything-c-etags-use-regexp-search
11723 ;; rule out anything-match-plugin because the input is one regexp.
11724 (delq 'anything-compile-source--match-plugin
11725 (copy-sequence anything-compile-source-functions))
11726 anything-compile-source-functions)))
11727 (when (or (equal arg '(16))
11728 (and anything-c-etags-mtime-alist
11729 (anything-c-etags-file-modified-p tag)))
11730 (remhash tag anything-c-etags-cache))
11731 (if (and tag (file-exists-p tag))
11732 (anything :sources 'anything-c-source-etags-select
11733 :keymap anything-c-etags-map
11734 :input init
11735 :buffer "*anything etags*")
11736 (message "Error: No tag file found, please create one with etags shell command."))))
11738 ;;;###autoload
11739 (defun anything-filelist ()
11740 "Preconfigured `anything' to open files instantly.
11742 See `anything-c-filelist-file-name' docstring for usage."
11743 (interactive)
11744 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11746 ;;;###autoload
11747 (defun anything-filelist+ ()
11748 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11750 This is a replacement for `anything-for-files'.
11751 See `anything-c-filelist-file-name' docstring for usage."
11752 (interactive)
11753 (anything-other-buffer
11754 '(anything-c-source-ffap-line
11755 anything-c-source-ffap-guesser
11756 anything-c-source-buffers-list
11757 anything-c-source-recentf
11758 anything-c-source-bookmarks
11759 anything-c-source-file-cache
11760 anything-c-source-filelist)
11761 "*anything file list*"))
11763 ;;;###autoload
11764 (defun anything-M-x ()
11765 "Preconfigured `anything' for Emacs commands.
11766 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11767 (interactive)
11768 (let* (in-help
11769 help-cand
11770 anything-persistent-action-use-special-display
11771 (history (loop with hist
11772 for i in extended-command-history
11773 for com = (intern i)
11774 when (fboundp com)
11775 collect i into hist finally return hist)))
11776 (flet ((pers-help (candidate)
11777 (let ((hbuf (get-buffer (help-buffer))))
11778 (if (and in-help (string= candidate help-cand))
11779 (progn
11780 ;; When M-x is started from a help buffer,
11781 ;; Don't kill it as it is anything-current-buffer.
11782 (unless (equal hbuf anything-current-buffer)
11783 (kill-buffer hbuf))
11784 (setq in-help nil))
11785 ;; Be sure anything-current-buffer
11786 ;; have not a dedicated window.
11787 (set-window-dedicated-p
11788 (get-buffer-window anything-current-buffer) nil)
11789 (describe-function (intern candidate))
11790 (message nil) ; Erase the new stupid message Type "q"[...]
11791 (setq in-help t))
11792 (setq help-cand candidate))))
11793 (let* ((command
11795 (anything
11796 :sources
11797 '(((name . "Emacs Commands history")
11798 (candidates . history)
11799 (filtered-candidate-transformer
11800 . (lambda (candidates sources)
11801 (loop for i in candidates
11802 do (set-text-properties 0 (length i) nil i)
11803 collect i)))
11804 (persistent-action . pers-help)
11805 (persistent-help . "Describe this command")
11806 (action . identity))
11807 ((name . "Emacs Commands")
11808 (init
11809 . (lambda ()
11810 (with-current-buffer (anything-candidate-buffer 'global)
11811 (goto-char (point-min))
11812 (loop
11813 for sym in (all-completions "" obarray 'commandp)
11814 do (insert (concat sym "\n"))))))
11815 (persistent-action . pers-help)
11816 (persistent-help . "Describe this command")
11817 (filtered-candidate-transformer . anything-M-x-transformer)
11818 (candidates-in-buffer)
11819 (action . identity)))
11820 :buffer "*anything M-x*")
11821 (keyboard-quit)))
11822 (sym-com (intern command)))
11823 (unless current-prefix-arg
11824 (setq current-prefix-arg anything-current-prefix-arg))
11825 ;; Avoid having `this-command' set to *exit-minibuffer.
11826 (setq this-command sym-com)
11827 (call-interactively sym-com)
11828 (setq extended-command-history
11829 (cons command (delete command history)))))))
11831 ;;;###autoload
11832 (defun anything-manage-advice ()
11833 "Preconfigured `anything' to disable/enable function advices."
11834 (interactive)
11835 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11837 ;;;###autoload
11838 (defun anything-bookmark-ext ()
11839 "Preconfigured `anything' for bookmark-extensions sources.
11840 Needs bookmark-ext.el:
11841 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11842 Contain also `anything-c-source-google-suggest'."
11843 (interactive)
11844 (anything
11845 :sources
11846 '(anything-c-source-bookmark-files&dirs
11847 anything-c-source-bookmark-w3m
11848 anything-c-source-google-suggest
11849 anything-c-source-bmkext-addressbook
11850 anything-c-source-bookmark-gnus
11851 anything-c-source-bookmark-info
11852 anything-c-source-bookmark-man
11853 anything-c-source-bookmark-images
11854 anything-c-source-bookmark-su-files&dirs
11855 anything-c-source-bookmark-ssh-files&dirs)
11856 :prompt "SearchBookmark: "
11857 :buffer "*anything bmkext*"))
11859 ;;;###autoload
11860 (defun anything-simple-call-tree ()
11861 "Preconfigured `anything' for simple-call-tree. List function relationships.
11863 Needs simple-call-tree.el.
11864 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11865 (interactive)
11866 (anything-other-buffer
11867 '(anything-c-source-simple-call-tree-functions-callers
11868 anything-c-source-simple-call-tree-callers-functions)
11869 "*anything simple-call-tree*"))
11871 ;;;###autoload
11872 (defun anything-mark-ring ()
11873 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11874 (interactive)
11875 (anything 'anything-c-source-mark-ring))
11877 ;;;###autoload
11878 (defun anything-global-mark-ring ()
11879 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11880 (interactive)
11881 (anything 'anything-c-source-global-mark-ring))
11883 ;;;###autoload
11884 (defun anything-all-mark-rings ()
11885 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11886 `anything-c-source-mark-ring'."
11887 (interactive)
11888 (anything '(anything-c-source-mark-ring
11889 anything-c-source-global-mark-ring)))
11891 ;;;###autoload
11892 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11893 "Preconfigured `anything' to edit or view EmacsWiki page.
11895 Needs yaoddmuse.el.
11897 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11898 (interactive)
11899 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11901 ;;;###autoload
11902 (defun anything-yaoddmuse-emacswiki-post-library ()
11903 "Preconfigured `anything' to post library to EmacsWiki.
11905 Needs yaoddmuse.el.
11907 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11908 (interactive)
11909 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11911 ;;;###autoload
11912 (defun anything-eval-expression (arg)
11913 "Preconfigured anything for `anything-c-source-evaluation-result'."
11914 (interactive "P")
11915 (anything :sources 'anything-c-source-evaluation-result
11916 :input (when arg (thing-at-point 'sexp))
11917 :buffer "*anything eval*"
11918 :keymap anything-eval-expression-map))
11920 ;;;###autoload
11921 (defun anything-eval-expression-with-eldoc ()
11922 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11923 (interactive)
11924 (declare (special eldoc-idle-delay))
11925 (let ((timer (run-with-idle-timer eldoc-idle-delay
11926 'repeat 'anything-eldoc-show-in-eval))
11927 (minibuffer-completing-symbol t) ; Enable lisp completion.
11928 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11929 (unwind-protect
11930 (minibuffer-with-setup-hook
11931 'anything-eldoc-store-minibuffer
11932 (call-interactively 'anything-eval-expression))
11933 (and timer (cancel-timer timer))
11934 (setq anything-eldoc-active-minibuffers-list
11935 (cdr anything-eldoc-active-minibuffers-list)))))
11937 ;;;###autoload
11938 (defun anything-calcul-expression ()
11939 "Preconfigured anything for `anything-c-source-calculation-result'."
11940 (interactive)
11941 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11943 ;;;###autoload
11944 (defun anything-surfraw (pattern engine)
11945 "Preconfigured `anything' to search PATTERN with search ENGINE."
11946 (interactive (list (read-string "SearchFor: ")
11947 (anything-comp-read
11948 "Engine: "
11949 (anything-c-build-elvi-list)
11950 :must-match t
11951 :name "Surfraw Search Engines"
11952 :history anything-surfraw-engines-history)))
11953 (let* ((engine-nodesc (car (split-string engine)))
11954 (url (with-temp-buffer
11955 (apply 'call-process "surfraw" nil t nil
11956 ;;JAVE
11957 (append (list engine-nodesc "-p") (split-string pattern)))
11958 (replace-regexp-in-string
11959 "\n" "" (buffer-string))))
11960 (browse-url-browser-function (or anything-surfraw-default-browser-function
11961 browse-url-browser-function)))
11962 (if (string= engine-nodesc "W")
11963 (anything-c-browse-url)
11964 (anything-c-browse-url url)
11965 (setq anything-surfraw-engines-history
11966 (cons engine (delete engine anything-surfraw-engines-history))))))
11968 ;;;###autoload
11969 (defun anything-call-source ()
11970 "Preconfigured `anything' to call anything source."
11971 (interactive)
11972 (anything 'anything-c-source-call-source nil nil nil nil
11973 anything-source-select-buffer))
11975 ;;;###autoload
11976 (defun anything-execute-anything-command ()
11977 "Preconfigured `anything' to execute preconfigured `anything'."
11978 (interactive)
11979 (anything-other-buffer 'anything-c-source-anything-commands
11980 "*anything commands*"))
11982 ;;;###autoload
11983 (defun anything-create (&optional string initial-input)
11984 "Preconfigured `anything' to do many create actions from STRING.
11985 See also `anything-create--actions'."
11986 (interactive)
11987 (setq string (or string (read-string "Create Anything: " initial-input)))
11988 (anything '(((name . "Anything Create")
11989 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
11990 (candidates . anything-create--actions)
11991 (candidate-number-limit)
11992 (action . (lambda (func) (funcall func string)))))))
11994 ;;;###autoload
11995 (defun anything-top ()
11996 "Preconfigured `anything' for top command."
11997 (interactive)
11998 (let ((anything-samewindow t)
11999 (anything-enable-shortcuts)
12000 (anything-display-function 'anything-default-display-buffer)
12001 (anything-candidate-number-limit 9999))
12002 (save-window-excursion
12003 (delete-other-windows)
12004 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12006 ;;;###autoload
12007 (defun anything-select-xfont ()
12008 "Preconfigured `anything' to select Xfont."
12009 (interactive)
12010 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12012 ;;;###autoload
12013 (defun anything-world-time ()
12014 "Preconfigured `anything' to show world time."
12015 (interactive)
12016 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12018 ;;;###autoload
12019 (defun anything-apt (arg query)
12020 "Preconfigured `anything' : frontend of APT package manager.
12021 With a prefix arg reload cache."
12022 (interactive "P\nsSearch Package: ")
12023 (when arg
12024 (setq anything-c-apt-installed-packages nil)
12025 (setq anything-c-apt-all-packages nil))
12026 (anything :sources 'anything-c-source-apt
12027 :prompt "Search Package: " :input query))
12029 ;;;###autoload
12030 (defun anything-esh-pcomplete ()
12031 "Preconfigured anything to provide anything completion in eshell."
12032 (interactive)
12033 (let* ((anything-quit-if-no-candidate t)
12034 (anything-execute-action-at-once-if-one t)
12035 (target (thing-at-point 'symbol))
12036 (end (point))
12037 (beg (or (and target (- end (length target)))
12038 ;; Nothing at point.
12039 (progn (insert " ") (point)))))
12040 (setq anything-ec-target (or target " "))
12041 (with-anything-show-completion beg end
12042 (anything :sources 'anything-c-source-esh
12043 :input (anything-ff-set-pattern ; Handle tramp filenames.
12044 (car (last (ignore-errors ; Needed in lisp symbols completion.
12045 (pcomplete-parse-arguments)))))))))
12047 ;;;###autoload
12048 (defun anything-eshell-history ()
12049 "Preconfigured anything for eshell history."
12050 (interactive)
12051 (let* ((end (point))
12052 (beg (save-excursion (eshell-bol) (point)))
12053 flag-empty)
12054 (when (eq beg end)
12055 (insert " ")
12056 (setq flag-empty t)
12057 (setq end (point)))
12058 (unwind-protect
12059 (with-anything-show-completion beg end
12060 (anything :sources 'anything-c-source-eshell-history
12061 :buffer "*Eshell history*"))
12062 (when (and flag-empty
12063 (looking-back " "))
12064 (delete-char -1)))))
12066 ;;;###autoload
12067 (defun anything-c-run-external-command (program)
12068 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12069 If program is already running exit with error.
12070 You can set your own list of commands with
12071 `anything-c-external-commands-list'."
12072 (interactive (list
12073 (anything-comp-read
12074 "RunProgram: "
12075 (anything-c-external-commands-list-1 'sort)
12076 :must-match t
12077 :name "External Commands"
12078 :history anything-external-command-history)))
12079 (anything-run-or-raise program)
12080 (setq anything-external-command-history
12081 (cons program (delete program
12082 (loop for i in anything-external-command-history
12083 when (executable-find i) collect i)))))
12085 ;;;###autoload
12086 (defun anything-ratpoison-commands ()
12087 "Preconfigured `anything' to execute ratpoison commands."
12088 (interactive)
12089 (anything-other-buffer 'anything-c-source-ratpoison-commands
12090 "*anything ratpoison commands*"))
12092 ;;;###autoload
12093 (defun anything-ucs ()
12094 "Preconfigured anything for `ucs-names' math symbols."
12095 (interactive)
12096 (anything :sources 'anything-c-source-ucs
12097 :keymap anything-c-ucs-map))
12101 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12104 (provide 'anything-config)
12106 ;;; Local Variables:
12107 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12108 ;;; End:
12110 ;; How to save (DO NOT REMOVE!!)
12111 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12112 ;;; anything-config.el ends here
12114 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12115 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12116 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12117 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12118 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12119 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12120 ;;; LocalWords: dotimes Thierry online vname
12121 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12122 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12123 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12124 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12125 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12126 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12127 ;;; LocalWords: startpos noselect dont desc