* anything-config.el (anything-comp-read): Handle default arg here in candidates.
[anything-config.git] / anything-config.el
blobe5540e982b08fd9e761766fafe9b0f1cfa5b6d2b
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.
77 ;;; Autodoc documentation:
78 ;; ---------------------
80 ;; * Commands defined here are:
81 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
82 ;; `anything-configuration'
83 ;; Customize `anything'.
84 ;; `anything-mini'
85 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
86 ;; `anything-for-files'
87 ;; Preconfigured `anything' for opening files.
88 ;; `anything-recentf'
89 ;; Preconfigured `anything' for `recentf'.
90 ;; `anything-info-at-point'
91 ;; Preconfigured `anything' for searching info at point.
92 ;; `anything-info-emacs'
93 ;; Preconfigured anything for Emacs manual index.
94 ;; `anything-show-kill-ring'
95 ;; Preconfigured `anything' for `kill-ring'.
96 ;; `anything-minibuffer-history'
97 ;; Preconfigured `anything' for `minibuffer-history'.
98 ;; `anything-gentoo'
99 ;; Preconfigured `anything' for gentoo linux.
100 ;; `anything-imenu'
101 ;; Preconfigured `anything' for `imenu'.
102 ;; `anything-google-suggest'
103 ;; Preconfigured `anything' for google search with google suggest.
104 ;; `anything-yahoo-suggest'
105 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
106 ;; `anything-for-buffers'
107 ;; Preconfigured `anything' for buffer.
108 ;; `anything-buffers-list'
109 ;; Enhanced preconfigured `anything' for buffer.
110 ;; `anything-bbdb'
111 ;; Preconfigured `anything' for BBDB.
112 ;; `anything-locate'
113 ;; Preconfigured `anything' for Locate.
114 ;; `anything-w3m-bookmarks'
115 ;; Preconfigured `anything' for w3m bookmark.
116 ;; `anything-firefox-bookmarks'
117 ;; Preconfigured `anything' for firefox bookmark.
118 ;; `anything-colors'
119 ;; Preconfigured `anything' for color.
120 ;; `anything-bookmarks'
121 ;; Preconfigured `anything' for bookmarks.
122 ;; `anything-c-pp-bookmarks'
123 ;; Preconfigured `anything' for bookmarks (pretty-printed).
124 ;; `anything-c-insert-latex-math'
125 ;; Preconfigured anything for latex math symbols completion.
126 ;; `anything-register'
127 ;; Preconfigured `anything' for Emacs registers.
128 ;; `anything-man-woman'
129 ;; Preconfigured `anything' for Man and Woman pages.
130 ;; `anything-org-keywords'
131 ;; Preconfigured `anything' for org keywords.
132 ;; `anything-emms'
133 ;; Preconfigured `anything' for emms sources.
134 ;; `anything-eev-anchors'
135 ;; Preconfigured `anything' for eev anchors.
136 ;; `anything-bm-list'
137 ;; Preconfigured `anything' for visible bookmarks.
138 ;; `anything-timers'
139 ;; Preconfigured `anything' for timers.
140 ;; `anything-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
142 ;; `anything-occur'
143 ;; Preconfigured Anything for Occur source.
144 ;; `anything-browse-code'
145 ;; Preconfigured anything to browse code.
146 ;; `anything-org-headlines'
147 ;; Preconfigured anything to show org headlines.
148 ;; `anything-info-gnus'
149 ;; Preconfigured anything to browse Gnus Manual.
150 ;; `anything-regexp'
151 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
152 ;; `anything-test-sources'
153 ;; List all anything sources for test.
154 ;; `anything-select-source'
155 ;; Select source.
156 ;; `anything-mark-all'
157 ;; Mark all visible unmarked candidates in current source.
158 ;; `anything-unmark-all'
159 ;; Unmark all candidates in all sources of current anything session.
160 ;; `anything-toggle-all-marks'
161 ;; Toggle all marks.
162 ;; `anything-c-buffer-help'
163 ;; Help command for anything buffers.
164 ;; `anything-buffer-diff-persistent'
165 ;; Toggle diff buffer without quitting anything.
166 ;; `anything-buffer-revert-persistent'
167 ;; Revert buffer without quitting anything.
168 ;; `anything-buffer-save-persistent'
169 ;; Save buffer without quitting anything.
170 ;; `anything-buffer-run-kill-buffers'
171 ;; Run kill buffer action from `anything-c-source-buffers-list'.
172 ;; `anything-buffer-run-grep'
173 ;; Run Grep action from `anything-c-source-buffers-list'.
174 ;; `anything-buffer-run-zgrep'
175 ;; Run Grep action from `anything-c-source-buffers-list'.
176 ;; `anything-buffer-run-query-replace-regexp'
177 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
178 ;; `anything-buffer-run-query-replace'
179 ;; Run Query replace action from `anything-c-source-buffers-list'.
180 ;; `anything-buffer-switch-other-window'
181 ;; Run switch to other window action from `anything-c-source-buffers-list'.
182 ;; `anything-buffer-switch-other-frame'
183 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
184 ;; `anything-buffer-switch-to-elscreen'
185 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
186 ;; `anything-c-copy-files-async'
187 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
188 ;; `anything-ff-help'
189 ;; Help command for `anything-find-files'.
190 ;; `anything-ff-run-toggle-auto-update'
191 ;; Not documented.
192 ;; `anything-ff-run-switch-to-history'
193 ;; Run Switch to history action from `anything-c-source-find-files'.
194 ;; `anything-ff-run-grep'
195 ;; Run Grep action from `anything-c-source-find-files'.
196 ;; `anything-ff-run-pdfgrep'
197 ;; Run Pdfgrep action from `anything-c-source-find-files'.
198 ;; `anything-ff-run-zgrep'
199 ;; Run Grep action from `anything-c-source-find-files'.
200 ;; `anything-ff-run-copy-file'
201 ;; Run Copy file action from `anything-c-source-find-files'.
202 ;; `anything-ff-run-rename-file'
203 ;; Run Rename file action from `anything-c-source-find-files'.
204 ;; `anything-ff-run-byte-compile-file'
205 ;; Run Byte compile file action from `anything-c-source-find-files'.
206 ;; `anything-ff-run-load-file'
207 ;; Run Load file action from `anything-c-source-find-files'.
208 ;; `anything-ff-run-eshell-command-on-file'
209 ;; Run eshell command on file action from `anything-c-source-find-files'.
210 ;; `anything-ff-run-ediff-file'
211 ;; Run Ediff file action from `anything-c-source-find-files'.
212 ;; `anything-ff-run-ediff-merge-file'
213 ;; Run Ediff merge file action from `anything-c-source-find-files'.
214 ;; `anything-ff-run-symlink-file'
215 ;; Run Symlink file action from `anything-c-source-find-files'.
216 ;; `anything-ff-run-delete-file'
217 ;; Run Delete file action from `anything-c-source-find-files'.
218 ;; `anything-ff-run-complete-fn-at-point'
219 ;; Run complete file name action from `anything-c-source-find-files'.
220 ;; `anything-ff-run-switch-to-eshell'
221 ;; Run switch to eshell action from `anything-c-source-find-files'.
222 ;; `anything-ff-run-switch-other-window'
223 ;; Run switch to other window action from `anything-c-source-find-files'.
224 ;; `anything-ff-run-switch-other-frame'
225 ;; Run switch to other frame action from `anything-c-source-find-files'.
226 ;; `anything-ff-run-open-file-externally'
227 ;; Run open file externally command action from `anything-c-source-find-files'.
228 ;; `anything-ff-run-gnus-attach-files'
229 ;; Run gnus attach files command action from `anything-c-source-find-files'.
230 ;; `anything-ff-run-etags'
231 ;; Run Etags command action from `anything-c-source-find-files'.
232 ;; `anything-ff-run-print-file'
233 ;; Run Print file action from `anything-c-source-find-files'.
234 ;; `anything-find-files-down-one-level'
235 ;; Go down one level like unix command `cd ..'.
236 ;; `anything-ff-properties-persistent'
237 ;; Show properties without quitting anything.
238 ;; `anything-ff-run-kill-buffer-persistent'
239 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
240 ;; `anything-ff-rotate-left-persistent'
241 ;; Rotate image left without quitting anything.
242 ;; `anything-ff-rotate-right-persistent'
243 ;; Rotate image right without quitting anything.
244 ;; `anything-find-files'
245 ;; Preconfigured `anything' for anything implementation of `find-file'.
246 ;; `anything-write-file'
247 ;; Preconfigured `anything' providing completion for `write-file'.
248 ;; `anything-insert-file'
249 ;; Preconfigured `anything' providing completion for `insert-file'.
250 ;; `anything-dired-rename-file'
251 ;; Preconfigured `anything' to rename files from dired.
252 ;; `anything-dired-copy-file'
253 ;; Preconfigured `anything' to copy files from dired.
254 ;; `anything-dired-symlink-file'
255 ;; Preconfigured `anything' to symlink files from dired.
256 ;; `anything-dired-hardlink-file'
257 ;; Preconfigured `anything' to hardlink files from dired.
258 ;; `anything-generic-file-help'
259 ;; Not documented.
260 ;; `anything-do-grep'
261 ;; Preconfigured anything for grep.
262 ;; `anything-c-goto-precedent-file'
263 ;; Go to precedent file in anything grep/etags buffers.
264 ;; `anything-c-goto-next-file'
265 ;; Go to precedent file in anything grep/etags buffers.
266 ;; `anything-grep-help'
267 ;; Not documented.
268 ;; `anything-c-grep-run-persistent-action'
269 ;; Run grep persistent action from `anything-do-grep-1'.
270 ;; `anything-c-grep-run-default-action'
271 ;; Run grep default action from `anything-do-grep-1'.
272 ;; `anything-c-grep-run-other-window-action'
273 ;; Run grep goto other window action from `anything-do-grep-1'.
274 ;; `anything-c-grep-run-save-buffer'
275 ;; Run grep save results action from `anything-do-grep-1'.
276 ;; `anything-pdfgrep-help'
277 ;; Not documented.
278 ;; `anything-do-pdfgrep'
279 ;; Not documented.
280 ;; `anything-yank-text-at-point'
281 ;; Yank text at point in minibuffer.
282 ;; `anything-etags-help'
283 ;; The help function for etags.
284 ;; `anything-c-etags-select'
285 ;; Preconfigured anything for etags.
286 ;; `anything-filelist'
287 ;; Preconfigured `anything' to open files instantly.
288 ;; `anything-filelist+'
289 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
290 ;; `anything-c-describe-attributes'
291 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
292 ;; `anything-M-x'
293 ;; Preconfigured `anything' for Emacs commands.
294 ;; `anything-manage-advice'
295 ;; Preconfigured `anything' to disable/enable function advices.
296 ;; `anything-bookmark-ext'
297 ;; Preconfigured `anything' for bookmark-extensions sources.
298 ;; `anything-simple-call-tree'
299 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
300 ;; `anything-mark-ring'
301 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
302 ;; `anything-global-mark-ring'
303 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
304 ;; `anything-all-mark-rings'
305 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
306 ;; `anything-yaoddmuse-cache-pages'
307 ;; Fetch the list of files on emacswiki and create cache file.
308 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
309 ;; Preconfigured `anything' to edit or view EmacsWiki page.
310 ;; `anything-yaoddmuse-emacswiki-post-library'
311 ;; Preconfigured `anything' to post library to EmacsWiki.
312 ;; `anything-eval-expression'
313 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
314 ;; `anything-eval-new-line-and-indent'
315 ;; Not documented.
316 ;; `anything-eval-expression-with-eldoc'
317 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
318 ;; `anything-calcul-expression'
319 ;; Preconfigured anything for `anything-c-source-calculation-result'.
320 ;; `anything-surfraw'
321 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
322 ;; `anything-call-source'
323 ;; Preconfigured `anything' to call anything source.
324 ;; `anything-call-source-from-anything'
325 ;; Call anything source within `anything' session.
326 ;; `anything-execute-anything-command'
327 ;; Preconfigured `anything' to execute preconfigured `anything'.
328 ;; `anything-create-from-anything'
329 ;; Run `anything-create' from `anything' as a fallback.
330 ;; `anything-create'
331 ;; Preconfigured `anything' to do many create actions from STRING.
332 ;; `anything-top'
333 ;; Preconfigured `anything' for top command.
334 ;; `anything-select-xfont'
335 ;; Preconfigured `anything' to select Xfont.
336 ;; `anything-world-time'
337 ;; Preconfigured `anything' to show world time.
338 ;; `anything-apt'
339 ;; Preconfigured `anything' : frontend of APT package manager.
340 ;; `anything-esh-pcomplete'
341 ;; Preconfigured anything to provide anything completion in eshell.
342 ;; `anything-eshell-history'
343 ;; Preconfigured anything for eshell history.
344 ;; `anything-lisp-completion-at-point'
345 ;; Anything lisp symbol completion at point.
346 ;; `anything-lisp-completion-at-point-or-indent'
347 ;; First call indent and second call complete lisp symbol.
348 ;; `anything-c-complete-file-name-at-point'
349 ;; Complete file name at point.
350 ;; `anything-c-run-external-command'
351 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
352 ;; `anything-ratpoison-commands'
353 ;; Preconfigured `anything' to execute ratpoison commands.
354 ;; `anything-c-set-variable'
355 ;; Set value to VAR interactively.
356 ;; `anything-c-adaptive-save-history'
357 ;; Save history information to file given by `anything-c-adaptive-history-file'.
358 ;; `anything-c-reset-adaptative-history'
359 ;; Delete all `anything-c-adaptive-history' and his file.
360 ;; `anything-c-toggle-match-plugin'
361 ;; Toggle anything-match-plugin.
363 ;; * User variables defined here:
364 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
365 ;; `anything-c-use-standard-keys'
366 ;; Default Value: nil
367 ;; `anything-c-adaptive-history-file'
368 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
369 ;; `anything-c-adaptive-history-length'
370 ;; Default Value: 50
371 ;; `anything-c-google-suggest-url'
372 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
373 ;; `anything-c-google-suggest-search-url'
374 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
375 ;; `anything-google-suggest-use-curl-p'
376 ;; Default Value: nil
377 ;; `anything-c-yahoo-suggest-url'
378 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
379 ;; `anything-c-yahoo-suggest-search-url'
380 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
381 ;; `anything-c-boring-buffer-regexp'
382 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
383 ;; `anything-c-boring-file-regexp'
384 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
385 ;; `anything-kill-ring-threshold'
386 ;; Default Value: 10
387 ;; `anything-su-or-sudo'
388 ;; Default Value: "su"
389 ;; `anything-for-files-prefered-list'
390 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
391 ;; `anything-create--actions-private'
392 ;; Default Value: nil
393 ;; `anything-allow-skipping-current-buffer'
394 ;; Default Value: t
395 ;; `anything-c-enable-eval-defun-hack'
396 ;; Default Value: t
397 ;; `anything-tramp-verbose'
398 ;; Default Value: 0
399 ;; `anything-raise-command'
400 ;; Default Value: nil
401 ;; `anything-command-map-prefix-key'
402 ;; Default Value: "<f5> a"
403 ;; `anything-c-find-files-show-icons'
404 ;; Default Value: nil
405 ;; `anything-c-find-files-icons-directory'
406 ;; Default Value: "/usr/local/share/emacs/24.0.50/etc/images/tree-widget/default"
407 ;; `anything-c-browse-code-regexp-lisp'
408 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
409 ;; `anything-c-browse-code-regexp-python'
410 ;; Default Value: "\\<def\\>\\|\\<class\\>"
411 ;; `anything-c-browse-code-regexp-alist'
412 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
413 ;; `anything-c-external-programs-associations'
414 ;; Default Value: nil
415 ;; `anything-ff-auto-update-initial-value'
416 ;; Default Value: t
417 ;; `anything-c-copy-async-prefered-emacs'
418 ;; Default Value: "emacs"
419 ;; `anything-ff-lynx-style-map'
420 ;; Default Value: t
421 ;; `anything-ff-history-max-length'
422 ;; Default Value: 100
423 ;; `anything-ff-smart-completion'
424 ;; Default Value: t
425 ;; `anything-ff-default-kbsize'
426 ;; Default Value: 1024.0
427 ;; `anything-ff-tramp-not-fancy'
428 ;; Default Value: t
429 ;; `anything-ff-exif-data-program'
430 ;; Default Value: "exiftran"
431 ;; `anything-ff-exif-data-program-args'
432 ;; Default Value: "-d"
433 ;; `anything-c-grep-use-ioccur-style-keys'
434 ;; Default Value: t
435 ;; `anything-c-pdfgrep-default-read-command'
436 ;; Default Value: "xpdf '%f' %p"
437 ;; `anything-c-etags-tag-file-name'
438 ;; Default Value: "TAGS"
439 ;; `anything-c-etags-tag-file-search-limit'
440 ;; Default Value: 10
441 ;; `anything-c-filelist-file-name'
442 ;; Default Value: nil
443 ;; `anything-c-eldoc-in-minibuffer-show-fn'
444 ;; Default Value: anything-c-eldoc-show-in-mode-line
445 ;; `anything-c-turn-on-show-completion'
446 ;; Default Value: t
447 ;; `anything-lisp-completion-or-indent-delay'
448 ;; Default Value: 0.6
449 ;; `anything-c-default-external-file-browser'
450 ;; Default Value: "nautilus"
451 ;; `anything-c-use-adaptative-sorting'
452 ;; Default Value: nil
453 ;; `anything-ff-newfile-prompt-p'
454 ;; Default Value: t
456 ;; * Anything sources defined here:
457 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
458 ;; `anything-c-source-regexp' (Regexp Builder)
459 ;; `anything-c-source-buffers' (Buffers)
460 ;; `anything-c-source-buffer-not-found' (Create buffer)
461 ;; `anything-c-source-buffers-list' (Buffers)
462 ;; `anything-c-source-file-name-history' (File Name History)
463 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
464 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
465 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
466 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
467 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
468 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
469 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
470 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
471 ;; `anything-c-source-file-cache' (File Cache)
472 ;; `anything-c-source-locate' (Locate)
473 ;; `anything-c-source-etags-select' (Etags)
474 ;; `anything-c-source-recentf' (Recentf)
475 ;; `anything-c-source-ffap-guesser' (File at point)
476 ;; `anything-c-source-ffap-line' (File/Lineno at point)
477 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
478 ;; `anything-c-source-filelist' (FileList)
479 ;; `anything-c-source-info-pages' (Info Pages)
480 ;; `anything-c-source-info-elisp' (Info index: elisp)
481 ;; `anything-c-source-info-cl' (Info index: cl)
482 ;; `anything-c-source-info-org' (Info index: org)
483 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
484 ;; `anything-c-source-info-zsh' (Info index: zsh)
485 ;; `anything-c-source-info-bash' (Info index: bash)
486 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
487 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
488 ;; `anything-c-source-info-find' (Info index: find)
489 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
490 ;; `anything-c-source-info-textutils' (Info index: textutils)
491 ;; `anything-c-source-info-libc' (Info index: libc)
492 ;; `anything-c-source-info-make' (Info index: make)
493 ;; `anything-c-source-info-automake' (Info index: automake)
494 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
495 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
496 ;; `anything-c-source-info-emacs' (Info index: emacs)
497 ;; `anything-c-source-info-elib' (Info index: elib)
498 ;; `anything-c-source-info-eieio' (Info index: eieio)
499 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
500 ;; `anything-c-source-info-guile' (Info index: guile)
501 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
502 ;; `anything-c-source-info-goops' (Info index: goops)
503 ;; `anything-c-source-info-screen' (Info index: screen)
504 ;; `anything-c-source-info-latex' (Info index: latex)
505 ;; `anything-c-source-info-gawk' (Info index: gawk)
506 ;; `anything-c-source-info-sed' (Info index: sed)
507 ;; `anything-c-source-info-m4' (Info index: m4)
508 ;; `anything-c-source-info-wget' (Info index: wget)
509 ;; `anything-c-source-info-binutils' (Info index: binutils)
510 ;; `anything-c-source-info-as' (Info index: as)
511 ;; `anything-c-source-info-bfd' (Info index: bfd)
512 ;; `anything-c-source-info-gprof' (Info index: gprof)
513 ;; `anything-c-source-info-ld' (Info index: ld)
514 ;; `anything-c-source-info-diff' (Info index: diff)
515 ;; `anything-c-source-info-flex' (Info index: flex)
516 ;; `anything-c-source-info-grep' (Info index: grep)
517 ;; `anything-c-source-info-gzip' (Info index: gzip)
518 ;; `anything-c-source-info-libtool' (Info index: libtool)
519 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
520 ;; `anything-c-source-info-info' (Info index: info)
521 ;; `anything-c-source-info-gdb' (Info index: gdb)
522 ;; `anything-c-source-info-stabs' (Info index: stabs)
523 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
524 ;; `anything-c-source-info-cvs' (Info index: cvs)
525 ;; `anything-c-source-info-bison' (Info index: bison)
526 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
527 ;; `anything-c-source-info-global' (Info index: global)
528 ;; `anything-c-source-man-pages' (Manual Pages)
529 ;; `anything-c-source-complex-command-history' (Complex Command History)
530 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
531 ;; `anything-c-source-emacs-commands' (Emacs Commands)
532 ;; `anything-c-source-lacarte' (Lacarte)
533 ;; `anything-c-source-emacs-functions' (Emacs Functions)
534 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
535 ;; `anything-c-source-advice' (Function Advice)
536 ;; `anything-c-source-emacs-variables' (Emacs Variables)
537 ;; `anything-c-source-bookmarks' (Bookmarks)
538 ;; `anything-c-source-bookmark-set' (Set Bookmark)
539 ;; `anything-c-source-bm' (Visible Bookmarks)
540 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
541 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
542 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
543 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
544 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
545 ;; `anything-c-source-bookmark-images' (Bookmark Images)
546 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
547 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
548 ;; `anything-c-source-bookmark-info' (Bookmark Info)
549 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
550 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
551 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
552 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
553 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
554 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
555 ;; `anything-c-source-imenu' (Imenu)
556 ;; `anything-c-source-ctags' (Exuberant ctags)
557 ;; `anything-c-source-semantic' (Semantic Tags)
558 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
559 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
560 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
561 ;; `anything-c-source-customize-face' (Customize Face)
562 ;; `anything-c-source-colors' (Colors)
563 ;; `anything-c-source-tracker-search' (Tracker Search)
564 ;; `anything-c-source-mac-spotlight' (mdfind)
565 ;; `anything-c-source-kill-ring' (Kill Ring)
566 ;; `anything-c-source-mark-ring' (mark-ring)
567 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
568 ;; `anything-c-source-register' (Registers)
569 ;; `anything-c-source-latex-math' (Latex Math Menu)
570 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
571 ;; `anything-c-source-rd-headline' (RD HeadLine)
572 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
573 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
574 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
575 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
576 ;; `anything-c-source-org-headline' (Org HeadLine)
577 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
578 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
579 ;; `anything-c-source-eev-anchor' (Anchors)
580 ;; `anything-c-source-org-keywords' (Org Keywords)
581 ;; `anything-c-source-picklist' (Picklist)
582 ;; `anything-c-source-bbdb' (BBDB)
583 ;; `anything-c-source-evaluation-result' (Evaluation Result)
584 ;; `anything-c-source-calculation-result' (Calculation Result)
585 ;; `anything-c-source-google-suggest' (Google Suggest)
586 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
587 ;; `anything-c-source-emms-streams' (Emms Streams)
588 ;; `anything-c-source-emms-dired' (Music Directory)
589 ;; `anything-c-source-emms-files' (Emms files)
590 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
591 ;; `anything-c-source-call-source' (Call anything source)
592 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
593 ;; `anything-c-source-occur' (Occur)
594 ;; `anything-c-source-browse-code' (Browse code)
595 ;; `anything-c-source-create' (Create)
596 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
597 ;; `anything-c-source-elscreen' (Elscreen)
598 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
599 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
600 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
601 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
602 ;; `anything-c-source-xfonts' (X Fonts)
603 ;; `anything-c-source-time-world' (Time World List)
604 ;; `anything-c-source-apt' (APT)
605 ;; `anything-c-source-gentoo' (Portage sources)
606 ;; `anything-c-source-use-flags' (Use Flags)
607 ;; `anything-c-source-emacs-process' (Emacs Process)
608 ;; `anything-c-source-esh' (Eshell completions)
609 ;; `anything-c-source-eshell-history' (Eshell history)
610 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
612 ;; *** END auto-documentation
615 ;;; Change log:
617 ;; Change log of this file is found at
618 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
620 ;; Change log of this project is found at
621 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
623 ;;; Contributors:
625 ;; Tamas Patrovics
626 ;; Tassilo Horn <tassilo@member.fsf.org>
627 ;; Vagn Johansen <gonz808@hotmail.com>
628 ;; Mathias Dahl <mathias.dahl@gmail.com>
629 ;; Bill Clementson <billclem@gmail.com>
630 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
631 ;; Drew Adams <drew.adams@oracle.com>
632 ;; Jason McBrayer <jmcbray@carcosa.net>
633 ;; Andy Stewart <lazycat.manatee@gmail.com>
634 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
635 ;; rubikitch <rubikitch@ruby-lang.org>
636 ;; Scott Vokes <vokes.s@gmail.com>
637 ;; Kenichirou Oyama <k1lowxb@gmail.com>
639 ;;; For Maintainers:
641 ;; Evaluate (autodoc-update-all) before commit. This function
642 ;; generates anything-c-source-* / functions / options list.
644 ;; Install also developer-tools/autodoc.el
645 ;; And eval it or run interactively.
647 ;; [EVAL IT] (autodoc-update-all)
649 ;; Please write details documentation about function, then others will
650 ;; read code more easier. -- Andy Stewart
654 ;;; TODO
656 ;; - Fix documentation, now many functions haven't documentations.
659 ;;; Code:
662 ;;; Require
665 (require 'anything)
666 (require 'thingatpt)
667 (require 'ffap)
668 (require 'cl)
669 (require 'dired-aux)
670 (require 'dired-x)
671 (require 'tramp)
672 (require 'grep)
673 (require 'url)
674 (require 'xml)
675 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
676 (eval-when-compile (require 'semantic nil t))
677 (require 'anything-match-plugin)
681 ;;; Declare external functions
684 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
685 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
686 (declare-function image-dired-update-property "image-dired.el" (prop value))
687 (declare-function woman-file-name-all-completions "woman.el" (topic))
688 (declare-function Man-getpage-in-background "man.el" (topic))
689 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
690 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
691 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
692 (declare-function org-get-current-options "ext:org-exp.el")
693 (declare-function emms-streams "ext:emms-streams")
694 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
695 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
696 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
697 (declare-function emms-stream-quit "ext:emms-streams")
698 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
699 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
700 (declare-function emms-playlist-first "ext:emms")
701 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
702 (declare-function term-line-mode "term")
703 (declare-function term-char-mode "term")
704 (declare-function term-send-input "term")
705 (declare-function term-send-eof "term")
706 (declare-function Info-index-nodes "info" (&optional file))
707 (declare-function Info-goto-node "info" (&optional fork))
708 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
709 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
710 (declare-function elscreen-goto "ext:elscreen.el" (screen))
711 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
712 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
713 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
714 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
715 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
716 (declare-function bbdb "ext:bbdb-com")
717 (declare-function bbdb-current-record "ext:bbdb-com")
718 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
719 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
720 (declare-function bbdb-current-record "ext:bbdb-com")
721 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
722 (declare-function bbdb-records "ext:bbdb-com"
723 (&optional dont-check-disk already-in-db-buffer))
724 (declare-function eshell-read-aliases-list "em-alias")
725 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
726 (declare-function eldoc-current-symbol "eldoc")
727 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
728 (declare-function eldoc-get-var-docstring "eldoc" (sym))
729 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
730 (declare-function find-library-name "find-func.el" (library))
731 (declare-function adoc-construct "ext:auto-document.el" (buf))
732 (declare-function adoc-first-line "ext:auto-document.el" (str))
733 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
737 ;;; compatibility
740 (unless (fboundp 'window-system)
741 (defun window-system (&optional arg)
742 window-system))
746 ;;; Customize
749 (defgroup anything-config nil
750 "Predefined configurations for `anything.el'."
751 :group 'anything)
753 (defcustom anything-c-adaptive-history-file
754 "~/.emacs.d/anything-c-adaptive-history"
755 "Path of file where history information is stored."
756 :type 'string
757 :group 'anything-config)
759 (defcustom anything-c-adaptive-history-length 50
760 "Maximum number of candidates stored for a source."
761 :type 'number
762 :group 'anything-config)
764 (defcustom anything-c-google-suggest-url
765 "http://google.com/complete/search?output=toolbar&q="
766 "URL used for looking up Google suggestions."
767 :type 'string
768 :group 'anything-config)
770 (defcustom anything-c-google-suggest-search-url
771 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
772 "URL used for Google searching."
773 :type 'string
774 :group 'anything-config)
776 (defcustom anything-google-suggest-use-curl-p nil
777 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
778 Otherwise `url-retrieve-synchronously' is used."
779 :type 'boolean
780 :group 'anything-config)
782 (defcustom anything-c-yahoo-suggest-url
783 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
784 "Url used for looking up Yahoo suggestions."
785 :type 'string
786 :group 'anything-config)
788 (defcustom anything-c-yahoo-suggest-search-url
789 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
790 "Url used for Yahoo searching."
791 :type 'string
792 :group 'anything-config)
794 (defcustom anything-c-boring-buffer-regexp
795 (rx (or
796 (group bos " ")
797 ;; anything-buffer
798 "*anything"
799 ;; echo area
800 " *Echo Area" " *Minibuf"))
801 "The regexp that match boring buffers.
802 Buffer candidates matching this regular expression will be
803 filtered from the list of candidates if the
804 `anything-c-skip-boring-buffers' candidate transformer is used, or
805 they will be displayed with face `file-name-shadow' if
806 `anything-c-shadow-boring-buffers' is used."
807 :type 'string
808 :group 'anything-config)
809 ;; (string-match anything-c-boring-buffer-regexp "buf")
810 ;; (string-match anything-c-boring-buffer-regexp " hidden")
811 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
813 (defcustom anything-c-boring-file-regexp
814 (rx (or
815 ;; Boring directories
816 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
817 ;; Boring files
818 (and line-start ".#")
819 (and (or ".class" ".la" ".o" "~") eol)))
820 "The regexp that match boring files.
821 File candidates matching this regular expression will be
822 filtered from the list of candidates if the
823 `anything-c-skip-boring-files' candidate transformer is used, or
824 they will be displayed with face `file-name-shadow' if
825 `anything-c-shadow-boring-files' is used."
826 :type 'string
827 :group 'anything-config)
829 (defcustom anything-kill-ring-threshold 10
830 "*Minimum length to be listed by `anything-c-source-kill-ring'."
831 :type 'integer
832 :group 'anything-config)
834 (defcustom anything-c-kill-ring-max-lines-number nil
835 "Max number of lines displayed per candidate in kill-ring browser.
836 If nil or zero, don't truncate candidate, show all."
837 :type 'integer
838 :group 'anything-config)
840 (defcustom anything-su-or-sudo "su"
841 "What command to use for root access."
842 :type 'string
843 :group 'anything-config)
845 (defcustom anything-for-files-prefered-list
846 '(anything-c-source-ffap-line
847 anything-c-source-ffap-guesser
848 anything-c-source-buffers-list
849 anything-c-source-recentf
850 anything-c-source-bookmarks
851 anything-c-source-file-cache
852 anything-c-source-files-in-current-dir+
853 anything-c-source-locate)
854 "Your prefered sources to find files."
855 :type 'list
856 :group 'anything-config)
858 (defcustom anything-create--actions-private nil
859 "User defined actions for `anything-create' / `anything-c-source-create'.
860 It is a list of (DISPLAY . FUNCTION) pairs like `action'
861 attribute of `anything-sources'.
863 It is prepended to predefined pairs."
864 :type 'list
865 :group 'anything-config)
867 (defcustom anything-allow-skipping-current-buffer t
868 "Show current buffer or not in anything buffer"
869 :type 'boolean
870 :group 'anything-config)
872 (defcustom anything-c-enable-eval-defun-hack t
873 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
874 This hack is invoked when pressing C-M-x in the form \
875 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
876 :type 'boolean
877 :group 'anything-config)
879 (defcustom anything-tramp-verbose 0
880 "*Just like `tramp-verbose' but specific to anything.
881 When set to 0 don't show tramp messages in anything.
882 If you want to have the default tramp messages set it to 3."
883 :type 'integer
884 :group 'anything-config)
886 (defcustom anything-raise-command nil
887 "*A shell command to jump to a window running specific program.
888 Need external program wmctrl.
889 This will be use with `format', so use something like \"wmctrl -xa %s\"."
890 :type 'string
891 :group 'anything-config)
893 (defun anything-set-anything-command-map-prefix-key (var key)
894 (declare (special anything-command-map-prefix-key))
895 (when (boundp 'anything-command-map-prefix-key)
896 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
897 (setq anything-command-map-prefix-key key)
898 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
899 'anything-command-map))
901 (defcustom anything-command-map-prefix-key "<f5> a"
902 "*The prefix key for all `anything-command-map' commands.
904 !!WARNING!!
905 This default value is very likely to be changed,
906 because it is under discussion."
907 :type 'string
908 :set 'anything-set-anything-command-map-prefix-key
909 :group 'anything-config)
911 (defcustom anything-c-browse-code-regexp-lisp
912 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
913 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
914 "*Regexp used to parse lisp buffer when browsing code."
915 :type 'string
916 :group 'anything-config)
918 (defcustom anything-c-browse-code-regexp-python
919 "\\<def\\>\\|\\<class\\>"
920 "*Regexp used to parse python buffer when browsing code."
921 :type 'string
922 :group 'anything-config)
924 (defcustom anything-c-browse-code-regexp-alist
925 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
926 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
927 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
928 (python-mode . ,anything-c-browse-code-regexp-python))
929 "*Alist to store regexps for browsing code corresponding \
930 to a specific `major-mode'."
931 :type 'list
932 :group 'anything-config)
934 (defcustom anything-c-external-programs-associations nil
935 "*Alist to store externals programs associated with file extension.
936 This variable overhide setting in .mailcap file.
937 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
938 :type 'list
939 :group 'anything-config)
941 (defcustom anything-ff-auto-update-initial-value t
942 "Auto update when only one candidate directory is matched.
943 This is the default value when starting `anything-find-files'."
944 :group 'anything-config
945 :type 'boolean)
947 (defcustom anything-c-copy-async-prefered-emacs "emacs"
948 "Path to the emacs you want to use for copying async.
949 Emacs versions < 24 fail to copy directory due to a bug not fixed
950 in `copy-directory'."
951 :group 'anything-config
952 :type 'string)
954 (defcustom anything-ff-lynx-style-map t
955 "Use arrow keys to navigate with `anything-find-files'."
956 :group 'anything-config
957 :type 'boolean)
959 (defcustom anything-ff-history-max-length 100
960 "*Number of elements shown in `anything-find-files' history."
961 :group 'anything-config
962 :type 'integer)
964 (defcustom anything-ff-smart-completion t
965 "Try to complete filenames smarter when non--nil.
966 See `anything-ff-transform-fname-for-completion' for more info."
967 :group 'anything-config
968 :type 'boolean)
970 (defcustom anything-ff-default-kbsize 1024.0
971 "Default Kbsize to use for showing files size.
972 It is a float, usually 1024.0 but could be 1000.0 on some systems."
973 :group 'anything-config
974 :type 'float)
976 (defcustom anything-ff-tramp-not-fancy t
977 "No colors when listing remote files when set to non--nil.
978 This make listing much faster, specially on slow machines."
979 :group 'anything-config
980 :type 'boolean)
982 (defcustom anything-ff-exif-data-program "exiftran"
983 "*Program used to extract exif data of an image file."
984 :group 'anything-config
985 :type 'string)
987 (defcustom anything-ff-exif-data-program-args "-d"
988 "*Arguments used for `anything-ff-exif-data-program'."
989 :group 'anything-config
990 :type 'string)
992 (defcustom anything-c-grep-use-ioccur-style-keys t
993 "Use Arrow keys to jump to occurences."
994 :group 'anything-config
995 :type 'boolean)
997 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
998 "Default command to read pdf files from pdfgrep.
999 Where '%f' format spec is filename and '%p' is page number"
1000 :group 'anything-config
1001 :type 'string)
1003 (defcustom anything-c-etags-tag-file-name "TAGS"
1004 "Etags tag file name."
1005 :type 'string
1006 :group 'anything-config)
1008 (defcustom anything-c-etags-tag-file-search-limit 10
1009 "The limit level of directory to search tag file.
1010 Don't search tag file deeply if outside this value."
1011 :type 'number
1012 :group 'anything-config)
1014 (defcustom anything-c-etags-use-regexp-search nil
1015 "When non--nil search etags candidates by regexp.
1016 This disable anything-match-plugin when enabled.
1017 When nil search is performed literally and *match-plugin is used
1018 if available."
1019 :group 'anything-config
1020 :type 'boolean)
1022 (defcustom anything-c-filelist-file-name nil
1023 "Filename of file list.
1024 Accept a list of string for multiple files.
1026 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1027 File list is created by make-filelist.rb script.
1029 Usage:
1030 ruby make-filelist.rb > /tmp/all.filelist
1032 Then
1033 ;; Assume that /tmp is ramdisk or tmpfs
1034 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1035 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1037 :type 'string
1038 :group 'anything-config)
1040 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1041 'anything-c-eldoc-show-in-mode-line
1042 "A function to display eldoc info.
1043 Should take one arg: the string to display."
1044 :group 'anything-config
1045 :type 'symbol)
1047 (defcustom anything-c-turn-on-show-completion t
1048 "Display candidate in buffer while moving selection when non--nil."
1049 :group 'anything-config
1050 :type 'boolean)
1052 (defcustom anything-lisp-completion-or-indent-delay 0.6
1053 "After this delay `anything-lisp-completion-counter' is reset to 0.
1054 This allow to indent again without completing lisp symbol after this delay.
1055 Default is 0.6 seconds."
1056 :group 'anything-config
1057 :type 'number)
1059 (defcustom anything-c-default-external-file-browser "nautilus"
1060 "Default external file browser for your system.
1061 Directories will be opened externally with it.
1062 Set to nil if you do not have external file browser
1063 or do not want to use it."
1064 :group 'anything-config
1065 :type 'string)
1067 (defcustom anything-c-use-adaptative-sorting nil
1068 "*Wheter to use or not adaptative sorting.
1069 Even if a source use it, it will have no effect when set to nil."
1070 :type 'boolean
1071 :group 'anything-config)
1073 (defcustom anything-ff-newfile-prompt-p t
1074 "Whether Prompt or not when creating new file.
1075 This set `ffap-newfile-prompt'."
1076 :type 'boolean
1077 :group 'anything-config)
1080 (defcustom anything-ff-avfs-directory nil
1081 "*The default avfs directory, usually '.avfs'.
1082 When this is set you will be able to expand archive filenames with `C-z'
1083 inside an avfs directory mounted with mountavfs.
1084 See <http://sourceforge.net/projects/avf/>."
1085 :type 'boolean
1086 :group 'anything-config)
1088 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1089 "*Minimal list of compressed files extension."
1090 :type 'list
1091 :group 'anything-config)
1093 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1094 "Default regexp to match locate database.
1095 If nil Search in all files."
1096 :type 'string
1097 :group 'anything-config)
1099 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1100 "Eldoc will show info in mode-line during this delay if user is idle."
1101 :type 'integer
1102 :group 'anything-config)
1104 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1105 "The file used to communicate with two emacs when copying files async."
1106 :type 'string
1107 :group 'anything-config)
1109 (defcustom anything-ff-printer-list nil
1110 "A list of available printers on your system.
1111 When non--nil let you choose a printer to print file.
1112 Otherwise when nil the variable `printer-name' will be used.
1113 On Unix based systems you can use `anything-ff-find-printers' to
1114 find a list of available printers."
1115 :type 'list
1116 :group 'anything-config)
1120 ;;; General internal variables
1123 (defvar anything-c-external-commands-list nil
1124 "A list of all external commands the user can execute. If this
1125 variable is not set by the user, it will be calculated
1126 automatically.")
1129 ;;; Faces
1132 (defface anything-buffer-saved-out
1133 '((t (:foreground "red")))
1134 "*Face used for buffer files modified outside of emacs."
1135 :group 'anything-config)
1137 (defface anything-buffer-not-saved
1138 '((t (:foreground "Indianred2")))
1139 "*Face used for buffer files not already saved on disk."
1140 :group 'anything-config)
1142 (defface anything-ff-prefix
1143 '((t (:background "yellow" :foreground "black")))
1144 "*Face used to prefix new file or url paths in `anything-find-files'."
1145 :group 'anything-config)
1147 (defface anything-ff-executable
1148 '((t (:foreground "green")))
1149 "*Face used for executable files in `anything-find-files'."
1150 :group 'anything-config)
1152 (defface anything-ff-directory
1153 '((t (:foreground "DarkRed" :background "LightGray")))
1154 "*Face used for directories in `anything-find-files'."
1155 :group 'anything-config)
1157 (defface anything-ff-symlink
1158 '((t (:foreground "DarkOrange")))
1159 "*Face used for symlinks in `anything-find-files'."
1160 :group 'anything-config)
1162 (defface anything-ff-invalid-symlink
1163 '((t (:foreground "black" :background "red")))
1164 "*Face used for invalid symlinks in `anything-find-files'."
1165 :group 'anything-config)
1167 (defface anything-ff-file
1168 '((t (:foreground "CadetBlue" :underline t)))
1169 "*Face used for file names in `anything-find-files'."
1170 :group 'anything-config)
1172 (defface anything-grep-match
1173 '((t (:inherit match)))
1174 "Face used to highlight grep matches."
1175 :group 'anything-config)
1177 (defface anything-grep-file
1178 '((t (:foreground "BlueViolet" :underline t)))
1179 "Face used to highlight grep results filenames."
1180 :group 'anything-config)
1182 (defface anything-grep-lineno
1183 '((t (:foreground "Darkorange1")))
1184 "Face used to highlight grep number lines."
1185 :group 'anything-config)
1187 (defface anything-grep-running
1188 '((t (:foreground "Red")))
1189 "Face used in mode line when grep is running."
1190 :group 'anything-config)
1192 (defface anything-grep-finish
1193 '((t (:foreground "Green")))
1194 "Face used in mode line when grep is finish."
1195 :group 'anything-config)
1197 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1198 "*Face used in anything-M-x to show keybinding."
1199 :group 'anything)
1201 (defface anything-bmkext-info
1202 '((t (:foreground "green")))
1203 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1204 :group 'anything)
1206 (defface anything-bmkext-w3m
1207 '((t (:foreground "yellow")))
1208 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1209 :group 'anything)
1211 (defface anything-bmkext-gnus
1212 '((t (:foreground "magenta")))
1213 "*Face used for Gnus bookmarks."
1214 :group 'anything)
1216 (defface anything-bmkext-man
1217 '((t (:foreground "Orange4")))
1218 "*Face used for Woman/man bookmarks."
1219 :group 'anything)
1221 (defface anything-bmkext-no--file
1222 '((t (:foreground "grey")))
1223 "*Face used for non--file bookmarks."
1224 :group 'anything)
1226 (defface anything-bmkext-file
1227 '((t (:foreground "Deepskyblue2")))
1228 "*Face used for non--file bookmarks."
1229 :group 'anything)
1231 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1232 "Face for su/sudo bookmarks."
1233 :group 'anything)
1235 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1236 "Face for w3m bookmarks" :group 'anything)
1238 (defface anything-emms-playlist
1239 '((t (:foreground "Springgreen4" :underline t)))
1240 "*Face used for tracks in current emms playlist."
1241 :group 'anything)
1243 (defface anything-apt-installed
1244 '((t (:foreground "green")))
1245 "*Face used for apt installed candidates."
1246 :group 'anything)
1248 (defface anything-gentoo-match-face '((t (:foreground "red")))
1249 "Face for anything-gentoo installed packages."
1250 :group 'traverse-faces)
1252 (defface anything-lisp-show-completion
1253 '((t (:background "DarkSlateGray")))
1254 "*Face used for showing candidates in `anything-lisp-completion'."
1255 :group 'anything-config)
1257 (defface anything-lisp-completion-info
1258 '((t (:foreground "red")))
1259 "*Face used for showing info in `anything-lisp-completion'."
1260 :group 'anything-config)
1262 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1263 "Face for source header in the anything buffer." :group 'anything)
1265 ;;;###autoload
1266 (defun anything-configuration ()
1267 "Customize `anything'."
1268 (interactive)
1269 (customize-group "anything-config"))
1273 ;;; Anything-command-map
1276 ;;;###autoload
1277 (defvar anything-command-map)
1278 (define-prefix-command 'anything-command-map)
1281 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1282 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1283 (define-key anything-command-map (kbd "l") 'anything-locate)
1284 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1285 (define-key anything-command-map (kbd "r") 'anything-regexp)
1286 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1287 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1288 (define-key anything-command-map (kbd "#") 'anything-emms)
1289 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1290 (define-key anything-command-map (kbd "t") 'anything-top)
1291 (define-key anything-command-map (kbd "i") 'anything-imenu)
1292 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1293 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1294 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1295 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1296 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1297 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1298 (define-key anything-command-map (kbd "f") 'anything-for-files)
1299 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1300 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1301 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1302 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1303 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1304 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1305 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1306 (define-key anything-command-map (kbd "c") 'anything-colors)
1307 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1308 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1309 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1310 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1311 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1312 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1313 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1314 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1315 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1316 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1318 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1319 ;; minibuffer-local-filename-must-match-map.
1320 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1321 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1322 (dolist (map (list minibuffer-local-filename-completion-map
1323 minibuffer-local-completion-map
1324 minibuffer-local-must-match-filename-map
1325 minibuffer-local-filename-must-match-map
1326 minibuffer-local-map
1327 minibuffer-local-isearch-map
1328 minibuffer-local-must-match-map
1329 minibuffer-local-ns-map))
1330 (define-key map "\C-r" 'anything-minibuffer-history))
1334 ;;; Menu
1337 (easy-menu-define nil global-map
1338 "`anything' menu"
1339 '("Anything"
1340 ["All anything commands" anything-execute-anything-command t]
1341 ["Find any Files/Buffers" anything-for-files t]
1342 "----"
1343 ("Files:"
1344 ["Find files" anything-find-files t]
1345 ["Recent Files" anything-recentf t]
1346 ["Locate" anything-locate t]
1347 ["Bookmarks" anything-c-pp-bookmarks t])
1348 ("Buffers:"
1349 ["Find buffers" anything-buffers-list t])
1350 ("Commands:"
1351 ["Emacs Commands" anything-M-x t]
1352 ["Externals Commands" anything-c-run-external-command t])
1353 ("Info:"
1354 ["Info at point" anything-info-at-point t]
1355 ["Emacs Manual index" anything-info-emacs t]
1356 ["Gnus Manual index" anything-info-gnus t])
1357 ("Org:"
1358 ["Org keywords" anything-org-keywords t]
1359 ["Org headlines" anything-org-headlines t])
1360 ("Tools:"
1361 ["Occur" anything-occur t]
1362 ["Grep" anything-do-grep t]
1363 ["Etags" anything-c-etags-select t]
1364 ["Lisp complete at point" anything-lisp-completion-at-point t]
1365 ["Browse Kill ring" anything-show-kill-ring t]
1366 ["Browse register" anything-register t]
1367 ["Browse code" anything-browse-code t]
1368 ["Mark Ring" anything-all-mark-rings t]
1369 ["Regexp handler" anything-regexp t]
1370 ["Colors & Faces" anything-colors t]
1371 ["Show xfonts" anything-select-xfont t]
1372 ["Ucs Symbols" anything-ucs t]
1373 ["Imenu" anything-imenu t]
1374 ["Google Suggest" anything-google-suggest t]
1375 ["Eval expression" anything-eval-expression-with-eldoc t]
1376 ["Calcul expression" anything-calcul-expression t]
1377 ["Man pages" anything-man-woman t]
1378 ["Top externals process" anything-top t]
1379 ["Emacs internals process" anything-list-emacs-process t])
1380 "----"
1381 ["Prefered Options" anything-configuration t]))
1385 ;;; Specialized keymaps
1388 (defvar anything-c-buffer-map
1389 (let ((map (copy-keymap anything-map)))
1390 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1391 ;; No need to have separate command for grep and zgrep
1392 ;; as we don't use recursivity for buffers.
1393 ;; So use zgrep for both as it is capable to handle non--compressed files.
1394 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1395 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1396 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1397 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1398 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1399 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1400 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1401 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1402 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1403 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1404 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1405 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1406 (define-key map (kbd "M-a") 'anything-mark-all)
1407 (when (locate-library "elscreen")
1408 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1409 (delq nil map))
1410 "Keymap for buffer sources in anything.")
1412 (defvar anything-find-files-map
1413 (let ((map (copy-keymap anything-map)))
1414 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1415 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1416 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1417 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1418 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1419 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1420 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1421 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1422 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1423 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1424 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1425 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1426 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1427 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1428 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1429 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1430 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1431 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1432 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1433 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1434 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1435 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1436 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1437 (define-key map (kbd "C-c ?") 'anything-ff-help)
1438 (define-key map (kbd "C-}") 'anything-narrow-window)
1439 (define-key map (kbd "C-{") 'anything-enlarge-window)
1440 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1441 (define-key map (kbd "M-a") 'anything-mark-all)
1442 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1443 (define-key map (kbd "M-u") 'anything-unmark-all)
1444 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1445 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1446 ;; Next 2 have no effect if candidate is not an image file.
1447 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1448 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1449 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1450 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1451 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1452 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1453 (when anything-ff-lynx-style-map
1454 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1455 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1456 (delq nil map))
1457 "Keymap for `anything-find-files'.")
1459 (defvar anything-c-read-file-map
1460 (let ((map (copy-keymap anything-map)))
1461 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1462 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1463 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1464 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1465 (when anything-ff-lynx-style-map
1466 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1467 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1468 (define-key map (kbd "<M-left>") 'anything-previous-source)
1469 (define-key map (kbd "<M-right>") 'anything-next-source))
1470 (delq nil map))
1471 "Keymap for `anything-c-read-file-name'.")
1473 (defvar anything-generic-files-map
1474 (let ((map (copy-keymap anything-map)))
1475 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1476 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1477 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1478 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1479 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1480 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1481 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1482 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1483 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1484 map)
1485 "Generic Keymap for files.")
1487 (defvar anything-c-grep-map
1488 (let ((map (copy-keymap anything-map)))
1489 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1490 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1491 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1492 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1493 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1494 (when anything-c-grep-use-ioccur-style-keys
1495 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1496 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1497 (define-key map (kbd "C-c ?") 'anything-grep-help)
1498 (delq nil map))
1499 "Keymap used in Grep sources.")
1501 (defvar anything-c-pdfgrep-map
1502 (let ((map (copy-keymap anything-map)))
1503 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1504 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1505 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1506 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1507 map)
1508 "Keymap used in pdfgrep.")
1510 (defvar anything-c-etags-map
1511 (let ((map (copy-keymap anything-map)))
1512 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1513 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1514 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1515 (define-key map (kbd "C-c ?") 'anything-etags-help)
1516 map)
1517 "Keymap used in Etags.")
1519 (defvar anything-eval-expression-map
1520 (let ((map (copy-keymap anything-map)))
1521 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1522 (define-key map (kbd "<tab>") 'lisp-indent-line)
1523 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1524 (define-key map (kbd "C-p") 'previous-line)
1525 (define-key map (kbd "C-n") 'next-line)
1526 (define-key map (kbd "<up>") 'previous-line)
1527 (define-key map (kbd "<down>") 'next-line)
1528 (define-key map (kbd "<right>") 'forward-char)
1529 (define-key map (kbd "<left>") 'backward-char)
1530 map))
1532 (defvar anything-c-ucs-map
1533 (let ((map (copy-keymap anything-map)))
1534 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1535 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1536 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1537 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1538 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1539 map)
1540 "Keymap for `anything-ucs'.")
1544 ;;; Embeded documentation.
1547 (defun anything-c-list-preconfigured-anything ()
1548 "Collect preconfigured anything functions in this file."
1549 (loop with doc
1550 with sym
1551 for entry in (cdr (assoc
1552 (file-truename (locate-library "anything-config"))
1553 load-history))
1554 if (and (consp entry)
1555 (eq (car entry) 'defun)
1556 (string-match "^Preconfigured.+$"
1557 (setq doc (or (documentation (setq sym (cdr entry)))
1558 ""))))
1559 collect (cons sym (match-string 0 doc))))
1561 (defun anything-c-format-preconfigured-anything ()
1562 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1563 (anything-c-list-preconfigured-anything)))
1565 ;;; Global help message - Used by `anything-help'
1568 (setq anything-help-message
1569 (lambda ()
1570 (concat
1571 "\\<anything-map>"
1572 "`anything' is QuickSilver-like candidate-selection framework.
1574 Narrow the list by typing some pattern,
1575 Multiple patterns are allowed by splitting by space.
1576 Select with natural Emacs operations, choose with RET.
1578 If you have any problems, press C-c C-x C-b!!
1579 Feel free to send bug reports. I'll fix them.
1580 The steps are described in the beginning of anything.el file.
1582 == Basic Operations ==
1583 C-p, Up: Previous Line
1584 C-n, Down : Next Line
1585 M-v, PageUp : Previous Page
1586 C-v, PageDown : Next Page
1587 Enter : Execute first (default) action / Select
1588 M-< : First Line
1589 M-> : Last Line
1590 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1591 M-PageDown, C-M-v : Next Page (other-window)
1593 Tab, C-i : Show action list
1594 Left : Previous Source
1595 Right, C-o : Next Source
1596 C-k : Delete pattern
1597 C-z : Persistent Action (Execute action with anything session kept)
1598 C-c C-x C-b: Send a bug report
1600 == Shortcuts For 2nd/3rd Action ==
1601 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1602 \\[anything-select-3rd-action] : Execute 3rd Action
1604 == Visible Marks ==
1605 Visible marks store candidate. Some actions uses marked candidates.
1607 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1608 \\[anything-prev-visible-mark] : Previous Mark
1609 \\[anything-next-visible-mark] : Next Mark
1611 == Miscellaneous Commands ==
1612 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1613 \\[anything-quit-and-find-file] : Drop into `find-file'
1614 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1615 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1616 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1617 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1618 \\[anything-force-update] : Recalculate And Redisplay Candidates
1620 == Global Commands ==
1621 \\<global-map>\\[anything-resume] revives last `anything' session.
1622 It is very useful, so you should bind any key.
1624 Single source is executed by \\[anything-call-source].
1626 == Preconfigured `anything' ==
1627 Preconfigured `anything' is commands that uses `anything' interface.
1628 You can use them without configuration.
1631 (apply 'concat (anything-c-format-preconfigured-anything))
1633 Enjoy!")))
1635 ;;; `anything-buffer-list' help
1638 ;;;###autoload
1639 (defun anything-c-buffer-help ()
1640 "Help command for anything buffers."
1641 (interactive)
1642 (let ((anything-help-message "== Anything Buffer ==
1643 \nTips:
1644 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1645 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1646 \nSpecific commands for `anything-buffers-list':
1647 \\<anything-c-buffer-map>
1648 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1649 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1650 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1651 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1652 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1653 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1654 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1655 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1656 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1657 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1658 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1659 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1660 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1661 \\[anything-mark-all]\t\t->Mark all.
1662 \\[anything-c-buffer-help]\t\t->Display this help.
1663 \n== Anything Map ==
1664 \\{anything-map}
1666 (anything-help)))
1669 ;;; Find files help (`anything-find-files')
1672 ;;;###autoload
1673 (defun anything-ff-help ()
1674 "Help command for `anything-find-files'."
1675 (interactive)
1676 (let ((anything-help-message "== Anything Find Files ==
1677 \nTips:
1678 \nEnter \"~/\" at anytime to reach home directory.
1679 Enter \"/\" at anytime to reach root of your file system.
1680 You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1681 Use `C-u C-z' to watch an image.
1682 To browse images directories turn on `anything-follow-mode'.
1683 \nSpecific commands for `anything-find-files':
1684 \\<anything-find-files-map>
1685 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1686 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1687 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1688 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1689 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1690 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1691 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1692 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1693 \\[anything-ff-run-load-file]\t\t->Load File.
1694 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1695 \\[anything-ff-run-delete-file]\t\t->Delete File.
1696 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1697 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1698 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1699 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1700 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1701 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1702 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1703 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1704 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1705 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1706 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1707 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1708 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1709 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1710 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1711 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1712 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1713 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1714 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1715 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1716 \\[anything-narrow-window]\t\t->Narrow anything window.
1717 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1718 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1719 \\[anything-ff-help]\t\t->Display this help info.
1720 \n== Anything Map ==
1721 \\{anything-map}
1723 (anything-help)))
1725 ;;; Help for `anything-c-read-file-name'
1728 ;;;###autoload
1729 (defun anything-read-file-name-help ()
1730 (interactive)
1731 (let ((anything-help-message "== Anything read file name Map ==\
1732 \nSpecific commands for anything-c-read-file-name:
1733 \\<anything-c-read-file-map>
1734 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1735 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1736 \\[anything-next-source]\t\t->Goto next source.
1737 \\[anything-previous-source]\t->Goto previous source.
1738 \\[anything-read-file-name-help]\t\t->Display this help info.
1739 \n== Anything Map ==
1740 \\{anything-map}
1742 (anything-help)))
1744 ;;; Generic file help - Used by locate.
1747 ;;;###autoload
1748 (defun anything-generic-file-help ()
1749 (interactive)
1750 (let ((anything-help-message "== Anything Generic files Map ==\
1751 \nSpecific commands for anything locate and others files sources:
1752 \\<anything-generic-files-map>
1753 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1754 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1755 \\[anything-ff-run-delete-file]\t\t->Delete file.
1756 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1757 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1758 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1759 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1760 \nLocate tips:
1761 You can add after writing search pattern any of the locate command line options.
1762 e.g -b, -e, -n <number>...etc.
1763 See Man locate for more infos.
1764 \n== Anything Map ==
1765 \\{anything-map}"))
1766 (anything-help)))
1769 ;;; Grep help
1772 ;;;###autoload
1773 (defun anything-grep-help ()
1774 (interactive)
1775 (let ((anything-help-message "== Anything Grep Map ==\
1776 \nSpecific commands for Grep and Etags:
1777 \\<anything-c-grep-map>
1778 \\[anything-c-goto-next-file]\t->Next File.
1779 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1780 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1781 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1782 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1783 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1784 \\[anything-grep-help]\t\t->Show this help.
1785 \n== Anything Map ==
1786 \\{anything-map}"))
1787 (anything-help)))
1789 ;;; Pdf grep help
1792 ;;;###autoload
1793 (defun anything-pdfgrep-help ()
1794 (interactive)
1795 (let ((anything-help-message "== Anything PdfGrep Map ==\
1796 \nSpecific commands for Pdf Grep:
1797 \\<anything-c-pdfgrep-map>
1798 \\[anything-c-goto-next-file]\t->Next File.
1799 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1800 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1801 \\[anything-pdfgrep-help]\t\t->Show this help.
1802 \n== Anything Map ==
1803 \\{anything-map}"))
1804 (anything-help)))
1806 ;;; Etags help
1809 ;;;###autoload
1810 (defun anything-etags-help ()
1811 "The help function for etags."
1812 (interactive)
1813 (let ((anything-help-message "== Anything Etags Map ==\
1814 \nSpecific commands for Etags:
1815 \\<anything-c-etags-map>
1816 \\[anything-c-goto-next-file]\t->Next File.
1817 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1818 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1819 \\[anything-etags-help]\t\t->Show this help.
1820 \n== Anything Map ==
1821 \\{anything-map}"))
1822 (anything-help)))
1824 ;;; Ucs help
1827 (defun anything-c-ucs-help ()
1828 "Help command for `anything-ucs'."
1829 (interactive)
1830 (let ((anything-help-message "== Anything Ucs ==
1831 \nSpecific commands for `anything-ucs':
1832 \\<anything-c-ucs-map>
1833 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1834 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1835 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1836 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1837 \\[anything-c-ucs-help]\t\t->Show this help.
1839 \n== Anything Map ==
1840 \\{anything-map}
1842 (anything-help)))
1846 ;;; Mode line strings
1849 (defvar anything-buffer-mode-line-string
1850 '("Buffer(s)"
1851 "\\<anything-c-buffer-map>\
1852 \\[anything-c-buffer-help]:Help, \
1853 \\<anything-map>\
1854 \\[anything-select-action]:Acts,\
1855 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1856 \\[anything-select-3rd-action]:NthAct,\
1857 \\[anything-send-bug-report-from-anything]:BugReport."
1858 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1860 (defvar anything-ff-mode-line-string
1861 "\\<anything-find-files-map>\
1862 \\[anything-ff-help]:Help, \
1863 \\[anything-send-bug-report-from-anything]:BugReport, \
1864 \\<anything-map>\
1865 \\[anything-select-action]:Acts, \
1866 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1867 \\[anything-select-3rd-action]:NthAct"
1868 "String displayed in mode-line in `anything-c-source-find-files'")
1870 (defvar anything-read-file-name-mode-line-string
1871 "\\<anything-c-read-file-map>\
1872 \\[anything-read-file-name-help]:Help, \
1873 \\<anything-map>\
1874 \\[anything-select-action]:Acts,\
1875 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1876 \\[anything-select-3rd-action]:NthAct"
1877 "String displayed in mode-line in `anything-c-source-find-files'")
1879 (defvar anything-generic-file-mode-line-string
1880 "\\<anything-generic-files-map>\
1881 \\[anything-generic-file-help]:Help, \
1882 \\<anything-map>\
1883 \\[anything-select-action]:Acts,\
1884 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1885 \\[anything-select-3rd-action]:NthAct,\
1886 \\[anything-send-bug-report-from-anything]:BugReport."
1887 "String displayed in mode-line in Locate.")
1889 (defvar anything-grep-mode-line-string
1890 "\\<anything-c-grep-map>\
1891 \\[anything-grep-help]:Help,\
1892 \\<anything-map>\
1893 \\[anything-select-action]:Acts,\
1894 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1895 \\[anything-select-3rd-action]:NthAct,\
1896 \\[anything-send-bug-report-from-anything]:BugReport."
1897 "String displayed in mode-line in `anything-do-grep'.")
1899 (defvar anything-pdfgrep-mode-line-string
1900 "\\<anything-c-pdfgrep-map>\
1901 \\[anything-pdfgrep-help]:Help,\
1902 \\<anything-map>\
1903 \\[anything-select-action]:Acts,\
1904 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1905 \\[anything-select-3rd-action]:NthAct,\
1906 \\[anything-send-bug-report-from-anything]:BugReport."
1907 "String displayed in mode-line in `anything-do-pdfgrep'.")
1909 (defvar anything-etags-mode-line-string
1910 "\\<anything-c-etags-map>\
1911 \\[anything-etags-help]:Help,\
1912 \\<anything-map>\
1913 \\[anything-select-action]:Acts,\
1914 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1915 \\[anything-select-3rd-action]:NthAct,\
1916 \\[anything-send-bug-report-from-anything]:BugReport."
1917 "String displayed in mode-line in `anything-c-etags-select'.")
1920 (defvar anything-c-ucs-mode-line-string
1921 "\\<anything-c-ucs-map>\
1922 \\[anything-c-ucs-help]:Help, \
1923 \\<anything-map>\
1924 \\[anything-select-action]:Acts,\
1925 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1926 \\[anything-select-3rd-action]:NthAct."
1927 "String displayed in mode-line in `anything-ucs'.")
1931 ;;; Preconfigured Anything
1934 ;;;###autoload
1935 (defun anything-mini ()
1936 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
1937 (interactive)
1938 (anything-other-buffer '(anything-c-source-buffers-list anything-c-source-recentf)
1939 "*anything mini*"))
1940 ;;;###autoload
1941 (defun anything-for-files ()
1942 "Preconfigured `anything' for opening files.
1943 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
1944 (interactive)
1945 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
1947 ;;;###autoload
1948 (defun anything-recentf ()
1949 "Preconfigured `anything' for `recentf'."
1950 (interactive)
1951 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
1953 ;;;###autoload
1954 (defun anything-info-at-point (arg)
1955 "Preconfigured `anything' for searching info at point.
1956 With a prefix-arg insert symbol at point."
1957 (interactive "P")
1958 (let ((anything-c-google-suggest-default-function
1959 'anything-c-google-suggest-emacs-lisp))
1960 (anything :sources'(anything-c-source-info-elisp
1961 anything-c-source-info-cl
1962 anything-c-source-info-pages
1963 anything-c-source-google-suggest)
1964 :input (and arg (thing-at-point 'symbol))
1965 :buffer "*anything info*")))
1967 ;;;###autoload
1968 (defun anything-info-emacs ()
1969 "Preconfigured anything for Emacs manual index."
1970 (interactive)
1971 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
1973 ;;;###autoload
1974 (defun anything-show-kill-ring ()
1975 "Preconfigured `anything' for `kill-ring'.
1976 It is drop-in replacement of `yank-pop'.
1977 You may bind this command to M-y.
1978 First call open the kill-ring browser, next calls move to next line."
1979 (interactive)
1980 (let ((buf "*anything kill-ring*"))
1981 (if (get-buffer-window buf)
1982 (with-anything-window
1983 (if (eq (overlay-end anything-selection-overlay) (point-max))
1984 (anything-beginning-of-buffer)
1985 (anything-next-line)))
1986 (anything-other-buffer 'anything-c-source-kill-ring buf))))
1988 ;;;###autoload
1989 (defun anything-minibuffer-history ()
1990 "Preconfigured `anything' for `minibuffer-history'."
1991 (interactive)
1992 (let ((enable-recursive-minibuffers t))
1993 (anything-other-buffer 'anything-c-source-minibuffer-history
1994 "*anything minibuffer-history*")))
1996 ;;;###autoload
1997 (defun anything-gentoo ()
1998 "Preconfigured `anything' for gentoo linux."
1999 (interactive)
2000 (anything-other-buffer '(anything-c-source-gentoo
2001 anything-c-source-use-flags)
2002 "*anything gentoo*"))
2004 ;;;###autoload
2005 (defun anything-imenu ()
2006 "Preconfigured `anything' for `imenu'."
2007 (interactive)
2008 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
2010 ;;;###autoload
2011 (defun anything-google-suggest ()
2012 "Preconfigured `anything' for google search with google suggest."
2013 (interactive)
2014 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
2016 ;;;###autoload
2017 (defun anything-yahoo-suggest ()
2018 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
2019 (interactive)
2020 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
2022 ;;; Converted from anything-show-*-only
2023 ;;;###autoload
2024 (defun anything-for-buffers ()
2025 "Preconfigured `anything' for buffer."
2026 (interactive)
2027 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
2029 ;;;###autoload
2030 (defun anything-buffers-list ()
2031 "Enhanced preconfigured `anything' for buffer."
2032 (interactive)
2033 (anything :sources '(anything-c-source-buffers-list
2034 anything-c-source-buffer-not-found)
2035 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
2037 ;;;###autoload
2038 (defun anything-bbdb ()
2039 "Preconfigured `anything' for BBDB.
2041 Needs BBDB.
2043 http://bbdb.sourceforge.net/"
2044 (interactive)
2045 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
2047 ;;;###autoload
2048 (defun anything-locate (arg)
2049 "Preconfigured `anything' for Locate.
2050 Note: you can add locate options after entering pattern.
2051 See 'man locate' for valid options.
2053 You can specify a specific database with prefix argument ARG \(C-u\).
2054 Many databases can be used: navigate and mark them.
2055 See also `anything-locate-with-db'.
2057 To create a user specific db, use
2058 \"updatedb -l 0 -o db_path -U directory\".
2059 Where db_path is a filename matched by
2060 `anything-locate-db-file-regexp'."
2061 (interactive "P")
2062 (anything-locate-1 arg))
2064 ;;;###autoload
2065 (defun anything-w3m-bookmarks ()
2066 "Preconfigured `anything' for w3m bookmark.
2068 Needs w3m and emacs-w3m.
2070 http://w3m.sourceforge.net/
2071 http://emacs-w3m.namazu.org/"
2072 (interactive)
2073 (anything-other-buffer 'anything-c-source-w3m-bookmarks
2074 "*anything w3m bookmarks*"))
2076 ;;;###autoload
2077 (defun anything-firefox-bookmarks ()
2078 "Preconfigured `anything' for firefox bookmark.
2079 You will have to enable html bookmarks in firefox:
2080 open about:config in firefox and double click on this line to enable value \
2081 to true:
2083 user_pref(\"browser.bookmarks.autoExportHTML\", false);
2085 You should have now:
2087 user_pref(\"browser.bookmarks.autoExportHTML\", true);
2089 After closing firefox, you will be able to browse you bookmarks.
2091 (interactive)
2092 (anything-other-buffer 'anything-c-source-firefox-bookmarks
2093 "*Anything Firefox*"))
2095 ;;;###autoload
2096 (defun anything-colors ()
2097 "Preconfigured `anything' for color."
2098 (interactive)
2099 (anything-other-buffer
2100 '(anything-c-source-colors anything-c-source-customize-face)
2101 "*anything colors*"))
2103 ;;;###autoload
2104 (defun anything-bookmarks ()
2105 "Preconfigured `anything' for bookmarks."
2106 (interactive)
2107 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
2109 ;;;###autoload
2110 (defun anything-c-pp-bookmarks ()
2111 "Preconfigured `anything' for bookmarks (pretty-printed)."
2112 (interactive)
2113 (anything-other-buffer '(anything-c-source-bookmarks-local
2114 anything-c-source-bookmarks-su
2115 anything-c-source-bookmarks-ssh)
2116 "*anything pp bookmarks*"))
2118 ;;;###autoload
2119 (defun anything-c-insert-latex-math ()
2120 "Preconfigured anything for latex math symbols completion."
2121 (interactive)
2122 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
2124 ;;;###autoload
2125 (defun anything-register ()
2126 "Preconfigured `anything' for Emacs registers."
2127 (interactive)
2128 (anything-other-buffer 'anything-c-source-register "*anything register*"))
2130 ;;;###autoload
2131 (defun anything-man-woman ()
2132 "Preconfigured `anything' for Man and Woman pages."
2133 (interactive)
2134 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
2136 ;;;###autoload
2137 (defun anything-org-keywords ()
2138 "Preconfigured `anything' for org keywords."
2139 (interactive)
2140 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
2142 ;;;###autoload
2143 (defun anything-emms ()
2144 "Preconfigured `anything' for emms sources."
2145 (interactive)
2146 (anything '(anything-c-source-emms-streams
2147 anything-c-source-emms-files
2148 anything-c-source-emms-dired)
2149 nil nil nil nil
2150 "*Anything Emms*"))
2152 ;;;###autoload
2153 (defun anything-eev-anchors ()
2154 "Preconfigured `anything' for eev anchors."
2155 (interactive)
2156 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
2158 ;;;###autoload
2159 (defun anything-bm-list ()
2160 "Preconfigured `anything' for visible bookmarks.
2162 Needs bm.el
2164 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
2165 (interactive)
2166 (let ((anything-outline-using t))
2167 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
2169 ;;;###autoload
2170 (defun anything-timers ()
2171 "Preconfigured `anything' for timers."
2172 (interactive)
2173 (anything-other-buffer '(anything-c-source-absolute-time-timers
2174 anything-c-source-idle-time-timers)
2175 "*anything timers*"))
2177 ;;;###autoload
2178 (defun anything-list-emacs-process ()
2179 "Preconfigured `anything' for emacs process."
2180 (interactive)
2181 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
2183 ;;;###autoload
2184 (defun anything-occur ()
2185 "Preconfigured Anything for Occur source.
2186 If region is active, search only in region,
2187 otherwise search in whole buffer."
2188 (interactive)
2189 (let ((anything-compile-source-functions
2190 ;; rule out anything-match-plugin because the input is one regexp.
2191 (delq 'anything-compile-source--match-plugin
2192 (copy-sequence anything-compile-source-functions))))
2193 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
2195 ;;;###autoload
2196 (defun anything-browse-code ()
2197 "Preconfigured anything to browse code."
2198 (interactive)
2199 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
2201 ;;;###autoload
2202 (defun anything-org-headlines ()
2203 "Preconfigured anything to show org headlines."
2204 (interactive)
2205 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
2207 ;;;###autoload
2208 (defun anything-info-gnus ()
2209 "Preconfigured anything to browse Gnus Manual."
2210 (interactive)
2211 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
2213 ;;;###autoload
2214 (defun anything-regexp ()
2215 "Preconfigured anything to build regexps and run query-replace-regexp \
2216 against."
2217 (interactive)
2218 (save-restriction
2219 (let ((anything-compile-source-functions
2220 ;; rule out anything-match-plugin because the input is one regexp.
2221 (delq 'anything-compile-source--match-plugin
2222 (copy-sequence anything-compile-source-functions))))
2223 (when (and (anything-region-active-p)
2224 ;; Don't narrow to region if buffer is already narrowed.
2225 (not (anything-current-buffer-narrowed-p)))
2226 (narrow-to-region (region-beginning) (region-end)))
2227 (anything :sources
2228 anything-c-source-regexp
2229 :buffer "*anything regexp*"
2230 :prompt "Regexp: "))))
2232 (defun anything-c-copy-files-async ()
2233 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
2234 (interactive)
2235 (let* ((flist (anything-c-read-file-name
2236 "Copy File async: "
2237 :marked-candidates t))
2238 (dest (anything-c-read-file-name
2239 "Copy File async To: "
2240 :preselect (car flist)
2241 :initial-input (car anything-ff-history)
2242 :history (anything-find-files-history :comp-read nil))))
2243 (anything-c-copy-async-with-log flist dest)))
2245 ;;;###autoload
2246 (defun anything-find-files (arg)
2247 "Preconfigured `anything' for anything implementation of `find-file'.
2248 Called with a prefix arg show history if some.
2249 Don't call it from programs, use `anything-find-files-1' instead.
2250 This is the starting point for nearly all actions you can do on files."
2251 (interactive "P")
2252 (let ((any-input (if (and arg anything-ff-history)
2253 (anything-find-files-history)
2254 (anything-find-files-initial-input)))
2255 (presel (buffer-file-name (current-buffer))))
2256 (when (and (eq major-mode 'org-agenda-mode)
2257 org-directory
2258 (not any-input))
2259 (setq any-input (expand-file-name org-directory)))
2260 (set-text-properties 0 (length any-input) nil any-input)
2261 (if any-input
2262 (anything-find-files-1 any-input)
2263 (setq any-input (expand-file-name (anything-c-current-directory)))
2264 (anything-find-files-1
2265 any-input (if anything-ff-transformer-show-only-basename
2266 (and presel (anything-c-basename presel))
2267 presel)))))
2269 ;;;###autoload
2270 (defun anything-write-file ()
2271 "Preconfigured `anything' providing completion for `write-file'."
2272 (interactive)
2273 (let ((anything-mp-highlight-delay nil))
2274 (anything :sources 'anything-c-source-write-file
2275 :input (expand-file-name default-directory)
2276 :prompt "Write buffer to file: "
2277 :buffer "*Anything write file*")))
2279 ;;;###autoload
2280 (defun anything-insert-file ()
2281 "Preconfigured `anything' providing completion for `insert-file'."
2282 (interactive)
2283 (let ((anything-mp-highlight-delay nil))
2284 (anything :sources 'anything-c-source-insert-file
2285 :input (expand-file-name default-directory)
2286 :prompt "Insert file: "
2287 :buffer "*Anything insert file*")))
2289 ;;;###autoload
2290 (defun anything-dired-rename-file ()
2291 "Preconfigured `anything' to rename files from dired."
2292 (interactive)
2293 (anything-dired-do-action-on-file :action 'rename))
2295 ;;;###autoload
2296 (defun anything-dired-copy-file ()
2297 "Preconfigured `anything' to copy files from dired."
2298 (interactive)
2299 (anything-dired-do-action-on-file :action 'copy))
2301 ;;;###autoload
2302 (defun anything-dired-symlink-file ()
2303 "Preconfigured `anything' to symlink files from dired."
2304 (interactive)
2305 (anything-dired-do-action-on-file :action 'symlink))
2307 ;;;###autoload
2308 (defun anything-dired-hardlink-file ()
2309 "Preconfigured `anything' to hardlink files from dired."
2310 (interactive)
2311 (anything-dired-do-action-on-file :action 'hardlink))
2313 ;;;###autoload
2314 (defun anything-do-grep ()
2315 "Preconfigured anything for grep.
2316 Contrarily to Emacs `grep' no default directory is given, but
2317 the full path of candidates in ONLY.
2318 That allow to grep different files not only in `default-directory' but anywhere
2319 by marking them (C-<SPACE>). If one or more directory is selected
2320 grep will search in all files of these directories.
2321 You can use also wildcard in the base name of candidate.
2322 If a prefix arg is given use the -r option of grep.
2323 The prefix arg can be passed before or after start.
2324 See also `anything-do-grep-1'."
2325 (interactive)
2326 (let ((only (anything-c-read-file-name
2327 "Search in file(s): "
2328 :marked-candidates t
2329 :preselect (or (dired-get-filename nil t)
2330 (buffer-file-name (current-buffer)))))
2331 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
2332 (anything-do-grep-1 only prefarg)))
2334 ;;;###autoload
2335 (defun anything-do-zgrep (candidate)
2336 "Preconfigured anything for zgrep."
2337 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
2338 (ls (anything-c-read-file-name
2339 "Search in file(s): "
2340 :marked-candidates t
2341 :preselect (or (dired-get-filename nil t)
2342 (buffer-file-name (current-buffer))))))
2343 (anything-ff-zgrep-1 ls prefarg)))
2345 (defun anything-c-etags-select (arg)
2346 "Preconfigured anything for etags.
2347 Called with one prefix arg use symbol at point as initial input.
2348 Called with two prefix arg reinitialize cache.
2349 If tag file have been modified reinitialize cache."
2350 (interactive "P")
2351 (let ((tag (anything-c-etags-get-tag-file))
2352 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
2353 (anything-quit-if-no-candidate t)
2354 (anything-execute-action-at-once-if-one t)
2355 (anything-compile-source-functions
2356 (if anything-c-etags-use-regexp-search
2357 ;; rule out anything-match-plugin because the input is one regexp.
2358 (delq 'anything-compile-source--match-plugin
2359 (copy-sequence anything-compile-source-functions))
2360 anything-compile-source-functions)))
2361 (when (or (equal arg '(16))
2362 (and anything-c-etags-mtime-alist
2363 (anything-c-etags-file-modified-p tag)))
2364 (remhash tag anything-c-etags-cache))
2365 (if (and tag (file-exists-p tag))
2366 (anything :sources 'anything-c-source-etags-select
2367 :keymap anything-c-etags-map
2368 :input init
2369 :buffer "*anything etags*")
2370 (message "Error: No tag file found, please create one with etags shell command."))))
2372 ;;;###autoload
2373 (defun anything-filelist ()
2374 "Preconfigured `anything' to open files instantly.
2376 See `anything-c-filelist-file-name' docstring for usage."
2377 (interactive)
2378 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
2380 ;;;###autoload
2381 (defun anything-filelist+ ()
2382 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2384 This is a replacement for `anything-for-files'.
2385 See `anything-c-filelist-file-name' docstring for usage."
2386 (interactive)
2387 (anything-other-buffer
2388 '(anything-c-source-ffap-line
2389 anything-c-source-ffap-guesser
2390 anything-c-source-buffers-list
2391 anything-c-source-recentf
2392 anything-c-source-bookmarks
2393 anything-c-source-file-cache
2394 anything-c-source-filelist)
2395 "*anything file list*"))
2397 ;;;###autoload
2398 (defun anything-M-x ()
2399 "Preconfigured `anything' for Emacs commands.
2400 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2401 (interactive)
2402 (let* (in-help
2403 help-cand
2404 anything-persistent-action-use-special-display
2405 (history (loop with hist
2406 for i in extended-command-history
2407 for com = (intern i)
2408 when (and (fboundp com) (not (member i hist)))
2409 collect i into hist finally return hist))
2410 (command (anything-comp-read
2411 "M-x " obarray
2412 :test 'commandp
2413 :must-match t
2414 :requires-pattern 2
2415 :name "Emacs Commands"
2416 :persistent-action
2417 #'(lambda (candidate)
2418 (let ((hbuf (get-buffer (help-buffer))))
2419 (if (and in-help (string= candidate help-cand))
2420 (progn
2421 ;; When M-x is started from a help buffer,
2422 ;; Don't kill it as it is anything-current-buffer.
2423 (unless (equal hbuf anything-current-buffer)
2424 (kill-buffer hbuf))
2425 (setq in-help nil))
2426 ;; Be sure anything-current-buffer have not a dedicated window.
2427 (set-window-dedicated-p
2428 (get-buffer-window anything-current-buffer) nil)
2429 (describe-function (intern candidate))
2430 (message nil) ; Erase the new stupid message Type "q"[...]
2431 (setq in-help t))
2432 (setq help-cand candidate)))
2433 :persistent-help "Describe this command"
2434 :history history
2435 :sort 'string-lessp
2436 :fc-transformer 'anything-M-x-transformer)))
2437 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
2438 (call-interactively (intern command))
2439 (setq extended-command-history (cons command (delete command history)))))
2441 ;;;###autoload
2442 (defun anything-manage-advice ()
2443 "Preconfigured `anything' to disable/enable function advices."
2444 (interactive)
2445 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2447 ;;;###autoload
2448 (defun anything-bookmark-ext ()
2449 "Preconfigured `anything' for bookmark-extensions sources.
2450 Needs bookmark-ext.el:
2451 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
2452 Contain also `anything-c-source-google-suggest'."
2453 (interactive)
2454 (anything
2455 :sources
2456 '(anything-c-source-bookmark-files&dirs
2457 anything-c-source-bookmark-w3m
2458 anything-c-source-google-suggest
2459 anything-c-source-bmkext-addressbook
2460 anything-c-source-bookmark-gnus
2461 anything-c-source-bookmark-info
2462 anything-c-source-bookmark-man
2463 anything-c-source-bookmark-images
2464 anything-c-source-bookmark-su-files&dirs
2465 anything-c-source-bookmark-ssh-files&dirs)
2466 :prompt "SearchBookmark: "
2467 :buffer "*anything bmkext*"))
2469 ;;;###autoload
2470 (defun anything-simple-call-tree ()
2471 "Preconfigured `anything' for simple-call-tree. List function relationships.
2473 Needs simple-call-tree.el.
2474 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
2475 (interactive)
2476 (anything-other-buffer
2477 '(anything-c-source-simple-call-tree-functions-callers
2478 anything-c-source-simple-call-tree-callers-functions)
2479 "*anything simple-call-tree*"))
2481 ;;;###autoload
2482 (defun anything-mark-ring ()
2483 "Preconfigured `anything' for `anything-c-source-mark-ring'."
2484 (interactive)
2485 (anything 'anything-c-source-mark-ring))
2487 ;;;###autoload
2488 (defun anything-global-mark-ring ()
2489 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
2490 (interactive)
2491 (anything 'anything-c-source-global-mark-ring))
2493 ;;;###autoload
2494 (defun anything-all-mark-rings ()
2495 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
2496 `anything-c-source-mark-ring'."
2497 (interactive)
2498 (anything '(anything-c-source-mark-ring
2499 anything-c-source-global-mark-ring)))
2501 ;;;###autoload
2502 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
2503 "Preconfigured `anything' to edit or view EmacsWiki page.
2505 Needs yaoddmuse.el.
2507 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2508 (interactive)
2509 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
2511 ;;;###autoload
2512 (defun anything-yaoddmuse-emacswiki-post-library ()
2513 "Preconfigured `anything' to post library to EmacsWiki.
2515 Needs yaoddmuse.el.
2517 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2518 (interactive)
2519 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
2521 ;;;###autoload
2522 (defun anything-eval-expression (arg)
2523 "Preconfigured anything for `anything-c-source-evaluation-result'."
2524 (interactive "P")
2525 (anything :sources 'anything-c-source-evaluation-result
2526 :input (when arg (thing-at-point 'sexp))
2527 :buffer "*anything eval*"
2528 :keymap anything-eval-expression-map))
2530 ;;;###autoload
2531 (defun anything-eval-expression-with-eldoc ()
2532 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
2533 (interactive)
2534 (declare (special eldoc-idle-delay))
2535 (let ((timer (run-with-idle-timer eldoc-idle-delay
2536 'repeat 'anything-eldoc-show-in-eval))
2537 (minibuffer-completing-symbol t) ; Enable lisp completion.
2538 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
2539 (unwind-protect
2540 (minibuffer-with-setup-hook
2541 'anything-eldoc-store-minibuffer
2542 (call-interactively 'anything-eval-expression))
2543 (and timer (cancel-timer timer))
2544 (setq anything-eldoc-active-minibuffers-list
2545 (cdr anything-eldoc-active-minibuffers-list)))))
2547 ;;;###autoload
2548 (defun anything-calcul-expression ()
2549 "Preconfigured anything for `anything-c-source-calculation-result'."
2550 (interactive)
2551 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
2553 ;;;###autoload
2554 (defun anything-surfraw (pattern engine)
2555 "Preconfigured `anything' to search PATTERN with search ENGINE."
2556 (interactive (list (read-string "SearchFor: ")
2557 (anything-comp-read
2558 "Engine: "
2559 (anything-c-build-elvi-list)
2560 :must-match t
2561 :name "Surfraw Search Engines"
2562 :history anything-surfraw-engines-history)))
2563 (let* ((engine-nodesc (car (split-string engine)))
2564 (url (with-temp-buffer
2565 (apply 'call-process "surfraw" nil t nil
2566 ;;JAVE
2567 (append (list engine-nodesc "-p") (split-string pattern)))
2568 (replace-regexp-in-string
2569 "\n" "" (buffer-string))))
2570 (browse-url-browser-function (or anything-surfraw-default-browser-function
2571 browse-url-browser-function)))
2572 (if (string= engine-nodesc "W")
2573 (anything-c-browse-url)
2574 (anything-c-browse-url url)
2575 (setq anything-surfraw-engines-history
2576 (cons engine (delete engine anything-surfraw-engines-history))))))
2578 ;;;###autoload
2579 (defun anything-call-source ()
2580 "Preconfigured `anything' to call anything source."
2581 (interactive)
2582 (anything 'anything-c-source-call-source nil nil nil nil
2583 anything-source-select-buffer))
2585 ;;;###autoload
2586 (defun anything-execute-anything-command ()
2587 "Preconfigured `anything' to execute preconfigured `anything'."
2588 (interactive)
2589 (anything-other-buffer 'anything-c-source-anything-commands
2590 "*anything commands*"))
2592 ;;;###autoload
2593 (defun anything-create (&optional string initial-input)
2594 "Preconfigured `anything' to do many create actions from STRING.
2595 See also `anything-create--actions'."
2596 (interactive)
2597 (setq string (or string (read-string "Create Anything: " initial-input)))
2598 (anything '(((name . "Anything Create")
2599 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
2600 (candidates . anything-create--actions)
2601 (candidate-number-limit)
2602 (action . (lambda (func) (funcall func string)))))))
2604 ;;;###autoload
2605 (defun anything-top ()
2606 "Preconfigured `anything' for top command."
2607 (interactive)
2608 (let ((anything-samewindow t)
2609 (anything-enable-shortcuts)
2610 (anything-display-function 'anything-default-display-buffer)
2611 (anything-candidate-number-limit 9999))
2612 (save-window-excursion
2613 (delete-other-windows)
2614 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
2616 ;;;###autoload
2617 (defun anything-select-xfont ()
2618 "Preconfigured `anything' to select Xfont."
2619 (interactive)
2620 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
2622 ;;;###autoload
2623 (defun anything-world-time ()
2624 "Preconfigured `anything' to show world time."
2625 (interactive)
2626 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
2628 ;;;###autoload
2629 (defun anything-apt (arg query)
2630 "Preconfigured `anything' : frontend of APT package manager.
2631 With a prefix arg reload cache."
2632 (interactive "P\nsSearch Package: ")
2633 (when arg
2634 (setq anything-c-apt-installed-packages nil)
2635 (setq anything-c-apt-all-packages nil))
2636 (anything :sources 'anything-c-source-apt
2637 :prompt "Search Package: " :input query))
2639 ;;;###autoload
2640 (defun anything-esh-pcomplete ()
2641 "Preconfigured anything to provide anything completion in eshell."
2642 (interactive)
2643 (let* ((anything-quit-if-no-candidate t)
2644 (anything-execute-action-at-once-if-one t)
2645 (target (thing-at-point 'symbol))
2646 (end (point))
2647 (beg (or (and target (- end (length target)))
2648 ;; Nothing at point.
2649 (progn (insert " ") (point)))))
2650 (setq anything-ec-target (or target " "))
2651 (with-anything-show-completion beg end
2652 (anything :sources 'anything-c-source-esh
2653 :input (anything-ff-set-pattern ; Handle tramp filenames.
2654 (car (last (ignore-errors ; Needed in lisp symbols completion.
2655 (pcomplete-parse-arguments)))))))))
2657 ;;;###autoload
2658 (defun anything-eshell-history ()
2659 "Preconfigured anything for eshell history."
2660 (interactive)
2661 (let* ((end (point))
2662 (beg (progn (save-excursion (insert " ") (point)))))
2663 (with-anything-show-completion beg end
2664 (anything-other-buffer anything-c-source-eshell-history "*Eshell history*"))))
2666 ;;;###autoload
2667 (defun anything-c-run-external-command (program)
2668 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
2669 If program is already running exit with error.
2670 You can set your own list of commands with
2671 `anything-c-external-commands-list'."
2672 (interactive (list
2673 (anything-comp-read
2674 "RunProgram: "
2675 (anything-c-external-commands-list-1 'sort)
2676 :must-match t
2677 :name "External Commands"
2678 :history anything-external-command-history)))
2679 (anything-run-or-raise program)
2680 (setq anything-external-command-history
2681 (cons program (delete program
2682 (loop for i in anything-external-command-history
2683 when (executable-find i) collect i)))))
2685 ;;;###autoload
2686 (defun anything-ratpoison-commands ()
2687 "Preconfigured `anything' to execute ratpoison commands."
2688 (interactive)
2689 (anything-other-buffer 'anything-c-source-ratpoison-commands
2690 "*anything ratpoison commands*"))
2692 ;;;###autoload
2693 (defun anything-ucs ()
2694 "Preconfigured anything for `ucs-names' math symbols."
2695 (interactive)
2696 (anything :sources 'anything-c-source-ucs
2697 :keymap anything-c-ucs-map))
2701 ;;; Utilities Functions
2704 (defun anything-ff-find-printers ()
2705 "Return a list of available printers on Unix systems."
2706 (let ((printer-list (with-temp-buffer
2707 (call-process "lpstat" nil t nil "-a")
2708 (split-string (buffer-string) "\n"))))
2709 (loop for p in printer-list
2710 for printer = (car (split-string p))
2711 when printer
2712 collect printer)))
2714 ;; Shut up byte compiler in emacs24*.
2715 (defun anything-c-switch-to-buffer (buffer-or-name)
2716 "Same as `switch-to-buffer' whithout warnings at compile time."
2717 (with-no-warnings
2718 (switch-to-buffer buffer-or-name)))
2720 (defsubst* anything-c-position (item seq &key (test 'eq))
2721 "A simple and faster replacement of CL `position'."
2722 (loop for i in seq for index from 0
2723 when (funcall test i item) return index))
2725 (defun anything-c-get-pid-from-process-name (process-name)
2726 "Get pid from running process PROCESS-NAME."
2727 (loop with process-list = (list-system-processes)
2728 for pid in process-list
2729 for process = (assoc-default 'comm (process-attributes pid))
2730 when (and process (string-match process-name process))
2731 return pid))
2733 (defun* anything-current-buffer-narrowed-p (&optional
2734 (buffer anything-current-buffer))
2735 "Check if BUFFER is narrowed.
2736 Default is `anything-current-buffer'."
2737 (with-current-buffer buffer
2738 (let ((beg (point-min))
2739 (end (point-max))
2740 (total (buffer-size)))
2741 (or (/= beg 1) (/= end (1+ total))))))
2743 (defun anything-region-active-p ()
2744 (and transient-mark-mode mark-active (/= (mark) (point))))
2746 (defun anything-goto-line (lineno)
2747 "Goto LINENO opening only outline headline if needed."
2748 (goto-char (point-min)) (forward-line (1- lineno))
2749 (when (or (eq major-mode 'org-mode)
2750 (and (boundp 'outline-minor-mode)
2751 outline-minor-mode))
2752 (org-reveal))
2753 (anything-match-line-color-current-line) (sit-for 0.3)
2754 (anything-match-line-cleanup))
2756 (defun anything-show-this-source-only ()
2757 "Show all candidates of this source."
2758 (interactive)
2759 (setq anything-candidate-number-limit nil)
2760 (anything-set-source-filter
2761 (list (assoc-default 'name (anything-get-current-source)))))
2763 ;;;###autoload
2764 (defun anything-test-sources ()
2765 "List all anything sources for test.
2766 The output is sexps which are evaluated by \\[eval-last-sexp]."
2767 (interactive)
2768 (with-output-to-temp-buffer "*Anything Test Sources*"
2769 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2770 (apropos-internal "^anything-c-source" #'boundp))
2771 (pop-to-buffer standard-output)))
2773 (defun anything-nest (&rest same-as-anything)
2774 "Nested `anything'. If you use `anything' within `anything', use it."
2775 (with-selected-window (anything-window)
2776 (let (anything-current-position
2777 anything-current-buffer
2778 (orig-anything-buffer anything-buffer)
2779 anything-pattern
2780 anything-buffer
2781 anything-sources
2782 anything-compiled-sources
2783 anything-buffer-chars-modified-tick
2784 (anything-samewindow t)
2785 (enable-recursive-minibuffers t))
2786 (unwind-protect
2787 (apply #'anything same-as-anything)
2788 (anything-initialize-overlays orig-anything-buffer)
2789 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2791 (defun anything-displaying-source-names ()
2792 "Display sources name."
2793 (with-current-buffer anything-buffer
2794 (goto-char (point-min))
2795 (loop with pos
2796 while (setq pos (next-single-property-change (point) 'anything-header))
2797 do (goto-char pos)
2798 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2799 do (forward-line 1))))
2801 ;; [Obsolete]
2802 (defun anything-select-source ()
2803 "[OBSOLETE] Select source."
2804 (interactive)
2805 (let ((default (assoc-default 'name (anything-get-current-source)))
2806 (source-names (anything-displaying-source-names))
2807 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2808 (anything-get-sources))))
2809 (setq anything-candidate-number-limit 9999)
2810 (anything-aif
2811 (let (anything-source-filter)
2812 (anything-nest '(((name . "Anything Source")
2813 (candidates . source-names)
2814 (action . identity))
2815 ((name . "Anything Source (ALL)")
2816 (candidates . all-source-names)
2817 (action . identity)))
2818 nil "Source: " nil
2819 default "*anything select source*"))
2820 (anything-set-source-filter (list it))
2821 (anything-set-source-filter nil))))
2823 (defun anything-c-match-on-file-name (candidate)
2824 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2825 (string-match anything-pattern (file-name-nondirectory candidate)))
2827 (defun anything-c-match-on-directory-name (candidate)
2828 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2829 (anything-aif (file-name-directory candidate)
2830 (string-match anything-pattern it)))
2832 (defun anything-c-string-match (candidate)
2833 "Return non-nil if `anything-pattern' match CANDIDATE.
2834 The match is done with `string-match'."
2835 (string-match anything-pattern candidate))
2837 (defun anything-c-skip-entries (list regexp)
2838 "Remove entries which matches REGEXP from LIST."
2839 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2840 list))
2842 (defun anything-c-shadow-entries (list regexp)
2843 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2844 (mapcar (lambda (file)
2845 ;; Add shadow face property to boring files.
2846 (let ((face (if (facep 'file-name-shadow)
2847 'file-name-shadow
2848 ;; fall back to default on XEmacs
2849 'default)))
2850 (if (string-match regexp file)
2851 (setq file (propertize file 'face face))))
2852 file)
2853 list))
2855 (defsubst anything-c-stringify (str-or-sym)
2856 "Get string of STR-OR-SYM."
2857 (if (stringp str-or-sym)
2858 str-or-sym
2859 (symbol-name str-or-sym)))
2861 (defsubst anything-c-symbolify (str-or-sym)
2862 "Get symbol of STR-OR-SYM."
2863 (if (symbolp str-or-sym)
2864 str-or-sym
2865 (intern str-or-sym)))
2867 (defun anything-c-describe-function (func)
2868 "FUNC is symbol or string."
2869 (describe-function (anything-c-symbolify func)))
2871 (defun anything-c-describe-variable (var)
2872 "VAR is symbol or string."
2873 (describe-variable (anything-c-symbolify var)))
2875 (defun anything-c-find-function (func)
2876 "FUNC is symbol or string."
2877 (find-function (anything-c-symbolify func)))
2879 (defun anything-c-find-variable (var)
2880 "VAR is symbol or string."
2881 (find-variable (anything-c-symbolify var)))
2883 (defun anything-c-kill-new (candidate &optional replace)
2884 "CANDIDATE is symbol or string.
2885 See `kill-new' for argument REPLACE."
2886 (kill-new (anything-c-stringify candidate) replace))
2888 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2889 "Remove duplicates elements in list SEQ.
2890 This is same as `remove-duplicates' but with memoisation.
2891 It is much faster, especially in large lists.
2892 A test function can be provided with TEST argument key.
2893 Default is `eq'."
2894 (let ((cont (make-hash-table :test test)))
2895 (loop for elm in seq
2896 unless (gethash elm cont)
2897 do (puthash elm elm cont)
2898 finally return
2899 (loop for i being the hash-values in cont collect i))))
2901 (defadvice eval-defun (after anything-source-hack activate)
2902 "Allow immediate execution of anything source when evaling it.
2903 See `anything-c-enable-eval-defun-hack'."
2904 (when anything-c-enable-eval-defun-hack
2905 (let ((varsym (save-excursion
2906 (beginning-of-defun)
2907 (forward-char 1)
2908 (when (memq (read (current-buffer)) '(defvar setq))
2909 (read (current-buffer))))))
2910 (when (string-match "^anything-c-source-" (symbol-name varsym))
2911 (anything varsym)))))
2912 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2914 (defadvice anything-quit-and-find-file (around use-anything-find-files activate)
2915 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
2916 (interactive)
2917 (anything-run-after-quit
2918 (lambda (f)
2919 (if (file-exists-p f)
2920 (anything-find-files-1 (file-name-directory f)
2921 (if anything-ff-transformer-show-only-basename
2922 (anything-c-basename f) f))
2923 (anything-find-files-1 f)))
2924 (anything-aif (get-buffer (anything-get-selection))
2925 (or (buffer-file-name it)
2926 (car (rassoc it dired-buffers))
2927 (and (with-current-buffer it
2928 (eq major-mode 'org-agenda-mode))
2929 org-directory
2930 (expand-file-name org-directory))
2931 default-directory)
2932 (let ((sel (anything-get-selection)))
2933 (if (file-exists-p sel)
2934 (expand-file-name sel)
2935 default-directory)))))
2937 (defmacro* anything-c-walk-directory (directory &key (path 'basename) (directories t) match)
2938 "Walk through DIRECTORY tree.
2939 PATH can be one of basename, relative, or full.
2940 DIRECTORIES when non--nil (default) return also directories names, otherwise
2941 skip directories names.
2942 MATCH match only filenames matching regexp MATCH."
2943 `(let (result
2944 (fn (case ,path
2945 (basename 'file-name-nondirectory)
2946 (relative 'file-relative-name)
2947 (full 'identity)
2948 (t (error "Error: Invalid path spec `%s', must be one of basename, relative or full." ,path)))))
2949 (labels ((ls-R (dir)
2950 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2951 for f in ls
2952 if (file-directory-p f)
2953 do (progn (when ,directories
2954 (push (funcall fn f) result))
2955 ;; Don't recurse in directory symlink.
2956 (unless (file-symlink-p f)
2957 (ls-R f)))
2958 else do
2959 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2960 (push (funcall fn f) result)))))
2961 (ls-R ,directory)
2962 (nreverse result))))
2964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2966 ;;; Anything regexp.
2969 (defun anything-c-query-replace-regexp (candidate)
2970 "Query replace regexp from `anything-regexp'.
2971 With a prefix arg replace only matches surrounded by word boundaries,
2972 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2973 (let ((regexp (funcall (anything-attr 'regexp))))
2974 (apply 'query-replace-regexp
2975 (anything-c-query-replace-args regexp))))
2977 (defun anything-c-kill-regexp-as-sexp (candidate)
2978 "Kill regexp in a format usable in lisp code."
2979 (anything-c-regexp-kill-new
2980 (prin1-to-string (funcall (anything-attr 'regexp)))))
2982 (defun anything-c-kill-regexp (candidate)
2983 "Kill regexp as it is in `anything-pattern'."
2984 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2986 (defun anything-c-query-replace-args (regexp)
2987 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2988 (let ((region-only (anything-region-active-p)))
2989 (list
2990 regexp
2991 (query-replace-read-to regexp
2992 (format "Query replace %sregexp %s"
2993 (if anything-current-prefix-arg "word " "")
2994 (if region-only "in region " ""))
2996 anything-current-prefix-arg
2997 (when region-only (region-beginning))
2998 (when region-only (region-end)))))
3000 (defvar anything-c-source-regexp
3001 '((name . "Regexp Builder")
3002 (init . (lambda ()
3003 (anything-candidate-buffer anything-current-buffer)))
3004 (candidates-in-buffer)
3005 (get-line . anything-c-regexp-get-line)
3006 (persistent-action . anything-c-regexp-persistent-action)
3007 (persistent-help . "Show this line")
3008 (multiline)
3009 (delayed)
3010 (requires-pattern . 2)
3011 (mode-line . "Press TAB to select action.")
3012 (regexp . (lambda () anything-input))
3013 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
3014 ("Query Replace Regexp (C-u Not inside word.)"
3015 . anything-c-query-replace-regexp)
3016 ("Kill Regexp" . anything-c-kill-regexp)))))
3018 (defun anything-c-regexp-get-line (s e)
3019 (propertize
3020 (apply 'concat
3021 ;; Line contents
3022 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
3023 ;; subexps
3024 (loop for i from 0 to (1- (/ (length (match-data)) 2))
3025 collect (format "\n %s'%s'"
3026 (if (zerop i) "Group 0: " (format "Group %d: " i))
3027 (match-string i))))
3028 ;; match beginning
3029 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
3030 ;; It is implementation problem of candidates-in-buffer.
3031 'anything-realvalue
3032 (1- s)))
3034 (defun anything-c-regexp-persistent-action (pt)
3035 (goto-char pt)
3036 (anything-persistent-highlight-point))
3038 (defun anything-c-regexp-kill-new (input)
3039 (kill-new input)
3040 (message "Killed: %s" input))
3044 ;;; Toggle all marks.
3047 ;;;###autoload
3048 (defun anything-mark-all ()
3049 "Mark all visible unmarked candidates in current source."
3050 (interactive)
3051 (with-anything-window
3052 (save-excursion
3053 (goto-char (anything-get-previous-header-pos))
3054 (anything-next-line)
3055 (let* ((next-head (anything-get-next-header-pos))
3056 (end (and next-head
3057 (save-excursion
3058 (goto-char next-head)
3059 (forward-line -1)
3060 (point))))
3061 (maxpoint (or end (point-max))))
3062 (while (< (point) maxpoint)
3063 (anything-mark-current-line)
3064 (let ((prefix (get-text-property (point-at-bol) 'display))
3065 (bn (anything-c-basename (anything-get-selection)))
3066 (src (assoc-default 'name (anything-get-current-source))))
3067 (when (and (not (anything-this-visible-mark))
3068 (not (or (string= prefix "[?]")
3069 (string= prefix "[@]"))))
3070 ;; Don't mark possibles directories ending with . or ..
3071 ;; and also autosave files/links.
3072 (unless
3073 (and (or (anything-file-completion-source-p)
3074 (equal src "Files from Current Directory"))
3075 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
3076 (anything-make-visible-mark))))
3077 (forward-line 1) (end-of-line))))
3078 (anything-mark-current-line)
3079 (message "%s candidates marked" (length anything-marked-candidates))))
3081 ;;;###autoload
3082 (defun anything-unmark-all ()
3083 "Unmark all candidates in all sources of current anything session."
3084 (interactive)
3085 (with-anything-window
3086 (let ((len (length anything-marked-candidates)))
3087 (save-excursion
3088 (anything-clear-visible-mark))
3089 (setq anything-marked-candidates nil)
3090 (anything-mark-current-line)
3091 (message "%s candidates unmarked" len))))
3093 ;;;###autoload
3094 (defun anything-toggle-all-marks ()
3095 "Toggle all marks.
3096 Mark all visible candidates of current source or unmark all candidates
3097 visible or invisible in all sources of current anything session"
3098 (interactive)
3099 (let ((marked (anything-marked-candidates)))
3100 (if (and (>= (length marked) 1)
3101 (with-anything-window anything-visible-mark-overlays))
3102 (anything-unmark-all)
3103 (anything-mark-all))))
3105 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
3109 ;;; Buffers
3112 (defun anything-c-buffer-list ()
3113 "Return the list of names of buffers with boring buffers filtered out.
3114 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
3115 The first buffer in the list will be the last recently used
3116 buffer that is not the current buffer."
3117 (let ((buffers (mapcar 'buffer-name (buffer-list))))
3118 (append (cdr buffers) (list (car buffers)))))
3120 (defvar anything-c-source-buffers
3121 '((name . "Buffers")
3122 (candidates . anything-c-buffer-list)
3123 (type . buffer)))
3124 ;; (anything 'anything-c-source-buffers)
3126 (defvar anything-c-source-buffer-not-found
3127 '((name . "Create buffer")
3128 (dummy)
3129 (filtered-candidate-transformer (lambda (cands source)
3130 (list anything-pattern)))
3131 (action . (lambda (candidate)
3132 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
3133 ;; (anything 'anything-c-source-buffer-not-found)
3135 ;;; Buffers-list (was buffers+)
3138 (eval-when-compile (require 'dired))
3140 (defun anything-c-highlight-buffers (buffers)
3141 (loop for i in buffers
3142 for buf = (get-buffer i)
3143 for bfname = (buffer-file-name buf)
3144 collect
3145 (cond (;; A dired buffer.
3146 (rassoc buf dired-buffers)
3147 (propertize i 'face 'anything-ff-directory
3148 'help-echo (car (rassoc buf dired-buffers))))
3149 ;; A buffer file modified somewhere outside of emacs.
3150 ((and bfname (not (file-remote-p bfname))
3151 (file-exists-p bfname)
3152 (not (verify-visited-file-modtime buf)))
3153 (propertize i 'face 'anything-buffer-saved-out
3154 'help-echo bfname))
3155 ;; A new buffer file not already saved on disk.
3156 ((and bfname (not (file-remote-p bfname))
3157 (not (verify-visited-file-modtime buf)))
3158 (propertize i 'face 'anything-buffer-not-saved
3159 'help-echo bfname))
3160 ;; A Remote buffer file modified and not saved on disk.
3161 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
3162 (let ((prefix (propertize
3163 " " 'display
3164 (propertize "@ " 'face 'anything-ff-prefix))))
3165 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
3166 'help-echo bfname)) i)))
3167 ;; A buffer file modified and not saved on disk.
3168 ((and bfname (buffer-modified-p buf))
3169 (propertize i 'face 'anything-ff-symlink
3170 'help-echo bfname))
3171 ;; A remote buffer file not modified and saved on disk.
3172 ((and bfname (file-remote-p bfname))
3173 (let ((prefix (propertize
3174 " " 'display
3175 (propertize "@ " 'face 'anything-ff-prefix))))
3176 (cons (concat prefix (propertize i 'face 'font-lock-type-face
3177 'help-echo bfname)) i)))
3178 ;; A buffer file not modified and saved on disk.
3179 (bfname
3180 (propertize i 'face 'font-lock-type-face
3181 'help-echo bfname))
3182 ;; Any non--file buffer.
3183 (t (propertize i 'face 'italic)))))
3186 (defvar anything-c-source-buffers-list
3187 '((name . "Buffers")
3188 (candidates . anything-c-buffer-list)
3189 (type . buffer)
3190 (match anything-c-buffer-match-major-mode)
3191 (diff-action . anything-buffer-toggle-diff)
3192 (revert-action . anything-buffer-revert-and-update)
3193 (save-action . anything-buffer-save-and-update)
3194 (candidate-transformer anything-c-skip-current-buffer
3195 anything-c-skip-boring-buffers
3196 anything-c-highlight-buffers)
3197 (persistent-action . anything-c-buffers-list-persistent-action)
3198 (volatile)
3199 (mode-line . anything-buffer-mode-line-string)
3200 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
3201 ;; (anything 'anything-c-source-buffers-list)
3203 (defun anything-c-buffer-match-major-mode (candidate)
3204 "Match maybe buffer by major-mode.
3205 If you give a major-mode or partial major-mode,
3206 it will list all buffers of this major-mode and/or buffers with name
3207 matching this major-mode.
3208 If you add a space after major-mode and then a space,
3209 it will match all buffers of the major-mode
3210 before space matching pattern after space.
3211 If you give a pattern which doesn't match a major-mode, it will search buffer
3212 with name matching pattern."
3213 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
3214 (buf (get-buffer cand)))
3215 (when buf
3216 (with-current-buffer buf
3217 (let ((mjm (symbol-name major-mode))
3218 (split (split-string anything-pattern)))
3219 (cond ((string-match "\\s-$" anything-pattern)
3220 (string-match (car split) mjm))
3221 ((string-match "\\s-" anything-pattern)
3222 (and (string-match (car split) mjm)
3223 (string-match (cadr split) cand)))
3224 (t (or (string-match anything-pattern mjm)
3225 (string-match anything-pattern cand)))))))))
3227 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
3228 "Query replace in marked buffers.
3229 If REGEXP-FLAG is given use `query-replace-regexp'."
3230 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
3231 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
3232 (bufs (anything-marked-candidates)))
3233 (loop
3234 with replace = (query-replace-read-from prompt regexp-flag)
3235 with tostring = (unless (consp replace)
3236 (query-replace-read-to
3237 replace prompt regexp-flag))
3238 for buf in bufs
3240 (save-window-excursion
3241 (anything-c-switch-to-buffer buf)
3242 (save-excursion
3243 (let ((case-fold-search t))
3244 (goto-char (point-min))
3245 (if (consp replace)
3246 (apply fn (list (car replace) (cdr replace)))
3247 (apply fn (list replace tostring)))))))))
3249 (defun anything-c-buffer-query-replace-regexp (candidate)
3250 (anything-c-buffer-query-replace-1 'regexp))
3252 (defun anything-c-buffer-query-replace (candidate)
3253 (anything-c-buffer-query-replace-1))
3255 (defun anything-buffer-toggle-diff (candidate)
3256 "Toggle diff buffer CANDIDATE with it's file."
3257 (if (get-buffer-window "*Diff*")
3258 (kill-buffer "*Diff*")
3259 (diff-buffer-with-file (get-buffer candidate))))
3261 ;;;###autoload
3262 (defun anything-buffer-diff-persistent ()
3263 "Toggle diff buffer without quitting anything."
3264 (interactive)
3265 (anything-execute-persistent-action 'diff-action))
3267 (defun anything-buffer-revert-and-update (candidate)
3268 (let ((marked (anything-marked-candidates)))
3269 (loop for buf in marked do (anything-revert-buffer buf))
3270 (anything-force-update)
3271 (anything-c-recenter-window)))
3273 ;;;###autoload
3274 (defun anything-buffer-revert-persistent ()
3275 "Revert buffer without quitting anything."
3276 (interactive)
3277 (anything-execute-persistent-action 'revert-action 'onewindow))
3279 (defun anything-buffer-save-and-update (candidate)
3280 (let ((marked (anything-marked-candidates))
3281 (enable-recursive-minibuffers t))
3282 (loop for buf in marked do
3283 (with-current-buffer (get-buffer buf)
3284 (save-buffer)))
3285 (anything-force-update)
3286 (anything-c-recenter-window)))
3288 ;;;###autoload
3289 (defun anything-buffer-save-persistent ()
3290 "Save buffer without quitting anything."
3291 (interactive)
3292 (anything-execute-persistent-action 'save-action 'onewindow))
3294 ;;;###autoload
3295 (defun anything-buffer-run-kill-buffers ()
3296 "Run kill buffer action from `anything-c-source-buffers-list'."
3297 (interactive)
3298 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
3300 ;;;###autoload
3301 (defun anything-buffer-run-grep ()
3302 "Run Grep action from `anything-c-source-buffers-list'."
3303 (interactive)
3304 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
3306 ;;;###autoload
3307 (defun anything-buffer-run-zgrep ()
3308 "Run Grep action from `anything-c-source-buffers-list'."
3309 (interactive)
3310 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
3312 ;;;###autoload
3313 (defun anything-buffer-run-query-replace-regexp ()
3314 "Run Query replace regexp action from `anything-c-source-buffers-list'."
3315 (interactive)
3316 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
3318 ;;;###autoload
3319 (defun anything-buffer-run-query-replace ()
3320 "Run Query replace action from `anything-c-source-buffers-list'."
3321 (interactive)
3322 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
3324 ;;;###autoload
3325 (defun anything-buffer-switch-other-window ()
3326 "Run switch to other window action from `anything-c-source-buffers-list'."
3327 (interactive)
3328 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
3330 ;;;###autoload
3331 (defun anything-buffer-switch-other-frame ()
3332 "Run switch to other frame action from `anything-c-source-buffers-list'."
3333 (interactive)
3334 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
3336 ;;;###autoload
3337 (defun anything-buffer-switch-to-elscreen ()
3338 "Run switch to elscreen action from `anything-c-source-buffers-list'."
3339 (interactive)
3340 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
3342 ;;;###autoload
3343 (defun anything-buffer-run-ediff ()
3344 "Run ediff action from `anything-c-source-buffers-list'."
3345 (interactive)
3346 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
3348 (defun anything-buffer-run-ediff-merge ()
3349 "Run ediff action from `anything-c-source-buffers-list'."
3350 (interactive)
3351 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
3353 (defun anything-c-buffers-persistent-kill (buffer)
3354 "Persistent action to kill buffer."
3355 (with-current-buffer (get-buffer buffer)
3356 (if (and (buffer-modified-p)
3357 (buffer-file-name (current-buffer)))
3358 (progn
3359 (save-buffer)
3360 (kill-buffer buffer))
3361 (kill-buffer buffer)))
3362 (anything-delete-current-selection))
3364 (defun anything-c-recenter-window ()
3365 "Make visible current selection by recentering anything window."
3366 (with-anything-window (recenter)))
3368 (defun anything-c-buffers-list-persistent-action (candidate)
3369 (if current-prefix-arg
3370 (anything-c-buffers-persistent-kill candidate)
3371 (anything-c-switch-to-buffer candidate)))
3374 ;;;; <File>
3377 ;;; File name history
3378 (defvar anything-c-source-file-name-history
3379 '((name . "File Name History")
3380 (candidates . file-name-history)
3381 (match anything-c-match-on-file-name
3382 anything-c-match-on-directory-name)
3383 (type . file)))
3384 ;; (anything 'anything-c-source-file-name-history)
3386 ;;; Files in current dir
3389 (defvar anything-c-source-files-in-current-dir
3390 '((name . "Files from Current Directory")
3391 (candidates . (lambda ()
3392 (with-anything-current-buffer
3393 (directory-files (anything-c-current-directory)))))
3394 ;; volatile is not needed, I think.
3395 (type . file)))
3396 ;; (anything 'anything-c-source-files-in-current-dir)
3398 (defun anything-c-highlight-files (files)
3399 (loop for i in files
3400 if (file-directory-p i)
3401 collect (propertize (file-name-nondirectory i)
3402 'face 'anything-ff-directory
3403 'help-echo (expand-file-name i))
3404 else
3405 collect (propertize (file-name-nondirectory i)
3406 'face 'anything-ff-file
3407 'help-echo (expand-file-name i))))
3409 (defvar anything-c-source-files-in-current-dir+
3410 '((name . "Files from Current Directory")
3411 (candidates . (lambda ()
3412 (with-anything-current-buffer
3413 (directory-files (anything-c-current-directory) t))))
3414 (candidate-transformer anything-c-highlight-files)
3415 ;; volatile is not needed, I think.
3416 (type . file)))
3417 ;; (anything 'anything-c-source-files-in-current-dir+)
3421 ;;; Anything-find-files - The anything files browser.
3424 ;; Internal.
3425 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
3426 "*The doc that is inserted in the Name header of a find-files or dired source.")
3427 (defvar anything-ff-auto-update-flag nil
3428 "Internal, flag to turn on/off auto-update in `anything-find-files'.
3429 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
3430 (defvar anything-ff-last-expanded nil
3431 "Store last expanded directory or file.")
3432 (defvar anything-ff-default-directory nil)
3433 (defvar anything-ff-history nil)
3434 (defvar anything-ff-cand-to-mark nil)
3437 (defvar anything-c-source-find-files
3438 `((name . "Find Files")
3439 (header-name . (lambda (name)
3440 (concat name anything-c-find-files-doc-header)))
3441 ;; It is needed for filenames with capital letters
3442 (disable-shortcuts)
3443 (init . (lambda ()
3444 (setq anything-ff-auto-update-flag
3445 anything-ff-auto-update-initial-value)))
3446 (candidates . anything-find-files-get-candidates)
3447 (filtered-candidate-transformer anything-c-find-files-transformer)
3448 (image-action1 . anything-ff-rotate-image-left)
3449 (image-action2 . anything-ff-rotate-image-right)
3450 (toggle-basename . anything-ff-toggle-basename)
3451 (properties-action . anything-ff-properties)
3452 (toggle-auto-update . anything-ff-toggle-auto-update)
3453 (kill-buffer-fname . anything-ff-kill-buffer-fname)
3454 (persistent-action . anything-find-files-persistent-action)
3455 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
3456 (mode-line . anything-ff-mode-line-string)
3457 (volatile)
3458 (candidate-number-limit . 9999)
3459 (action-transformer . anything-find-files-action-transformer)
3460 (action
3461 . ,(delq
3463 `(("Find File" . anything-c-find-file-or-marked)
3464 ("Find file in Dired" . anything-c-point-file-in-dired)
3465 ,(and (locate-library "elscreen")
3466 '("Find file in Elscreen" . anything-elscreen-find-file))
3467 ,(and (locate-library "popwin")
3468 '("Find file in popup window" . popwin:find-file))
3469 ("Checksum File" . anything-ff-checksum)
3470 ("Complete at point `M-tab'"
3471 . anything-c-insert-file-name-completion-at-point)
3472 ("Open file externally `C-c C-x, C-u to choose'"
3473 . anything-c-open-file-externally)
3474 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
3475 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
3476 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
3477 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
3478 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
3479 . anything-find-files-eshell-command-on-file)
3480 ("Find file as root" . anything-find-file-as-root)
3481 ("Find file in hex dump" . hexl-find-file)
3482 ("Ediff File `C-='" . anything-find-files-ediff-files)
3483 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
3484 ("Delete File(s) `M-D'" . anything-delete-marked-files)
3485 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
3486 ("Copy file(s) Async" . anything-ff-copy-async)
3487 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
3488 ("Serial rename files" . anything-ff-serial-rename)
3489 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
3490 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
3491 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
3492 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
3493 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
3494 ("Find file other window `C-o'" . find-file-other-window)
3495 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
3496 ("Find file other frame `C-c C-o'" . find-file-other-frame)
3497 ("Print File `C-c p'" . anything-ff-print)
3498 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
3499 ;; (anything 'anything-c-source-find-files)
3501 (defun anything-find-files-set-prompt-for-action (prompt files)
3502 "Set prompt for action in `anything-find-files'."
3503 (let ((len (length files)))
3504 (if (> len 1)
3505 (format "%s * %d Files to: " prompt len)
3506 (format "%s %s to: " prompt (car files)))))
3508 (defun anything-dwim-target-directory ()
3509 "Return value of `default-directory' of buffer in other window.
3510 If there is only one window return the value ot `default-directory'
3511 for current buffer."
3512 (with-anything-current-buffer
3513 (let ((num-windows (length (window-list))))
3514 (if (> num-windows 1)
3515 (save-window-excursion
3516 (other-window 1)
3517 default-directory)
3518 (car anything-ff-history)))))
3520 (defun anything-find-files-do-action (action)
3521 "Generic function for creating action from `anything-c-source-find-files'.
3522 ACTION must be an action supported by `anything-dired-action'."
3523 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
3524 (anything-marked-candidates)))
3525 (cand (anything-get-selection)) ; Target
3526 (prompt (anything-find-files-set-prompt-for-action
3527 (capitalize (symbol-name action)) ifiles))
3528 (parg anything-current-prefix-arg)
3529 (dest (anything-c-read-file-name
3530 prompt
3531 :preselect (if anything-ff-transformer-show-only-basename
3532 (anything-c-basename cand) cand)
3533 :initial-input (anything-dwim-target-directory)
3534 :history (anything-find-files-history :comp-read nil)))
3535 (win-conf (current-window-configuration)))
3536 (unwind-protect
3537 (let ((default-directory anything-ff-default-directory))
3538 (anything-dired-action
3539 dest :files ifiles :action action :follow parg))
3540 ;; Don't reset win-conf when following.
3541 (unless parg (set-window-configuration win-conf)))))
3543 (defun anything-find-files-copy (candidate)
3544 "Copy files from `anything-find-files'."
3545 (anything-find-files-do-action 'copy))
3547 (defun anything-find-files-rename (candidate)
3548 "Rename files from `anything-find-files'."
3549 (anything-find-files-do-action 'rename))
3551 (defun anything-find-files-symlink (candidate)
3552 "Symlink files from `anything-find-files'."
3553 (anything-find-files-do-action 'symlink))
3555 (defun anything-find-files-relsymlink (candidate)
3556 "Relsymlink files from `anything-find-files'."
3557 (anything-find-files-do-action 'relsymlink))
3559 (defun anything-find-files-hardlink (candidate)
3560 "Hardlink files from `anything-find-files'."
3561 (anything-find-files-do-action 'hardlink))
3563 (defun anything-find-files-byte-compile (candidate)
3564 "Byte compile elisp files from `anything-find-files'."
3565 (let ((files (anything-marked-candidates))
3566 (parg anything-current-prefix-arg))
3567 (loop for fname in files
3568 do (byte-compile-file fname parg))))
3570 (defun anything-find-files-load-files (candidate)
3571 "Load elisp files from `anything-find-files'."
3572 (let ((files (anything-marked-candidates)))
3573 (loop for fname in files
3574 do (load fname))))
3576 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
3577 "Generic function to ediff/merge files in `anything-find-files'."
3578 (let ((bname (anything-c-basename candidate))
3579 (prompt (if merge "Ediff Merge `%s' With File: "
3580 "Ediff `%s' With File: "))
3581 (fun (if merge 'ediff-merge-files 'ediff-files)))
3582 (funcall fun
3583 candidate
3584 (condition-case quit
3585 (anything-c-read-file-name
3586 (format prompt bname))
3587 (quit
3588 (if (y-or-n-p "Search file for ediff with locate? ")
3589 (anything-c-locate-read-file-name
3590 (format prompt bname) (concat bname " -b"))
3591 (error "Error: Ediff Operation aborted")))))))
3593 (defun anything-find-files-ediff-files (candidate)
3594 (anything-find-files-ediff-files-1 candidate))
3596 (defun anything-find-files-ediff-merge-files (candidate)
3597 (anything-find-files-ediff-files-1 candidate 'merge))
3599 (defun anything-find-files-grep (candidate)
3600 "Default action to grep files from `anything-find-files'."
3601 (anything-do-grep-1 (anything-marked-candidates)
3602 anything-current-prefix-arg))
3604 (defun anything-ff-zgrep (candidate)
3605 "Default action to zgrep files from `anything-find-files'."
3606 (let ((prefarg anything-current-prefix-arg)
3607 (ls (anything-marked-candidates)))
3608 (anything-ff-zgrep-1 ls prefarg)))
3610 (defun anything-ff-pdfgrep (candidate)
3611 "Default action to pdfgrep files from `anything-find-files'."
3612 (let ((cands (loop for file in (anything-marked-candidates)
3613 if (or (string= (file-name-extension file) "pdf")
3614 (string= (file-name-extension file) "PDF"))
3615 collect file))
3616 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
3617 (when cands
3618 (anything-do-pdfgrep-1 cands))))
3620 (defun anything-ff-etags-select (candidate)
3621 "Default action to jump to etags from `anything-find-files'."
3622 (when (get-buffer anything-action-buffer)
3623 (kill-buffer anything-action-buffer))
3624 (let ((default-directory anything-ff-default-directory))
3625 (anything-c-etags-select anything-current-prefix-arg)))
3627 (defun anything-find-files-switch-to-hist (candidate)
3628 "Switch to anything-find-files history."
3629 (anything-find-files t))
3631 ;;; Asynchronous copy of files.
3634 (defun anything-c-copy-files-async-1 (flist dest)
3635 "Copy a list of Files FLIST to DEST asynchronously.
3636 It use another emacs process to do the job.
3637 Communication with background emacs is done with temp file
3638 `anything-c-copy-files-async-log-file'."
3639 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3640 "-Q" "--batch" "--eval"
3641 (format "(progn
3642 (require 'dired) (require 'cl)
3643 (let ((dired-recursive-copies 'always)
3644 failures success
3645 (ovw-count 0)
3646 (cpf-count 0))
3647 (dolist (f '%S)
3648 (condition-case err
3649 (let ((file-exists (file-exists-p
3650 (expand-file-name
3651 (file-name-nondirectory (directory-file-name f))
3652 (file-name-directory
3653 (file-name-as-directory \"%s\"))))))
3654 (dired-copy-file f \"%s\" t)
3655 (if file-exists
3656 (progn (push (cons \"Overwriting\" f) success)
3657 (incf ovw-count))
3658 (push (cons \"Copying\" f) success)
3659 (incf cpf-count)))
3660 (file-error
3661 (push (dired-make-relative
3662 (expand-file-name
3663 (file-name-nondirectory (directory-file-name f))
3664 (file-name-directory \"%s\")))
3665 failures))))
3666 (with-current-buffer (find-file-noselect \"%s\")
3667 (erase-buffer)
3668 (when failures
3669 (dolist (fail (reverse failures))
3670 (insert (concat \"Failed to copy \" fail \"\n\"))))
3671 (when success
3672 (loop for (a . s) in (reverse success) do
3673 (insert (concat a \" \" s \" to %s done\n\"))))
3674 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3675 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3676 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3677 (save-buffer))))"
3678 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3680 (defun anything-c-copy-async-with-log (flist dest)
3681 "Copy file list FLIST to DEST showing log.
3682 Log is send to `anything-c-copy-files-async-log-file'.
3683 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3684 (declare (special auto-revert-interval))
3685 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3686 (set (make-local-variable 'auto-revert-interval) 1)
3687 (erase-buffer)
3688 (insert "Wait copying files...\n")
3689 (sit-for 0.5) (save-buffer)
3690 (goto-char (point-max))
3691 (auto-revert-mode 1)
3692 (anything-c-copy-files-async-1 flist dest))
3694 (defun anything-ff-copy-async (candidate)
3695 "Anything find files action to copy files async.
3696 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3697 (let ((flist (anything-marked-candidates))
3698 (dest (anything-c-read-file-name
3699 "Copy File(s) async To: "
3700 :preselect candidate
3701 :initial-input (car anything-ff-history)
3702 :history (anything-find-files-history :comp-read nil))))
3703 (anything-c-copy-async-with-log flist dest)))
3705 (defvar eshell-command-aliases-list nil)
3706 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3707 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3709 Basename of CANDIDATE can be a wild-card.
3710 If MAP is given run `eshell-command' on all marked files at once,
3711 Otherwise, run `eshell-command' on each marked files.
3713 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3714 `eshell-command-aliases-list' will not be loaded first time you use this."
3715 (when (or eshell-command-aliases-list
3716 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3717 (and eshell-command-aliases-list (eshell-read-aliases-list))
3718 (let* ((cand-list (anything-marked-candidates))
3719 (default-directory (or anything-ff-default-directory
3720 ;; If candidate is an url *-ff-default-directory is nil
3721 ;; so keep value of default-directory.
3722 default-directory))
3723 (command (anything-comp-read
3724 "Command: "
3725 (loop for (a . c) in eshell-command-aliases-list
3726 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3727 collect (propertize a 'help-echo (car c)) into ls
3728 finally return (sort ls 'string<))))
3729 (com-value (car (assoc-default command eshell-command-aliases-list))))
3730 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3731 (> (length cand-list) 1))
3732 ;; Run eshell-command with ALL marked files as arguments.
3733 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3734 (eshell-command (format "%s %s" command mapfiles)))
3735 ;; Run eshell-command on EACH marked files.
3736 (loop
3737 for i in cand-list
3738 for bn = (anything-c-basename i)
3739 for files = (if (and bn (string-match "^\*" bn))
3740 ;; Assume if fname is a wildcard
3741 ;; cand-list have a length of 1.
3742 (mapconcat
3743 'shell-quote-argument
3744 (file-expand-wildcards i t) " ")
3745 (format "'%s'" i))
3746 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3747 ;; This allow to enter other args AFTER filename
3748 ;; i.e <command %s some_more_args>
3749 (format command files)
3750 (format "%s %s" command files))
3751 do (eshell-command com))))))
3753 (defun anything-find-files-eshell-command-on-file (candidate)
3754 "Run `eshell-command' on CANDIDATE or marked candidates.
3755 See `anything-find-files-eshell-command-on-file-1' for more info."
3756 (anything-find-files-eshell-command-on-file-1
3757 candidate anything-current-prefix-arg))
3759 (defun anything-ff-switch-to-eshell (candidate)
3760 "Switch to eshell and cd to `anything-ff-default-directory'."
3761 (flet ((cd-eshell ()
3762 (goto-char (point-max))
3763 (insert
3764 (format "cd '%s'" anything-ff-default-directory))
3765 (eshell-send-input)))
3766 (if (get-buffer "*eshell*")
3767 (progn
3768 (anything-c-switch-to-buffer "*eshell*")
3769 (cd-eshell))
3770 (call-interactively 'eshell)
3771 (cd-eshell))))
3773 (defun anything-ff-serial-rename-action (method)
3774 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3775 See `anything-ff-serial-rename-1'."
3776 (let ((cands (anything-marked-candidates))
3777 (name (read-string "NewName: "))
3778 (start (read-number "StartAtNumber: "))
3779 (dir (expand-file-name
3780 (anything-c-read-file-name
3781 "Serial Rename to directory: " :initial-input
3782 (expand-file-name anything-ff-default-directory)))))
3783 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3784 (length cands) dir name))
3785 (anything-ff-serial-rename-1 dir cands name start :method method)
3786 (anything-find-files-1 dir))))
3788 (defun anything-ff-member-directory-p (file directory)
3789 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3790 (cur-dir (expand-file-name (file-name-as-directory directory))))
3791 (string= dir-file cur-dir)))
3793 (defun* anything-ff-serial-rename-1
3794 (directory collection new-name start-at-num &key (method 'rename))
3795 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3796 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3797 METHOD can be one of rename, copy or symlink.
3798 Files will be renamed if they are files of current directory, otherwise they
3799 will be treated with METHOD.
3800 Default METHOD is rename."
3801 ;; Maybe remove directories selected by error in collection.
3802 (setq collection (remove-if 'file-directory-p collection))
3803 (flet ((symlink-file (file dest)
3804 (let ((flist (list file)))
3805 (anything-dired-action
3806 dest :action 'symlink :files flist))))
3808 (let* ((tmp-dir (file-name-as-directory
3809 (concat (file-name-as-directory directory)
3810 (symbol-name (gensym "tmp")))))
3811 (fn (case method
3812 (copy 'copy-file)
3813 (symlink 'symlink-file)
3814 (rename 'rename-file)
3815 (t (error "Error: Unknow method %s" method)))))
3816 (make-directory tmp-dir)
3817 (loop for i in collection
3818 for count from start-at-num
3819 for fnum = (if (< count 10) "0%s" "%s")
3820 for nname = (concat tmp-dir new-name (format fnum count)
3821 (file-name-extension i 'dot))
3822 do (if (anything-ff-member-directory-p i directory)
3823 (rename-file i nname)
3824 (funcall fn i nname)))
3825 (loop with dirlist = (directory-files
3826 tmp-dir t directory-files-no-dot-files-regexp)
3827 for f in dirlist do
3828 (if (file-symlink-p f)
3829 (symlink-file (file-truename f)
3830 (concat (file-name-as-directory directory)
3831 (anything-c-basename f)))
3832 (rename-file f directory)))
3833 (delete-directory tmp-dir t))))
3835 (defun anything-ff-serial-rename (candidate)
3836 "Serial rename all marked files to `anything-ff-default-directory'.
3837 Rename only file of current directory, and symlink files coming from
3838 other directories.
3839 See `anything-ff-serial-rename-1'."
3840 (anything-ff-serial-rename-action 'rename))
3842 (defun anything-ff-serial-rename-by-symlink (candidate)
3843 "Serial rename all marked files to `anything-ff-default-directory'.
3844 Rename only file of current directory, and symlink files coming from
3845 other directories.
3846 See `anything-ff-serial-rename-1'."
3847 (anything-ff-serial-rename-action 'symlink))
3849 (defun anything-ff-serial-rename-by-copying (candidate)
3850 "Serial rename all marked files to `anything-ff-default-directory'.
3851 Rename only file of current directory, and copy files coming from
3852 other directories.
3853 See `anything-ff-serial-rename-1'."
3854 (anything-ff-serial-rename-action 'copy))
3856 (defun anything-c-quit-and-execute-action (action)
3857 "Quit current anything session and execute ACTION."
3858 (setq anything-saved-action action)
3859 (anything-exit-minibuffer))
3861 (defun anything-ff-toggle-auto-update (candidate)
3862 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3863 (message "[Auto expansion %s]"
3864 (if anything-ff-auto-update-flag "enabled" "disabled")))
3866 ;;;###autoload
3867 (defun anything-ff-run-toggle-auto-update ()
3868 (interactive)
3869 (anything-execute-persistent-action 'toggle-auto-update))
3871 ;;;###autoload
3872 (defun anything-ff-run-switch-to-history ()
3873 "Run Switch to history action from `anything-c-source-find-files'."
3874 (interactive)
3875 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3877 ;;;###autoload
3878 (defun anything-ff-run-grep ()
3879 "Run Grep action from `anything-c-source-find-files'."
3880 (interactive)
3881 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3883 ;;;###autoload
3884 (defun anything-ff-run-pdfgrep ()
3885 "Run Pdfgrep action from `anything-c-source-find-files'."
3886 (interactive)
3887 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3889 ;;;###autoload
3890 (defun anything-ff-run-zgrep ()
3891 "Run Grep action from `anything-c-source-find-files'."
3892 (interactive)
3893 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3895 ;;;###autoload
3896 (defun anything-ff-run-copy-file ()
3897 "Run Copy file action from `anything-c-source-find-files'."
3898 (interactive)
3899 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3901 ;;;###autoload
3902 (defun anything-ff-run-rename-file ()
3903 "Run Rename file action from `anything-c-source-find-files'."
3904 (interactive)
3905 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3907 ;;;###autoload
3908 (defun anything-ff-run-byte-compile-file ()
3909 "Run Byte compile file action from `anything-c-source-find-files'."
3910 (interactive)
3911 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3913 ;;;###autoload
3914 (defun anything-ff-run-load-file ()
3915 "Run Load file action from `anything-c-source-find-files'."
3916 (interactive)
3917 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3919 ;;;###autoload
3920 (defun anything-ff-run-eshell-command-on-file ()
3921 "Run eshell command on file action from `anything-c-source-find-files'."
3922 (interactive)
3923 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3925 ;;;###autoload
3926 (defun anything-ff-run-ediff-file ()
3927 "Run Ediff file action from `anything-c-source-find-files'."
3928 (interactive)
3929 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3931 ;;;###autoload
3932 (defun anything-ff-run-ediff-merge-file ()
3933 "Run Ediff merge file action from `anything-c-source-find-files'."
3934 (interactive)
3935 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3937 ;;;###autoload
3938 (defun anything-ff-run-symlink-file ()
3939 "Run Symlink file action from `anything-c-source-find-files'."
3940 (interactive)
3941 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3943 ;;;###autoload
3944 (defun anything-ff-run-delete-file ()
3945 "Run Delete file action from `anything-c-source-find-files'."
3946 (interactive)
3947 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3949 ;;;###autoload
3950 (defun anything-ff-run-complete-fn-at-point ()
3951 "Run complete file name action from `anything-c-source-find-files'."
3952 (interactive)
3953 (anything-c-quit-and-execute-action
3954 'anything-c-insert-file-name-completion-at-point))
3956 ;;;###autoload
3957 (defun anything-ff-run-switch-to-eshell ()
3958 "Run switch to eshell action from `anything-c-source-find-files'."
3959 (interactive)
3960 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3962 ;;;###autoload
3963 (defun anything-ff-run-switch-other-window ()
3964 "Run switch to other window action from `anything-c-source-find-files'."
3965 (interactive)
3966 (anything-c-quit-and-execute-action 'find-file-other-window))
3968 ;;;###autoload
3969 (defun anything-ff-run-switch-other-frame ()
3970 "Run switch to other frame action from `anything-c-source-find-files'."
3971 (interactive)
3972 (anything-c-quit-and-execute-action 'find-file-other-frame))
3974 ;;;###autoload
3975 (defun anything-ff-run-open-file-externally ()
3976 "Run open file externally command action from `anything-c-source-find-files'."
3977 (interactive)
3978 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3980 (defun anything-ff-locate (candidate)
3981 "Locate action function for `anything-find-files'."
3982 (let ((input (concat (anything-c-basename
3983 (expand-file-name
3984 candidate
3985 anything-ff-default-directory))
3986 ;; The locate '-b' option doesn't exists
3987 ;; in everything.
3988 (unless (and (eq system-type 'windows-nt)
3989 (string-match "^es" anything-c-locate-command))
3990 " -b")))
3991 (anything-mp-highlight-delay 0.7))
3992 (anything-locate-1 anything-current-prefix-arg input)))
3994 ;;;###autoload
3995 (defun anything-ff-run-locate ()
3996 "Run locate action from `anything-c-source-find-files'."
3997 (interactive)
3998 (anything-c-quit-and-execute-action 'anything-ff-locate))
4000 ;;;###autoload
4001 (defun anything-ff-run-gnus-attach-files ()
4002 "Run gnus attach files command action from `anything-c-source-find-files'."
4003 (interactive)
4004 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
4006 ;;;###autoload
4007 (defun anything-ff-run-etags ()
4008 "Run Etags command action from `anything-c-source-find-files'."
4009 (interactive)
4010 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
4013 (defun anything-ff-print (candidate)
4014 "Print marked files.
4015 You have to set in order
4016 variables `lpr-command',`lpr-switches' and/or `printer-name'.
4018 e.g:
4019 \(setq lpr-command \"gtklp\"\)
4020 \(setq lpr-switches '(\"-P\")\)
4021 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
4023 Same as `dired-do-print' but for anything."
4024 (let* ((file-list (anything-marked-candidates))
4025 (len (length file-list))
4026 (printer-name (if anything-ff-printer-list
4027 (anything-comp-read
4028 "Printer: " anything-ff-printer-list)
4029 printer-name))
4030 (command (read-string
4031 (format "Print *%s File(s):\n%s with: "
4033 (mapconcat
4034 (lambda (f) (format "- %s\n" f))
4035 file-list ""))
4036 (when (and lpr-command
4037 (or lpr-switches
4038 printer-name))
4039 (mapconcat 'identity
4040 (cons lpr-command
4041 (append (if (stringp lpr-switches)
4042 (list lpr-switches)
4043 lpr-switches)
4044 (list printer-name)))
4045 " "))))
4046 (file-args (mapconcat #'(lambda (x)
4047 (format "'%s'" x))
4048 file-list " "))
4049 (cmd-line (concat command " " file-args)))
4050 (if command
4051 (start-process-shell-command "anything-print" nil cmd-line)
4052 (error "Error: Please verify your printer settings in Emacs."))))
4054 ;;;###autoload
4055 (defun anything-ff-run-print-file ()
4056 "Run Print file action from `anything-c-source-find-files'."
4057 (interactive)
4058 (anything-c-quit-and-execute-action 'anything-ff-print))
4060 (defun* anything-ff-checksum (file)
4061 "Calculate the checksum of FILE with completion on algorithms to use.
4062 The checksum is copied to kill-ring."
4063 (let ((algo-list '(md5 sha1 sha224 sha256 sha384 sha512)))
4064 (kill-new
4065 (secure-hash (intern
4066 (anything-comp-read
4067 "Algorithm: " algo-list))
4068 file))
4069 (message "Checksum copied to kill-ring.")))
4071 (defun anything-ff-toggle-basename (candidate)
4072 (setq anything-ff-transformer-show-only-basename
4073 (not anything-ff-transformer-show-only-basename))
4074 (save-excursion
4075 (anything-force-update)))
4077 (defun anything-ff-run-toggle-basename ()
4078 (interactive)
4079 (anything-execute-persistent-action 'toggle-basename))
4081 (defun* anything-reduce-file-name (fname level &key unix-close expand)
4082 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
4083 If LEVEL is positive reduce from end else from beginning.
4084 If UNIX-CLOSE is non--nil close filename with /.
4085 If EXPAND is non--nil expand-file-name."
4086 (let* ((exp-fname (expand-file-name fname))
4087 (fname-list (split-string (if (or (string= fname "~/") expand)
4088 exp-fname fname) "/" t))
4089 (len (length fname-list))
4090 (pop-list (if (< level 0)
4091 (subseq fname-list (* level -1))
4092 (subseq fname-list 0 (- len level))))
4093 (result (mapconcat 'identity pop-list "/"))
4094 (empty (string= result "")))
4095 (when unix-close (setq result (concat result "/")))
4096 (if (string-match "^~" result)
4097 (if (string= result "~/") "~/" result)
4098 (if (< level 0)
4099 (if empty "../" (concat "../" result))
4100 (cond ((eq system-type 'windows-nt)
4101 (if empty "c:/" result))
4102 (empty "/")
4104 (concat "/" result)))))))
4106 (defun anything-file-completion-source-p ()
4107 "Test if current source is a dired or find-files source."
4108 (let ((ff-sources '("Find Files" "Copy Files"
4109 "Read File Name History"
4110 "Rename Files" "Symlink Files"
4111 "Hardlink Files" "Write File"
4112 "Insert File" "Read file name"))
4113 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
4114 (loop for i in ff-sources thereis (string= cur-source i))))
4116 (defun anything-find-files-down-one-level (arg)
4117 "Go down one level like unix command `cd ..'.
4118 If prefix numeric arg is given go ARG level down."
4119 (interactive "p")
4120 (with-anything-window
4121 (setq anything-follow-mode nil))
4122 ;; When going to precedent level we want to be at the line
4123 ;; corresponding to actual directory, so store this info
4124 ;; in `anything-ff-last-expanded'.
4125 (if (and (not (file-directory-p anything-pattern))
4126 (file-exists-p anything-pattern))
4127 (setq anything-ff-last-expanded anything-pattern)
4128 (setq anything-ff-last-expanded anything-ff-default-directory))
4129 (when (anything-file-completion-source-p)
4130 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
4131 :unix-close t :expand t)))
4132 (anything-set-pattern new-pattern))))
4134 (defun anything-ff-retrieve-last-expanded ()
4135 "Move overlay to last visited directory `anything-ff-last-expanded'.
4136 This happen after using `anything-find-files-down-one-level',
4137 or hitting C-z on \"..\"."
4138 (when (and anything-ff-last-expanded
4139 (anything-file-completion-source-p))
4140 (let ((dirname (if anything-ff-transformer-show-only-basename
4141 (anything-c-basename
4142 (directory-file-name anything-ff-last-expanded))
4143 (directory-file-name anything-ff-last-expanded))))
4144 (with-anything-window
4145 (when (or (re-search-forward (concat dirname "$") nil t)
4146 (re-search-forward
4147 (concat anything-ff-last-expanded "$") nil t))
4148 (forward-line 0)
4149 (anything-mark-current-line)))
4150 (setq anything-ff-last-expanded nil))))
4151 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
4153 ;; Auto-update - anything-find-files auto expansion of directories.
4155 (defun anything-ff-update-when-only-one-matched ()
4156 "Expand to directory when sole completion.
4157 When only one candidate is remaining and it is a directory,
4158 expand to this directory."
4159 (let ((history-p (string= (assoc-default
4160 'name (anything-get-current-source))
4161 "Read File Name History"))
4162 (completed-p (string= (file-name-as-directory anything-pattern)
4163 anything-ff-default-directory)))
4164 (when (and anything-ff-auto-update-flag
4165 (or (and (anything-file-completion-source-p)
4166 (<= (anything-approximate-candidate-number) 2)
4167 (>= (length (anything-c-basename anything-pattern)) 2))
4168 completed-p)
4169 (not history-p))
4170 (with-anything-window
4171 (and (not completed-p) (anything-next-line))
4172 (let ((cur-cand (anything-get-selection)))
4173 (when (file-directory-p cur-cand)
4174 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
4175 ;; Maybe we are here because completed-p is true
4176 ;; So check this again to be sure.
4177 ;; (this happen only on windows dirs)
4178 (<= (anything-approximate-candidate-number) 2)) ; [2]
4179 ;; If after going to next line the candidate is not "." or ".." [1]
4180 ;; and only one candidate is remaining [2],
4181 ;; assume candidate is a new directory to expand, and do it.
4182 (anything-set-pattern (file-name-as-directory cur-cand))
4183 ;; The candidate is one of "." or ".." (it should be "..").
4184 ;; that mean we have entered the last letter of the directory name
4185 ;; in prompt, so expansion is already done, just add the "/" at end
4186 ;; of name unless anything-pattern ends with "."
4187 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
4188 (anything-set-pattern (file-name-as-directory anything-pattern))))
4189 (anything-check-minibuffer-input-1)))))))
4190 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
4192 ;; Allow expanding to home directory or root
4193 ;; when entering respectively "~/" or "//" at end of pattern.
4194 ;; e.g /home/thierry/labo/anything-config-qp/~/
4195 ;; will expand to "~/"
4196 ;; and /home/thierry/labo/anything-config-qp//
4197 ;; will expand to "/"
4198 (defun anything-ff-auto-expand-to-home-or-root ()
4199 "Goto home or root directory when adding ~/ or / at end of pattern.
4200 This happen only in function using sources that are
4201 `anything-file-completion-source-p' compliant."
4202 (when (and (anything-file-completion-source-p)
4203 (string-match ".*\\(/~/\\|/\\{2\\}\\)$" anything-pattern))
4204 (let ((match (match-string 1 anything-pattern)))
4205 (cond ((string= match "//")
4206 (if (eq system-type 'windows-nt)
4207 (setq anything-pattern "c:/")
4208 (setq anything-pattern "/")))
4209 ((string= match "/~/")
4210 (if (eq system-type 'windows-nt)
4211 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
4212 (setq anything-pattern "~/")))))
4213 (setq anything-ff-default-directory anything-pattern)
4214 ;; For some reasons, i must use here with-current-buffer => mini buffer
4215 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
4216 (with-current-buffer (window-buffer (minibuffer-window))
4217 (delete-minibuffer-contents)
4218 (insert anything-pattern))))
4220 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
4222 (defun anything-c-point-file-in-dired (file)
4223 "Put point on filename FILE in dired buffer."
4224 (dired (file-name-directory file))
4225 (dired-goto-file file))
4227 (defun anything-create-tramp-name (fname)
4228 "Build filename for `anything-pattern' like /su:: or /sudo::."
4229 (apply #'tramp-make-tramp-file-name
4230 (loop with v = (tramp-dissect-file-name fname)
4231 for i across v collect i)))
4233 (defun anything-ff-set-pattern (pattern)
4234 "Handle tramp filenames in `anything-pattern'."
4235 (let ((methods (mapcar 'car tramp-methods))
4236 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
4237 cur-method tramp-name)
4238 (cond ((string= pattern "") "")
4239 ((string-match ".*\\(~//\\|//\\)$" pattern)
4240 (if (eq system-type 'windows-nt) "c:/" "/"))
4241 ((string-match "^~\\|.*/~/$" pattern)
4242 (let* ((home (getenv "HOME"))
4243 (replace (if (eq system-type 'windows-nt)
4244 (replace-regexp-in-string
4245 "\\\\" "/" home)
4246 home)))
4247 (replace-match replace nil t pattern)))
4248 ;; Match "/method:maybe_hostname:"
4249 ((and (string-match reg pattern)
4250 (setq cur-method (match-string 1 pattern))
4251 (member cur-method methods))
4252 (setq tramp-name (anything-create-tramp-name
4253 (match-string 0 pattern)))
4254 (replace-match tramp-name nil t pattern))
4255 ;; Match "/hostname:"
4256 ((and (string-match tramp-file-name-regexp pattern)
4257 (setq cur-method (match-string 1 pattern))
4258 (and cur-method (not (member cur-method methods))))
4259 (setq tramp-name (anything-create-tramp-name
4260 (match-string 0 pattern)))
4261 (replace-match tramp-name nil t pattern))
4262 ;; Match "/method:" in this case don't try to connect.
4263 ((and (not (string-match reg pattern))
4264 (string-match tramp-file-name-regexp pattern)
4265 (member (match-string 1 pattern) methods))
4266 "Invalid tramp file name") ; Write in anything-buffer.
4267 ;; PATTERN is a directory, end it with "/".
4268 ;; This will make PATTERN not ending yet with "/"
4269 ;; candidate for `anything-ff-default-directory',
4270 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
4271 ;; when descending level.
4272 ((file-directory-p pattern)
4273 (file-name-as-directory pattern))
4274 ;; Return PATTERN unchanged.
4275 (t pattern))))
4278 (defun anything-find-files-get-candidates ()
4279 "Create candidate list for `anything-c-source-find-files'."
4280 (let* ((path (anything-ff-set-pattern anything-pattern))
4281 (path-name-dir (if (file-directory-p path)
4282 (file-name-as-directory path)
4283 (file-name-directory path)))
4284 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
4285 (set-text-properties 0 (length path) nil path)
4286 (setq anything-pattern (anything-ff-transform-fname-for-completion path))
4287 (setq anything-ff-default-directory
4288 (if (string= anything-pattern "")
4289 (if (eq system-type 'windows-nt) "c:/" "/")
4290 (unless (string-match ffap-url-regexp path)
4291 path-name-dir)))
4292 (cond ((or (string= path "Invalid tramp file name")
4293 (file-regular-p path)
4294 (and (not (file-exists-p path)) (string-match "/$" path))
4295 (and ffap-url-regexp (string-match ffap-url-regexp path)))
4296 (list path))
4297 ((string= path "") (directory-files "/" t))
4298 ((and (file-directory-p path) (not (file-readable-p path)))
4299 (list (format "Opening directory: access denied, `%s'" path)))
4300 ((file-directory-p path) (directory-files path t))
4302 (append (list path) (directory-files path-name-dir t))))))
4304 (defun anything-ff-transform-fname-for-completion (fname)
4305 "Return FNAME with it's basename modified as a regexp.
4306 e.g foo => f.*o.*o .
4307 If basename contain one or more space or FNAME is a valid directory name
4308 return FNAME unchanged."
4309 (let ((bn (anything-c-basename fname)))
4310 (if (or (not anything-ff-smart-completion)
4311 (string-match "\\s-" bn)
4312 (string-match "/$" fname) ; Allow mkdir.
4313 (file-directory-p fname))
4314 fname ; Fall back to match-plugin.
4315 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
4316 (mapconcat 'identity (split-string bn "" t) ".*") bn))
4317 (concat (file-name-directory fname) bn))))
4319 (defun anything-ff-save-history ()
4320 "Store the last value of `anything-ff-default-directory' \
4321 in `anything-ff-history'."
4322 (when (and anything-ff-default-directory
4323 (anything-file-completion-source-p))
4324 (push anything-ff-default-directory anything-ff-history)))
4325 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
4327 (defun anything-ff-valid-symlink-p (file)
4328 (file-exists-p (file-truename file)))
4330 (defun anything-ff-properties (candidate)
4331 "Show file properties of CANDIDATE in a tooltip or message."
4332 (let ((type (anything-ff-attributes candidate :type t))
4333 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
4334 (if (window-system)
4335 (tooltip-show
4336 (concat
4337 (anything-c-basename candidate) ": \n"
4338 "Type: " type "\n"
4339 (when (string= type "symlink")
4340 (format "True name: '%s'\n"
4341 (cond ((string-match "^\.#" (anything-c-basename candidate))
4342 "Autosave symlink")
4343 ((anything-ff-valid-symlink-p candidate)
4344 (file-truename candidate))
4345 (t "Invalid Symlink"))))
4346 dired-line))
4347 (message dired-line) (sit-for 5))))
4349 ;;;###autoload
4350 (defun anything-ff-properties-persistent ()
4351 "Show properties without quitting anything."
4352 (interactive)
4353 (anything-execute-persistent-action 'properties-action))
4355 (defun anything-ff-kill-buffer-fname (candidate)
4356 (let* ((buf (get-file-buffer candidate))
4357 (buf-name (buffer-name buf)))
4358 (if buf
4359 (progn
4360 (kill-buffer buf) (message "Buffer `%s' killed" buf))
4361 (message "No buffer to kill"))))
4363 (defun anything-ff-kill-or-find-buffer-fname (candidate)
4364 "Find file CANDIDATE or kill it's buffer if it is visible.
4365 Never kill `anything-current-buffer'.
4366 Never kill buffer modified.
4367 This is called normally on third hit of \
4368 \\<anything-map>\\[anything-execute-persistent-action]
4369 in `anything-find-files-persistent-action'."
4370 (let* ((buf (get-file-buffer candidate))
4371 (buf-name (buffer-name buf)))
4372 (if (and buf (get-buffer-window buf)
4373 (not (eq buf (get-buffer anything-current-buffer)))
4374 (not (buffer-modified-p buf)))
4375 (progn
4376 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
4377 (find-file candidate))))
4379 ;;;###autoload
4380 (defun anything-ff-run-kill-buffer-persistent ()
4381 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
4382 (interactive)
4383 (anything-execute-persistent-action 'kill-buffer-fname))
4385 (defun anything-ff-human-size (size)
4386 "Return a string showing SIZE of a file in human readable form.
4387 SIZE can be an integer or a float depending it's value.
4388 `file-attributes' will take care of that to avoid overflow error.
4389 KBSIZE if a floating point number, default value is 1024.0."
4390 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
4391 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
4392 (K (cons "K" (/ size anything-ff-default-kbsize)))
4393 (B (cons "B" size)))
4394 (loop with result = B
4395 for (a . b) in
4396 (loop for (x . y) in (list M G K B)
4397 unless (< y 1) collect (cons x y))
4398 when (< b (cdr result)) do (setq result (cons a b))
4399 finally return (if (string= (car result) "B")
4400 (format "%s" size)
4401 (format "%.1f%s" (cdr result) (car result))))))
4403 (defun* anything-ff-attributes
4404 (file &key type links uid gid access-time modif-time
4405 status size mode gid-change inode device-num dired human-size)
4406 "Easy interface for `file-attributes'."
4407 (let ((all (destructuring-bind
4408 (type links uid gid access-time modif-time
4409 status size mode gid-change inode device-num)
4410 (file-attributes file 'string)
4411 (list :type type
4412 :links links
4413 :uid uid
4414 :gid gid
4415 :access-time access-time
4416 :modif-time modif-time
4417 :status status
4418 :size size
4419 :mode mode
4420 :gid-change gid-change
4421 :inode inode
4422 :device-num device-num))))
4423 (cond (type
4424 (let ((result (getf all :type)))
4425 (cond ((stringp result)
4426 "symlink")
4427 (result "directory")
4428 (t "file"))))
4429 (links (getf all :links))
4430 (uid (getf all :uid))
4431 (gid (getf all :gid))
4432 (access-time
4433 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
4434 (modif-time
4435 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
4436 (status
4437 (format-time-string "%Y-%m-%d %R" (getf all :status)))
4438 (size (if human-size (anything-ff-human-size (getf all :size))
4439 (getf all :size)))
4440 (mode (getf all :mode))
4441 (gid-change (getf all :gid-change))
4442 (inode (getf all :inode))
4443 (device-num (getf all :device-num))
4444 (dired
4445 (concat
4446 (getf all :mode) " "
4447 (number-to-string (getf all :links)) " "
4448 (getf all :uid) ":"
4449 (getf all :gid) " "
4450 (if human-size (anything-ff-human-size (getf all :size))
4451 (int-to-string (getf all :size))) " "
4452 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
4453 (t all))))
4455 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
4456 "Return filename FNAME maybe prefixed with [?] or [@].
4457 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4458 existing filename or valid symlink and there is no need to test it.
4459 NEW-FILE when non--nil mean FNAME is a non existing file and
4460 return FNAME prefixed with [?]."
4461 (let* ((prefix-new (propertize
4462 " " 'display
4463 (propertize "[?]" 'face 'anything-ff-prefix)))
4464 (prefix-url (propertize
4465 " " 'display
4466 (propertize "[@]" 'face 'anything-ff-prefix))))
4467 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
4468 ((string-match ffap-url-regexp fname)
4469 (concat prefix-url " " fname))
4470 ((or new-file (not (file-exists-p fname)))
4471 (concat prefix-new " " fname)))))
4473 (defun anything-c-find-files-transformer (files sources)
4474 "Transformer for `anything-c-source-find-files'.
4475 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4476 is non--nil."
4477 (if (and (string-match tramp-file-name-regexp anything-pattern)
4478 anything-ff-tramp-not-fancy)
4479 (if anything-ff-transformer-show-only-basename
4480 (loop for i in files collect
4481 (if (string-match "[.]\\{1,2\\}$" i)
4482 i (cons (anything-c-basename i) i)))
4483 files)
4484 (anything-ff-highlight-files files sources)))
4486 (defvar anything-ff-transformer-show-only-basename nil)
4487 (defun anything-ff-highlight-files (files sources)
4488 "Candidate transformer for `anything-c-source-find-files' without icons."
4489 (loop for i in files
4490 for disp = (if (and anything-ff-transformer-show-only-basename
4491 (not (string-match "[.]\\{1,2\\}$" i))
4492 (not (string-match ffap-url-regexp i)))
4493 (anything-c-basename i) i)
4494 collect
4495 (cond ((and (stringp (car (file-attributes i)))
4496 (not (anything-ff-valid-symlink-p i))
4497 (not (string-match "^\.#" (anything-c-basename i))))
4498 (cons (anything-ff-prefix-filename
4499 (propertize disp 'face 'anything-ff-invalid-symlink) t)
4501 ((stringp (car (file-attributes i)))
4502 (cons (anything-ff-prefix-filename
4503 (propertize disp 'face 'anything-ff-symlink) t)
4505 ((eq t (car (file-attributes i)))
4506 (cons (anything-ff-prefix-filename
4507 (propertize disp 'face 'anything-ff-directory) t)
4509 ((file-executable-p i)
4510 (cons (anything-ff-prefix-filename
4511 (propertize disp 'face 'anything-ff-executable) t)
4513 ((file-exists-p i)
4514 (cons (anything-ff-prefix-filename
4515 (propertize disp 'face 'anything-ff-file) t)
4518 (cons (anything-ff-prefix-filename
4519 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4520 i)))))
4522 (defun anything-find-files-action-transformer (actions candidate)
4523 "Action transformer for `anything-c-source-find-files'."
4524 (cond ((with-anything-current-buffer
4525 (eq major-mode 'message-mode))
4526 (append (subseq actions 0 4)
4527 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4528 (subseq actions 4)))
4529 ((string-match (image-file-name-regexp) candidate)
4530 (append (subseq actions 0 4)
4531 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4532 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4533 (subseq actions 4)))
4534 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4535 (car it) candidate))
4536 (append (subseq actions 0 4)
4537 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4538 . anything-find-files-byte-compile)
4539 ("Load File(s) `M-L'" . anything-find-files-load-files))
4540 (subseq actions 4)))
4541 ((and (string-match "\.html?$" candidate)
4542 (file-exists-p candidate))
4543 (append (subseq actions 0 4)
4544 '(("Browse url file" . browse-url-of-file))
4545 (subseq actions 5)))
4546 ((or (string= (file-name-extension candidate) "pdf")
4547 (string= (file-name-extension candidate) "PDF"))
4548 (append (subseq actions 0 4)
4549 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4550 (subseq actions 5)))
4551 (t actions)))
4553 (defun anything-ff-gnus-attach-files (candidate)
4554 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4555 (let ((flist (anything-marked-candidates)))
4556 (gnus-dired-attach flist)))
4558 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4559 "Rotate current image at NUM-ARG degrees.
4560 This is a destructive operation on FILE made by external tool mogrify."
4561 (declare (special image-dired-display-image-buffer))
4562 (setq file (file-truename file)) ; For symlinked images.
4563 ;; When FILE is not an image-file, do nothing.
4564 (when (string-match (image-file-name-regexp) file)
4565 (if (executable-find "mogrify")
4566 (progn
4567 (shell-command (format "mogrify -rotate %s %s"
4568 (or num-arg 90)
4569 (shell-quote-argument file)))
4570 (when (buffer-live-p image-dired-display-image-buffer)
4571 (kill-buffer image-dired-display-image-buffer))
4572 (image-dired-display-image file)
4573 (message nil)
4574 (display-buffer (get-buffer image-dired-display-image-buffer)))
4575 (error "mogrify not found"))))
4577 (defun anything-ff-rotate-image-left (candidate)
4578 "Rotate image file CANDIDATE left.
4579 This affect directly file CANDIDATE."
4580 (anything-ff-rotate-current-image-1 candidate -90))
4582 (defun anything-ff-rotate-image-right (candidate)
4583 "Rotate image file CANDIDATE right.
4584 This affect directly file CANDIDATE."
4585 (anything-ff-rotate-current-image-1 candidate))
4587 (defun anything-ff-rotate-left-persistent ()
4588 "Rotate image left without quitting anything."
4589 (interactive)
4590 (anything-execute-persistent-action 'image-action1))
4592 (defun anything-ff-rotate-right-persistent ()
4593 "Rotate image right without quitting anything."
4594 (interactive)
4595 (anything-execute-persistent-action 'image-action2))
4597 (defun anything-ff-exif-data (candidate)
4598 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4599 (if (and anything-ff-exif-data-program
4600 (executable-find anything-ff-exif-data-program))
4601 (shell-command-to-string (format "%s %s %s"
4602 anything-ff-exif-data-program
4603 anything-ff-exif-data-program-args
4604 candidate))
4605 (format "No program %s found to extract exif"
4606 anything-ff-exif-data-program)))
4608 (defun anything-find-files-persistent-action (candidate)
4609 "Open subtree CANDIDATE without quitting anything.
4610 If CANDIDATE is not a directory expand CANDIDATE filename.
4611 If CANDIDATE is alone, open file CANDIDATE filename.
4612 That's mean:
4613 First hit on C-z expand CANDIDATE second hit open file.
4614 If a prefix arg is given or `anything-follow-mode' is on open file."
4615 (let ((follow (buffer-local-value
4616 'anything-follow-mode
4617 (get-buffer-create anything-buffer)))
4618 (new-pattern (anything-get-selection))
4619 (num-lines-buf (with-current-buffer anything-buffer
4620 (count-lines (point-min) (point-max)))))
4621 (flet ((insert-in-minibuffer (fname)
4622 (with-selected-window (minibuffer-window)
4623 (unless follow
4624 (delete-minibuffer-contents)
4625 (set-text-properties 0 (length fname) nil fname)
4626 (insert fname)))))
4627 (cond (;; A symlink directory, expand it's truename.
4628 (and (file-directory-p candidate) (file-symlink-p candidate))
4629 (insert-in-minibuffer (file-name-as-directory
4630 (file-truename
4631 (expand-file-name candidate)))))
4632 ;; A directory, open it.
4633 ((file-directory-p candidate)
4634 (when (string= (anything-c-basename candidate) "..")
4635 (setq anything-ff-last-expanded anything-ff-default-directory))
4636 (insert-in-minibuffer (file-name-as-directory
4637 (expand-file-name candidate))))
4638 ;; A symlink file, expand to it's true name. (first hit)
4639 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4640 (insert-in-minibuffer (file-truename candidate)))
4641 ;; A regular file, expand it, (first hit)
4642 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4643 (insert-in-minibuffer new-pattern))
4644 ;; An image file and it is the second hit on C-z,
4645 ;; show the file in `image-dired'.
4646 ((string-match (image-file-name-regexp) candidate)
4647 (when (buffer-live-p image-dired-display-image-buffer)
4648 (kill-buffer image-dired-display-image-buffer))
4649 (image-dired-display-image candidate)
4650 (message nil)
4651 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4652 (with-current-buffer image-dired-display-image-buffer
4653 (let ((exif-data (anything-ff-exif-data candidate)))
4654 (image-dired-update-property 'help-echo exif-data))))
4655 ;; Allow browsing archive on avfs fs.
4656 ;; Assume volume is already mounted with mountavfs.
4657 ((and anything-ff-avfs-directory
4658 (string-match
4659 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4660 (file-name-directory candidate))
4661 (anything-ff-file-compressed-p candidate))
4662 (insert-in-minibuffer (concat candidate "#")))
4663 ;; On second hit we open file.
4664 ;; On Third hit we kill it's buffer maybe.
4666 (anything-ff-kill-or-find-buffer-fname candidate))))))
4668 (defun anything-ff-file-compressed-p (candidate)
4669 "Whether CANDIDATE is a compressed file or not."
4670 (member (file-name-extension candidate)
4671 anything-ff-file-compressed-list))
4673 (defun anything-c-insert-file-name-completion-at-point (candidate)
4674 "Insert file name completion at point."
4675 (with-anything-current-buffer
4676 (if buffer-read-only
4677 (error "Error: Buffer `%s' is read-only" (buffer-name))
4678 (let* ((end (point))
4679 (guess (substring-no-properties (thing-at-point 'filename)))
4680 (beg (- (point) (length guess)))
4681 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4682 (string-match-p "^[^\~]" guess))))
4683 (set-text-properties 0 (length candidate) nil candidate)
4684 (if (and guess (not (string= guess ""))
4685 (string-match-p "^~\\|/.*" guess))
4686 (progn
4687 (delete-region beg end)
4688 (insert (if full-path-p
4689 (expand-file-name candidate)
4690 (abbreviate-file-name candidate))))
4691 (error "Aborting completion: No valid file name at point"))))))
4693 (defun* anything-find-files-history (&key (comp-read t))
4694 "The `anything-find-files' history.
4695 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4696 in an `anything-comp-read'."
4697 (let ((history (when anything-ff-history
4698 (loop with dup for i in anything-ff-history
4699 ;; Remove duplicate and not existing files.
4700 ;; Keep remote files.
4701 unless (or (member i dup)
4702 (and (not (file-remote-p i))
4703 (not (file-exists-p i))))
4704 collect i into dup
4705 finally return dup)))) ; Remove dups.
4706 (when history
4707 (setq anything-ff-history
4708 (if (>= (length history) anything-ff-history-max-length)
4709 (subseq history 0 anything-ff-history-max-length)
4710 history))
4711 (if comp-read
4712 (anything-comp-read
4713 "Switch to Directory: "
4714 anything-ff-history
4715 :name "Anything Find Files History"
4716 :must-match t)
4717 anything-ff-history))))
4719 (defun anything-find-files-1 (fname &optional preselect)
4720 "Find FNAME with `anything' completion.
4721 Like `find-file' but with `anything' support.
4722 Use it for non--interactive calls of `anything-find-files'."
4723 (when (get-buffer anything-action-buffer)
4724 (kill-buffer anything-action-buffer))
4725 (let ((anything-mp-highlight-delay nil)
4726 ;; Be sure we don't erase the precedent minibuffer if some.
4727 (anything-ff-auto-update-initial-value
4728 (not (minibuffer-window-active-p (minibuffer-window))))
4729 anything-samewindow)
4730 (anything :sources 'anything-c-source-find-files
4731 :input fname
4732 :preselect preselect
4733 :keymap anything-find-files-map
4734 :prompt "Find Files or Url: "
4735 :buffer "*Anything Find Files*")))
4738 (defun anything-find-files-initial-input (&optional input)
4739 "Return INPUT if present, otherwise try to guess it."
4740 (or (and input (expand-file-name input))
4741 (anything-find-files-input
4742 (ffap-guesser)
4743 (thing-at-point 'filename))))
4745 (defun anything-find-files-input (fap tap)
4746 "Default input of `anything-find-files'."
4747 (let* ((def-dir (anything-c-current-directory))
4748 (lib (anything-find-library-at-point))
4749 (url (anything-ff-find-url-at-point))
4750 (file-p (and fap (not (string= fap ""))
4751 (file-exists-p fap)
4752 tap (not (string= tap ""))
4753 (file-exists-p
4754 (file-name-directory (expand-file-name tap def-dir))))))
4755 (cond (lib) ; e.g we are inside a require sexp.
4756 (url) ; String at point is an hyperlink.
4757 (file-p (expand-file-name tap def-dir))
4758 (t (and (not (string= fap "")) fap)))))
4760 (defun anything-c-current-directory ()
4761 "Return current-directory name at point.
4762 Useful in dired buffers when there is inserted subdirs."
4763 (if (eq major-mode 'dired-mode)
4764 (dired-current-directory)
4765 default-directory))
4767 (defun anything-ff-find-url-at-point ()
4768 "Try to find link to an url in text-property at point."
4769 (let* ((he (get-text-property (point) 'help-echo))
4770 (ov (overlays-at (point)))
4771 (ov-he (and ov (overlay-get
4772 (car (overlays-at (point))) 'help-echo)))
4773 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4774 (nt-prop (get-text-property (point) 'nt-link)))
4775 ;; Org link.
4776 (when (and (stringp he) (string-match "^LINK: " he))
4777 (setq he (replace-match "" t t he)))
4778 (loop for i in (list he ov-he w3m-l nt-prop)
4779 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4781 (defun anything-find-library-at-point ()
4782 "Try to find library path at point.
4783 Find inside `require' and `declare-function' sexp."
4784 (require 'find-func)
4785 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4786 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4787 (sexp (and beg-sexp end-sexp
4788 (buffer-substring-no-properties
4789 (1+ beg-sexp) (1- end-sexp)))))
4790 (ignore-errors
4791 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4792 (find-library-name
4793 (replace-regexp-in-string
4794 "'\\|\)\\|\(" ""
4795 ;; If require use third arg, ignore it,
4796 ;; always use library path found in `load-path'.
4797 (second (split-string (match-string 0 sexp))))))
4798 ((and sexp (string-match-p "^declare-function" sexp))
4799 (find-library-name
4800 (replace-regexp-in-string
4801 "\"\\|ext:" ""
4802 (third (split-string sexp)))))
4803 (t nil)))))
4805 ;;; Anything completion for `write-file'.==> C-x C-w
4806 (defvar anything-c-source-write-file
4807 `((name . "Write File")
4808 (header-name . (lambda (name)
4809 (concat name anything-c-find-files-doc-header)))
4810 ;; It is needed for filenames with capital letters
4811 (disable-shortcuts)
4812 (candidates . anything-find-files-get-candidates)
4813 (filtered-candidate-transformer anything-c-find-files-transformer)
4814 (persistent-action . anything-find-files-persistent-action)
4815 (persistent-help . "Expand Candidate")
4816 (volatile)
4817 (action .
4818 (("Write File" . (lambda (candidate)
4819 (write-file candidate 'confirm)))))))
4821 ;;; Anything completion for `insert-file'.==> C-x i
4822 (defvar anything-c-source-insert-file
4823 `((name . "Insert File")
4824 (header-name . (lambda (name)
4825 (concat name anything-c-find-files-doc-header)))
4826 ;; It is needed for filenames with capital letters
4827 (disable-shortcuts)
4828 (candidates . anything-find-files-get-candidates)
4829 (filtered-candidate-transformer anything-c-find-files-transformer)
4830 (persistent-action . anything-find-files-persistent-action)
4831 (persistent-help . "Expand Candidate")
4832 (volatile)
4833 (action .
4834 (("Insert File" . (lambda (candidate)
4835 (when (y-or-n-p (format "Really insert %s in %s "
4836 candidate anything-current-buffer))
4837 (insert-file-contents candidate))))))))
4839 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4840 (defvar anything-c-source-copy-files
4841 `((name . "Copy Files")
4842 (header-name . (lambda (name)
4843 (concat name anything-c-find-files-doc-header)))
4844 ;; It is needed for filenames with capital letters
4845 (disable-shortcuts)
4846 (candidates . anything-find-files-get-candidates)
4847 (filtered-candidate-transformer anything-c-find-files-transformer)
4848 (persistent-action . anything-find-files-persistent-action)
4849 (persistent-help . "Expand Candidate")
4850 (volatile)
4851 (action .
4852 (("Copy File"
4853 . (lambda (candidate)
4854 (anything-dired-action candidate :action 'copy)))
4855 ("Copy and Follow"
4856 . (lambda (candidate)
4857 (anything-dired-action candidate :action 'copy :follow t)))))))
4860 (defvar anything-c-source-rename-files
4861 `((name . "Rename Files")
4862 (header-name . (lambda (name)
4863 (concat name anything-c-find-files-doc-header)))
4864 ;; It is needed for filenames with capital letters
4865 (disable-shortcuts)
4866 (candidates . anything-find-files-get-candidates)
4867 (filtered-candidate-transformer anything-c-find-files-transformer)
4868 (persistent-action . anything-find-files-persistent-action)
4869 (persistent-help . "Expand Candidate")
4870 (volatile)
4871 (action .
4872 (("Rename File"
4873 . (lambda (candidate)
4874 (anything-dired-action candidate :action 'rename)))
4875 ("Rename and Follow"
4876 . (lambda (candidate)
4877 (anything-dired-action candidate :action 'rename :follow t)))))))
4879 (defvar anything-c-source-symlink-files
4880 `((name . "Symlink Files")
4881 (header-name . (lambda (name)
4882 (concat name anything-c-find-files-doc-header)))
4883 ;; It is needed for filenames with capital letters
4884 (disable-shortcuts)
4885 (candidates . anything-find-files-get-candidates)
4886 (filtered-candidate-transformer anything-c-find-files-transformer)
4887 (persistent-action . anything-find-files-persistent-action)
4888 (persistent-help . "Expand Candidate")
4889 (volatile)
4890 (action
4891 . (("Symlink File"
4892 . (lambda (candidate)
4893 (anything-dired-action candidate :action 'symlink)))
4894 ("RelSymlink File"
4895 . (lambda (candidate)
4896 (anything-dired-action candidate :action 'relsymlink)))))))
4899 (defvar anything-c-source-hardlink-files
4900 `((name . "Hardlink Files")
4901 (header-name . (lambda (name)
4902 (concat name anything-c-find-files-doc-header)))
4903 ;; It is needed for filenames with capital letters
4904 (disable-shortcuts)
4905 (candidates . anything-find-files-get-candidates)
4906 (filtered-candidate-transformer anything-c-find-files-transformer)
4907 (persistent-action . anything-find-files-persistent-action)
4908 (persistent-help . "Expand Candidate")
4909 (volatile)
4910 (action
4911 . (("Hardlink File"
4912 . (lambda (candidate)
4913 (anything-dired-action candidate :action 'hardlink)))))))
4915 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4916 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4917 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4918 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4919 (let ((fn (case action
4920 ('copy 'dired-copy-file)
4921 ('rename 'dired-rename-file)
4922 ('symlink 'make-symbolic-link)
4923 ('relsymlink 'dired-make-relative-symlink)
4924 ('hardlink 'dired-hardlink)))
4925 (marker (case action
4926 ((copy rename) dired-keep-marker-copy)
4927 ('symlink dired-keep-marker-symlink)
4928 ('relsymlink dired-keep-marker-relsymlink)
4929 ('hardlink dired-keep-marker-hardlink)))
4930 (dirflag (and (= (length files) 1)
4931 (file-directory-p (car files))
4932 (not (file-directory-p candidate)))))
4933 (dired-create-files
4934 fn (symbol-name action) files
4935 ;; CANDIDATE is the destination.
4936 (if (file-directory-p candidate)
4937 ;; When CANDIDATE is a directory, build file-name in this directory.
4938 ;; Else we use CANDIDATE.
4939 #'(lambda (from)
4940 (expand-file-name (file-name-nondirectory from) candidate))
4941 #'(lambda (from) candidate))
4942 marker)
4943 (when (and follow (not (get-buffer dired-log-buffer)))
4944 (let ((target (directory-file-name candidate)))
4945 (unwind-protect
4946 (progn
4947 (setq anything-ff-cand-to-mark
4948 (anything-get-dest-fnames-from-list files candidate dirflag))
4949 (if (and dirflag (eq action 'rename))
4950 (anything-find-files-1 (file-name-directory target)
4951 (if anything-ff-transformer-show-only-basename
4952 (anything-c-basename target) target))
4953 (anything-find-files-1 (expand-file-name candidate))))
4954 (setq anything-ff-cand-to-mark nil))))))
4957 (defun anything-c-basename (fname)
4958 "Resolve basename of file or directory named FNAME."
4959 (file-name-nondirectory (directory-file-name fname)))
4961 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4962 "Transform filenames of FLIST to abs of DEST-CAND.
4963 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4964 members of FLIST."
4965 ;; At this point files have been renamed/copied at destination.
4966 ;; That's mean DEST-CAND exists.
4967 (loop
4968 with dest = (expand-file-name dest-cand)
4969 for src in flist
4970 for basename-src = (anything-c-basename src)
4971 for fname = (cond (rename-dir-flag (directory-file-name dest))
4972 ((file-directory-p dest)
4973 (concat (file-name-as-directory dest) basename-src))
4974 (t dest))
4975 when (file-exists-p fname)
4976 collect fname into tmp-list
4977 finally return (sort tmp-list 'string<)))
4979 (defun anything-ff-maybe-mark-candidates ()
4980 "Mark all candidates of list `anything-ff-cand-to-mark'."
4981 (when (and (string= (assoc-default 'name (anything-get-current-source))
4982 (assoc-default 'name anything-c-source-find-files))
4983 anything-ff-cand-to-mark)
4984 (with-anything-window
4985 (while anything-ff-cand-to-mark
4986 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4987 (progn
4988 (anything-make-visible-mark)
4989 (anything-next-line)
4990 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4991 (anything-next-line)))
4992 (unless (anything-this-visible-mark)
4993 (anything-prev-visible-mark)))))
4995 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4997 (defun* anything-dired-do-action-on-file (&key action)
4998 (let* ((files (dired-get-marked-files))
4999 (len (length files))
5000 (fname (if (> len 1)
5001 (format "* %d Files" len)
5002 (car files)))
5003 (source (case action
5004 ('copy 'anything-c-source-copy-files)
5005 ('rename 'anything-c-source-rename-files)
5006 ('symlink 'anything-c-source-symlink-files)
5007 ('hardlink 'anything-c-source-hardlink-files)))
5008 (prompt-fm (case action
5009 ('copy "Copy %s to: ")
5010 ('rename "Rename %s to: ")
5011 ('symlink "Symlink %s to: ")
5012 ('hardlink "Hardlink %s to: ")))
5013 (buffer (case action
5014 ('copy "*Anything Copy Files*")
5015 ('rename "*Anything Rename Files*")
5016 ('symlink "*Anything Symlink Files*")
5017 ('hardlink "*Anything Hardlink Files*")))
5018 (anything-mp-highlight-delay nil))
5019 (anything :sources source
5020 :input (or (dired-dwim-target-directory)
5021 (expand-file-name (anything-c-current-directory)))
5022 :preselect (dired-get-filename)
5023 :prompt (format prompt-fm fname)
5024 :keymap anything-c-read-file-map
5025 :buffer buffer)))
5027 ;;;###autoload
5028 (define-minor-mode anything-dired-mode ()
5029 "Enable anything completion in Dired functions.
5030 Bindings affected are C, R, S, H."
5031 :group 'anything-config
5032 :global t
5033 (if anything-dired-mode
5034 (progn
5035 (substitute-key-definition
5036 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
5037 (substitute-key-definition
5038 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
5039 (substitute-key-definition
5040 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
5041 (substitute-key-definition
5042 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
5043 (substitute-key-definition
5044 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
5045 (substitute-key-definition
5046 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
5047 (substitute-key-definition
5048 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
5049 (substitute-key-definition
5050 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
5052 (defalias 'anything-dired-bindings 'anything-dired-mode)
5054 (defun* anything-c-read-file-name (prompt
5055 &key
5056 (initial-input (expand-file-name default-directory))
5057 (buffer "*Anything Completions*")
5058 test
5059 (preselect nil)
5060 must-match
5061 (history nil)
5062 (marked-candidates nil)
5063 (alistp t)
5064 (persistent-action 'anything-find-files-persistent-action)
5065 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
5066 "Anything `read-file-name' emulation.
5067 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
5068 (when (get-buffer anything-action-buffer)
5069 (kill-buffer anything-action-buffer))
5070 (let ((anything-mp-highlight-delay nil)
5071 ;; Be sure we don't erase the underlying minibuffer if some.
5072 (anything-ff-auto-update-initial-value
5073 (not (minibuffer-window-active-p (minibuffer-window))))
5074 anything-same-window)
5075 (flet ((action-fn (candidate)
5076 (if marked-candidates
5077 (anything-marked-candidates)
5078 (identity candidate))))
5079 (or (anything
5080 :sources
5081 `(((name . "Read File Name History")
5082 (header-name . (lambda (name)
5083 (concat name anything-c-find-files-doc-header)))
5084 (disable-shortcuts)
5085 (mode-line . anything-read-file-name-mode-line-string)
5086 (candidates . (lambda ()
5087 (anything-comp-read-get-candidates history nil nil alistp)))
5088 (persistent-action . ,persistent-action)
5089 (persistent-help . ,persistent-help)
5090 (action . ,'action-fn))
5091 ((name . "Read file name")
5092 (header-name . (lambda (name)
5093 (concat name anything-c-find-files-doc-header)))
5094 ;; It is needed for filenames with capital letters
5095 (disable-shortcuts)
5096 (mode-line . anything-read-file-name-mode-line-string)
5097 (candidates . (lambda ()
5098 (let ((seq (anything-find-files-get-candidates)))
5099 (if test
5100 (loop
5101 for fname in seq when (funcall test fname)
5102 collect fname into ls
5103 finally return
5104 (if must-match ls
5105 (append (list anything-pattern) ls)))
5106 (if must-match
5107 (if (file-exists-p (car seq)) seq (cdr seq))
5108 seq)))))
5109 (filtered-candidate-transformer anything-c-find-files-transformer)
5110 (persistent-action . ,persistent-action)
5111 (candidate-number-limit . 9999)
5112 (toggle-auto-update . anything-ff-toggle-auto-update)
5113 (persistent-help . ,persistent-help)
5114 (volatile)
5115 (action . ,'action-fn)))
5116 :input initial-input
5117 :prompt prompt
5118 :keymap anything-c-read-file-map
5119 :resume 'noresume
5120 :buffer buffer
5121 :preselect preselect)
5122 (keyboard-quit)))))
5125 ;;; File Cache
5126 (defvar anything-c-file-cache-initialized-p nil)
5128 (defvar anything-c-file-cache-files nil)
5130 (defvar anything-c-source-file-cache
5131 '((name . "File Cache")
5132 (init
5133 . (lambda ()
5134 (require 'filecache nil t)
5135 (unless anything-c-file-cache-initialized-p
5136 (setq anything-c-file-cache-files
5137 (loop for item in file-cache-alist append
5138 (destructuring-bind (base &rest dirs) item
5139 (loop for dir in dirs collect
5140 (concat dir base)))))
5141 (defadvice file-cache-add-file (after file-cache-list activate)
5142 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
5143 (setq anything-c-file-cache-initialized-p t))))
5144 (candidates . anything-c-file-cache-files)
5145 (match anything-c-match-on-file-name
5146 anything-c-match-on-directory-name)
5147 (type . file)))
5148 ;; (anything 'anything-c-source-file-cache)
5151 ;;; Locate
5154 ;; NOTE for WINDOZE users:
5155 ;; You have to install Everything with his command line interface here:
5156 ;; http://www.voidtools.com/download.php
5158 (defvar anything-c-locate-command
5159 (case system-type
5160 ('gnu/linux "locate -i -r %s")
5161 ('berkeley-unix "locate -i %s")
5162 ('windows-nt "es -i -r %s")
5163 (t "locate %s"))
5164 "A list of arguments for locate program.
5165 The \"-r\" option must be the last option.")
5167 (defun anything-locate-1 (&optional localdb init)
5168 "Generic function to run Locate.
5169 if LOCALDB is non--nil search and use a local locate db file.
5170 INIT is a string to use as initial input in prompt.
5171 See `anything-locate-with-db' and `anything-locate'."
5172 (anything-locate-with-db
5173 (and localdb
5174 (anything-c-read-file-name
5175 "LocateDBFiles: "
5176 :marked-candidates t
5177 :preselect anything-locate-db-file-regexp
5178 :test #'(lambda (x)
5179 (if anything-locate-db-file-regexp
5180 ;; Select only locate db files and directories
5181 ;; to allow navigation.
5182 (or (string-match
5183 anything-locate-db-file-regexp x)
5184 (file-directory-p x))
5185 x))))
5186 init))
5187 ;; (anything-locate-1 t)
5189 (defun anything-locate-with-db (&optional db initial-input)
5190 "Run locate -d DB.
5191 If DB is not given or nil use locate without -d option.
5192 Argument DB can be given as a string or list of db files.
5193 Argument INITIAL-INPUT is a string to use as initial-input.
5194 See also `anything-locate'."
5195 (when (and db (stringp db)) (setq db (list db)))
5196 (let ((anything-c-locate-command
5197 (if db
5198 (replace-regexp-in-string
5199 "locate"
5200 (format "locate -d %s"
5201 (mapconcat 'identity
5202 ;; Remove eventually
5203 ;; marked directories by error.
5204 (loop for i in db
5205 unless (file-directory-p i)
5206 collect i) ":"))
5207 anything-c-locate-command)
5208 anything-c-locate-command)))
5209 (anything :sources 'anything-c-source-locate
5210 :buffer "*anything locate*"
5211 :input initial-input
5212 :keymap anything-generic-files-map)))
5213 ;; (anything-locate-with-db "~/locate.db")
5215 (defun anything-c-locate-init ()
5216 "Initialize async locate process for `anything-c-source-locate'."
5217 (setq mode-line-format
5218 '(" " mode-line-buffer-identification " "
5219 (line-number-mode "%l") " "
5220 (:eval (propertize "(Locate Process Running) "
5221 'face '((:foreground "red"))))))
5222 (prog1
5223 (start-process-shell-command "locate-process" nil
5224 (format anything-c-locate-command
5225 anything-pattern))
5226 (set-process-sentinel (get-process "locate-process")
5227 #'(lambda (process event)
5228 (when (string= event "finished\n")
5229 (with-anything-window
5230 (force-mode-line-update nil)
5231 (anything-update-move-first-line)))))))
5233 (defvar anything-c-source-locate
5234 '((name . "Locate")
5235 (candidates . anything-c-locate-init)
5236 (type . file)
5237 (properties-action . anything-ff-properties)
5238 (requires-pattern . 3)
5239 (candidate-number-limit . 9999)
5240 (mode-line . anything-generic-file-mode-line-string)
5241 (delayed))
5242 "Find files matching the current input pattern with locate.")
5243 ;; (anything 'anything-c-source-locate)
5245 (defun anything-c-locate-read-file-name (prompt &optional init)
5246 "Search a file with locate and return it's filename.
5247 Use argument PROMPT and INIT for `anything' arguments
5248 prompt and input."
5249 (anything :sources
5250 '((name . "Locate")
5251 (candidates . anything-c-locate-init)
5252 (action . identity)
5253 (properties-action . anything-ff-properties)
5254 (requires-pattern . 3)
5255 (candidate-number-limit . 9999)
5256 (mode-line . anything-generic-file-mode-line-string)
5257 (delayed))
5258 :prompt prompt
5259 :input init
5260 :buffer "*anything locate rfn*"))
5264 ;;; Anything Incremental Grep.
5267 ;; Allow to grep incrementally with anything interface.
5268 ;; It allow also to Grep files recursively without using 'find' shell command.
5269 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
5270 (defvar anything-c-grep-default-command
5271 "grep -d skip %e -niH -e %p %f"
5272 "Default grep format command for `anything-do-grep-1'.
5273 Where:
5274 '%e' format spec is for --exclude or --include grep options.
5275 '%p' format spec is for pattern.
5276 '%f' format spec is for filenames.")
5278 (defvar anything-c-grep-default-recurse-command
5279 "grep -d recurse %e -niH -e %p %f"
5280 "Default recursive grep format command for `anything-do-grep-1'.
5281 See `anything-c-grep-default-command' for format specs.")
5283 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
5285 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
5287 (defvar anything-c-grep-default-function 'anything-c-grep-init)
5289 (defvar anything-c-grep-debug-command-line nil
5290 "Turn on anything grep command-line debugging when non--nil.")
5292 (defvar anything-c-zgrep-recurse-flag nil)
5294 (defvar anything-c-grep-history nil)
5296 (defvar anything-c-grep-max-length-history 100
5297 "*Max number of elements to save in `anything-c-grep-history'.")
5299 (defun anything-c-grep-prepare-candidates (candidates)
5300 "Prepare filenames and directories CANDIDATES for grep command line."
5301 ;; If one or more candidate is a directory, search in all files
5302 ;; of this candidate (e.g /home/user/directory/*).
5303 ;; If r option is enabled search also in subdidrectories.
5304 ;; We need here to expand wildcards to support crap windows filenames
5305 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
5306 (if anything-c-zgrep-recurse-flag
5307 (mapconcat 'shell-quote-argument candidates " ")
5308 (loop for i in candidates append
5309 (cond ( ;; Candidate is a directory and we use recursion.
5310 (and (file-directory-p i)
5311 (anything-c-grep-recurse-p))
5312 (list (expand-file-name i)))
5313 ;; Candidate is a directory, search in all files.
5314 ((file-directory-p i)
5315 (file-expand-wildcards
5316 (concat (file-name-as-directory (expand-file-name i)) "*") t))
5317 ;; Candidate is a file or wildcard and we use recursion, use the
5318 ;; current directory instead of candidate.
5319 ((and (or (file-exists-p i) (string-match "\*" i))
5320 (anything-c-grep-recurse-p))
5321 (list (expand-file-name
5322 (directory-file-name ; Needed for windoze.
5323 (file-name-directory (directory-file-name i))))))
5324 ;; Candidate use wildcard.
5325 ((string-match "^\*" (anything-c-basename i))
5326 (file-expand-wildcards i t))
5327 ;; Else should be one or more file.
5328 (t (list i))) into all-files
5329 finally return
5330 (mapconcat 'shell-quote-argument all-files " "))))
5332 (defun anything-c-grep-recurse-p ()
5333 "Check if `anything-do-grep-1' have switched to recursive."
5334 (let ((args (replace-regexp-in-string
5335 "grep" "" anything-c-grep-default-command)))
5336 (string-match-p "r\\|recurse" args)))
5338 (defun anything-c-grep-init (only-files &optional include zgrep)
5339 "Start an asynchronous grep process in ONLY-FILES list."
5340 (let* ((fnargs (anything-c-grep-prepare-candidates
5341 (if (file-remote-p anything-ff-default-directory)
5342 (mapcar #'(lambda (x)
5343 (file-remote-p x 'localname))
5344 only-files)
5345 only-files)))
5346 (ignored-files (mapconcat
5347 #'(lambda (x)
5348 (concat "--exclude=" (shell-quote-argument x)))
5349 grep-find-ignored-files " "))
5350 (ignored-dirs (mapconcat
5351 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
5352 #'(lambda (x)
5353 (concat "--exclude-dir=" (shell-quote-argument x)))
5354 grep-find-ignored-directories " "))
5355 (exclude (if (anything-c-grep-recurse-p)
5356 (concat (or include ignored-files) " " ignored-dirs)
5357 ignored-files))
5358 (cmd-line (format-spec
5359 anything-c-grep-default-command
5360 (delq nil
5361 (list (unless zgrep (cons ?e exclude))
5362 (cons ?p (shell-quote-argument anything-pattern))
5363 (cons ?f fnargs))))))
5364 (when anything-c-grep-debug-command-line
5365 (with-current-buffer (get-buffer-create "*any grep debug*")
5366 (goto-char (point-max))
5367 (insert (concat ">>> " cmd-line "\n\n"))))
5368 (setq mode-line-format
5369 '(" " mode-line-buffer-identification " "
5370 (line-number-mode "%l") " "
5371 (:eval (when (get-process "grep-process")
5372 (propertize "[Grep Process Running] "
5373 'face 'anything-grep-running)))))
5374 (force-mode-line-update nil)
5375 (prog1
5376 (let ((default-directory anything-ff-default-directory))
5377 (start-file-process-shell-command "grep-process" nil cmd-line))
5378 (message nil)
5379 (set-process-sentinel
5380 (get-process "grep-process")
5381 #'(lambda (process event)
5382 (when (string= event "finished\n")
5383 (with-anything-window
5384 (anything-update-move-first-line)
5385 (setq mode-line-format
5386 '(" " mode-line-buffer-identification " "
5387 (line-number-mode "%l") " "
5388 (:eval (propertize
5389 (format "[Grep Process Finished - (%s results)] "
5390 (let ((nlines (1- (count-lines
5391 (point-min)
5392 (point-max)))))
5393 (if (> nlines 0) nlines 0)))
5394 'face 'anything-grep-finish))))
5395 (force-mode-line-update nil))))))))
5397 (defun anything-c-grep-action (candidate &optional where mark)
5398 "Define a default action for `anything-do-grep' on CANDIDATE.
5399 WHERE can be one of other-window, elscreen, other-frame."
5400 (let* ((split (anything-c-grep-split-line candidate))
5401 (lineno (string-to-number (nth 1 split)))
5402 (loc-fname (car split))
5403 (tramp-method (file-remote-p anything-ff-default-directory 'method))
5404 (tramp-host (file-remote-p anything-ff-default-directory 'host))
5405 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
5406 (fname (if tramp-host
5407 (concat tramp-prefix loc-fname) loc-fname)))
5408 (case where
5409 (other-window (find-file-other-window fname))
5410 (elscreen (anything-elscreen-find-file fname))
5411 (other-frame (find-file-other-frame fname))
5412 (t (find-file fname)))
5413 (anything-goto-line lineno)
5414 (when mark
5415 (set-marker (mark-marker) (point))
5416 (push-mark (point) 'nomsg))
5417 ;; Save history
5418 (unless (or anything-in-persistent-action
5419 (string= anything-pattern ""))
5420 (setq anything-c-grep-history
5421 (cons anything-pattern
5422 (delete anything-pattern anything-c-grep-history)))
5423 (when (> (length anything-c-grep-history)
5424 anything-c-grep-max-length-history)
5425 (setq anything-c-grep-history
5426 (delete (car (last anything-c-grep-history))
5427 anything-c-grep-history))))))
5429 (defun anything-c-grep-other-window (candidate)
5430 "Jump to result in other window from anything grep."
5431 (anything-c-grep-action candidate 'other-window))
5433 (defun anything-c-grep-other-frame (candidate)
5434 "Jump to result in other frame from anything grep."
5435 (anything-c-grep-action candidate 'other-frame))
5437 (defun anything-c-grep-jump-elscreen (candidate)
5438 "Jump to result in elscreen from anything grep."
5439 (anything-c-grep-action candidate 'elscreen))
5441 (defun anything-c-grep-save-results (candidate)
5442 "Save anything grep result in a `grep-mode' buffer."
5443 (let ((buf "*grep*")
5444 new-buf)
5445 (when (get-buffer buf)
5446 (setq new-buf (read-string "GrepBufferName: " buf))
5447 (loop for b in (anything-c-buffer-list)
5448 when (and (string= new-buf b)
5449 (not (y-or-n-p
5450 (format "Buffer `%s' already exists overwrite? "
5451 new-buf))))
5452 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
5453 (setq buf new-buf))
5454 (with-current-buffer (get-buffer-create buf)
5455 (let ((inhibit-read-only t))
5456 (erase-buffer)
5457 (insert "-*- mode: grep -*-\n\n"
5458 (format "Grep Results for `%s':\n\n" anything-pattern))
5459 (save-excursion
5460 (insert (with-current-buffer anything-buffer
5461 (forward-line 1)
5462 (buffer-substring (point) (point-max))))
5463 (grep-mode))))
5464 (message "Anything Grep Results saved in `%s' buffer" buf)))
5466 (defun anything-c-grep-persistent-action (candidate)
5467 "Persistent action for `anything-do-grep'.
5468 With a prefix arg record CANDIDATE in `mark-ring'."
5469 (if current-prefix-arg
5470 (anything-c-grep-action candidate nil 'mark)
5471 (anything-c-grep-action candidate))
5472 (anything-match-line-color-current-line))
5474 (defun anything-c-grep-guess-extensions (files)
5475 "Try to guess file extensions in FILES list when using grep recurse.
5476 These extensions will be added to command line with --include arg of grep."
5477 (loop
5478 with glob-list = nil
5479 with lst = (if (file-directory-p (car files))
5480 (directory-files
5481 (car files) nil
5482 directory-files-no-dot-files-regexp)
5483 files)
5484 for i in lst
5485 for ext = (file-name-extension i t)
5486 for glob = (and ext (not (string= ext ""))
5487 (concat "*" ext))
5488 unless (or (not glob)
5489 (member glob glob-list)
5490 (member glob grep-find-ignored-files))
5491 collect glob into glob-list
5492 finally return glob-list))
5494 (defun anything-do-grep-1 (only &optional recurse zgrep)
5495 "Launch grep with a list of ONLY files.
5496 When RECURSE is given use -r option of grep and prompt user
5497 to set the --include args of grep.
5498 You can give more than one arg separated by space.
5499 e.g *.el *.py *.tex.
5500 If it's empty --exclude `grep-find-ignored-files' is used instead."
5501 (let* ((anything-compile-source-functions
5502 ;; rule out anything-match-plugin because the input is one regexp.
5503 (delq 'anything-compile-source--match-plugin
5504 (copy-sequence anything-compile-source-functions)))
5505 (exts (anything-c-grep-guess-extensions only))
5506 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5507 (include-files (and recurse (not zgrep)
5508 (read-string "OnlyExt(*.[ext]): "
5509 globs)))
5510 ;; Set `minibuffer-history' AFTER includes-files
5511 ;; to avoid storing wild-cards here.
5512 (minibuffer-history anything-c-grep-history)
5513 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5514 (recurse anything-c-grep-default-recurse-command)
5515 (zgrep anything-c-default-zgrep-command)
5516 (t anything-c-grep-default-command)))
5517 ;; Disable match-plugin and use here own highlighting.
5518 (anything-mp-highlight-delay nil))
5519 (when include-files
5520 (setq include-files
5521 (and (not (string= include-files ""))
5522 (mapconcat #'(lambda (x)
5523 (concat "--include=" (shell-quote-argument x)))
5524 (split-string include-files) " "))))
5525 ;; When called as action from an other source e.g *-find-files
5526 ;; we have to kill action buffer.
5527 (when (get-buffer anything-action-buffer)
5528 (kill-buffer anything-action-buffer))
5529 ;; `anything-find-files' haven't already started,
5530 ;; give a default value to `anything-ff-default-directory'.
5531 (setq anything-ff-default-directory (or anything-ff-default-directory
5532 default-directory))
5533 (anything
5534 :sources
5535 `(((name . "Grep (C-c ? Help)")
5536 (candidates
5537 . (lambda ()
5538 (funcall anything-c-grep-default-function only include-files zgrep)))
5539 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5540 (candidate-number-limit . 9999)
5541 (mode-line . anything-grep-mode-line-string)
5542 (jump-persistent . anything-c-grep-persistent-action)
5543 (action . ,(delq
5545 `(("Find File" . anything-c-grep-action)
5546 ("Find file other frame" . anything-c-grep-other-frame)
5547 ,(and (locate-library "elscreen")
5548 '("Find file in Elscreen"
5549 . anything-c-grep-jump-elscreen))
5550 ("Save results in grep buffer" . anything-c-grep-save-results)
5551 ("Find file other window" . anything-c-grep-other-window))))
5552 (persistent-action . anything-c-grep-persistent-action)
5553 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5554 (requires-pattern . 3)
5555 (delayed)))
5556 :keymap anything-c-grep-map
5557 :buffer "*anything grep*")))
5559 (defun anything-ff-zgrep-1 (flist recursive)
5560 (unwind-protect
5561 (let* ((def-dir (or anything-ff-default-directory
5562 default-directory))
5563 (only (if recursive
5564 (or (gethash def-dir anything-c-rzgrep-cache)
5565 (puthash
5566 def-dir
5567 (anything-c-walk-directory
5568 def-dir
5569 :directories nil
5570 :path 'full
5571 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5572 anything-c-rzgrep-cache))
5573 flist)))
5574 (when recursive (setq anything-c-zgrep-recurse-flag t))
5575 (anything-do-grep-1 only recursive 'zgrep))
5576 (setq anything-c-zgrep-recurse-flag nil)))
5578 (defun anything-c-grep-split-line (line)
5579 "Split a grep output line."
5580 (let (beg fname lineno str)
5581 ;; Don't print until grep line is valid.
5582 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5583 (with-temp-buffer
5584 (insert line)
5585 (goto-char (point-min))
5586 (setq beg (point))
5587 (forward-char 2)
5588 (re-search-forward ":" nil t)
5589 (setq fname (buffer-substring-no-properties beg (1- (point))))
5590 (setq beg (point))
5591 (re-search-forward ":" nil t)
5592 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5593 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5594 (list fname lineno str))))
5596 (defun anything-c-grep-cand-transformer (candidates sources)
5597 "Filtered candidate transformer function for `anything-do-grep'."
5598 (loop for i in candidates
5599 for split = (and i (anything-c-grep-split-line i))
5600 for fname = (car split)
5601 for lineno = (nth 1 split)
5602 for str = (nth 2 split)
5603 when (and fname lineno str)
5604 collect
5605 (cons (concat (propertize (file-name-nondirectory fname)
5606 'face 'anything-grep-file
5607 'help-echo fname) ":"
5608 (propertize lineno 'face 'anything-grep-lineno) ":"
5609 (anything-c-grep-highlight-match str))
5610 i)))
5612 (defun anything-c-grep-highlight-match (str)
5613 "Highlight in string STR all occurences matching `anything-pattern'."
5614 (condition-case nil
5615 (with-temp-buffer
5616 (insert str)
5617 (goto-char (point-min))
5618 (while (and (re-search-forward anything-pattern nil t)
5619 (> (- (match-end 0) (match-beginning 0)) 0))
5620 (add-text-properties
5621 (match-beginning 0) (match-end 0)
5622 '(face anything-grep-match)))
5623 (buffer-string))
5624 (error nil)))
5626 ;; Go to next or precedent file (common to etags and grep).
5627 (defun anything-c-goto-next-or-prec-file (n)
5628 "Go to next or precedent candidate file in anything grep/etags buffers.
5629 If N is positive go forward otherwise go backward."
5630 (with-anything-window
5631 (let* ((current-line-list (split-string
5632 (buffer-substring
5633 (point-at-bol)
5634 (point-at-eol)) ":"))
5635 (current-fname (nth 0 current-line-list))
5636 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5637 (catch 'break
5638 (while (not (funcall fn-b-o-f))
5639 (forward-line n) ; Go forward or backward depending of n value.
5640 (unless (search-forward current-fname (point-at-eol) t)
5641 (anything-mark-current-line)
5642 (throw 'break nil))))
5643 (cond ((and (eq n 1) (eobp))
5644 (re-search-backward ".")
5645 (forward-line 0)
5646 (anything-mark-current-line))
5647 ((and (< n 1) (bobp))
5648 (forward-line 1)
5649 (anything-mark-current-line))))))
5651 ;;;###autoload
5652 (defun anything-c-goto-precedent-file ()
5653 "Go to precedent file in anything grep/etags buffers."
5654 (interactive)
5655 (anything-c-goto-next-or-prec-file -1))
5657 ;;;###autoload
5658 (defun anything-c-goto-next-file ()
5659 "Go to precedent file in anything grep/etags buffers."
5660 (interactive)
5661 (anything-c-goto-next-or-prec-file 1))
5663 ;;;###autoload
5664 (defun anything-c-grep-run-persistent-action ()
5665 "Run grep persistent action from `anything-do-grep-1'."
5666 (interactive)
5667 (anything-execute-persistent-action 'jump-persistent))
5669 ;;;###autoload
5670 (defun anything-c-grep-run-default-action ()
5671 "Run grep default action from `anything-do-grep-1'."
5672 (interactive)
5673 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5675 ;;;###autoload
5676 (defun anything-c-grep-run-other-window-action ()
5677 "Run grep goto other window action from `anything-do-grep-1'."
5678 (interactive)
5679 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5681 ;;;###autoload
5682 (defun anything-c-grep-run-save-buffer ()
5683 "Run grep save results action from `anything-do-grep-1'."
5684 (interactive)
5685 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5687 ;; Grep buffers
5688 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5689 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5690 If one of selected buffers is not a file--buffer,
5691 it is ignored and grep will run on all others file--buffers.
5692 If only one candidate is selected and it is not a file--buffer,
5693 switch to this buffer and run `anything-occur'.
5694 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5695 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5696 (cands (if prefarg
5697 (buffer-list)
5698 (anything-marked-candidates)))
5699 (win-conf (current-window-configuration))
5700 ;; Non--fname buffers are ignored.
5701 (bufs (loop for buf in cands
5702 for fname = (buffer-file-name (get-buffer buf))
5703 when fname
5704 collect (expand-file-name fname))))
5705 (if bufs
5706 (if zgrep
5707 (anything-do-grep-1 bufs nil 'zgrep)
5708 (anything-do-grep-1 bufs))
5709 ;; bufs is empty, thats mean we have only CANDIDATE
5710 ;; and it is not a buffer-filename, fallback to occur.
5711 (anything-c-switch-to-buffer candidate)
5712 (when (get-buffer anything-action-buffer)
5713 (kill-buffer anything-action-buffer))
5714 (anything-occur)
5715 (when (eq anything-exit-status 1)
5716 (set-window-configuration win-conf)))))
5718 (defun anything-c-grep-buffers (candidate)
5719 "Action to grep buffers."
5720 (anything-c-grep-buffers-1 candidate))
5722 (defun anything-c-zgrep-buffers (candidate)
5723 "Action to zgrep buffers."
5724 (anything-c-grep-buffers-1 candidate 'zgrep))
5727 ;;; Anything interface for pdfgrep
5728 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5729 ;; and a pdf-reader (e.g xpdf) are needed.
5731 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5732 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5733 (defvar anything-c-pdfgrep-debug-command-line nil)
5735 (defun anything-c-pdfgrep-init (only-files)
5736 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5737 (let* ((fnargs (anything-c-grep-prepare-candidates
5738 (if (file-remote-p anything-ff-default-directory)
5739 (mapcar #'(lambda (x)
5740 (file-remote-p x 'localname))
5741 only-files)
5742 only-files)))
5743 (cmd-line (format anything-c-pdfgrep-default-command
5744 anything-pattern
5745 fnargs)))
5746 (when anything-c-pdfgrep-debug-command-line
5747 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5748 (goto-char (point-max))
5749 (insert (concat ">>> " cmd-line "\n\n"))))
5750 (setq mode-line-format
5751 '(" " mode-line-buffer-identification " "
5752 (line-number-mode "%l") " "
5753 (:eval (propertize "(Pdfgrep Process Running) "
5754 'face '((:foreground "red"))))))
5755 (prog1
5756 (let ((default-directory anything-ff-default-directory))
5757 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5758 (message nil)
5759 (set-process-sentinel
5760 (get-process "pdfgrep-process")
5761 #'(lambda (process event)
5762 (when (string= event "finished\n")
5763 (with-anything-window
5764 (anything-update-move-first-line))
5765 (force-mode-line-update nil)))))))
5768 (defun anything-do-pdfgrep-1 (only)
5769 "Launch pdfgrep with a list of ONLY files."
5770 (unless (executable-find "pdfgrep")
5771 (error "Error: No such program `pdfgrep'."))
5772 (let* ((anything-compile-source-functions
5773 ;; rule out anything-match-plugin because the input is one regexp.
5774 (delq 'anything-compile-source--match-plugin
5775 (copy-sequence anything-compile-source-functions)))
5776 ;; Disable match-plugin and use here own highlighting.
5777 (anything-mp-highlight-delay nil))
5778 ;; When called as action from an other source e.g *-find-files
5779 ;; we have to kill action buffer.
5780 (when (get-buffer anything-action-buffer)
5781 (kill-buffer anything-action-buffer))
5782 ;; If `anything-find-files' haven't already started,
5783 ;; give a default value to `anything-ff-default-directory'.
5784 (setq anything-ff-default-directory (or anything-ff-default-directory
5785 default-directory))
5786 (anything
5787 :sources
5788 `(((name . "PdfGrep")
5789 (candidates
5790 . (lambda ()
5791 (funcall anything-c-pdfgrep-default-function only)))
5792 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5793 (candidate-number-limit . 9999)
5794 (mode-line . anything-pdfgrep-mode-line-string)
5795 (action . anything-c-pdfgrep-action)
5796 (persistent-help . "Jump to PDF Page")
5797 (requires-pattern . 3)
5798 (delayed)))
5799 :keymap anything-c-pdfgrep-map
5800 :buffer "*anything grep*")))
5803 (defun anything-c-pdfgrep-action (candidate)
5804 (let* ((split (anything-c-grep-split-line candidate))
5805 (pageno (nth 1 split))
5806 (fname (car split)))
5807 (start-file-process-shell-command
5808 "pdf-reader" nil
5809 (format-spec anything-c-pdfgrep-default-read-command
5810 (list (cons ?f fname) (cons ?p pageno))))))
5812 (defun anything-do-pdfgrep ()
5813 (interactive)
5814 (let ((only (anything-c-read-file-name
5815 "Search in file(s): "
5816 :marked-candidates t
5817 :test #'(lambda (file)
5818 (or (string= (file-name-extension file) "pdf")
5819 (string= (file-name-extension file) "PDF")
5820 (file-directory-p file)))
5821 :preselect (or (dired-get-filename nil t)
5822 (buffer-file-name (current-buffer)))))
5823 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5824 (anything-do-pdfgrep-1 only)))
5827 ;; Yank text at point.
5830 ;; Internal
5831 (defvar anything-yank-point nil)
5833 ;;;###autoload
5834 (defun anything-yank-text-at-point ()
5835 "Yank text at point in minibuffer."
5836 (interactive)
5837 (let (input)
5838 (flet ((insert-in-minibuffer (word)
5839 (with-selected-window (minibuffer-window)
5840 (let ((str anything-pattern))
5841 (delete-minibuffer-contents)
5842 (set-text-properties 0 (length word) nil word)
5843 (insert (concat str word))))))
5844 (with-anything-current-buffer
5845 ;; Start to initial point if C-w have never been hit.
5846 (unless anything-yank-point (setq anything-yank-point (point)))
5847 (and anything-yank-point (goto-char anything-yank-point))
5848 (forward-word 1)
5849 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5850 (setq anything-yank-point (point))) ; End of last forward-word
5851 (insert-in-minibuffer input))))
5853 (defun anything-reset-yank-point ()
5854 (setq anything-yank-point nil))
5856 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5857 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5858 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
5861 ;;; Recentf files
5864 (defvar anything-c-source-recentf
5865 '((name . "Recentf")
5866 (init . (lambda ()
5867 (require 'recentf)
5868 (or recentf-mode (recentf-mode 1))
5869 ;; Big value empowers anything/recentf
5870 (when (and (numberp recentf-max-saved-items)
5871 (<= recentf-max-saved-items 20))
5872 (setq recentf-max-saved-items 500))))
5873 (candidates . recentf-list)
5874 (match anything-c-match-on-file-name
5875 anything-c-match-on-directory-name)
5876 (type . file))
5877 "See (info \"(emacs)File Conveniences\").
5878 if `recentf-max-saved-items' is too small, set it to 500.")
5879 ;; (anything 'anything-c-source-recentf)
5881 ;;; ffap
5882 (eval-when-compile (require 'ffap))
5883 (defvar anything-c-source-ffap-guesser
5884 '((name . "File at point")
5885 (init . (lambda () (require 'ffap)))
5886 (candidates . (lambda ()
5887 (anything-aif
5888 (with-anything-current-buffer
5889 (ffap-guesser))
5890 (list it))))
5891 (type . file)))
5892 ;; (anything 'anything-c-source-ffap-guesser)
5894 ;;; ffap with line number
5895 (defun anything-c-ffap-file-line-at-point ()
5896 "Get (FILENAME . LINENO) at point."
5897 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5898 (save-excursion
5899 (beginning-of-line)
5900 (when (and (search-forward it nil t)
5901 (looking-at ":\\([0-9]+\\)"))
5902 (cons it (string-to-number (match-string 1)))))))
5904 (defvar anything-c-ffap-line-location nil
5905 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5906 It is cleared after jumping line.")
5908 (defun anything-c-ffap-line-candidates ()
5909 (with-anything-current-buffer
5910 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5911 (when anything-c-ffap-line-location
5912 (destructuring-bind (file . line) anything-c-ffap-line-location
5913 (list (cons (format "%s (line %d)" file line) file)))))
5915 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5916 (defun anything-c-ffap-line-goto-line ()
5917 (when (car anything-c-ffap-line-location)
5918 (unwind-protect
5919 (ignore-errors
5920 (with-selected-window
5921 (get-buffer-window
5922 (get-file-buffer (car anything-c-ffap-line-location)))
5923 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5924 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5925 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5927 (defvar anything-c-source-ffap-line
5928 '((name . "File/Lineno at point")
5929 (init . (lambda () (require 'ffap)))
5930 (candidates . anything-c-ffap-line-candidates)
5931 (type . file)))
5932 ;; (anything 'anything-c-source-ffap-line)
5934 ;;; list of files gleaned from every dired buffer
5935 (defun anything-c-files-in-all-dired-candidates ()
5936 (save-excursion
5937 (mapcan
5938 (lambda (dir)
5939 (cond ((listp dir) ;filelist
5940 dir)
5941 ((equal "" (file-name-nondirectory dir)) ;dir
5942 (directory-files dir t))
5943 (t ;wildcard
5944 (file-expand-wildcards dir t))))
5945 (delq nil
5946 (mapcar (lambda (buf)
5947 (set-buffer buf)
5948 (when (eq major-mode 'dired-mode)
5949 (if (consp dired-directory)
5950 (cdr dired-directory) ;filelist
5951 dired-directory))) ;dir or wildcard
5952 (buffer-list))))))
5953 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5955 (defvar anything-c-source-files-in-all-dired
5956 '((name . "Files in all dired buffer.")
5957 (candidates . anything-c-files-in-all-dired-candidates)
5958 (type . file)))
5959 ;; (anything 'anything-c-source-files-in-all-dired)
5961 (defvar anything-c-source-filelist
5962 '((name . "FileList")
5963 (grep-candidates . anything-c-filelist-file-name)
5964 (candidate-number-limit . 200)
5965 (requires-pattern . 4)
5966 (type . file))
5967 "Source to find files instantly.
5968 See `anything-c-filelist-file-name' docstring for usage.")
5971 ;;;; <info>
5972 ;;; Info pages
5973 (defvar anything-c-info-pages nil
5974 "All info pages on system.
5975 Will be calculated the first time you invoke anything with this
5976 source.")
5978 (defvar anything-c-source-info-pages
5979 `((name . "Info Pages")
5980 (candidates
5981 . (lambda ()
5982 (if anything-c-info-pages
5983 anything-c-info-pages
5984 (setq anything-c-info-pages
5985 (save-window-excursion
5986 (save-excursion
5987 (require 'info)
5988 (Info-find-node "dir" "top")
5989 (goto-char (point-min))
5990 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5991 topics)
5992 (while (re-search-forward info-topic-regexp nil t)
5993 (add-to-list 'topics (match-string-no-properties 1)))
5994 (goto-char (point-min))
5995 (Info-exit)
5996 topics)))))))
5997 (action . (("Show with Info" .(lambda (node-str)
5998 (info (replace-regexp-in-string
5999 "^[^:]+: " "" node-str))))))
6000 (requires-pattern . 2)))
6001 ;; (anything 'anything-c-source-info-pages)
6004 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
6005 (defun anything-c-describe-attributes (anything-attribute)
6006 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
6007 Same as `anything-describe-anything-attribute' but with anything completion."
6008 (interactive (list (intern
6009 (anything-comp-read
6010 "Describe anything attribute: "
6011 (mapcar 'symbol-name anything-additional-attributes)
6012 :must-match t
6013 :persistent-action
6014 #'(lambda (candidate)
6015 (with-output-to-temp-buffer "*Help*"
6016 (princ (get (intern candidate) 'anything-attrdoc))))))))
6017 (with-output-to-temp-buffer "*Help*"
6018 (princ (get anything-attribute 'anything-attrdoc))))
6021 ;;; Use info-index plug-in.
6024 ;; Note that `name' attribute is not needed since
6025 ;; `anything-c-insert-summary' have been removed.
6026 ;; Info Elisp
6027 (defvar anything-c-source-info-elisp
6028 '((name . "Info index: elisp")
6029 (info-index . "elisp")))
6030 ;; (anything 'anything-c-source-info-elisp)
6032 ;; Info-Common-Lisp
6033 (defvar anything-c-source-info-cl
6034 '((name . "Info index: cl")
6035 (info-index . "cl")))
6036 ;; (anything 'anything-c-source-info-cl)
6038 ;; Info Index org
6039 (defvar anything-c-source-info-org
6040 '((name . "Info index: org")
6041 (info-index . "org")))
6042 ;; (anything 'anything-c-source-info-org)
6044 ;; Info Index gnus
6045 (defvar anything-c-source-info-gnus
6046 '((name . "Info index: Gnus")
6047 (info-index . "gnus")))
6049 ;; Info Index ratpoison
6050 (defvar anything-c-source-info-ratpoison
6051 '((name . "Info index: ratpoison")
6052 (info-index . "ratpoison")))
6053 ;; (anything 'anything-c-source-info-ratpoison)
6055 ;; Info Index zsh
6056 (defvar anything-c-source-info-zsh
6057 '((name . "Info index: zsh")
6058 (info-index . "zsh")))
6059 ;; (anything 'anything-c-source-info-zsh)
6061 ;; Info Index bash
6062 (defvar anything-c-source-info-bash
6063 '((name . "Info index: bash")
6064 (info-index . "bash")))
6065 ;; (anything 'anything-c-source-info-bash)
6067 ;; Info Index coreutils
6068 (defvar anything-c-source-info-coreutils
6069 '((name . "Info index: coreutils")
6070 (info-index . "coreutils")))
6071 ;; (anything 'anything-c-source-info-coreutils)
6073 ;; Info Index fileutils
6074 (defvar anything-c-source-info-fileutils
6075 '((name . "Info index: fileutils")
6076 (info-index . "fileutils")))
6077 ;; (anything 'anything-c-source-info-fileutils)
6079 ;; Info Index find
6080 (defvar anything-c-source-info-find
6081 '((name . "Info index: find")
6082 (info-index . "find")))
6083 ;; (anything 'anything-c-source-info-find)
6085 ;; Info Index sh-utils
6086 (defvar anything-c-source-info-sh-utils
6087 '((name . "Info index: sh-utils")
6088 (info-index . "sh-utils")))
6089 ;; (anything 'anything-c-source-info-sh-utils)
6091 ;; Info Index textutils
6092 (defvar anything-c-source-info-textutils
6093 '((name . "Info index: textutils")
6094 (info-index . "textutils")))
6095 ;; (anything 'anything-c-source-info-textutils)
6097 ;; Info Index libc
6098 (defvar anything-c-source-info-libc
6099 '((name . "Info index: libc")
6100 (info-index . "libc")))
6101 ;; (anything 'anything-c-source-info-libc)
6103 ;; Info Index make
6104 (defvar anything-c-source-info-make
6105 '((name . "Info index: make")
6106 (info-index . "make")))
6107 ;; (anything 'anything-c-source-info-make)
6109 ;; Info Index automake
6110 (defvar anything-c-source-info-automake
6111 '((name . "Info index: automake")
6112 (info-index . "automake")))
6113 ;; (anything 'anything-c-source-info-automake)
6115 ;; Info Index autoconf
6116 (defvar anything-c-source-info-autoconf
6117 '((name . "Info index: autoconf")
6118 (info-index . "autoconf")))
6119 ;; (anything 'anything-c-source-info-autoconf)
6121 ;; Info Index emacs-lisp-intro
6122 (defvar anything-c-source-info-emacs-lisp-intro
6123 '((name . "Info index: emacs-lisp-intro")
6124 (info-index . "emacs-lisp-intro")))
6125 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
6127 ;; Info Index emacs
6128 (defvar anything-c-source-info-emacs
6129 '((name . "Info index: emacs")
6130 (info-index . "emacs")))
6131 ;; (anything 'anything-c-source-info-emacs)
6133 ;; Info Index elib
6134 (defvar anything-c-source-info-elib
6135 '((name . "Info index: elib")
6136 (info-index . "elib")))
6137 ;; (anything 'anything-c-source-info-elib)
6139 ;; Info Index eieio
6140 (defvar anything-c-source-info-eieio
6141 '((name . "Info index: eieio")
6142 (info-index . "eieio")))
6143 ;; (anything 'anything-c-source-info-eieio)
6145 ;; Info Index gauche-refe
6146 (defvar anything-c-source-info-gauche-refe
6147 '((name . "Info index: gauche")
6148 (info-index . "gauche-refe")))
6149 ;; (anything 'anything-c-source-info-gauche-refe)
6151 ;; Info Index guile
6152 (defvar anything-c-source-info-guile
6153 '((name . "Info index: guile")
6154 (info-index . "guile")))
6155 ;; (anything 'anything-c-source-info-guile)
6157 ;; Info Index guile-tut
6158 (defvar anything-c-source-info-guile-tut
6159 '((name . "Info index: guile-tut")
6160 (info-index . "guile-tut")))
6161 ;; (anything 'anything-c-source-info-guile-tut)
6163 ;; Info Index goops
6164 (defvar anything-c-source-info-goops
6165 '((name . "Info index: goops")
6166 (info-index . "goops")))
6167 ;; (anything 'anything-c-source-info-goops)
6169 ;; Info Index screen
6170 (defvar anything-c-source-info-screen
6171 '((name . "Info index: screen")
6172 (info-index . "screen")
6173 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
6174 ;; (anything 'anything-c-source-info-screen)
6176 ;; Info Index latex
6177 (defvar anything-c-source-info-latex
6178 '((name . "Info index: latex")
6179 (info-index . "latex")))
6180 ;; (anything 'anything-c-source-info-latex)
6182 ;; Info Index gawk
6183 (defvar anything-c-source-info-gawk
6184 '((name . "Info index: gawk")
6185 (info-index . "gawk")))
6186 ;; (anything 'anything-c-source-info-gawk)
6188 ;; Info Index sed
6189 (defvar anything-c-source-info-sed
6190 '((name . "Info index: sed")
6191 (info-index . "sed")))
6192 ;; (anything 'anything-c-source-info-sed)
6194 ;; Info Index m4
6195 (defvar anything-c-source-info-m4
6196 '((name . "Info index: m4")
6197 (info-index . "m4")))
6198 ;; (anything 'anything-c-source-info-m4)
6200 ;; Info Index wget
6201 (defvar anything-c-source-info-wget
6202 '((name . "Info index: wget")
6203 (info-index . "wget")))
6204 ;; (anything 'anything-c-source-info-wget)
6206 ;; Info Index binutils
6207 (defvar anything-c-source-info-binutils
6208 '((name . "Info index: binutils")
6209 (info-index . "binutils")))
6210 ;; (anything 'anything-c-source-info-binutils)
6212 ;; Info Index as
6213 (defvar anything-c-source-info-as
6214 '((name . "Info index: as")
6215 (info-index . "as")))
6216 ;; (anything 'anything-c-source-info-as)
6218 ;; Info Index bfd
6219 (defvar anything-c-source-info-bfd
6220 '((name . "Info index: bfd")
6221 (info-index . "bfd")))
6222 ;; (anything 'anything-c-source-info-bfd)
6224 ;; Info Index gprof
6225 (defvar anything-c-source-info-gprof
6226 '((name . "Info index: gprof")
6227 (info-index . "gprof")))
6228 ;; (anything 'anything-c-source-info-gprof)
6230 ;; Info Index ld
6231 (defvar anything-c-source-info-ld
6232 '((name . "Info index: ld")
6233 (info-index . "ld")))
6234 ;; (anything 'anything-c-source-info-ld)
6236 ;; Info Index diff
6237 (defvar anything-c-source-info-diff
6238 '((name . "Info index: diff")
6239 (info-index . "diff")))
6240 ;; (anything 'anything-c-source-info-diff)
6242 ;; Info Index flex
6243 (defvar anything-c-source-info-flex
6244 '((name . "Info index: flex")
6245 (info-index . "flex")))
6246 ;; (anything 'anything-c-source-info-flex)
6248 ;; Info Index grep
6249 (defvar anything-c-source-info-grep
6250 '((name . "Info index: grep")
6251 (info-index . "grep")))
6252 ;; (anything 'anything-c-source-info-grep)
6254 ;; Info Index gzip
6255 (defvar anything-c-source-info-gzip
6256 '((name . "Info index: gzip")
6257 (info-index . "gzip")))
6258 ;; (anything 'anything-c-source-info-gzip)
6260 ;; Info Index libtool
6261 (defvar anything-c-source-info-libtool
6262 '((name . "Info index: libtool")
6263 (info-index . "libtool")))
6264 ;; (anything 'anything-c-source-info-libtool)
6266 ;; Info Index texinfo
6267 (defvar anything-c-source-info-texinfo
6268 '((name . "Info index: texinfo")
6269 (info-index . "texinfo")))
6270 ;; (anything 'anything-c-source-info-texinfo)
6272 ;; Info Index info
6273 (defvar anything-c-source-info-info
6274 '((name . "Info index: info")
6275 (info-index . "info")))
6276 ;; (anything 'anything-c-source-info-info)
6278 ;; Info Index gdb
6279 (defvar anything-c-source-info-gdb
6280 '((name . "Info index: gdb")
6281 (info-index . "gdb")))
6282 ;; (anything 'anything-c-source-info-gdb)
6284 ;; Info Index stabs
6285 (defvar anything-c-source-info-stabs
6286 '((name . "Info index: stabs")
6287 (info-index . "stabs")))
6288 ;; (anything 'anything-c-source-info-stabs)
6290 ;; Info Index cvsbook
6291 (defvar anything-c-source-info-cvsbook
6292 '((name . "Info index: cvsbook")
6293 (info-index . "cvsbook")))
6294 ;; (anything 'anything-c-source-info-cvsbook)
6296 ;; Info Index cvs
6297 (defvar anything-c-source-info-cvs
6298 '((name . "Info index: cvs")
6299 (info-index . "cvs")))
6300 ;; (anything 'anything-c-source-info-cvs)
6302 ;; Info Index bison
6303 (defvar anything-c-source-info-bison
6304 '((name . "Info index: bison")
6305 (info-index . "bison")))
6306 ;; (anything 'anything-c-source-info-bison)
6308 ;; Info Index id-utils
6309 (defvar anything-c-source-info-id-utils
6310 '((name . "Info index: id-utils")
6311 (info-index . "id-utils")))
6312 ;; (anything 'anything-c-source-info-id-utils)
6314 ;; Info Index global
6315 (defvar anything-c-source-info-global
6316 '((name . "Info index: global")
6317 (info-index . "global")))
6318 ;; (anything 'anything-c-source-info-global)
6321 ;;;; <Help>
6322 ;;; Man and woman UI
6325 (defvar anything-c-man-pages nil
6326 "All man pages on system.
6327 Will be calculated the first time you invoke anything with this
6328 source.")
6330 (defun anything-c-man-default-action (candidate)
6331 "Default action for jumping to a woman or man page from anything."
6332 (let ((wfiles (woman-file-name-all-completions candidate)))
6333 (condition-case err
6334 (if (> (length wfiles) 1)
6335 (woman-find-file
6336 (anything-comp-read
6337 "ManFile: " wfiles :must-match t))
6338 (woman candidate))
6339 ;; If woman is unable to format correctly
6340 ;; use man instead.
6341 (error (kill-buffer) ; Kill woman buffer.
6342 (let ((Man-notify-method 'meek))
6343 (Man-getpage-in-background candidate))))))
6345 (defvar anything-c-source-man-pages
6346 `((name . "Manual Pages")
6347 (candidates . (lambda ()
6348 (if anything-c-man-pages
6349 anything-c-man-pages
6350 ;; XEmacs doesn't have a woman :)
6351 (setq anything-c-man-pages
6352 (ignore-errors
6353 (require 'woman)
6354 (woman-file-name "")
6355 (sort (mapcar 'car woman-topic-all-completions)
6356 'string-lessp))))))
6357 (action ("Show with Woman" . anything-c-man-default-action))
6358 ;; Woman does not work OS X
6359 ;; http://xahlee.org/emacs/modernization_man_page.html
6360 (action-transformer . (lambda (actions candidate)
6361 (if (eq system-type 'darwin)
6362 '(("Show with Man" . man))
6363 actions)))
6364 (requires-pattern . 2)))
6365 ;; (anything 'anything-c-source-man-pages)
6368 ;;;; <Command>
6369 ;;; Complex command history
6372 (defvar anything-c-source-complex-command-history
6373 '((name . "Complex Command History")
6374 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
6375 (type . sexp)))
6376 ;; (anything 'anything-c-source-complex-command-history)
6378 ;;; M-x history (not related to `anything-M-x')
6381 (defvar anything-c-source-extended-command-history
6382 '((name . "Emacs Commands History")
6383 (candidates . extended-command-history)
6384 (type . command)))
6385 ;; (anything 'anything-c-source-extended-command-history)
6387 ;;; Emacs commands (Basic source for emacs commands)
6390 (defvar anything-c-source-emacs-commands
6391 '((name . "Emacs Commands")
6392 (candidates . (lambda ()
6393 (let (commands)
6394 (mapatoms (lambda (a)
6395 (if (commandp a)
6396 (push (symbol-name a)
6397 commands))))
6398 (sort commands 'string-lessp))))
6399 (type . command)
6400 (requires-pattern . 2))
6401 "Source for completing and invoking Emacs commands.
6402 A command is a function with interactive spec that can
6403 be invoked with `M-x'.
6405 To get non-interactive functions listed, use
6406 `anything-c-source-emacs-functions'.")
6407 ;; (anything 'anything-c-source-emacs-commands)
6410 ;;; Anything M-x - Enhanced M-x UI
6413 ;; Another replacement of `M-x' that act exactly like the
6414 ;; vanilla Emacs one, no problem of windows configuration, prefix args
6415 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
6416 ;; anything invocation.
6417 ;; Documentation of commands available without quitting,
6418 ;; Show keybindings of commands.
6419 ;; Show history.
6420 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
6421 "Return alist of MODE-MAP."
6422 (loop for key being the key-seqs of mode-map using (key-bindings com)
6423 for str-key = (key-description key)
6424 for ismenu = (string-match "<menu-bar>" str-key)
6425 unless ismenu collect (cons str-key com)))
6427 (defun anything-get-mode-map-from-mode (mode)
6428 "Guess the mode-map name according to MODE.
6429 Some modes don't use conventional mode-map name
6430 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
6431 Return nil if no mode-map found."
6432 (loop
6433 ;; Start with a conventional mode-map name.
6434 with mode-map = (intern-soft (format "%s-map" mode))
6435 with mode-string = (symbol-name mode)
6436 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
6437 while (not mode-map)
6438 for count downfrom (length mode-name)
6439 ;; Return when no result after parsing entire string.
6440 when (eq count 0) return nil
6441 for sub-name = (substring mode-name 0 count)
6442 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
6443 finally return mode-map))
6445 (defun anything-M-x-current-mode-map-alist ()
6446 "Return mode-map alist of current `major-mode'."
6447 (let ((map (anything-get-mode-map-from-mode major-mode)))
6448 (when (and map (boundp map))
6449 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
6452 (defun anything-M-x-transformer (candidates sources)
6453 "filtered-candidate-transformer to show bindings in emacs commands.
6454 Show global bindings and local bindings according to current `major-mode'."
6455 (with-anything-current-buffer
6456 (loop
6457 with local-map = (anything-M-x-current-mode-map-alist)
6458 for cand in candidates
6459 for local-key = (car (rassq cand local-map))
6460 for key = (substitute-command-keys (format "\\[%s]" cand))
6461 collect
6462 (cons (cond ((and (string-match "^M-x" key) local-key)
6463 (format "%s (%s)"
6464 cand (propertize
6465 local-key
6466 'face 'anything-M-x-key-face)))
6467 ((string-match "^M-x" key) cand)
6468 (t (format "%s (%s)"
6469 cand (propertize
6471 'face 'anything-M-x-key-face)))) cand))))
6474 ;;; LaCarte
6475 (defvar anything-c-source-lacarte
6476 '((name . "Lacarte")
6477 (init . (lambda () (require 'lacarte )))
6478 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6479 (candidate-number-limit . 9999)
6480 (action . anything-c-call-interactively))
6481 "Needs lacarte.el.
6483 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6484 ;; (anything 'anything-c-source-lacarte)
6487 ;;;; <Function>
6488 ;;; Emacs functions
6491 (defvar anything-c-source-emacs-functions
6492 '((name . "Emacs Functions")
6493 (candidates . (lambda ()
6494 (let (commands)
6495 (mapatoms (lambda (a)
6496 (if (functionp a)
6497 (push (symbol-name a) commands))))
6498 (sort commands 'string-lessp))))
6499 (type . function)
6500 (requires-pattern . 2))
6501 "Source for completing Emacs functions.")
6502 ;; (anything 'anything-c-source-emacs-functions)
6504 ;;; With abbrev expansion
6505 ;;; Similar to my exec-abbrev-cmd.el
6506 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6507 (defvar anything-c-function-abbrev-regexp nil
6508 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6509 Regexp built from the current `anything-pattern' interpreting it
6510 as abbreviation.
6511 Only for internal use.")
6513 (defun anything-c-match-function-by-abbrev (candidate)
6514 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6516 Abbreviations are made by taking the first character from each
6517 word in the function's name, e.g. \"bb\" is an abbrev for
6518 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6519 (string-match anything-c-function-abbrev-regexp candidate))
6521 (defvar anything-c-source-emacs-functions-with-abbrevs
6522 (append anything-c-source-emacs-functions
6523 '((match anything-c-match-function-by-abbrev
6524 anything-c-string-match))
6525 '((init
6526 . (lambda ()
6527 (defadvice anything-update
6528 (before anything-c-update-function-abbrev-regexp activate)
6529 (let ((char-list (append anything-pattern nil))
6530 (str "^"))
6531 (dolist (c char-list)
6532 (setq str (concat str (list c) "[^-]*-")))
6533 (setq str (concat (substring str 0 (1- (length str))) "$"))
6534 (setq anything-c-function-abbrev-regexp str))))))))
6535 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6537 (defvar anything-c-source-advice
6538 '((name . "Function Advice")
6539 (candidates . anything-c-advice-candidates)
6540 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6541 ;; (real-to-display . anything-c-advice-real-to-display)
6542 (persistent-action . anything-c-advice-persistent-action)
6543 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6544 ;; (anything 'anything-c-source-advice)
6545 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6546 ;; (testadvice)
6548 (defun anything-c-advice-candidates ()
6549 (require 'advice)
6550 (loop for (fname) in ad-advised-functions
6551 for function = (intern fname)
6552 append
6553 (loop for class in ad-advice-classes append
6554 (loop for advice in (ad-get-advice-info-field function class)
6555 for enabled = (ad-advice-enabled advice)
6556 collect
6557 (cons (format
6558 "%s %s %s"
6559 (if enabled "Enabled " "Disabled")
6560 (propertize fname 'face 'font-lock-function-name-face)
6561 (ad-make-single-advice-docstring advice class nil))
6562 (list function class advice))))))
6564 (defun anything-c-advice-persistent-action (func-class-advice)
6565 (if current-prefix-arg
6566 (anything-c-advice-toggle func-class-advice)
6567 (describe-function (car func-class-advice))))
6569 (defun anything-c-advice-toggle (func-class-advice)
6570 (destructuring-bind (function class advice) func-class-advice
6571 (cond ((ad-advice-enabled advice)
6572 (ad-advice-set-enabled advice nil)
6573 (message "Disabled"))
6574 (t ;disabled
6575 (ad-advice-set-enabled advice t)
6576 (message "Enabled")))
6577 (ad-activate function)
6578 (and anything-in-persistent-action
6579 (anything-c-advice-update-current-display-string))))
6581 (defun anything-c-advice-update-current-display-string ()
6582 (anything-edit-current-selection
6583 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6584 ((looking-at "Enabled") "Disabled")))
6585 realvalue)
6586 (when newword
6587 (delete-region (point) (progn (forward-word 1) (point)))
6588 (insert newword)))))
6591 ;;;; <Variable>
6592 ;;; Emacs variables
6595 (defvar anything-c-source-emacs-variables
6596 '((name . "Emacs Variables")
6597 (candidates . (lambda ()
6598 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6599 (type . variable)
6600 (requires-pattern . 2))
6601 "Source for completing Emacs variables.")
6602 ;; (anything 'anything-c-source-emacs-variables)
6605 ;;; Bookmarks
6608 ;; Bind some faces for bookmarks.
6609 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6610 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6611 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6613 (eval-when-compile (require 'bookmark))
6614 (defvar anything-c-source-bookmarks
6615 '((name . "Bookmarks")
6616 (init . (lambda ()
6617 (require 'bookmark)))
6618 (candidates . bookmark-all-names)
6619 (type . bookmark))
6620 "See (info \"(emacs)Bookmarks\").")
6621 ;; (anything 'anything-c-source-bookmarks)
6623 ;;; bookmark-set
6624 (defvar anything-c-source-bookmark-set
6625 '((name . "Set Bookmark")
6626 (dummy)
6627 (action . bookmark-set))
6628 "See (info \"(emacs)Bookmarks\").")
6629 ;; (anything 'anything-c-source-bookmark-set)
6631 ;;; Visible Bookmarks
6632 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6635 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6636 (defvar anything-c-source-bm
6637 '((name . "Visible Bookmarks")
6638 (init . anything-c-bm-init)
6639 (candidates-in-buffer)
6640 (type . line))
6641 "Needs bm.el.
6643 http://www.nongnu.org/bm/")
6645 (defun anything-c-bm-init ()
6646 "Init function for `anything-c-source-bm'."
6647 (when (require 'bm nil t)
6648 (with-no-warnings
6649 (let ((bookmarks (bm-lists))
6650 (buf (anything-candidate-buffer 'global)))
6651 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6652 '< :key 'overlay-start))
6653 (let ((start (overlay-start bm))
6654 (end (overlay-end bm))
6655 (annotation (or (overlay-get bm 'annotation) "")))
6656 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6657 (let ((str (format "%5d: [%s]: %s\n"
6658 (line-number-at-pos start)
6659 annotation
6660 (buffer-substring start (1- end)))))
6661 (with-current-buffer buf (insert str))))))))))
6663 ;;; Special bookmarks
6664 (defvar anything-c-source-bookmarks-ssh
6665 '((name . "Bookmarks-ssh")
6666 (init . (lambda ()
6667 (require 'bookmark)))
6668 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6669 (type . bookmark))
6670 "See (info \"(emacs)Bookmarks\").")
6671 ;; (anything 'anything-c-source-bookmarks-ssh)
6673 (defvar anything-c-source-bookmarks-su
6674 '((name . "Bookmarks-root")
6675 (init . (lambda ()
6676 (require 'bookmark)))
6677 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6678 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6680 (type . bookmark))
6681 "See (info \"(emacs)Bookmarks\").")
6682 ;; (anything 'anything-c-source-bookmarks-su)
6684 (defvar anything-c-source-bookmarks-local
6685 '((name . "Bookmarks-Local")
6686 (init . (lambda ()
6687 (require 'bookmark)))
6688 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6689 (filtered-candidate-transformer
6690 anything-c-adaptive-sort
6691 anything-c-highlight-bookmark)
6692 (type . bookmark))
6693 "See (info \"(emacs)Bookmarks\").")
6694 ;; (anything 'anything-c-source-bookmarks-local)
6696 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6697 (let* ((lis-all (bookmark-all-names))
6698 (lis-loc (cond (local (loop for i in lis-all
6699 unless (string-match "^(ssh)\\|^(su)" i)
6700 collect i))
6701 (su (loop for i in lis-all
6702 when (string-match "^(su)" i)
6703 collect i))
6704 (sudo (loop for i in lis-all
6705 when (string-match "^(sudo)" i)
6706 collect i))
6707 (ssh (loop for i in lis-all
6708 when (string-match "^(ssh)" i)
6709 collect i)))))
6710 (sort lis-loc 'string-lessp)))
6712 (defun anything-c-bookmark-root-logged-p ()
6713 (catch 'break
6714 (dolist (i (mapcar #'buffer-name (buffer-list)))
6715 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6716 (throw 'break t)))))
6718 (defun anything-c-highlight-bookmark-su (files source)
6719 (if (anything-c-bookmark-root-logged-p)
6720 (anything-c-highlight-bookmark files source)
6721 (anything-c-highlight-not-logged files source)))
6723 (defun anything-c-highlight-not-logged (files source)
6724 (loop for i in files
6725 collect (propertize i 'face anything-c-bookmarks-face3)))
6727 (defun anything-c-highlight-bookmark (bookmarks source)
6728 "Used as `candidate-transformer' to colorize bookmarks.
6729 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6730 (loop for i in bookmarks
6731 for isfile = (bookmark-get-filename i)
6732 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6733 (bmkext-get-buffer-name i))
6734 for handlerp = (and (fboundp 'bookmark-get-handler)
6735 (bookmark-get-handler i))
6736 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6737 (bmkext-w3m-bookmark-p i))
6738 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6739 (bmkext-gnus-bookmark-p i))
6740 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6741 (bmkext-man-bookmark-p i))
6742 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6743 (bmkext-woman-bookmark-p i))
6744 for handlerp = (bookmark-get-handler i)
6745 for isannotation = (bookmark-get-annotation i)
6746 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6747 for isinfo = (eq handlerp 'Info-bookmark-jump)
6748 ;; Add a * if bookmark have annotation
6749 if (and isannotation (not (string-equal isannotation "")))
6750 do (setq i (concat "*" i))
6751 collect (cond (;; info buffers
6752 isinfo
6753 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6754 (;; w3m buffers
6755 isw3m
6756 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6757 (;; gnus buffers
6758 isgnus
6759 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6760 (;; Man Woman
6761 (or iswoman isman)
6762 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6763 (;; Addressbook
6764 isabook
6765 (propertize i 'face '((:foreground "Tomato"))))
6766 (;; directories
6767 (and isfile (file-directory-p isfile))
6768 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6769 (;; regular files
6771 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6775 ;;; Sources to filter bookmark-extensions bookmarks.
6778 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6779 ;; If you want to enable google-maps in addressbook you will need
6780 ;; Julien Danjou google-maps-el package available here:
6781 ;; http://julien.danjou.info/google-maps-el.html
6783 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6784 "Return a filtered `bookmark-alist' sorted alphabetically."
6785 (loop
6786 with alist = (if args
6787 (apply #'(lambda (x) (funcall fn x)) args)
6788 (funcall fn))
6789 for i in alist
6790 for b = (car i)
6791 collect b into sa
6792 finally return (sort sa 'string-lessp)))
6794 ;;; Addressbook.
6797 (defvar anything-c-source-bmkext-addressbook
6798 '((name . "Bookmark Addressbook")
6799 (init . (lambda ()
6800 (require 'bookmark-extensions)
6801 (bookmark-maybe-load-default-file)))
6802 (candidates . anything-c-bmkext-addressbook-setup-alist)
6803 (persistent-action
6804 . (lambda (candidate)
6805 (let ((bmk (anything-bookmark-get-bookmark-from-name
6806 candidate)))
6807 (bookmark--jump-via bmk 'pop-to-buffer))))
6808 (persistent-help . "Show contact - Prefix with C-u to append")
6809 (filtered-candidate-transformer
6810 anything-c-adaptive-sort
6811 anything-c-highlight-bookmark)
6812 (action . (("Show Contact(s)"
6813 . (lambda (candidate)
6814 (let* ((contacts (anything-marked-candidates))
6815 (current-prefix-arg (or anything-current-prefix-arg
6816 (> (length contacts) 1))))
6817 (bookmark-jump
6818 (anything-bookmark-get-bookmark-from-name (car contacts)))
6819 (anything-aif (cdr contacts)
6820 (loop for bmk in it do
6821 (bookmark-jump
6822 (anything-bookmark-get-bookmark-from-name bmk)))))))
6823 ("Send Mail"
6824 . (lambda (candidate)
6825 (let* ((contacts (anything-marked-candidates))
6826 (bmk (anything-bookmark-get-bookmark-from-name
6827 (car contacts)))
6828 (append (message-buffers)))
6829 (if append
6830 (addressbook-set-mail-buffer1 bmk 'append)
6831 (addressbook-set-mail-buffer1 bmk))
6832 (setq contacts (cdr contacts))
6833 (when contacts
6834 (loop for bmk in contacts do
6835 (addressbook-set-mail-buffer1 bmk 'append))))))
6836 ("Edit Bookmark"
6837 . (lambda (candidate)
6838 (let ((bmk (anything-bookmark-get-bookmark-from-name
6839 candidate)))
6840 (addressbook-bookmark-edit
6841 (assoc bmk bookmark-alist)))))
6842 ("Insert Email at point"
6843 . (lambda (candidate)
6844 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6845 candidate))
6846 (mlist (split-string
6847 (assoc-default
6848 'email (assoc bmk bookmark-alist))
6849 ", ")))
6850 (insert
6851 (if (> (length mlist) 1)
6852 (anything-comp-read
6853 "Insert Mail Address: " mlist :must-match t)
6854 (car mlist))))))
6855 ("Show annotation"
6856 . (lambda (candidate)
6857 (let ((bmk (anything-bookmark-get-bookmark-from-name
6858 candidate)))
6859 (bookmark-show-annotation bmk))))
6860 ("Edit annotation"
6861 . (lambda (candidate)
6862 (let ((bmk (anything-bookmark-get-bookmark-from-name
6863 candidate)))
6864 (bookmark-edit-annotation bmk))))
6865 ("Show Google map"
6866 . (lambda (candidate)
6867 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6868 candidate))
6869 (full-bmk (assoc bmk bookmark-alist)))
6870 (addressbook-google-map full-bmk))))))))
6873 (defun anything-c-bmkext-addressbook-setup-alist ()
6874 "Specialized filter function for bookmarks w3m."
6875 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6877 ;; W3m bookmarks from bookmark-extensions.
6878 (defvar anything-c-source-bookmark-w3m
6879 '((name . "Bookmark W3m")
6880 (init . (lambda ()
6881 (require 'bookmark-extensions)
6882 (bookmark-maybe-load-default-file)))
6883 (candidates . anything-c-bookmark-w3m-setup-alist)
6884 (filtered-candidate-transformer
6885 anything-c-adaptive-sort
6886 anything-c-highlight-bookmark)
6887 (type . bookmark)))
6888 ;; (anything 'anything-c-source-bookmark-w3m)
6890 (defun anything-c-bookmark-w3m-setup-alist ()
6891 "Specialized filter function for bookmarks w3m."
6892 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6894 ;; Images
6895 (defvar anything-c-source-bookmark-images
6896 '((name . "Bookmark Images")
6897 (init . (lambda ()
6898 (require 'bookmark-extensions)
6899 (bookmark-maybe-load-default-file)))
6900 (candidates . anything-c-bookmark-images-setup-alist)
6901 (filtered-candidate-transformer
6902 anything-c-adaptive-sort
6903 anything-c-highlight-bookmark)
6904 (type . bookmark)))
6905 ;; (anything 'anything-c-source-bookmark-images)
6907 (defun anything-c-bookmark-images-setup-alist ()
6908 "Specialized filter function for images bookmarks."
6909 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6911 ;; Woman Man
6912 (defvar anything-c-source-bookmark-man
6913 '((name . "Bookmark Woman&Man")
6914 (init . (lambda ()
6915 (require 'bookmark-extensions)
6916 (bookmark-maybe-load-default-file)))
6917 (candidates . anything-c-bookmark-man-setup-alist)
6918 (filtered-candidate-transformer
6919 anything-c-adaptive-sort
6920 anything-c-highlight-bookmark)
6921 (type . bookmark)))
6922 ;; (anything 'anything-c-source-bookmark-man)
6924 (defun anything-c-bookmark-man-setup-alist ()
6925 "Specialized filter function for bookmarks w3m."
6926 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6927 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6929 ;; Gnus
6930 (defvar anything-c-source-bookmark-gnus
6931 '((name . "Bookmark Gnus")
6932 (init . (lambda ()
6933 (require 'bookmark-extensions)
6934 (bookmark-maybe-load-default-file)))
6935 (candidates . anything-c-bookmark-gnus-setup-alist)
6936 (filtered-candidate-transformer
6937 anything-c-adaptive-sort
6938 anything-c-highlight-bookmark)
6939 (type . bookmark)))
6940 ;; (anything 'anything-c-source-bookmark-gnus)
6942 (defun anything-c-bookmark-gnus-setup-alist ()
6943 "Specialized filter function for bookmarks gnus."
6944 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6946 ;; Info
6947 (defvar anything-c-source-bookmark-info
6948 '((name . "Bookmark Info")
6949 (init . (lambda ()
6950 (require 'bookmark-extensions)
6951 (bookmark-maybe-load-default-file)))
6952 (candidates . anything-c-bookmark-info-setup-alist)
6953 (filtered-candidate-transformer
6954 anything-c-adaptive-sort
6955 anything-c-highlight-bookmark)
6956 (type . bookmark)))
6957 ;; (anything 'anything-c-source-bookmark-info)
6959 (defun anything-c-bookmark-info-setup-alist ()
6960 "Specialized filter function for bookmarks info."
6961 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6963 ;; Local Files&directories
6964 (defvar anything-c-source-bookmark-files&dirs
6965 '((name . "Bookmark Files&Directories")
6966 (init . (lambda ()
6967 (require 'bookmark-extensions)
6968 (bookmark-maybe-load-default-file)))
6969 (candidates . anything-c-bookmark-local-files-setup-alist)
6970 (filtered-candidate-transformer
6971 anything-c-adaptive-sort
6972 anything-c-highlight-bookmark)
6973 (type . bookmark)))
6974 ;; (anything 'anything-c-source-bookmark-files&dirs)
6976 (defun anything-c-bookmark-local-files-setup-alist ()
6977 "Specialized filter function for bookmarks locals files."
6978 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6980 ;; Su Files&directories
6981 (defvar anything-c-source-bookmark-su-files&dirs
6982 '((name . "Bookmark Root-Files&Directories")
6983 (init . (lambda ()
6984 (require 'bookmark-extensions)
6985 (bookmark-maybe-load-default-file)))
6986 (candidates . anything-c-bookmark-su-files-setup-alist)
6987 (filtered-candidate-transformer
6988 anything-c-adaptive-sort
6989 anything-c-highlight-bookmark-su)
6990 (type . bookmark)))
6991 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6993 (defun anything-c-bookmark-su-files-setup-alist ()
6994 "Specialized filter function for bookmarks su/sudo files."
6995 (declare (special bmkext-su-or-sudo-regexp))
6996 (loop
6997 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6998 for i in l
6999 for isfile = (bookmark-get-filename i)
7000 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
7001 (save-match-data
7002 (string-match tramp-file-name-regexp isfile)))
7003 for issu = (and istramp
7004 (string-match bmkext-su-or-sudo-regexp isfile))
7005 if issu
7006 collect i))
7008 ;; Ssh Files&directories
7009 (defvar anything-c-source-bookmark-ssh-files&dirs
7010 '((name . "Bookmark Ssh-Files&Directories")
7011 (init . (lambda ()
7012 (require 'bookmark-extensions)
7013 (bookmark-maybe-load-default-file)))
7014 (candidates . anything-c-bookmark-ssh-files-setup-alist)
7015 (filtered-candidate-transformer . anything-c-adaptive-sort)
7016 (type . bookmark)))
7017 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
7019 (defun anything-c-bookmark-ssh-files-setup-alist ()
7020 "Specialized filter function for bookmarks ssh files."
7021 (loop
7022 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
7023 for i in l
7024 for isfile = (bookmark-get-filename i)
7025 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
7026 (save-match-data
7027 (string-match tramp-file-name-regexp isfile)))
7028 for isssh = (and istramp
7029 (string-match "/ssh:" isfile))
7030 if isssh
7031 collect i))
7035 ;;; Firefox bookmarks
7038 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
7039 ;; (only for firefox versions >=3)
7040 ;; To achieve that, open about:config in firefox and double click on this line to enable value
7041 ;; to true:
7042 ;; user_pref("browser.bookmarks.autoExportHTML", false);
7043 ;; You should have now:
7044 ;; user_pref("browser.bookmarks.autoExportHTML", true);
7046 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
7047 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
7049 (defun anything-get-firefox-user-init-dir ()
7050 "Guess the default Firefox user directory name."
7051 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
7052 (moz-user-dir
7053 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
7054 (goto-char (point-min))
7055 (prog1
7056 (when (search-forward "Path=" nil t)
7057 (buffer-substring-no-properties (point) (point-at-eol)))
7058 (kill-buffer)))))
7059 (file-name-as-directory (concat moz-dir moz-user-dir))))
7061 (defun anything-guess-firefox-bookmark-file ()
7062 "Return the path of the Firefox bookmarks file."
7063 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
7065 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
7066 "Parse html bookmark FILE and return an alist with (title . url) as elements."
7067 (let (bookmarks-alist url title)
7068 (with-temp-buffer
7069 (insert-file-contents file)
7070 (goto-char (point-min))
7071 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
7072 (forward-line 0)
7073 (when (re-search-forward url-regexp nil t)
7074 (setq url (match-string 0)))
7075 (when (re-search-forward bmk-regexp nil t)
7076 (setq title (match-string 1)))
7077 (push (cons title url) bookmarks-alist)
7078 (forward-line)))
7079 (nreverse bookmarks-alist)))
7081 (defvar anything-c-firefox-bookmarks-alist nil)
7082 (defvar anything-c-source-firefox-bookmarks
7083 '((name . "Firefox Bookmarks")
7084 (init . (lambda ()
7085 (setq anything-c-firefox-bookmarks-alist
7086 (anything-html-bookmarks-to-alist
7087 (anything-guess-firefox-bookmark-file)
7088 anything-firefox-bookmark-url-regexp
7089 anything-firefox-bookmarks-regexp))))
7090 (candidates . (lambda ()
7091 (mapcar #'car anything-c-firefox-bookmarks-alist)))
7092 (filtered-candidate-transformer
7093 anything-c-adaptive-sort
7094 anything-c-highlight-firefox-bookmarks)
7095 (action . (("Browse Url Firefox"
7096 . (lambda (candidate)
7097 (browse-url-firefox
7098 (anything-c-firefox-bookmarks-get-value candidate))))
7099 ("Browse Url w3m"
7100 . (lambda (candidate)
7101 (w3m-browse-url
7102 (anything-c-firefox-bookmarks-get-value candidate))))
7103 ("Copy Url"
7104 . (lambda (elm)
7105 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
7107 ;; (anything 'anything-c-source-firefox-bookmarks)
7109 (defun anything-c-firefox-bookmarks-get-value (elm)
7110 (assoc-default elm anything-c-firefox-bookmarks-alist))
7112 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
7113 (loop for i in bookmarks
7114 collect (propertize
7115 i 'face '((:foreground "YellowGreen"))
7116 'help-echo (anything-c-firefox-bookmarks-get-value i))))
7120 ;;; W3m bookmark - anything interface.
7123 ;; Some users have the emacs-w3m library in load-path
7124 ;; without having the w3m executable :-;
7125 ;; So check if w3m program is present before trying to load
7126 ;; emacs-w3m.
7127 (eval-when-compile
7128 (when (executable-find "w3m")
7129 (require 'w3m-bookmark nil t)))
7131 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
7132 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
7133 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
7134 (defvar anything-c-w3m-bookmarks-alist nil)
7135 (defvar anything-c-source-w3m-bookmarks
7136 '((name . "W3m Bookmarks")
7137 (init . (lambda ()
7138 (setq anything-c-w3m-bookmarks-alist
7139 (anything-html-bookmarks-to-alist
7140 w3m-bookmark-file
7141 anything-w3m-bookmark-url-regexp
7142 anything-w3m-bookmarks-regexp))))
7143 (candidates . (lambda ()
7144 (mapcar #'car anything-c-w3m-bookmarks-alist)))
7145 (filtered-candidate-transformer
7146 anything-c-adaptive-sort
7147 anything-c-highlight-w3m-bookmarks)
7148 (action . (("Browse Url"
7149 . (lambda (candidate)
7150 (anything-c-w3m-browse-bookmark candidate)))
7151 ("Copy Url"
7152 . (lambda (elm)
7153 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
7154 ("Browse Url Firefox"
7155 . (lambda (candidate)
7156 (anything-c-w3m-browse-bookmark candidate t)))
7157 ("Delete Bookmark"
7158 . (lambda (candidate)
7159 (anything-c-w3m-delete-bookmark candidate)))
7160 ("Rename Bookmark"
7161 . (lambda (candidate)
7162 (anything-c-w3m-rename-bookmark candidate)))))
7163 (persistent-action . (lambda (candidate)
7164 (if current-prefix-arg
7165 (anything-c-w3m-browse-bookmark candidate t)
7166 (anything-c-w3m-browse-bookmark candidate nil t))))
7167 (persistent-help . "Open URL with emacs-w3m in new tab / \
7168 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
7169 "Needs w3m and emacs-w3m.
7171 http://w3m.sourceforge.net/
7172 http://emacs-w3m.namazu.org/")
7174 ;; (anything 'anything-c-source-w3m-bookmarks)
7176 (defun anything-c-w3m-bookmarks-get-value (elm)
7177 (replace-regexp-in-string
7178 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
7180 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
7181 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
7182 (arg (and (eq fn 'w3m-browse-url) new-tab)))
7183 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
7185 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
7186 (loop for i in bookmarks
7187 collect (propertize
7188 i 'face 'anything-w3m-bookmarks-face
7189 'help-echo (anything-c-w3m-bookmarks-get-value i))))
7192 (defun anything-c-w3m-delete-bookmark (elm)
7193 "Delete w3m bookmark from `w3m-bookmark-file'."
7194 (with-current-buffer
7195 (find-file-literally w3m-bookmark-file)
7196 (goto-char (point-min))
7197 (when (re-search-forward elm nil t)
7198 (beginning-of-line)
7199 (delete-region (point)
7200 (line-end-position))
7201 (delete-blank-lines))
7202 (save-buffer)
7203 (kill-buffer)))
7205 (defun anything-c-w3m-rename-bookmark (elm)
7206 "Rename w3m bookmark in `w3m-bookmark-file'."
7207 (let* ((old-title (replace-regexp-in-string ">" "" elm))
7208 (new-title (read-string "NewTitle: " old-title)))
7209 (with-current-buffer
7210 (find-file-literally w3m-bookmark-file)
7211 (goto-char (point-min))
7212 (when (re-search-forward (concat elm "<") nil t)
7213 (goto-char (1- (point)))
7214 (delete-char (- (length old-title)))
7215 (insert new-title))
7216 (save-buffer)
7217 (kill-buffer))))
7220 ;;;; <Library>
7221 ;;; Elisp library scan
7224 (defvar anything-c-source-elisp-library-scan
7225 '((name . "Elisp libraries (Scan)")
7226 (init . (anything-c-elisp-library-scan-init))
7227 (candidates-in-buffer)
7228 (action ("Find library"
7229 . (lambda (candidate) (find-file (find-library-name candidate))))
7230 ("Find library other window"
7231 . (lambda (candidate)
7232 (find-file-other-window (find-library-name candidate))))
7233 ("Load library"
7234 . (lambda (candidate) (load-library candidate))))))
7235 ;; (anything 'anything-c-source-elisp-library-scan)
7237 (defun anything-c-elisp-library-scan-init ()
7238 "Init anything buffer status."
7239 (let ((anything-buffer (anything-candidate-buffer 'global))
7240 (library-list (anything-c-elisp-library-scan-list)))
7241 (with-current-buffer anything-buffer
7242 (dolist (library library-list)
7243 (insert (format "%s\n" library))))))
7245 (defun anything-c-elisp-library-scan-list (&optional dirs string)
7246 "Do completion for file names passed to `locate-file'.
7247 DIRS is directory to search path.
7248 STRING is string to match."
7249 ;; Use `load-path' as path when ignore `dirs'.
7250 (or dirs (setq dirs load-path))
7251 ;; Init with blank when ignore `string'.
7252 (or string (setq string ""))
7253 ;; Get library list.
7254 (let ((string-dir (file-name-directory string))
7255 ;; File regexp that suffix match `load-file-rep-suffixes'.
7256 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
7257 name
7258 names)
7259 (dolist (dir dirs)
7260 (unless dir
7261 (setq dir default-directory))
7262 (if string-dir
7263 (setq dir (expand-file-name string-dir dir)))
7264 (when (file-directory-p dir)
7265 (dolist (file (file-name-all-completions
7266 (file-name-nondirectory string) dir))
7267 ;; Suffixes match `load-file-rep-suffixes'.
7268 (setq name (if string-dir (concat string-dir file) file))
7269 (if (string-match match-regexp name)
7270 (add-to-list 'names name)))))
7271 names))
7274 ;;;; <Programming>
7278 ;;; Imenu
7281 (defvar anything-c-imenu-delimiter " / ")
7283 (defvar anything-c-imenu-index-filter nil)
7284 (make-variable-buffer-local 'anything-c-imenu-index-filter)
7286 (defvar anything-c-cached-imenu-alist nil)
7287 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
7289 (defvar anything-c-cached-imenu-candidates nil)
7290 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
7292 (defvar anything-c-cached-imenu-tick nil)
7293 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
7295 (eval-when-compile (require 'imenu))
7296 (setq imenu-auto-rescan t)
7298 (defun anything-imenu-create-candidates (entry)
7299 "Create candidates with ENTRY."
7300 (if (listp (cdr entry))
7301 (mapcan
7302 (lambda (sub)
7303 (if (consp (cdr sub))
7304 (mapcar
7305 (lambda (subentry)
7306 (concat (car entry) anything-c-imenu-delimiter subentry))
7307 (anything-imenu-create-candidates sub))
7308 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
7309 (cdr entry))
7310 (list entry)))
7312 (defvar anything-c-source-imenu
7313 '((name . "Imenu")
7314 (init . (lambda () (require 'imenu)))
7315 (candidates . anything-c-imenu-candidates)
7316 (persistent-action . (lambda (elm)
7317 (anything-c-imenu-default-action elm)
7318 (unless (fboundp 'semantic-imenu-tag-overlay)
7319 (anything-match-line-color-current-line))))
7320 (persistent-help . "Show this entry")
7321 (action . anything-c-imenu-default-action))
7322 "See (info \"(emacs)Imenu\")")
7324 ;; (anything 'anything-c-source-imenu)
7326 (defun anything-c-imenu-candidates ()
7327 (with-anything-current-buffer
7328 (let ((tick (buffer-modified-tick)))
7329 (if (eq anything-c-cached-imenu-tick tick)
7330 anything-c-cached-imenu-candidates
7331 (setq imenu--index-alist nil)
7332 (setq anything-c-cached-imenu-tick tick
7333 anything-c-cached-imenu-candidates
7334 (ignore-errors
7335 (mapcan
7336 'anything-imenu-create-candidates
7337 (setq anything-c-cached-imenu-alist
7338 (let ((index (imenu--make-index-alist)))
7339 (if anything-c-imenu-index-filter
7340 (funcall anything-c-imenu-index-filter index)
7341 index))))))
7342 (setq anything-c-cached-imenu-candidates
7343 (mapcar #'(lambda (x)
7344 (if (stringp x)
7346 (car x)))
7347 anything-c-cached-imenu-candidates))))))
7349 (setq imenu-default-goto-function 'imenu-default-goto-function)
7350 (defun anything-c-imenu-default-action (elm)
7351 "The default action for `anything-c-source-imenu'."
7352 (let ((path (split-string elm anything-c-imenu-delimiter))
7353 (alist anything-c-cached-imenu-alist))
7354 (dolist (elm path)
7355 (setq alist (assoc elm alist)))
7356 (imenu alist)))
7360 ;;; Ctags
7363 (defvar anything-c-ctags-modes
7364 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
7365 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
7366 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
7368 (defun anything-c-source-ctags-init ()
7369 (when (and buffer-file-name
7370 (memq major-mode anything-c-ctags-modes)
7371 (anything-current-buffer-is-modified))
7372 (with-current-buffer (anything-candidate-buffer 'local)
7373 (call-process-shell-command
7374 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
7375 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
7376 anything-buffer-file-name)
7377 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
7378 nil (current-buffer))
7379 (goto-char (point-min))
7380 (forward-line 2)
7381 (delete-region (point-min) (point))
7382 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
7383 for lineno-start = (point)
7384 for lineno = (buffer-substring
7385 lineno-start
7386 (1- (search-forward "," (point-at-eol) t)))
7388 (beginning-of-line)
7389 (insert (format "%5s:" lineno))
7390 (search-forward "\177" (point-at-eol) t)
7391 (delete-region (1- (point)) (point-at-eol))
7392 (forward-line 1)))))
7394 (defvar anything-c-source-ctags
7395 '((name . "Exuberant ctags")
7396 (init . anything-c-source-ctags-init)
7397 (candidates-in-buffer)
7398 (adjust)
7399 (type . line))
7400 "Needs Exuberant Ctags.
7402 http://ctags.sourceforge.net/")
7403 ;; (anything 'anything-c-source-ctags)
7406 ;;; Etags
7409 ;; anything-etags.el is deprecated, if this file is found,
7410 ;; warn user at compile time.
7411 (eval-when-compile
7412 (when (locate-library "anything-etags.el")
7413 (display-warning
7414 '(anything-config)
7415 "You are using obsolete library `anything-etags.el' and should remove it."
7416 :warning)))
7418 (defvar anything-c-etags-tag-file-dir nil
7419 "Etags file directory.")
7420 (defvar anything-c-etags-mtime-alist nil
7421 "Store the last modification time of etags files here.")
7422 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
7423 "Cache content of etags files used here for faster access.")
7425 (defun anything-c-etags-get-tag-file (&optional directory)
7426 "Return the path of etags file if found."
7427 ;; Get tag file from `default-directory' or upper directory.
7428 (let ((current-dir (anything-c-etags-find-tag-file-directory
7429 (or directory default-directory))))
7430 ;; Return nil if not find tag file.
7431 (when current-dir
7432 ;; Set tag file directory.
7433 (setq anything-c-etags-tag-file-dir current-dir)
7434 (expand-file-name anything-c-etags-tag-file-name current-dir))))
7436 (defun anything-c-etags-find-tag-file-directory (current-dir)
7437 "Try to find the directory containing tag file.
7438 If not found in CURRENT-DIR search in upper directory."
7439 (flet ((file-exists? (dir)
7440 (let ((tag-path (expand-file-name
7441 anything-c-etags-tag-file-name dir)))
7442 (and (stringp tag-path)
7443 (file-exists-p tag-path)
7444 (file-readable-p tag-path)))))
7445 (loop with count = 0
7446 until (file-exists? current-dir)
7447 ;; Return nil if outside the value of
7448 ;; `anything-c-etags-tag-file-search-limit'.
7449 if (= count anything-c-etags-tag-file-search-limit)
7450 do (return nil)
7451 ;; Or search upper directories.
7452 else
7453 do (incf count)
7454 (setq current-dir (expand-file-name (concat current-dir "../")))
7455 finally return current-dir)))
7457 (defun anything-c-source-etags-header-name (x)
7458 "Create header name for this anything etags session."
7459 (concat "Etags in "
7460 (with-anything-current-buffer
7461 (anything-c-etags-get-tag-file))))
7463 (defmacro anything-c-etags-create-buffer (file)
7464 "Create the `anything-buffer' based on contents of etags tag FILE."
7465 `(let* ((tag-fname ,file)
7467 (split (with-current-buffer (find-file-noselect tag-fname)
7468 (prog1
7469 (split-string (buffer-string) "\n" 'omit-nulls)
7470 (setq max (line-number-at-pos (point-max)))
7471 (kill-buffer))))
7472 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7473 (loop
7474 with fname
7475 with cand
7476 for i in split for count from 0
7477 for elm = (unless (string-match "^\x0c" i)
7478 (anything-aif (string-match "\177" i)
7479 (substring i 0 it)
7481 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7482 (setq fname (match-string 1 elm)))
7483 (elm (setq cand (concat fname ": " elm)))
7484 (t (setq cand nil)))
7485 when cand do (progn
7486 (insert (concat cand "\n"))
7487 (progress-reporter-update progress-reporter count)))))
7489 (defun anything-c-etags-init ()
7490 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7491 If no entry in cache, create one."
7492 (let ((tagfile (anything-c-etags-get-tag-file)))
7493 (when tagfile
7494 (with-current-buffer (anything-candidate-buffer 'global)
7495 (anything-aif (gethash tagfile anything-c-etags-cache)
7496 ;; An entry is present in cache, insert it.
7497 (insert it)
7498 ;; No entry, create a new buffer using content of tag file (slower).
7499 (anything-c-etags-create-buffer tagfile)
7500 ;; Store content of buffer in cache.
7501 (puthash tagfile (buffer-string) anything-c-etags-cache)
7502 ;; Store or set the last modification of tag file.
7503 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7504 ;; If an entry exists modify it.
7505 (setcdr it (anything-c-etags-mtime tagfile))
7506 ;; No entry create a new one.
7507 (add-to-list 'anything-c-etags-mtime-alist
7508 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7510 (defvar anything-c-source-etags-select
7511 '((name . "Etags")
7512 (header-name . anything-c-source-etags-header-name)
7513 (init . anything-c-etags-init)
7514 (candidates-in-buffer)
7515 (search . (anything-c-etags-search-fn))
7516 (mode-line . anything-etags-mode-line-string)
7517 (action . anything-c-etags-default-action)
7518 (persistent-action . (lambda (candidate)
7519 (anything-c-etags-default-action candidate)
7520 (anything-match-line-color-current-line))))
7521 "Anything source for Etags.")
7523 (defun anything-c-etags-search-fn (pattern bound noerror)
7524 "Search function for `anything-c-source-etags-select'."
7525 (re-search-forward
7526 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
7527 bound noerror))
7529 (defun anything-c-etags-default-action (candidate)
7530 "Anything default action to jump to an etags entry."
7531 (let* ((split (split-string candidate ": "))
7532 (fname (expand-file-name
7533 (car split) anything-c-etags-tag-file-dir))
7534 (elm (cadr split)))
7535 (find-file fname)
7536 (goto-char (point-min))
7537 (search-forward elm nil t)
7538 (goto-char (match-beginning 0))))
7540 (defun anything-c-etags-mtime (file)
7541 "Last modification time of etags tag FILE."
7542 (cadr (nth 5 (file-attributes file))))
7544 (defun anything-c-etags-file-modified-p (file)
7545 "Check if tag FILE have been modified in this session.
7546 If FILE is nil return nil."
7547 (let ((last-modif (and file
7548 (assoc-default file anything-c-etags-mtime-alist))))
7549 (and last-modif
7550 (/= last-modif (anything-c-etags-mtime file)))))
7554 ;;; Semantic
7557 (defvar anything-semantic-candidates nil)
7559 (defun anything-semantic-construct-candidates (tags depth)
7560 (when (require 'semantic nil t)
7561 (apply
7562 'append
7563 (mapcar
7564 (lambda (tag)
7565 (if (listp tag)
7566 (let ((type (semantic-tag-type tag))
7567 (class (semantic-tag-class tag)))
7568 (if (or (and (stringp type)
7569 (or (string= type "class")
7570 (string= type "namespace")))
7571 (eq class 'function)
7572 (eq class 'variable))
7573 (cons (cons (concat (make-string (* depth 2) ?\s)
7574 (semantic-format-tag-summarize tag nil t))
7575 tag)
7576 (anything-semantic-construct-candidates
7577 (semantic-tag-components tag) (1+ depth)))))))
7578 tags))))
7580 (defun anything-semantic-default-action (candidate)
7581 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7582 (semantic-go-to-tag tag)))
7584 (defvar anything-c-source-semantic
7585 '((name . "Semantic Tags")
7586 (init . (lambda ()
7587 (setq anything-semantic-candidates
7588 (ignore-errors (anything-semantic-construct-candidates
7589 (semantic-fetch-tags) 0)))))
7590 (candidates . (lambda ()
7591 (if anything-semantic-candidates
7592 (mapcar 'car anything-semantic-candidates))))
7593 (persistent-action . (lambda (elm)
7594 (anything-semantic-default-action elm)
7595 (anything-match-line-color-current-line)))
7596 (persistent-help . "Show this entry")
7597 (action . anything-semantic-default-action)
7598 "Needs semantic in CEDET.
7600 http://cedet.sourceforge.net/semantic.shtml
7601 http://cedet.sourceforge.net/"))
7603 ;; (anything 'anything-c-source-semantic)
7606 ;;; Anything interface of `simple-call-tree.el'.
7608 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7610 ;; Function is called by
7611 (defvar anything-c-source-simple-call-tree-functions-callers
7612 '((name . "Function is called by")
7613 (init . anything-c-simple-call-tree-functions-callers-init)
7614 (multiline)
7615 (candidates . anything-c-simple-call-tree-candidates)
7616 (persistent-action . anything-c-simple-call-tree-persistent-action)
7617 (persistent-help . "Show function definitions by rotation")
7618 (action ("Find definition selected by persistent-action" .
7619 anything-c-simple-call-tree-find-definition)))
7620 "Needs simple-call-tree.el.
7621 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7623 (defvar anything-c-simple-call-tree-tick nil)
7624 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7625 (defun anything-c-simple-call-tree-analyze-maybe ()
7626 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7627 (simple-call-tree-analyze)
7628 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7630 (defun anything-c-simple-call-tree-init-base (function message)
7631 (require 'simple-call-tree)
7632 (with-no-warnings
7633 (when (anything-current-buffer-is-modified)
7634 (anything-c-simple-call-tree-analyze-maybe)
7635 (let ((list (funcall function simple-call-tree-alist)))
7636 (with-current-buffer (anything-candidate-buffer 'local)
7637 (dolist (entry list)
7638 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7639 (insert (car entry) message
7640 (if (string= funcs " ")
7641 " no functions."
7642 funcs)
7643 "\n\n"))))))))
7645 (defun anything-c-simple-call-tree-functions-callers-init ()
7646 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7647 " is called by\n"))
7649 (defun anything-c-simple-call-tree-candidates ()
7650 (with-current-buffer (anything-candidate-buffer)
7651 (split-string (buffer-string) "\n\n")))
7653 (defvar anything-c-simple-call-tree-related-functions nil)
7654 (defvar anything-c-simple-call-tree-function-index 0)
7655 (defun anything-c-simple-call-tree-persistent-action (candidate)
7656 (unless (eq last-command 'anything-execute-persistent-action)
7657 (setq anything-c-simple-call-tree-related-functions
7658 (delete "no functions."
7659 (split-string
7660 (replace-regexp-in-string " \\| is called by\\| calls "
7661 "" candidate)
7662 "\n")))
7663 (setq anything-c-simple-call-tree-function-index -1))
7664 (incf anything-c-simple-call-tree-function-index)
7665 (anything-c-simple-call-tree-find-definition candidate))
7667 (defun anything-c-simple-call-tree-find-definition (candidate)
7668 (find-function
7669 (intern
7670 (nth (mod anything-c-simple-call-tree-function-index
7671 (length anything-c-simple-call-tree-related-functions))
7672 anything-c-simple-call-tree-related-functions))))
7674 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7676 ;;; Function calls
7677 (defvar anything-c-source-simple-call-tree-callers-functions
7678 '((name . "Function calls")
7679 (init . anything-c-simple-call-tree-callers-functions-init)
7680 (multiline)
7681 (candidates . anything-c-simple-call-tree-candidates)
7682 (persistent-action . anything-c-simple-call-tree-persistent-action)
7683 (persistent-help . "Show function definitions by rotation")
7684 (action ("Find definition selected by persistent-action" .
7685 anything-c-simple-call-tree-find-definition)))
7686 "Needs simple-call-tree.el.
7687 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7689 (defun anything-c-simple-call-tree-callers-functions-init ()
7690 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7692 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7696 ;;; Anything UI of auto-document.el
7698 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7700 ;; Commands/Options with doc
7701 (defvar anything-c-auto-document-data nil)
7702 (make-variable-buffer-local 'anything-c-auto-document-data)
7703 (defvar anything-c-source-commands-and-options-in-file
7704 '((name . "Commands/Options in file")
7705 (header-name
7706 . (lambda (x) (format "Commands/Options in %s"
7707 (buffer-local-value 'buffer-file-name
7708 anything-current-buffer))))
7709 (candidates . anything-command-and-options-candidates)
7710 (multiline)
7711 (action . imenu))
7712 "List Commands and Options with doc. It needs auto-document.el .
7714 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7716 (eval-when-compile (require 'auto-document nil t))
7717 (defun anything-command-and-options-candidates ()
7718 (with-anything-current-buffer
7719 (when (and (require 'auto-document nil t)
7720 (eq major-mode 'emacs-lisp-mode)
7721 (or (anything-current-buffer-is-modified)
7722 (not anything-c-auto-document-data)))
7723 (or imenu--index-alist (imenu--make-index-alist t))
7724 (setq anything-c-auto-document-data
7725 (destructuring-bind (commands options)
7726 (adoc-construct anything-current-buffer)
7727 (append
7728 (loop for (command . doc) in commands
7729 for cmdname = (symbol-name command)
7730 collect
7731 (cons
7732 (format "Command: %s\n %s"
7733 (propertize cmdname 'face font-lock-function-name-face)
7734 (adoc-first-line doc))
7735 (assoc cmdname imenu--index-alist)))
7736 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7737 for (option doc default) in options
7738 for optname = (symbol-name option)
7739 collect
7740 (cons
7741 (format "Option: %s\n %s\n default = %s"
7742 (propertize optname 'face font-lock-variable-name-face)
7743 (adoc-first-line doc)
7744 (adoc-prin1-to-string default))
7745 (assoc optname
7746 var-alist)))))))
7747 anything-c-auto-document-data))
7749 ;; (anything 'anything-c-source-commands-and-options-in-file)
7752 ;;;; <Color and Face>
7755 ;;; Customize Face
7758 (defvar anything-c-source-customize-face
7759 '((name . "Customize Face")
7760 (init . (lambda ()
7761 (unless (anything-candidate-buffer)
7762 (save-window-excursion (list-faces-display))
7763 (anything-candidate-buffer (get-buffer "*Faces*")))))
7764 (candidates-in-buffer)
7765 (get-line . buffer-substring)
7766 (action . (lambda (line)
7767 (customize-face (intern (car (split-string line))))))
7768 (requires-pattern . 3))
7769 "See (info \"(emacs)Faces\")")
7770 ;; (anything 'anything-c-source-customize-face)
7772 ;;; Colors browser
7775 (defvar anything-c-source-colors
7776 '((name . "Colors")
7777 (init . (lambda () (unless (anything-candidate-buffer)
7778 (save-window-excursion (list-colors-display))
7779 (anything-candidate-buffer (get-buffer "*Colors*")))))
7780 (candidates-in-buffer)
7781 (get-line . buffer-substring)
7782 (action
7783 ("Copy Name" . (lambda (candidate)
7784 (kill-new (anything-c-colors-get-name candidate))))
7785 ("Copy RGB" . (lambda (candidate)
7786 (kill-new (anything-c-colors-get-rgb candidate))))
7787 ("Insert Name" . (lambda (candidate)
7788 (with-anything-current-buffer
7789 (insert (anything-c-colors-get-name candidate)))))
7790 ("Insert RGB" . (lambda (candidate)
7791 (with-anything-current-buffer
7792 (insert (anything-c-colors-get-rgb candidate))))))))
7793 ;; (anything 'anything-c-source-colors)
7795 (defun anything-c-colors-get-name (candidate)
7796 "Get color name."
7797 (replace-regexp-in-string
7798 " " ""
7799 (with-temp-buffer
7800 (insert (capitalize candidate))
7801 (goto-char (point-min))
7802 (search-forward-regexp "\\s-\\{2,\\}")
7803 (delete-region (point) (point-max))
7804 (buffer-string))))
7806 (defun anything-c-colors-get-rgb (candidate)
7807 "Get color RGB."
7808 (replace-regexp-in-string
7809 " " ""
7810 (with-temp-buffer
7811 (insert (capitalize candidate))
7812 (goto-char (point-max))
7813 (search-backward-regexp "\\s-\\{2,\\}")
7814 (delete-region (point) (point-min))
7815 (buffer-string))))
7818 ;;;; <Search Engine>
7819 ;;; Tracker desktop search
7820 (defvar anything-c-source-tracker-search
7821 '((name . "Tracker Search")
7822 (candidates . (lambda ()
7823 (start-process "tracker-search-process" nil
7824 "tracker-search"
7825 anything-pattern)))
7826 (type . file)
7827 (requires-pattern . 3)
7828 (delayed))
7829 "Source for retrieving files matching the current input pattern
7830 with the tracker desktop search.")
7831 ;; (anything 'anything-c-source-tracker-search)
7833 ;;; Spotlight (MacOS X desktop search)
7834 (defvar anything-c-source-mac-spotlight
7835 '((name . "mdfind")
7836 (candidates
7837 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7838 (type . file)
7839 (requires-pattern . 3)
7840 (delayed))
7841 "Source for retrieving files via Spotlight's command line
7842 utility mdfind.")
7843 ;; (anything 'anything-c-source-mac-spotlight)
7845 ;;; Picklist
7846 (defvar anything-c-source-picklist
7847 '((name . "Picklist")
7848 (candidates . (lambda () (mapcar 'car picklist-list)))
7849 (type . file)))
7850 ;; (anything 'anything-c-source-picklist)
7854 ;;; Kill ring
7857 (defvar anything-c-source-kill-ring
7858 '((name . "Kill Ring")
7859 (init . (lambda () (anything-attrset 'last-command last-command)))
7860 (candidates . anything-c-kill-ring-candidates)
7861 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7862 (action . anything-c-kill-ring-action)
7863 (last-command)
7864 (migemo)
7865 (multiline))
7866 "Source for browse and insert contents of kill-ring.")
7868 (defun anything-c-kill-ring-candidates ()
7869 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7870 unless (or (< (length kill) anything-kill-ring-threshold)
7871 (string-match "^[\\s\\t]+$" kill))
7872 collect kill))
7874 (defun anything-c-kill-ring-transformer (candidates source)
7875 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7876 (loop for i in candidates
7877 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7878 if (and anything-c-kill-ring-max-lines-number
7879 (> nlines anything-c-kill-ring-max-lines-number))
7880 collect (cons
7881 (with-temp-buffer
7882 (insert i)
7883 (goto-char (point-min))
7884 (concat
7885 (buffer-substring
7886 (point-min)
7887 (save-excursion
7888 (forward-line anything-c-kill-ring-max-lines-number)
7889 (point)))
7890 "[...]")) i)
7891 else collect i))
7893 (defun anything-c-kill-ring-action (str)
7894 "Insert STR in `kill-ring' and set STR to the head.
7895 If this action is executed just after `yank',
7896 replace with STR as yanked string."
7897 (setq kill-ring (delete str kill-ring))
7898 (if (not (eq (anything-attr 'last-command) 'yank))
7899 (insert-for-yank str)
7900 ;; from `yank-pop'
7901 (let ((inhibit-read-only t)
7902 (before (< (point) (mark t))))
7903 (if before
7904 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7905 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7906 (setq yank-undo-function nil)
7907 (set-marker (mark-marker) (point) (current-buffer))
7908 (insert-for-yank str)
7909 ;; Set the window start back where it was in the yank command,
7910 ;; if possible.
7911 (set-window-start (selected-window) yank-window-start t)
7912 (if before
7913 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7914 ;; It is cleaner to avoid activation, even though the command
7915 ;; loop would deactivate the mark because we inserted text.
7916 (goto-char (prog1 (mark t)
7917 (set-marker (mark-marker) (point) (current-buffer)))))))
7918 (kill-new str))
7920 ;; (anything 'anything-c-source-kill-ring)
7923 ;;;; <Mark ring>
7924 ;; DO NOT include these sources in `anything-sources' use
7925 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7926 ;; `anything-all-mark-rings' instead.
7928 (defun anything-c-source-mark-ring-candidates ()
7929 (flet ((get-marks (pos)
7930 (save-excursion
7931 (goto-char pos)
7932 (beginning-of-line)
7933 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7934 (when (string= "" line)
7935 (setq line "<EMPTY LINE>"))
7936 (format "%7d: %s" (line-number-at-pos) line)))))
7937 (with-anything-current-buffer
7938 (loop
7939 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7940 with recip = nil
7941 for i in marks
7942 for m = (get-marks i)
7943 unless (member m recip)
7944 collect m into recip
7945 finally return recip))))
7947 (defvar anything-mark-ring-cache nil)
7948 (defvar anything-c-source-mark-ring
7949 '((name . "mark-ring")
7950 (init . (lambda ()
7951 (setq anything-mark-ring-cache
7952 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7953 (candidates . (lambda ()
7954 (anything-aif anything-mark-ring-cache
7955 it)))
7956 (action . (("Goto line"
7957 . (lambda (candidate)
7958 (anything-goto-line (string-to-number candidate))))))
7959 (persistent-action . (lambda (candidate)
7960 (anything-goto-line (string-to-number candidate))
7961 (anything-match-line-color-current-line)))
7962 (persistent-help . "Show this line")))
7964 ;; (anything 'anything-c-source-mark-ring)
7966 ;;; Global-mark-ring
7967 (defvar anything-c-source-global-mark-ring
7968 '((name . "global-mark-ring")
7969 (candidates . anything-c-source-global-mark-ring-candidates)
7970 (action . (("Goto line"
7971 . (lambda (candidate)
7972 (let ((items (split-string candidate ":")))
7973 (anything-c-switch-to-buffer (second items))
7974 (anything-goto-line (string-to-number (car items))))))))
7975 (persistent-action . (lambda (candidate)
7976 (let ((items (split-string candidate ":")))
7977 (anything-c-switch-to-buffer (second items))
7978 (anything-goto-line (string-to-number (car items)))
7979 (anything-match-line-color-current-line))))
7980 (persistent-help . "Show this line")))
7982 (defun anything-c-source-global-mark-ring-candidates ()
7983 (flet ((buf-fn (m)
7984 (with-current-buffer (marker-buffer m)
7985 (goto-char m)
7986 (beginning-of-line)
7987 (let (line)
7988 (if (string= "" line)
7989 (setq line "<EMPTY LINE>")
7990 (setq line (car (split-string (thing-at-point 'line)
7991 "[\n\r]"))))
7992 (format "%7d:%s: %s"
7993 (line-number-at-pos) (marker-buffer m) line)))))
7994 (loop
7995 with marks = global-mark-ring
7996 with recip = nil
7997 for i in marks
7998 for gm = (unless (or (string-match
7999 "^ " (format "%s" (marker-buffer i)))
8000 (null (marker-buffer i)))
8001 (buf-fn i))
8002 when (and gm (not (member gm recip)))
8003 collect gm into recip
8004 finally return recip)))
8006 ;; (anything 'anything-c-source-global-mark-ring)
8009 ;;;; <Register>
8010 ;;; Insert from register
8011 (defvar anything-c-source-register
8012 '((name . "Registers")
8013 (candidates . anything-c-register-candidates)
8014 (action-transformer . anything-c-register-action-transformer)
8015 (multiline)
8016 (action))
8017 "See (info \"(emacs)Registers\")")
8019 (defun anything-c-register-candidates ()
8020 "Collecting register contents and appropriate commands."
8021 (loop for (char . val) in register-alist
8022 for key = (single-key-description char)
8023 for string-actions =
8024 (cond
8025 ((numberp val)
8026 (list (int-to-string val)
8027 'insert-register
8028 'increment-register))
8029 ((markerp val)
8030 (let ((buf (marker-buffer val)))
8031 (if (null buf)
8032 (list "a marker in no buffer")
8033 (list (concat
8034 "a buffer position:"
8035 (buffer-name buf)
8036 ", position "
8037 (int-to-string (marker-position val)))
8038 'jump-to-register
8039 'insert-register))))
8040 ((and (consp val) (window-configuration-p (car val)))
8041 (list "window configuration."
8042 'jump-to-register))
8043 ((and (consp val) (frame-configuration-p (car val)))
8044 (list "frame configuration."
8045 'jump-to-register))
8046 ((and (consp val) (eq (car val) 'file))
8047 (list (concat "file:"
8048 (prin1-to-string (cdr val))
8049 ".")
8050 'jump-to-register))
8051 ((and (consp val) (eq (car val) 'file-query))
8052 (list (concat "file:a file-query reference: file "
8053 (car (cdr val))
8054 ", position "
8055 (int-to-string (car (cdr (cdr val))))
8056 ".")
8057 'jump-to-register))
8058 ((consp val)
8059 (let ((lines (format "%4d" (length val))))
8060 (list (format "%s: %s\n" lines
8061 (truncate-string-to-width
8062 (mapconcat 'identity (list (car val))
8063 ;; (mapconcat (lambda (y) y) val
8064 "^J") (- (window-width) 15)))
8065 'insert-register)))
8066 ((stringp val)
8067 (list ;; without properties
8068 (substring-no-properties val)
8069 'insert-register
8070 'append-to-register
8071 'prepend-to-register))
8073 "GARBAGE!"))
8074 collect (cons (format "register %3s: %s" key (car string-actions))
8075 (cons char (cdr string-actions)))))
8077 (defun anything-c-register-action-transformer (actions register-and-functions)
8078 "Decide actions by the contents of register."
8079 (loop with func-actions =
8080 '((insert-register
8081 "Insert Register" .
8082 (lambda (c) (insert-register (car c))))
8083 (jump-to-register
8084 "Jump to Register" .
8085 (lambda (c) (jump-to-register (car c))))
8086 (append-to-register
8087 "Append Region to Register" .
8088 (lambda (c) (append-to-register
8089 (car c) (region-beginning) (region-end))))
8090 (prepend-to-register
8091 "Prepend Region to Register" .
8092 (lambda (c) (prepend-to-register
8093 (car c) (region-beginning) (region-end))))
8094 (increment-register
8095 "Increment Prefix Arg to Register" .
8096 (lambda (c) (increment-register
8097 anything-current-prefix-arg (car c)))))
8098 for func in (cdr register-and-functions)
8099 for cell = (assq func func-actions)
8100 when cell
8101 collect (cdr cell)))
8103 ;; (anything 'anything-c-source-register)
8106 ;;; Latex completion
8107 (defun anything-c-latex-math-candidates ()
8108 "Collect candidates for latex math completion."
8109 (declare (special LaTeX-math-menu))
8110 (loop for i in (cddr LaTeX-math-menu)
8111 for elm = (loop for s in i when (vectorp s)
8112 collect (cons (aref s 0) (aref s 1)))
8113 append elm))
8115 (defvar anything-c-source-latex-math
8116 '((name . "Latex Math Menu")
8117 (init . (lambda ()
8118 (with-anything-current-buffer
8119 (LaTeX-math-mode 1))))
8120 (candidate-number-limit . 9999)
8121 (candidates . anything-c-latex-math-candidates)
8122 (action . (lambda (candidate)
8123 (call-interactively candidate)))))
8126 ;;;; <Headline Extraction>
8127 (defvar anything-c-source-fixme
8128 '((name . "TODO/FIXME/DRY comments")
8129 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
8130 (adjust)
8131 (recenter))
8132 "Show TODO/FIXME/DRY comments in current file.")
8133 ;; (anything 'anything-c-source-fixme)
8135 (defvar anything-c-source-rd-headline
8136 '((name . "RD HeadLine")
8137 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
8138 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
8139 (migemo)
8140 (subexp . 1))
8141 "Show RD headlines.
8143 RD is Ruby's POD.
8144 http://en.wikipedia.org/wiki/Ruby_Document_format")
8145 ;; (anything 'anything-c-source-rd-headline)
8147 (defvar anything-c-source-oddmuse-headline
8148 '((name . "Oddmuse HeadLine")
8149 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
8150 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
8151 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
8152 (migemo)
8153 (subexp . 1))
8154 "Show Oddmuse headlines, such as EmacsWiki.")
8155 ;; (anything 'anything-c-source-oddmuse-headline)
8157 (defvar anything-c-source-emacs-source-defun
8158 '((name . "Emacs Source DEFUN")
8159 (headline . "DEFUN\\|DEFVAR")
8160 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
8161 (or buffer-file-name ""))))
8162 "Show DEFUN/DEFVAR in Emacs C source file.")
8163 ;; (anything 'anything-c-source-emacs-source-defun)
8165 (defvar anything-c-source-emacs-lisp-expectations
8166 '((name . "Emacs Lisp Expectations")
8167 (headline . "(desc[ ]\\|(expectations")
8168 (condition . (eq major-mode 'emacs-lisp-mode)))
8169 "Show descriptions (desc) in Emacs Lisp Expectations.
8171 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8172 ;; (anything 'anything-c-source-emacs-lisp-expectations)
8174 (defvar anything-c-source-emacs-lisp-toplevels
8175 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
8176 (headline . "^(\\|(@\\*\\|^;;;;")
8177 (get-line . buffer-substring)
8178 (condition . (eq major-mode 'emacs-lisp-mode))
8179 (adjust))
8180 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
8181 linkd.el is optional because linkd stars are extracted by regexp.
8182 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
8183 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
8186 ;;; Anything yaoddmuse
8188 ;; Be sure to have yaoddmuse.el installed
8189 ;; install-elisp may be required if you want to install elisp file from here.
8190 (defvar anything-yaoddmuse-use-cache-file nil)
8191 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
8192 (defvar anything-c-yaoddmuse-ew-cache nil)
8194 (defun anything-yaoddmuse-get-candidates ()
8195 (declare (special yaoddmuse-pages-hash))
8196 (if anything-yaoddmuse-use-cache-file
8197 (ignore-errors
8198 (unless anything-c-yaoddmuse-ew-cache
8199 (load anything-c-yaoddmuse-cache-file)
8200 (setq anything-c-yaoddmuse-ew-cache
8201 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8202 anything-c-yaoddmuse-ew-cache)
8203 (yaoddmuse-update-pagename t)
8204 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8206 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
8207 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
8208 (candidates . anything-yaoddmuse-get-candidates)
8209 (action . (("Edit page" . (lambda (candidate)
8210 (yaoddmuse-edit "EmacsWiki" candidate)))
8211 ("Browse page"
8212 . (lambda (candidate)
8213 (yaoddmuse-browse-page "EmacsWiki" candidate)))
8214 ("Browse page other window"
8215 . (lambda (candidate)
8216 (if (one-window-p)
8217 (split-window-vertically))
8218 (yaoddmuse-browse-page "EmacsWiki" candidate)))
8219 ("Browse diff"
8220 . (lambda (candidate)
8221 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
8222 ("Copy URL"
8223 . (lambda (candidate)
8224 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
8225 (message "Have copy page %s's URL to yank." candidate)))
8226 ("Create page"
8227 . (lambda (candidate)
8228 (yaoddmuse-edit "EmacsWiki" anything-input)))
8229 ("Update cache"
8230 . (lambda (candidate)
8231 (if anything-yaoddmuse-use-cache-file
8232 (progn
8233 (anything-yaoddmuse-cache-pages t)
8234 (setq anything-c-yaoddmuse-ew-cache
8235 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8236 (yaoddmuse-update-pagename))))))
8237 (action-transformer anything-c-yaoddmuse-action-transformer))
8238 "Needs yaoddmuse.el.
8240 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8242 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
8244 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
8245 '((name . "Yaoddmuse Post library (EmacsWiki)")
8246 (init . (anything-yaoddmuse-init))
8247 (candidates-in-buffer)
8248 (action . (("Post library and Browse"
8249 . (lambda (candidate)
8250 (yaoddmuse-post-file
8251 (find-library-name candidate)
8252 "EmacsWiki"
8253 (file-name-nondirectory (find-library-name candidate))
8254 nil t)))
8255 ("Post library"
8256 . (lambda (candidate)
8257 (yaoddmuse-post-file
8258 (find-library-name candidate)
8259 "EmacsWiki"
8260 (file-name-nondirectory
8261 (find-library-name candidate))))))))
8262 "Needs yaoddmuse.el.
8264 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8266 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
8268 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
8269 "Allow the use of `install-elisp' only on elisp files."
8270 (if (string-match "\.el$" candidate)
8271 (append actions '(("Install Elisp"
8272 . (lambda (elm)
8273 (install-elisp-from-emacswiki elm)))))
8274 actions))
8276 ;;;###autoload
8277 (defun anything-yaoddmuse-cache-pages (&optional load)
8278 "Fetch the list of files on emacswiki and create cache file.
8279 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
8280 (interactive)
8281 (declare (special yaoddmuse-pages-hash))
8282 (yaoddmuse-update-pagename)
8283 (save-excursion
8284 (find-file anything-c-yaoddmuse-cache-file)
8285 (erase-buffer)
8286 (insert "(puthash \"EmacsWiki\" '(")
8287 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
8289 (insert (concat "(\"" (car i) "\") ")))
8290 (insert ") yaoddmuse-pages-hash)\n")
8291 (save-buffer)
8292 (kill-buffer (current-buffer))
8293 (when (or current-prefix-arg
8294 load)
8295 (load anything-c-yaoddmuse-cache-file))))
8297 (defun anything-yaoddmuse-init ()
8298 "Init anything buffer status."
8299 (let ((anything-buffer (anything-candidate-buffer 'global))
8300 (library-list (yaoddmuse-get-library-list)))
8301 (with-current-buffer anything-buffer
8302 ;; Insert library name.
8303 (dolist (library library-list)
8304 (insert (format "%s\n" library)))
8305 ;; Sort lines.
8306 (sort-lines nil (point-min) (point-max)))))
8309 ;;; Eev anchors
8310 (defvar anything-c-source-eev-anchor
8311 '((name . "Anchors")
8312 (candidates
8313 . (lambda ()
8314 (ignore-errors
8315 (with-anything-current-buffer
8316 (loop initially (goto-char (point-min))
8317 while (re-search-forward
8318 (format ee-anchor-format "\\([^\.].+\\)") nil t)
8319 for anchor = (match-string-no-properties 1)
8320 collect (cons (format "%5d:%s"
8321 (line-number-at-pos (match-beginning 0))
8322 (format ee-anchor-format anchor))
8323 anchor))))))
8324 (persistent-action . (lambda (item)
8325 (ee-to item)
8326 (anything-match-line-color-current-line)))
8327 (persistent-help . "Show this entry")
8328 (action . (("Goto link" . ee-to)))))
8329 ;; (anything 'anything-c-source-eev-anchor)
8332 ;;; Org headlines
8335 (defvar anything-c-source-org-headline
8336 '((name . "Org HeadLine")
8337 (headline "^\\*\\{1,8\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
8338 (condition . (eq major-mode 'org-mode))
8339 (migemo)
8340 (subexp . 1)
8341 (persistent-action . (lambda (elm)
8342 (anything-c-action-line-goto elm)
8343 (org-cycle)))
8344 (action-transformer
8345 . (lambda (actions candidate)
8346 '(("Go to Line" . anything-c-action-line-goto)
8347 ("Insert Link to This Headline"
8348 . anything-c-org-headline-insert-link-to-headline)))))
8349 "Show Org headlines.
8350 org-mode is very very much extended text-mode/outline-mode.
8352 See (find-library \"org.el\")
8353 See http://orgmode.org for the latest version.")
8355 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
8356 (insert
8357 (save-excursion
8358 (anything-goto-line (car lineno-and-content))
8359 (and (looking-at org-complex-heading-regexp)
8360 (org-make-link-string (concat "*" (match-string 4)))))))
8361 ;; (anything 'anything-c-source-org-headline)
8363 ;;; Org keywords
8366 (defvar anything-c-source-org-keywords
8367 '((name . "Org Keywords")
8368 (init . anything-c-org-keywords-init)
8369 (candidates . anything-c-org-keywords-candidates)
8370 (action . anything-c-org-keywords-insert)
8371 (persistent-action . anything-c-org-keywords-show-help)
8372 (persistent-help . "Show an example and info page to describe this keyword.")
8373 (keywords-examples)
8374 (keywords)))
8375 ;; (anything 'anything-c-source-org-keywords)
8377 (defvar anything-c-org-keywords-info-location
8378 '(("#+TITLE:" . "(org)Export options")
8379 ("#+AUTHOR:" . "(org)Export options")
8380 ("#+DATE:" . "(org)Export options")
8381 ("#+EMAIL:" . "(org)Export options")
8382 ("#+DESCRIPTION:" . "(org)Export options")
8383 ("#+KEYWORDS:" . "(org)Export options")
8384 ("#+LANGUAGE:" . "(org)Export options")
8385 ("#+TEXT:" . "(org)Export options")
8386 ("#+TEXT:" . "(org)Export options")
8387 ("#+OPTIONS:" . "(org)Export options")
8388 ("#+BIND:" . "(org)Export options")
8389 ("#+LINK_UP:" . "(org)Export options")
8390 ("#+LINK_HOME:" . "(org)Export options")
8391 ("#+LATEX_HEADER:" . "(org)Export options")
8392 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
8393 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
8394 ("#+INFOJS_OPT" . "(org)Javascript support")
8395 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
8396 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
8397 ("#+ORGTBL" . "(org)Radio tables")
8398 ("#+HTML:" . "(org)Quoting HTML tags")
8399 ("#+LaTeX:" . "(org)Quoting LaTeX code")
8400 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
8401 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
8402 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
8403 ("#+BEGIN_VERSE" . "(org)Paragraphs")
8404 ("#+BEGIN_SRC" . "(org)Literal examples")
8405 ("#+CAPTION" . "(org)Tables in HTML export")
8406 ("#+LABEL" . "(org)Tables in LaTeX export")
8407 ("#+ATTR_HTML" . "(org)Links")
8408 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
8410 (defun anything-c-org-keywords-init ()
8411 (unless (anything-attr 'keywords-examples)
8412 (require 'org)
8413 (anything-attrset 'keywords-examples
8414 (append
8415 (mapcar
8416 (lambda (x)
8417 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8418 (cons (match-string 2 x) (match-string 1 x)))
8419 (org-split-string (org-get-current-options) "\n"))
8420 (mapcar 'list org-additional-option-like-keywords)))
8421 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
8423 (defun anything-c-org-keywords-candidates ()
8424 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
8425 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
8426 (anything-attr 'keywords)))
8428 (defun anything-c-org-keywords-insert (keyword)
8429 (cond ((and (string-match "BEGIN" keyword)
8430 (anything-region-active-p))
8431 (let ((beg (region-beginning))
8432 (end (region-end)))
8433 (goto-char end)
8434 (insert "\n#+" (replace-regexp-in-string
8435 "BEGIN" "END" keyword) "\n")
8436 (goto-char beg)
8437 (insert "#+" keyword " ")
8438 (save-excursion (insert "\n"))))
8439 ((string-match "BEGIN" keyword)
8440 (insert "#+" keyword " ")
8441 (save-excursion
8442 (insert "\n#+" (replace-regexp-in-string
8443 "BEGIN" "END" keyword) "\n")))
8444 (t (insert "#+" keyword " "))))
8446 (defun anything-c-org-keywords-show-help (keyword)
8447 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
8448 "(org)In-buffer settings"))
8449 (search-forward (concat "#+" keyword) nil t)
8450 (anything-persistent-highlight-point)
8451 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8455 ;;; bbdb
8458 (defvar bbdb-records)
8459 (defvar bbdb-buffer-name)
8461 (defun anything-c-bbdb-candidates ()
8462 "Return a list of all names in the bbdb database. The format
8463 is \"Firstname Lastname\"."
8464 (mapcar (lambda (bbdb-record)
8465 (replace-regexp-in-string
8466 "\\s-+$" ""
8467 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8468 (bbdb-records)))
8470 (defun anything-c-bbdb-create-contact (actions candidate)
8471 "Action transformer that returns only an entry to add the
8472 current `anything-pattern' as new contact. All other actions are
8473 removed."
8474 (if (string= candidate "*Add to contacts*")
8475 '(("Add to contacts" . (lambda (actions)
8476 (bbdb-create-internal
8477 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8478 (read-from-minibuffer "Company: ")
8479 (read-from-minibuffer "Email: ")
8482 (read-from-minibuffer "Note: ")))))
8483 actions))
8485 (defun anything-c-bbdb-get-record (candidate)
8486 "Return record that match CANDIDATE."
8487 (bbdb candidate nil)
8488 (set-buffer "*BBDB*")
8489 (bbdb-current-record))
8491 (defvar anything-c-bbdb-name nil
8492 "Only for internal use.")
8494 (defvar anything-c-source-bbdb
8495 '((name . "BBDB")
8496 (candidates . anything-c-bbdb-candidates)
8497 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8498 ("View person's data" . anything-c-bbdb-view-person-action))
8499 (filtered-candidate-transformer . (lambda (candidates source)
8500 (setq anything-c-bbdb-name anything-pattern)
8501 (if (not candidates)
8502 (list "*Add to contacts*")
8503 candidates)))
8504 (action-transformer . (lambda (actions candidate)
8505 (anything-c-bbdb-create-contact actions candidate))))
8506 "Needs BBDB.
8508 http://bbdb.sourceforge.net/")
8509 ;; (anything 'anything-c-source-bbdb)
8511 (defun anything-c-bbdb-view-person-action (candidate)
8512 "View BBDB data of single CANDIDATE or marked candidates."
8513 (anything-aif (anything-marked-candidates)
8514 (let ((bbdb-append-records (length it)))
8515 (dolist (i it)
8516 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8517 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8519 (defun anything-c-bbdb-collect-mail-addresses ()
8520 "Return a list of all mail addresses of records in bbdb buffer."
8521 (with-current-buffer bbdb-buffer-name
8522 (loop for i in bbdb-records
8523 if (bbdb-record-net (car i))
8524 collect (bbdb-dwim-net-address (car i)))))
8526 (defun anything-c-bbdb-compose-mail (candidate)
8527 "Compose a mail with all records of bbdb buffer."
8528 (anything-c-bbdb-view-person-action candidate)
8529 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8530 (address-str (mapconcat 'identity address-list ",\n ")))
8531 (compose-mail address-str)))
8534 ;;; Evaluation Result
8537 ;; Internal
8538 (defvar anything-eldoc-active-minibuffers-list nil)
8540 (defvar anything-c-source-evaluation-result
8541 '((name . "Evaluation Result")
8542 (disable-shortcuts)
8543 (dummy)
8544 (multiline)
8545 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8546 (filtered-candidate-transformer . (lambda (candidates source)
8547 (list
8548 (condition-case nil
8549 (with-anything-current-buffer
8550 (pp-to-string
8551 (eval (read anything-pattern))))
8552 (error "Error")))))
8553 (action . (("Copy result to kill-ring" . (lambda (candidate)
8554 (with-current-buffer anything-buffer
8555 (let ((end (save-excursion
8556 (goto-char (point-max))
8557 (search-backward "\n")
8558 (point))))
8559 (kill-region (point) end)))))
8560 ("copy sexp to kill-ring" . (lambda (candidate)
8561 (kill-new anything-input)))))))
8562 ;; (anything 'anything-c-source-evaluation-result)
8564 (defun anything-eval-new-line-and-indent ()
8565 (interactive)
8566 (newline) (lisp-indent-line))
8568 (defun anything-eldoc-store-minibuffer ()
8569 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8570 (with-selected-window (minibuffer-window)
8571 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8573 (defun anything-eldoc-show-in-eval ()
8574 "Return eldoc in mode-line for current minibuffer input."
8575 (let ((buf (with-selected-window (minibuffer-window)
8576 (buffer-name))))
8577 (when (member buf anything-eldoc-active-minibuffers-list)
8578 (let* ((str-all (with-current-buffer buf
8579 (minibuffer-completion-contents)))
8580 (sym (when str-all
8581 (with-temp-buffer
8582 (insert str-all)
8583 (goto-char (point-max))
8584 (unless (looking-back ")\\|\"") (forward-char -1))
8585 (eldoc-current-symbol))))
8586 (info-fn (eldoc-fnsym-in-current-sexp))
8587 (doc (or (eldoc-get-var-docstring sym)
8588 (eldoc-get-fnsym-args-string
8589 (car info-fn) (cadr info-fn)))))
8590 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8592 (defun anything-c-eldoc-show-in-mode-line (str)
8593 "Show string STR in mode-line."
8594 (save-window-excursion
8595 (with-current-buffer anything-buffer
8596 (let ((mode-line-format (concat " " str)))
8597 (force-mode-line-update)
8598 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8599 (force-mode-line-update))))
8601 ;;; Calculation Result
8604 (defvar anything-c-source-calculation-result
8605 '((name . "Calculation Result")
8606 (dummy)
8607 (filtered-candidate-transformer . (lambda (candidates source)
8608 (list
8609 (condition-case nil
8610 (calc-eval anything-pattern)
8611 (error "error")))))
8612 (action ("Copy result to kill-ring" . kill-new))))
8613 ;; (anything 'anything-c-source-calculation-result)
8616 ;;; Google Suggestions
8619 ;; Internal
8620 (defvar anything-ggs-max-length-real-flag 0)
8621 (defvar anything-ggs-max-length-num-flag 0)
8623 (defun anything-c-google-suggest-fetch (input)
8624 "Fetch suggestions for INPUT from XML buffer.
8625 Return an alist with elements like (data . number_results)."
8626 (setq anything-ggs-max-length-real-flag 0
8627 anything-ggs-max-length-num-flag 0)
8628 (let ((request (concat anything-c-google-suggest-url
8629 (url-hexify-string input))))
8630 (flet ((fetch ()
8631 (loop
8632 with result-alist = (xml-get-children
8633 (car (xml-parse-region
8634 (point-min) (point-max)))
8635 'CompleteSuggestion)
8636 for i in result-alist
8637 for data = (cdr (caadr (assoc 'suggestion i)))
8638 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8639 for lqueries = (length (anything-c-ggs-set-number-result
8640 nqueries))
8641 for ldata = (length data)
8643 (progn
8644 (when (> ldata anything-ggs-max-length-real-flag)
8645 (setq anything-ggs-max-length-real-flag ldata))
8646 (when (> lqueries anything-ggs-max-length-num-flag)
8647 (setq anything-ggs-max-length-num-flag lqueries)))
8648 collect (cons data nqueries) into cont
8649 finally return cont)))
8650 (if anything-google-suggest-use-curl-p
8651 (with-temp-buffer
8652 (call-process "curl" nil t nil request)
8653 (fetch))
8654 (with-current-buffer
8655 (url-retrieve-synchronously request)
8656 (fetch))))))
8658 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8659 "Set candidates with result and number of google results found."
8660 (let ((suggestions
8661 (loop with suggested-results = (anything-c-google-suggest-fetch
8662 (or (and request-prefix
8663 (concat request-prefix " " anything-pattern))
8664 anything-pattern))
8665 for (real . numresult) in suggested-results
8666 ;; Prepare number of results with ","
8667 for fnumresult = (anything-c-ggs-set-number-result numresult)
8668 ;; Calculate number of spaces to add before fnumresult
8669 ;; if it is smaller than longest result
8670 ;; `anything-ggs-max-length-num-flag'.
8671 ;; e.g 1,234,567
8672 ;; 345,678
8673 ;; To be sure it is aligned properly.
8674 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8675 (- anything-ggs-max-length-num-flag (length fnumresult))
8677 ;; Add now the spaces before fnumresult.
8678 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8679 for interval = (- anything-ggs-max-length-real-flag (length real))
8680 for spaces = (make-string (+ 2 interval) ? )
8681 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8682 collect (cons display real))))
8683 (if (loop for (disp . dat) in suggestions
8684 thereis (equal dat anything-pattern))
8685 suggestions
8686 ;; if there is no suggestion exactly matching the input then
8687 ;; prepend a Search on Google item to the list
8688 (append
8689 suggestions
8690 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8691 anything-input))))))
8693 (defun anything-c-ggs-set-number-result (num)
8694 (if num
8695 (progn
8696 (and (numberp num) (setq num (number-to-string num)))
8697 (loop for i in (reverse (split-string num "" t))
8698 for count from 1
8699 append (list i) into C
8700 when (= count 3)
8701 append (list ",") into C
8702 and do (setq count 0)
8703 finally return
8704 (replace-regexp-in-string
8705 "^," "" (mapconcat 'identity (reverse C) ""))))
8706 "?"))
8708 (defvar anything-c-google-suggest-default-browser-function nil
8709 "*The browse url function you prefer to use with google suggest.
8710 When nil, use the first browser function available
8711 See `anything-browse-url-default-browser-alist'.")
8713 (defun anything-c-google-suggest-action (candidate)
8714 "Default action to jump to a google suggested candidate."
8715 (let ((arg (concat anything-c-google-suggest-search-url
8716 (url-hexify-string candidate))))
8717 (anything-aif anything-c-google-suggest-default-browser-function
8718 (funcall it arg)
8719 (anything-c-browse-url arg))))
8721 (defvar anything-c-google-suggest-default-function
8722 'anything-c-google-suggest-set-candidates
8723 "Default function to use in anything google suggest.")
8725 (defvar anything-c-source-google-suggest
8726 '((name . "Google Suggest")
8727 (candidates . (lambda ()
8728 (funcall anything-c-google-suggest-default-function)))
8729 (action . (("Google Search" . anything-c-google-suggest-action)))
8730 (volatile)
8731 (requires-pattern . 3)
8732 (delayed)))
8734 (defun anything-c-google-suggest-emacs-lisp ()
8735 "Try to emacs lisp complete with google suggestions."
8736 (anything-c-google-suggest-set-candidates "emacs lisp"))
8738 ;; (anything 'anything-c-source-google-suggest)
8740 ;;; Yahoo suggestions
8743 (defun anything-c-yahoo-suggest-fetch (input)
8744 "Fetch Yahoo suggestions for INPUT from XML buffer.
8745 Return an alist with elements like (data . number_results)."
8746 (let ((request (concat anything-c-yahoo-suggest-url
8747 (url-hexify-string input))))
8748 (flet ((fetch ()
8749 (loop
8750 with result-alist = (xml-get-children
8751 (car (xml-parse-region (point-min) (point-max)))
8752 'Result)
8753 for i in result-alist
8754 collect (caddr i))))
8755 (with-current-buffer
8756 (url-retrieve-synchronously request)
8757 (fetch)))))
8759 (defun anything-c-yahoo-suggest-set-candidates ()
8760 "Set candidates with Yahoo results found."
8761 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8762 (or suggestions
8763 (append
8764 suggestions
8765 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8766 anything-input))))))
8768 (defun anything-c-yahoo-suggest-action (candidate)
8769 "Default action to jump to a Yahoo suggested candidate."
8770 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8771 (url-hexify-string candidate))))
8773 (defvar anything-c-source-yahoo-suggest
8774 '((name . "Yahoo Suggest")
8775 (candidates . anything-c-yahoo-suggest-set-candidates)
8776 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8777 (volatile)
8778 (requires-pattern . 3)
8779 (delayed)))
8781 ;; (anything 'anything-c-source-yahoo-suggest)
8784 ;;; Web browser functions.
8787 (require 'browse-url)
8788 ;; If default setting of `w3m-command' is not
8789 ;; what you want you and you modify it, you will have to reeval
8790 ;; also `anything-browse-url-default-browser-alist'.
8791 (defvar w3m-command "/usr/bin/w3m")
8792 (defvar anything-c-home-url "http://www.google.fr"
8793 "*Default url to use as home url.")
8795 (defvar browse-url-chromium-program "chromium-browser")
8796 (defvar browse-url-uzbl-program "uzbl-browser")
8797 (defvar anything-browse-url-default-browser-alist
8798 `((,w3m-command . w3m-browse-url)
8799 (,browse-url-firefox-program . browse-url-firefox)
8800 (,browse-url-chromium-program . browse-url-chromium)
8801 (,browse-url-uzbl-program . browse-url-uzbl)
8802 (,browse-url-kde-program . browse-url-kde)
8803 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8804 (,browse-url-mozilla-program . browse-url-mozilla)
8805 (,browse-url-galeon-program . browse-url-galeon)
8806 (,browse-url-netscape-program . browse-url-netscape)
8807 (,browse-url-mosaic-program . browse-url-mosaic)
8808 (,browse-url-xterm-program . browse-url-text-xterm))
8809 "*Alist of (executable . function) to try to find a suitable url browser.")
8811 (defun* anything-c-generic-browser (url name &rest args)
8812 "Browse URL with NAME browser."
8813 (let ((proc (concat name " " url)))
8814 (message "Starting %s..." name)
8815 (apply 'start-process proc nil name
8816 (append args (list url)))
8817 (set-process-sentinel
8818 (get-process proc)
8819 #'(lambda (process event)
8820 (when (string= event "finished\n")
8821 (message "%s process %s" process event))))))
8823 (defun browse-url-chromium (url)
8824 "Browse URL with google chrome browser."
8825 (interactive "sURL: ")
8826 (anything-c-generic-browser
8827 url browse-url-chromium-program))
8829 (defun browse-url-uzbl (url &optional ignore)
8830 "Browse URL with uzbl browser."
8831 (interactive "sURL: ")
8832 (anything-c-generic-browser url browse-url-uzbl-program "-u"))
8834 (defun anything-browse-url-default-browser (url &rest args)
8835 "Find the first available browser and ask it to load URL."
8836 (let ((default-browser-fn
8837 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8838 thereis (and exe (executable-find exe) fn))))
8839 (if default-browser-fn
8840 (apply default-browser-fn url args)
8841 (error "No usable browser found"))))
8843 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8844 "Default command to browse URL."
8845 (if browse-url-browser-function
8846 (browse-url url)
8847 (anything-browse-url-default-browser url)))
8850 ;;; Surfraw
8852 ;; Need external program surfraw.
8853 ;; <http://surfraw.alioth.debian.org/>
8855 (defvar anything-surfraw-default-browser-function nil
8856 "*The browse url function you prefer to use with surfraw.
8857 When nil, fallback to `browse-url-browser-function'.")
8859 ;; Internal
8860 (defvar anything-surfraw-engines-history nil)
8862 (defun anything-c-build-elvi-list ()
8863 "Return list of all engines and descriptions handled by surfraw."
8864 (cdr
8865 (with-temp-buffer
8866 (call-process "surfraw" nil t nil
8867 "-elvi")
8868 (split-string (buffer-string) "\n"))))
8871 ;;; Emms
8874 (defun anything-emms-stream-edit-bookmark (elm)
8875 "Change the information of current emms-stream bookmark from anything."
8876 (declare (special emms-stream-list))
8877 (let* ((cur-buf anything-current-buffer)
8878 (bookmark (assoc elm emms-stream-list))
8879 (name (read-from-minibuffer "Description: "
8880 (nth 0 bookmark)))
8881 (url (read-from-minibuffer "URL: "
8882 (nth 1 bookmark)))
8883 (fd (read-from-minibuffer "Feed Descriptor: "
8884 (int-to-string (nth 2 bookmark))))
8885 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8886 (format "%s" (car (last bookmark))))))
8887 (save-excursion
8888 (emms-streams)
8889 (when (re-search-forward (concat "^" name) nil t)
8890 (beginning-of-line)
8891 (emms-stream-delete-bookmark)
8892 (emms-stream-add-bookmark name url (string-to-number fd) type)
8893 (emms-stream-save-bookmarks-file)
8894 (emms-stream-quit)
8895 (anything-c-switch-to-buffer cur-buf)))))
8897 (defun anything-emms-stream-delete-bookmark (elm)
8898 "Delete an emms-stream bookmark from anything."
8899 (let* ((cur-buf anything-current-buffer)
8900 (bookmark (assoc elm emms-stream-list))
8901 (name (nth 0 bookmark)))
8902 (save-excursion
8903 (emms-streams)
8904 (when (re-search-forward (concat "^" name) nil t)
8905 (beginning-of-line)
8906 (emms-stream-delete-bookmark)
8907 (emms-stream-save-bookmarks-file)
8908 (emms-stream-quit)
8909 (anything-c-switch-to-buffer cur-buf)))))
8911 (defvar anything-c-source-emms-streams
8912 '((name . "Emms Streams")
8913 (init . (lambda ()
8914 (emms-stream-init)))
8915 (candidates . (lambda ()
8916 (declare (special emms-stream-list))
8917 (mapcar 'car emms-stream-list)))
8918 (action . (("Play" . (lambda (elm)
8919 (declare (special emms-stream-list))
8920 (let* ((stream (assoc elm emms-stream-list))
8921 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8922 (url (second stream)))
8923 (funcall fn url))))
8924 ("Delete" . anything-emms-stream-delete-bookmark)
8925 ("Edit" . anything-emms-stream-edit-bookmark)))
8926 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8927 ;; (anything 'anything-c-source-emms-streams)
8929 ;; Don't forget to set `emms-source-file-default-directory'
8930 (defvar anything-c-source-emms-dired
8931 '((name . "Music Directory")
8932 (candidates . (lambda ()
8933 (cddr (directory-files emms-source-file-default-directory))))
8934 (action .
8935 (("Play Directory" . (lambda (item)
8936 (emms-play-directory
8937 (expand-file-name
8938 item
8939 emms-source-file-default-directory))))
8940 ("Open dired in file's directory" . (lambda (item)
8941 (anything-c-open-dired
8942 (expand-file-name
8943 item
8944 emms-source-file-default-directory))))))
8945 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8946 ;; (anything 'anything-c-source-emms-dired)
8949 (defun anything-c-emms-files-modifier (candidates source)
8950 (let ((current-playlist (with-current-emms-playlist
8951 (loop
8952 with cur-list = (emms-playlist-tracks-in-region
8953 (point-min) (point-max))
8954 for i in cur-list
8955 collect (assoc-default 'name i)))))
8956 (loop for i in candidates
8957 if (member (cdr i) current-playlist)
8958 collect (cons (propertize (car i)
8959 'face 'anything-emms-playlist)
8960 (cdr i)) into lis
8961 else collect i into lis
8962 finally return lis)))
8964 (defun anything-c-emms-play-current-playlist ()
8965 "Play current playlist."
8966 (with-current-emms-playlist
8967 (emms-playlist-first)
8968 (emms-playlist-mode-play-smart)))
8970 (defvar anything-c-source-emms-files
8971 '((name . "Emms files")
8972 (candidates . (lambda ()
8973 (loop for v being the hash-values in emms-cache-db
8974 for name = (assoc-default 'name v)
8975 for artist = (or (assoc-default 'info-artist v) "unknown")
8976 for genre = (or (assoc-default 'info-genre v) "unknown")
8977 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8978 for song = (or (assoc-default 'info-title v) "unknown")
8979 for info = (concat artist " - " genre " - " tracknum ": " song)
8980 unless (string-match "^http:" name) collect (cons info name))))
8981 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8982 (action . (("Play file" . emms-play-file)
8983 ("Add to Playlist and play (C-u clear current)"
8984 . (lambda (candidate)
8985 (when anything-current-prefix-arg
8986 (emms-playlist-current-clear))
8987 (emms-playlist-new)
8988 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8989 (unless emms-player-playing-p
8990 (anything-c-emms-play-current-playlist))))))))
8992 ;; (anything 'anything-c-source-emms-files)
8995 ;;; Jabber Contacts (jabber.el)
8996 (defun anything-c-jabber-online-contacts ()
8997 "List online Jabber contacts."
8998 (with-no-warnings
8999 (let (jids)
9000 (dolist (item (jabber-concat-rosters) jids)
9001 (when (get item 'connected)
9002 (push (if (get item 'name)
9003 (cons (get item 'name) item)
9004 (cons (symbol-name item) item)) jids))))))
9006 (defvar anything-c-source-jabber-contacts
9007 '((name . "Jabber Contacts")
9008 (init . (lambda () (require 'jabber)))
9009 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
9010 (action . (lambda (x)
9011 (jabber-chat-with
9012 (jabber-read-account)
9013 (symbol-name
9014 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
9015 ;; (anything 'anything-c-source-jabber-contacts)
9019 ;;; Call source.
9020 (defvar anything-source-select-buffer "*anything source select*")
9021 (defvar anything-c-source-call-source
9022 `((name . "Call anything source")
9023 (candidate-number-limit)
9024 (candidates
9025 . (lambda ()
9026 (loop for vname in (all-completions "anything-c-source-" obarray)
9027 for var = (intern vname)
9028 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
9029 if name collect
9030 (cons (format "%s `%s'"
9031 name (propertize vname 'face 'font-lock-variable-name-face))
9032 var))))
9033 (action
9034 . (("Invoke anything with selected source"
9036 (lambda (candidate)
9037 (setq anything-candidate-number-limit 9999)
9038 (anything candidate nil nil nil nil
9039 anything-source-select-buffer)))
9040 ("Describe variable" . describe-variable)
9041 ("Find variable" . find-variable)))
9042 (persistent-action . describe-variable)
9043 (persistent-help . "Show description of this source")))
9044 ;; (anything 'anything-c-source-call-source)
9046 (defun anything-call-source-from-anything ()
9047 "Call anything source within `anything' session."
9048 (interactive)
9049 (setq anything-input-idle-delay 0)
9050 (anything-set-sources '(anything-c-source-call-source)))
9052 ;;; Execute Preconfigured anything.
9053 (defvar anything-c-source-anything-commands
9054 '((name . "Preconfigured Anything")
9055 (candidates . anything-c-anything-commands-candidates)
9056 (type . command)
9057 (candidate-number-limit)))
9058 ;; (anything 'anything-c-source-anything-commands)
9060 (defun anything-c-anything-commands-candidates ()
9061 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
9062 collect (cons (if (where-is-internal cmd nil t)
9063 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
9064 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
9065 cmd)))
9068 ;;; Occur
9071 (defun anything-c-occur-init ()
9072 "Create the initial anything occur buffer.
9073 If region is active use region as buffer contents
9074 instead of whole buffer."
9075 (with-current-buffer (anything-candidate-buffer 'global)
9076 (erase-buffer)
9077 (let ((buf-contents
9078 (with-anything-current-buffer
9079 (if (anything-region-active-p)
9080 (buffer-substring (region-beginning) (region-end))
9081 (buffer-substring (point-min) (point-max))))))
9082 (insert buf-contents))))
9084 (defun anything-c-occur-get-line (s e)
9085 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
9087 (defun anything-c-occur-query-replace-regexp (candidate)
9088 "Query replace regexp starting from CANDIDATE.
9089 If region is active ignore CANDIDATE and replace only in region.
9090 With a prefix arg replace only matches surrounded by word boundaries,
9091 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
9092 (let ((regexp anything-input))
9093 (unless (anything-region-active-p)
9094 (anything-c-action-line-goto candidate))
9095 (apply 'query-replace-regexp
9096 (anything-c-query-replace-args regexp))))
9098 (defvar anything-c-source-occur
9099 '((name . "Occur")
9100 (init . anything-c-occur-init)
9101 (candidates-in-buffer)
9102 (migemo)
9103 (get-line . anything-c-occur-get-line)
9104 (display-to-real . anything-c-display-to-real-line)
9105 (action . (("Go to Line" . anything-c-action-line-goto)
9106 ("Query replace regexp (C-u Not inside word.)"
9107 . anything-c-occur-query-replace-regexp)))
9108 (recenter)
9109 (requires-pattern . 1)
9110 (delayed)
9111 (volatile)))
9112 ;; (anything 'anything-c-source-occur)
9115 ;;; Anything browse code.
9116 (defun anything-c-browse-code-get-line (beg end)
9117 "Select line if it match the regexp corresponding to current `major-mode'.
9118 Line is parsed for BEG position to END position."
9119 (let ((str-line (buffer-substring beg end))
9120 (regexp (assoc-default major-mode
9121 anything-c-browse-code-regexp-alist))
9122 (num-line (if (string= anything-pattern "") beg (1- beg))))
9123 (when (and regexp (string-match regexp str-line))
9124 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
9127 (defvar anything-c-source-browse-code
9128 '((name . "Browse code")
9129 (init . (lambda ()
9130 (anything-candidate-buffer anything-current-buffer)
9131 (with-anything-current-buffer
9132 (jit-lock-fontify-now))))
9133 (candidate-number-limit . 9999)
9134 (candidates-in-buffer)
9135 (get-line . anything-c-browse-code-get-line)
9136 (type . line)
9137 (recenter)))
9140 ;; Do many actions for input
9141 (defvar anything-c-source-create
9142 '((name . "Create")
9143 (dummy)
9144 (action)
9145 (action-transformer . anything-create--actions))
9146 "Do many create actions from `anything-pattern'.
9147 See also `anything-create--actions'.")
9148 ;; (anything 'anything-c-source-create)
9150 (defun anything-create-from-anything ()
9151 "Run `anything-create' from `anything' as a fallback."
9152 (interactive)
9153 (anything-run-after-quit 'anything-create nil anything-pattern))
9155 (defun anything-create--actions (&rest ignored)
9156 "Default actions for `anything-create' / `anything-c-source-create'."
9157 (remove-if-not
9158 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
9159 (append anything-create--actions-private
9160 '(("find-file" . find-file)
9161 ("find-file other window" . find-file-other-window)
9162 ("New buffer" . anything-c-switch-to-buffer)
9163 ("New buffer other window" . switch-to-buffer-other-window)
9164 ("Bookmark Set" . bookmark-set)
9165 ("Set Register" .
9166 (lambda (x) (set-register (read-char "Register: ") x)))
9167 ("Insert Linkd star" . linkd-insert-star)
9168 ("Insert Linkd Tag" . linkd-insert-tag)
9169 ("Insert Linkd Link" . linkd-insert-link)
9170 ("Insert Linkd Lisp" . linkd-insert-lisp)
9171 ("Insert Linkd Wiki" . linkd-insert-wiki)
9172 ("Google Search" . google)))))
9175 ;; Minibuffer History
9178 (defvar anything-c-source-minibuffer-history
9179 '((name . "Minibuffer History")
9180 (header-name . (lambda (name)
9181 (format "%s (%s)" name minibuffer-history-variable)))
9182 (candidates
9183 . (lambda ()
9184 (let ((history (loop
9185 for i in (symbol-value minibuffer-history-variable)
9186 unless (string= "" i) collect i)))
9187 (if (consp (car history))
9188 (mapcar 'prin1-to-string history)
9189 history))))
9190 (migemo)
9191 (action . insert)))
9192 ;; (anything 'anything-c-source-minibuffer-history)
9195 ;;; Elscreen
9198 (defvar anything-c-source-elscreen
9199 '((name . "Elscreen")
9200 (candidates . (lambda ()
9201 (if (cdr (elscreen-get-screen-to-name-alist))
9202 (sort
9203 (loop for sname in (elscreen-get-screen-to-name-alist)
9204 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
9205 finally (return lst))
9206 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
9207 (action . (("Change Screen".
9208 (lambda (candidate)
9209 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
9210 ("Kill Screen(s)".
9211 (lambda (candidate)
9212 (dolist (i (anything-marked-candidates))
9213 (elscreen-goto (- (aref i 1) (aref "0" 0)))
9214 (elscreen-kill))))
9215 ("Only Screen".
9216 (lambda (candidate)
9217 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
9218 (elscreen-kill-others)))))))
9219 ;; (anything 'anything-c-source-elscreen)
9222 ;;;; <System>
9224 ;;; Top (process)
9225 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
9226 "Top command (batch mode). %s is replaced with `frame-width'.")
9227 (defvar anything-c-source-top
9228 '((name . "Top (Press C-c C-u to refresh)")
9229 (init . anything-c-top-init)
9230 (candidates-in-buffer)
9231 (display-to-real . anything-c-top-display-to-real)
9232 (update . anything-c-top-update)
9233 (persistent-action . anything-c-top-sh-persistent-action)
9234 (persistent-help . "SIGTERM")
9235 (action
9236 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
9237 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
9238 ("Copy PID" . (lambda (pid) (kill-new pid))))))
9239 ;; (anything 'anything-c-source-top)
9241 (defun anything-c-top-sh (cmd)
9242 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
9244 (defun anything-c-top-sh-persistent-action (pid)
9245 (delete-other-windows)
9246 (anything-c-top-sh (format "kill -TERM %s" pid))
9247 (anything-force-update))
9249 (defun anything-c-top-init ()
9250 (with-current-buffer (anything-candidate-buffer 'global)
9251 (call-process-shell-command
9252 (format anything-c-top-command
9253 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
9254 nil (current-buffer))))
9256 (defun anything-c-top-display-to-real (line)
9257 (car (split-string line)))
9259 (defun anything-c-top-update ()
9260 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
9261 (anything-c-top-init)))
9263 ;;; Timers
9264 (defvar anything-c-source-absolute-time-timers
9265 '((name . "Absolute Time Timers")
9266 (candidates . timer-list)
9267 (type . timer)))
9268 ;; (anything 'anything-c-source-absolute-time-timers)
9270 (defvar anything-c-source-idle-time-timers
9271 '((name . "Idle Time Timers")
9272 (candidates . timer-idle-list)
9273 (type . timer)))
9274 ;; (anything 'anything-c-source-idle-time-timers)
9276 (defun anything-c-timer-real-to-display (timer)
9277 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
9278 (append timer nil) ;use `append' to convert vector->list
9279 (format "%s repeat=%5S %s(%s)"
9280 (let ((time (list t1 t2 t3)))
9281 (if idle-delay
9282 (format-time-string "idle-for=%5s" time)
9283 (format-time-string "%m/%d %T" time)))
9284 repeat-delay
9285 func
9286 (mapconcat 'prin1-to-string args " "))))
9288 ;;; X RandR resolution change
9289 ;;; FIXME I do not care multi-display.
9290 (defvar anything-c-xrandr-output "VGA")
9291 (defvar anything-c-xrandr-screen "0")
9292 (defvar anything-c-source-xrandr-change-resolution
9293 '((name . "Change Resolution")
9294 (candidates
9295 . (lambda ()
9296 (with-temp-buffer
9297 (call-process "xrandr" nil (current-buffer) nil
9298 "--screen" anything-c-xrandr-screen "-q")
9299 (goto-char 1)
9300 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
9301 collect (match-string 1)))))
9302 (action
9303 ("Change Resolution" . (lambda (mode)
9304 (call-process "xrandr" nil nil nil
9305 "--screen" anything-c-xrandr-screen
9306 "--output" anything-c-xrandr-output
9307 "--mode" mode))))))
9308 ;; (anything 'anything-c-source-xrandr-change-resolution)
9310 ;;; Xfont selection
9313 (defun anything-c-persistent-xfont-action (elm)
9314 "Show current font temporarily"
9315 (let ((current-font (cdr (assoc 'font (frame-parameters))))
9316 (default-font elm))
9317 (unwind-protect
9318 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
9319 (set-frame-font current-font))))
9321 (defvar anything-c-xfonts-cache nil)
9322 (defvar anything-c-source-xfonts
9323 '((name . "X Fonts")
9324 (init . (lambda ()
9325 (unless anything-c-xfonts-cache
9326 (setq anything-c-xfonts-cache
9327 (x-list-fonts "*")))))
9328 (candidates . anything-c-xfonts-cache)
9329 (action . (("Copy to kill ring" . (lambda (elm)
9330 (kill-new elm)))
9331 ("Set Font" . (lambda (elm)
9332 (kill-new elm)
9333 (set-frame-font elm 'keep-size)
9334 (message "New font have been copied to kill ring")))))
9335 (persistent-action . anything-c-persistent-xfont-action)
9336 (persistent-help . "Switch to this font temporarily")))
9337 ;; (anything 'anything-c-source-xfonts)
9339 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
9342 (defvar anything-c-ucs-max-len 0)
9343 (defun anything-c-calculate-ucs-max-len ()
9344 "Calculate the length of longest `ucs-names' candidate."
9345 (loop with count = 0
9346 for (n . v) in (ucs-names)
9347 for len = (length n)
9348 if (> len count)
9349 do (setq count len)
9350 finally return count))
9352 (defun anything-c-ucs-init ()
9353 "Initialize an anything buffer with ucs symbols.
9354 Only math* symbols are collected."
9355 (unless (> anything-c-ucs-max-len 0)
9356 (setq anything-c-ucs-max-len
9357 (anything-c-calculate-ucs-max-len)))
9358 (with-current-buffer (anything-candidate-buffer
9359 (get-buffer-create "*anything ucs*"))
9360 ;; `ucs-names' fn will not run again, data is cached in
9361 ;; var `ucs-names'.
9362 (loop for (n . v) in (ucs-names)
9363 for len = (length n)
9364 for diff = (+ (- anything-c-ucs-max-len len) 2)
9365 unless (string= "" n)
9366 do (progn (insert (concat
9367 n ":"
9368 (make-string
9369 diff ? )))
9370 (ucs-insert v)
9371 (insert "\n")))))
9373 (defun anything-c-ucs-forward-char (candidate)
9374 (with-anything-current-buffer
9375 (forward-char 1)))
9377 (defun anything-c-ucs-backward-char (candidate)
9378 (with-anything-current-buffer
9379 (forward-char -1)))
9381 (defun anything-c-ucs-delete-backward (candidate)
9382 (with-anything-current-buffer
9383 (delete-char -1)))
9385 (defun anything-c-ucs-insert-char (candidate)
9386 (with-anything-current-buffer
9387 (insert
9388 (replace-regexp-in-string
9389 " " ""
9390 (cadr (split-string candidate ":"))))))
9392 (defun anything-c-ucs-persistent-insert ()
9393 (interactive)
9394 (anything-execute-persistent-action 'action-insert))
9396 (defun anything-c-ucs-persistent-forward ()
9397 (interactive)
9398 (anything-execute-persistent-action 'action-forward))
9400 (defun anything-c-ucs-persistent-backward ()
9401 (interactive)
9402 (anything-execute-persistent-action 'action-back))
9404 (defun anything-c-ucs-persistent-delete ()
9405 (interactive)
9406 (anything-execute-persistent-action 'action-delete))
9408 (defvar anything-c-source-ucs
9409 '((name . "Ucs names")
9410 (init . anything-c-ucs-init)
9411 (candidate-number-limit . 9999)
9412 (candidates-in-buffer)
9413 (mode-line . anything-c-ucs-mode-line-string)
9414 (action-insert . anything-c-ucs-insert-char)
9415 (action-forward . anything-c-ucs-forward-char)
9416 (action-back . anything-c-ucs-backward-char)
9417 (action-delete . anything-c-ucs-delete-backward)
9418 (action . (("Insert" . anything-c-ucs-insert-char)
9419 ("Forward char" . anything-c-ucs-forward-char)
9420 ("Backward char" . anything-c-ucs-backward-char)
9421 ("Delete char backward" . anything-c-ucs-delete-backward))))
9422 "Source for collecting `ucs-names' math symbols.")
9425 ;;; Emacs process
9428 (defvar anything-c-source-emacs-process
9429 '((name . "Emacs Process")
9430 (candidates . (lambda () (mapcar #'process-name (process-list))))
9431 (persistent-action . (lambda (elm)
9432 (delete-process (get-process elm))
9433 (anything-delete-current-selection)))
9434 (persistent-help . "Kill Process")
9435 (action ("Kill Process" . (lambda (elm)
9436 (delete-process (get-process elm)))))))
9437 ;; (anything 'anything-c-source-emacs-process)
9439 ;;; World time
9442 (defvar anything-c-source-time-world
9443 '((name . "Time World List")
9444 (init . (lambda ()
9445 (let ((anything-buffer (anything-candidate-buffer 'global)))
9446 (with-current-buffer anything-buffer
9447 (display-time-world-display display-time-world-list)))))
9448 (candidates-in-buffer)))
9452 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9455 (defvar anything-c-source-apt
9456 '((name . "APT")
9457 (init . anything-c-apt-init)
9458 (candidates-in-buffer)
9459 (candidate-transformer anything-c-apt-candidate-transformer)
9460 (display-to-real . anything-c-apt-display-to-real)
9461 (requires-pattern . 2)
9462 (delayed)
9463 (action
9464 ("Show package description" . anything-c-apt-cache-show)
9465 ("Install package" . anything-c-apt-install)
9466 ("Remove package" . anything-c-apt-uninstall)
9467 ("Purge package" . anything-c-apt-purge))
9468 (persistent-action . anything-c-apt-persistent-action)
9469 (persistent-help . "Show - C-u Refresh")))
9470 ;; (anything 'anything-c-source-apt)
9472 (defvar anything-c-apt-query "emacs")
9473 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9474 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9475 (defvar anything-c-apt-installed-packages nil)
9476 (defvar anything-c-apt-all-packages nil)
9479 (defun anything-c-apt-refresh ()
9480 "Refresh installed candidates list."
9481 (setq anything-c-apt-installed-packages nil)
9482 (setq anything-c-apt-all-packages nil)
9483 (anything-force-update))
9485 (defun anything-c-apt-persistent-action (candidate)
9486 "Persistent action for APT source."
9487 (if current-prefix-arg
9488 (anything-c-apt-refresh)
9489 (anything-c-apt-cache-show candidate)))
9491 (defun anything-c-apt-candidate-transformer (candidates)
9492 "Show installed candidates in a different color."
9493 (loop
9494 with all
9495 for cand in candidates
9496 for name = (anything-c-apt-display-to-real cand)
9497 if (member name anything-c-apt-installed-packages)
9498 collect (propertize cand 'face 'anything-apt-installed) into all
9499 else collect cand into all finally return all))
9501 (defun anything-c-apt-init ()
9502 "Initialize list of debian packages."
9503 (let ((query ""))
9504 (unless (and anything-c-apt-installed-packages
9505 anything-c-apt-all-packages)
9506 (message "Loading package list...")
9507 (setq anything-c-apt-installed-packages
9508 (with-temp-buffer
9509 (call-process-shell-command "dpkg --get-selections"
9510 nil (current-buffer))
9511 (loop for i in (split-string (buffer-string) "\n" t)
9512 collect (car (split-string i)))))
9513 (setq anything-c-apt-all-packages
9514 (with-current-buffer
9515 (anything-candidate-buffer
9516 (get-buffer-create (format "*anything-apt*")))
9517 (erase-buffer)
9518 (call-process-shell-command
9519 (format anything-c-apt-search-command query)
9520 nil (current-buffer))))
9521 (message "Loading package list done")
9522 (sit-for 0.5))))
9524 (defun anything-c-apt-display-to-real (line)
9525 "Return only name of a debian package.
9526 LINE is displayed like:
9527 package name - description."
9528 (car (split-string line " - ")))
9530 (defun anything-c-shell-command-if-needed (command)
9531 "Run shell command COMMAND to describe package.
9532 If a buffer named COMMAND already exists, just switch to it."
9533 (let ((buf (get-buffer command)))
9534 (anything-c-switch-to-buffer (get-buffer-create command))
9535 (unless buf (insert (shell-command-to-string command)))))
9537 (defun anything-c-apt-cache-show (package)
9538 "Show information on apt package PACKAGE."
9539 (anything-c-shell-command-if-needed
9540 (format anything-c-apt-show-command package)))
9542 (defun anything-c-apt-install (package)
9543 "Run 'apt-get install' shell command on PACKAGE."
9544 (anything-c-apt-generic-action :action 'install))
9546 (defun anything-c-apt-uninstall (package)
9547 "Run 'apt-get remove' shell command on PACKAGE."
9548 (anything-c-apt-generic-action :action 'uninstall))
9550 (defun anything-c-apt-purge (package)
9551 "Run 'apt-get purge' shell command on PACKAGE."
9552 (anything-c-apt-generic-action :action 'purge))
9554 (defun* anything-c-apt-generic-action (&key action)
9555 "Run 'apt-get ACTION'.
9556 Support install, remove and purge actions."
9557 (ansi-term (getenv "SHELL") "anything apt")
9558 (term-line-mode)
9559 (let ((command (case action
9560 ('install "sudo apt-get install ")
9561 ('uninstall "sudo apt-get remove ")
9562 ('purge "sudo apt-get purge ")
9563 (t (error "Unknow action"))))
9564 (beg (point))
9566 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9567 (anything-marked-candidates) " ")))
9568 (goto-char (point-max))
9569 (insert (concat command cand-list))
9570 (setq end (point))
9571 (if (y-or-n-p (format "%s package" (symbol-name action)))
9572 (progn
9573 (setq anything-c-external-commands-list nil)
9574 (setq anything-c-apt-installed-packages nil)
9575 (term-char-mode) (term-send-input))
9576 (delete-region beg end) (term-send-eof) (kill-buffer))))
9578 ;; (anything-c-apt-install "jed")
9581 ;;; Anything UI for gentoo portage.
9584 (defvar anything-c-gentoo-use-flags nil)
9585 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9586 (defvar anything-c-cache-gentoo nil)
9587 (defvar anything-c-cache-world nil)
9588 (defvar anything-c-source-gentoo
9589 '((name . "Portage sources")
9590 (init . (lambda ()
9591 (get-buffer-create anything-c-gentoo-buffer)
9592 (unless anything-c-cache-gentoo
9593 (anything-c-gentoo-setup-cache))
9594 (unless anything-c-cache-world
9595 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9596 (anything-c-gentoo-init-list)))
9597 (candidates-in-buffer)
9598 (match . identity)
9599 (candidate-transformer anything-c-highlight-world)
9600 (action . (("Show package" . (lambda (elm)
9601 (anything-c-gentoo-eshell-action elm "eix")))
9602 ("Show history" . (lambda (elm)
9603 (if (member elm anything-c-cache-world)
9604 (anything-c-gentoo-eshell-action elm "genlop -qe")
9605 (message "No infos on packages not yet installed"))))
9606 ("Copy in kill-ring" . kill-new)
9607 ("insert at point" . insert)
9608 ("Browse HomePage" . (lambda (elm)
9609 (let ((urls (anything-c-gentoo-get-url elm)))
9610 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9611 ("Show extra infos" . (lambda (elm)
9612 (if (member elm anything-c-cache-world)
9613 (anything-c-gentoo-eshell-action elm "genlop -qi")
9614 (message "No infos on packages not yet installed"))))
9615 ("Show use flags" . (lambda (elm)
9616 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9617 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9618 (font-lock-mode 1)))
9619 ("Run emerge pretend" . (lambda (elm)
9620 (anything-c-gentoo-eshell-action elm "emerge -p")))
9621 ("Emerge" . (lambda (elm)
9622 (anything-gentoo-install elm :action 'install)))
9623 ("Unmerge" . (lambda (elm)
9624 (anything-gentoo-install elm :action 'uninstall)))
9625 ("Show dependencies" . (lambda (elm)
9626 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9627 ("Show related files" . (lambda (elm)
9628 (anything-c-gentoo-default-action elm "equery" "files")))
9629 ("Refresh" . (lambda (elm)
9630 (anything-c-gentoo-setup-cache)
9631 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9633 ;; (anything 'anything-c-source-gentoo)
9635 (defun* anything-gentoo-install (candidate &key action)
9636 (setq anything-c-external-commands-list nil)
9637 (ansi-term (getenv "SHELL") "Gentoo emerge")
9638 (term-line-mode)
9639 (let ((command (case action
9640 ('install "sudo emerge -av ")
9641 ('uninstall "sudo emerge -avC ")
9642 (t (error "Unknow action"))))
9643 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9644 (beg (point)) end)
9645 (goto-char (point-max))
9646 (insert (concat command elms))
9647 (setq end (point))
9648 (term-char-mode) (term-send-input)))
9650 (defun anything-c-gentoo-default-action (elm command &rest args)
9651 "Gentoo default action that use `anything-c-gentoo-buffer'."
9652 (if (member elm anything-c-cache-world)
9653 (progn
9654 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9655 (erase-buffer)
9656 (let ((com-list (append args (list elm))))
9657 (apply #'call-process command nil t nil
9658 com-list)))
9659 (message "No infos on packages not yet installed")))
9661 (defvar anything-c-source-use-flags
9662 '((name . "Use Flags")
9663 (init . (lambda ()
9664 (unless anything-c-gentoo-use-flags
9665 (anything-c-gentoo-setup-use-flags-cache))
9666 (anything-c-gentoo-get-use)))
9667 (candidates-in-buffer)
9668 (match . identity)
9669 (candidate-transformer anything-c-highlight-local-use)
9670 (action . (("Description"
9671 . (lambda (elm)
9672 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9673 (erase-buffer)
9674 (apply #'call-process "euse" nil t nil
9675 `("-i"
9676 ,elm))
9677 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9678 (font-lock-mode 1)))
9679 ("Enable"
9680 . (lambda (elm)
9681 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9682 ("Disable"
9683 . (lambda (elm)
9684 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9685 ("Remove"
9686 . (lambda (elm)
9687 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9688 ("Show which dep use this flag"
9689 . (lambda (elm)
9690 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9691 (erase-buffer)
9692 (apply #'call-process "equery" nil t nil
9693 `("-C"
9695 ,elm))))))))
9698 ;; (anything 'anything-c-source-use-flags)
9700 (defun anything-c-gentoo-init-list ()
9701 "Initialize buffer with all packages in Portage."
9702 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9703 (buf (anything-candidate-buffer 'portage-buf)))
9704 (with-current-buffer buf
9705 (dolist (i anything-c-cache-gentoo)
9706 (insert (concat i "\n"))))))
9708 (defun anything-c-gentoo-setup-cache ()
9709 "Set up `anything-c-cache-gentoo'"
9710 (setq anything-c-cache-gentoo
9711 (split-string (with-temp-buffer
9712 (call-process "eix" nil t nil
9713 "--only-names")
9714 (buffer-string)))))
9716 (defun anything-c-gentoo-eshell-action (elm command)
9717 (when (get-buffer "*EShell Command Output*")
9718 (kill-buffer "*EShell Command Output*"))
9719 (message "Wait searching...")
9720 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9721 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9722 (progn
9723 (save-window-excursion
9724 (pop-to-buffer "*scratch*")
9725 (eshell-command (format "%s %s" command elm)))
9726 (pop-to-buffer "*EShell Command Output*"))
9727 (eshell-command (format "%s %s" command elm)))))
9729 (defun anything-c-gentoo-get-use ()
9730 "Initialize buffer with all use flags."
9731 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9732 (buf (anything-candidate-buffer 'use-buf)))
9733 (with-current-buffer buf
9734 (dolist (i anything-c-gentoo-use-flags)
9735 (insert (concat i "\n"))))))
9738 (defun anything-c-gentoo-setup-use-flags-cache ()
9739 "Setup `anything-c-gentoo-use-flags'"
9740 (setq anything-c-gentoo-use-flags
9741 (split-string (with-temp-buffer
9742 (call-process "eix" nil t nil
9743 "--print-all-useflags")
9744 (buffer-string)))))
9746 (defun anything-c-gentoo-get-url (elm)
9747 "Return a list of urls from eix output."
9748 (loop
9749 with url-list = (split-string
9750 (with-temp-buffer
9751 (call-process "eix" nil t nil
9752 elm "--format" "<homepage>\n")
9753 (buffer-string)))
9754 with all
9755 for i in url-list
9756 when (and (string-match "^http://.*" i)
9757 (not (member i all)))
9758 collect i into all
9759 finally return all))
9761 (defun anything-c-gentoo-get-world ()
9762 "Return list of all installed package on your system."
9763 (split-string (with-temp-buffer
9764 (call-process "qlist" nil t nil
9765 "-I")
9766 (buffer-string))))
9768 (defun anything-c-gentoo-get-local-use ()
9769 (split-string (with-temp-buffer
9770 (call-process "portageq" nil t nil
9771 "envvar"
9772 "USE")
9773 (buffer-string))))
9776 (defun anything-c-highlight-world (eix)
9777 "Highlight all installed package."
9778 (loop for i in eix
9779 if (member i anything-c-cache-world)
9780 collect (propertize i 'face 'anything-gentoo-match-face)
9781 else
9782 collect i))
9784 (defun anything-c-highlight-local-use (use-flags)
9785 (let ((local-uses (anything-c-gentoo-get-local-use)))
9786 (loop for i in use-flags
9787 if (member i local-uses)
9788 collect (propertize i 'face 'anything-gentoo-match-face)
9789 else
9790 collect i)))
9794 ;;; Anything ratpoison UI
9797 (defvar anything-c-source-ratpoison-commands
9798 '((name . "Ratpoison Commands")
9799 (init . anything-c-ratpoison-commands-init)
9800 (candidates-in-buffer)
9801 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9802 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9803 (candidate-number-limit)))
9804 ;; (anything 'anything-c-source-ratpoison-commands)
9806 (defun anything-c-ratpoison-commands-init ()
9807 (unless (anything-candidate-buffer)
9808 (with-current-buffer (anything-candidate-buffer 'global)
9809 ;; with ratpoison prefix key
9810 (save-excursion
9811 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9812 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9813 (replace-match "<ratpoison> \\1: \\2"))
9814 (goto-char (point-max))
9815 ;; direct binding
9816 (save-excursion
9817 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9818 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9819 (replace-match "\\1: \\2")))))
9821 (defun anything-c-ratpoison-commands-display-to-real (display)
9822 (and (string-match ": " display)
9823 (substring display (match-end 0))))
9825 (defun anything-c-ratpoison-commands-execute (candidate)
9826 (call-process "ratpoison" nil nil nil "-ic" candidate))
9830 ;;; Anything `completing-read' replacement
9833 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9834 "Convert COLLECTION to list removing elements that don't match TEST.
9835 SORT-FN is a predicate to sort COLLECTION.
9836 ALISTP is a flag to not use `all-completions' which doesn't handle alists correctly\
9837 for anything.
9838 If collection is an `obarray', a TEST is needed. See `obarray'."
9839 (let ((cands
9840 (cond ((and (eq collection obarray) test)
9841 (all-completions "" collection test))
9842 ((and (vectorp collection) test)
9843 (loop for i across collection when (funcall test i) collect i))
9844 ((vectorp collection)
9845 (loop for i across collection collect i))
9846 ((and alistp test)
9847 (loop for i in collection when (funcall test i) collect i))
9848 (alistp collection)
9849 ((and collection test)
9850 (all-completions "" collection test))
9851 (t (all-completions "" collection)))))
9852 (if sort-fn (sort cands sort-fn) cands)))
9854 (defun anything-cr-default-transformer (candidates source)
9855 "Default filter candidate function for `anything-comp-read'.
9856 Do nothing, just return candidate list unmodified."
9857 candidates)
9859 (defun* anything-comp-read (prompt collection
9860 &key
9861 test
9862 initial-input
9863 default
9864 preselect
9865 (buffer "*Anything Completions*")
9866 must-match
9867 (requires-pattern 0)
9868 (history nil)
9869 (persistent-action nil)
9870 (persistent-help "DoNothing")
9871 (name "Anything Completions")
9872 (volatile t)
9873 sort
9874 (fc-transformer 'anything-cr-default-transformer)
9875 (marked-candidates nil)
9876 (alistp t))
9877 "Anything `completing-read' emulation.
9878 PROMPT is the prompt name to use.
9879 COLLECTION can be a list, vector, obarray or hash-table.
9880 Keys:
9882 TEST: A predicate called with one arg i.e candidate.
9883 INITIAL-INPUT: Same as initial-input arg in `anything'.
9884 PRESELECT: See preselect arg of `anything'.
9885 DEFAULT: This option is used only for compatibility with regular
9886 Emacs `completing-read'.
9887 BUFFER: Name of anything-buffer.
9888 MUST-MATCH: Candidate selected must be one of COLLECTION.
9889 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9890 HISTORY: A list containing specific history, default is nil.
9891 When it is non--nil, all elements of HISTORY are displayed in
9892 anything-buffer before COLLECTION.
9893 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9894 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9895 NAME: The name related to this local source.
9896 VOLATILE: Use volatile attribute.
9897 SORT: A predicate to give to `sort' e.g `string-lessp'.
9898 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9899 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9900 ALISTP: when non--nil \(default\) cdr of alist is returned otherwise it is the car.
9902 Any prefix args passed during `anything-comp-read' invocation will be recorded
9903 in `anything-current-prefix-arg', otherwise if prefix args where given before
9904 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9905 That's mean you can pass prefix arg before or after calling
9906 a command that use `anything-comp-read'.
9907 It support now also a function as argument, See `all-completions' for more details."
9908 (when (get-buffer anything-action-buffer)
9909 (kill-buffer anything-action-buffer))
9910 (flet ((action-fn (candidate)
9911 (if marked-candidates
9912 (anything-marked-candidates)
9913 (identity candidate))))
9914 (let ((hist `((name . ,(format "%s History" name))
9915 (candidates . (lambda ()
9916 (let ((all (anything-comp-read-get-candidates
9917 history nil nil ,alistp)))
9918 (if (and default (not (string= default "")))
9919 (delq nil (cons default (delete default all)))
9920 all))))
9921 (persistent-action . ,persistent-action)
9922 (persistent-help . ,persistent-help)
9923 (action . ,'action-fn)))
9924 (src `((name . ,name)
9925 (candidates
9926 . (lambda ()
9927 (let ((cands (anything-comp-read-get-candidates
9928 collection test sort alistp)))
9929 (unless (or must-match (string= anything-pattern ""))
9930 (setq cands (append (list anything-pattern) cands)))
9931 (if (and default (not (string= default "")))
9932 (delq nil (cons default (delete default cands)))
9933 cands))))
9934 (filtered-candidate-transformer ,fc-transformer)
9935 (requires-pattern . ,requires-pattern)
9936 (persistent-action . ,persistent-action)
9937 (persistent-help . ,persistent-help)
9938 (action . ,'action-fn))))
9939 (when volatile (setq src (append src '((volatile)))))
9940 (or (anything
9941 :sources `(,hist ,src)
9942 :input initial-input
9943 :default default
9944 :preselect preselect
9945 :prompt prompt
9946 :resume 'noresume
9947 :buffer buffer)
9948 (keyboard-quit)))))
9950 ;; Generic completing-read
9952 ;; Support also function as collection.
9953 ;; e.g M-x man is supported.
9954 ;; Support hash-table and vectors as collection.
9955 ;; NOTE:
9956 ;; Some crap emacs functions may not be supported
9957 ;; like ffap-alternate-file (bad use of completing-read)
9958 ;; and maybe others.
9959 ;; Provide a mode `anything-completion-mode' which turn on
9960 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9962 (defun anything-completing-read-default
9963 (prompt collection &optional
9964 predicate require-match
9965 initial-input hist def
9966 inherit-input-method)
9967 "An anything replacement of `completing-read'.
9968 This function should be used only as a `completing-read-function'.
9970 Don't use it directly, use instead `anything-comp-read' in your programs \
9971 which is more powerful.
9973 See documentation of `completing-read' and `all-completions' for details."
9974 (let ((init initial-input)
9975 (anything-candidate-number-limit 9999))
9976 (anything-comp-read
9977 prompt collection
9978 :test predicate
9979 :fc-transformer #'(lambda (candidates source)
9980 (loop for i in candidates
9981 if (consp i) collect (car i)
9982 else collect i))
9983 :history (eval (or (car-safe hist) hist))
9984 :must-match require-match
9985 :alistp nil
9986 :default def
9987 :preselect def
9988 :initial-input init)))
9990 (defun anything-generic-read-file-name
9991 (prompt &optional dir default-filename mustmatch initial predicate)
9992 "An anything replacement of `read-file-name'."
9993 (let* ((default (and default-filename
9994 (if (listp default-filename)
9995 (car default-filename)
9996 default-filename)))
9997 (init (or default initial dir default-directory))
9998 (ini-input (and init (expand-file-name init)))
9999 (anything-ff-auto-update-flag nil))
10000 (anything-c-read-file-name prompt
10001 :initial-input (expand-file-name init dir)
10002 :alistp nil
10003 :must-match mustmatch
10004 :test predicate)))
10006 (defvar anything-completion-mode-string " AC")
10007 ;;;###autoload
10008 (define-minor-mode anything-completion-mode
10009 "Toggle generic anything completion.
10010 All functions in Emacs that use `completing-read'
10011 or `read-file-name' and friends will use anything interface
10012 when this mode is turned on.
10013 Called with a positive arg, turn on inconditionnaly, with a
10014 negative arg turn off.
10015 You can turn it on with `ac-mode'.
10017 Some crap emacs functions may not be supported,
10018 e.g `ffap-alternate-file' and maybe others."
10019 :group 'anything
10020 :global t
10021 :lighter anything-completion-mode-string
10022 (declare (special completing-read-function))
10023 (if anything-completion-mode
10024 (progn
10025 (setq completing-read-function 'anything-completing-read-default
10026 read-file-name-function 'anything-generic-read-file-name)
10027 (message "Anything completion enabled"))
10028 (setq completing-read-function 'completing-read-default
10029 read-file-name-function 'read-file-name-default)
10030 (message "Anything completion disabled")))
10032 (defalias 'ac-mode 'anything-completion-mode)
10036 ;;; Eshell completion.
10038 ;; Enable like this in .emacs:
10040 ;; (add-hook 'eshell-mode-hook
10041 ;; #'(lambda ()
10042 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
10044 (defvar anything-c-source-esh
10045 '((name . "Eshell completions")
10046 (init . (lambda ()
10047 (setq pcomplete-current-completions nil
10048 pcomplete-last-completion-raw nil)))
10049 (candidates . anything-esh-get-candidates)
10050 (action . anything-ec-insert))
10051 "Anything source for Eshell completion.")
10053 ;; Internal.
10054 (defvar anything-ec-target "")
10055 (defun anything-ec-insert (candidate)
10056 "Insert CANDIDATE at point.
10057 This is the same as `ac-insert', just inlined here for compatibility."
10058 (let ((pt (point)))
10059 (when (and anything-ec-target
10060 (search-backward anything-ec-target nil t)
10061 (string= (buffer-substring (point) pt) anything-ec-target))
10062 (delete-region (point) pt)))
10063 (insert candidate))
10065 (defun anything-esh-get-candidates ()
10066 "Get candidates for eshell completion using `pcomplete'."
10067 (catch 'pcompleted
10068 (let* ((pcomplete-stub)
10069 pcomplete-seen pcomplete-norm-func
10070 pcomplete-args pcomplete-last pcomplete-index
10071 (pcomplete-autolist pcomplete-autolist)
10072 (pcomplete-suffix-list pcomplete-suffix-list))
10073 (with-anything-current-buffer
10074 (loop
10075 with table = (pcomplete-completions)
10076 with entry = (condition-case nil
10077 ;; For Emacs24
10078 (funcall (pcomplete-entries) anything-pattern nil nil)
10079 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10080 (error
10082 (let ((fc (car (last (pcomplete-parse-arguments)))))
10083 ;; Check if last arg require fname completion.
10084 (and (file-name-directory fc) fc))))
10085 for i in (if (listp table) table ; Emacs23 or commands.
10086 (all-completions pcomplete-stub table)) ; Emacs24
10087 for file-cand = (and entry (expand-file-name i (file-name-directory entry)))
10088 if (and file-cand (file-exists-p file-cand)) collect file-cand into ls
10089 else collect i into ls
10090 finally return
10091 (if (and entry (not (string= entry "")) (file-exists-p entry))
10092 (append (list (expand-file-name entry default-directory)) ls) ls))))))
10094 ;;; Eshell history.
10097 (defvar anything-c-source-eshell-history
10098 '((name . "Eshell history")
10099 (init . (lambda ()
10100 (with-current-buffer (anything-candidate-buffer 'global)
10101 (insert-file-contents eshell-history-file-name))))
10102 (candidates-in-buffer)
10103 (filtered-candidate-transformer . (lambda (candidates sources)
10104 (reverse candidates)))
10105 (candidate-number-limit . 9999)
10106 (action . (lambda (candidate)
10107 (insert candidate))))
10108 "Anything source for Eshell history.")
10111 ;;; Show completion - an alternative of anything-show-completion.el.
10113 ;; Provide show completion with macro `with-anything-show-completion'.
10116 ;; Internal
10117 (defvar anything-c-show-completion-overlay nil)
10119 ;; Called each time cursor move in anything-buffer.
10120 (defun anything-c-show-completion ()
10121 (with-anything-current-buffer
10122 (overlay-put anything-c-show-completion-overlay
10123 'display (anything-get-selection))))
10125 (defun anything-c-show-completion-init-overlay (beg end)
10126 (with-anything-current-buffer
10127 (and anything-c-turn-on-show-completion
10128 (setq anything-c-show-completion-overlay (make-overlay beg end))
10129 (overlay-put anything-c-show-completion-overlay
10130 'face 'anything-lisp-show-completion))))
10132 (defmacro with-anything-show-completion (beg end &rest body)
10133 "Show anything candidate in an overlay at point.
10134 BEG and END are the beginning and end position of the current completion
10135 in `anything-current-buffer'.
10136 BODY is an anything call where we want to enable show completion.
10137 If `anything-c-turn-on-show-completion' is nil just do nothing."
10138 (declare (indent 2) (debug t))
10139 `(let ((anything-move-selection-after-hook
10140 (and anything-c-turn-on-show-completion
10141 (append (list 'anything-c-show-completion)
10142 anything-move-selection-after-hook))))
10143 (unwind-protect
10144 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10145 ,@body)
10146 (and anything-c-turn-on-show-completion
10147 (delete-overlay anything-c-show-completion-overlay)))))
10150 ;;; Lisp symbol completion.
10153 ;;;###autoload
10154 (defun anything-lisp-completion-at-point ()
10155 "Anything lisp symbol completion at point."
10156 (interactive)
10157 (let* ((data (lisp-completion-at-point))
10158 (beg (car data))
10159 (end (point)) ; 'cadr data' is wrong when no space after point.
10160 (plist (nthcdr 3 data))
10161 (pred (plist-get plist :predicate))
10162 (lgst-len 0)
10163 (target (and beg end (buffer-substring-no-properties beg end)))
10164 (candidates (all-completions target (nth 2 data) pred))
10165 (anything-quit-if-no-candidate t)
10166 (anything-execute-action-at-once-if-one t)
10167 (anything-match-plugin-enabled
10168 (member 'anything-compile-source--match-plugin
10169 anything-compile-source-functions)))
10170 (if candidates
10171 (with-anything-show-completion beg end
10172 ;; Overlay is initialized now in anything-current-buffer.
10173 (anything
10174 :sources
10175 '((name . "Lisp completion")
10176 (init . (lambda ()
10177 (with-current-buffer (anything-candidate-buffer 'global)
10178 (loop for sym in candidates
10179 for len = (length sym)
10180 when (> len lgst-len) do (setq lgst-len len)
10181 do (insert (concat sym "\n"))))))
10182 (candidates-in-buffer)
10183 (persistent-action . (lambda (candidate)
10184 (let ((cursor-in-echo-area t)
10185 mode-line-in-non-selected-windows)
10186 (anything-c-eldoc-show-in-mode-line
10187 (propertize
10188 (anything-c-get-first-line-documentation
10189 (intern candidate))
10190 'face 'anything-lisp-completion-info)))))
10191 (persistent-help . "Show brief doc in mode-line")
10192 (filtered-candidate-transformer anything-lisp-completion-transformer)
10193 (action . (lambda (candidate)
10194 (delete-region beg end)
10195 (insert candidate))))
10196 :input (if anything-match-plugin-enabled (concat target " ") target)))
10197 (message "[No Match]"))))
10199 (defun anything-lisp-completion-transformer (candidates source)
10200 "Anything candidates transformer for lisp completion."
10201 (declare (special lgst-len))
10202 (loop for c in candidates
10203 for sym = (intern c)
10204 for annot = (cond ((commandp sym) " (Com)")
10205 ((fboundp sym) " (Fun)")
10206 ((boundp sym) " (Var)")
10207 ((facep sym) " (Face)"))
10208 for spaces = (make-string (- lgst-len (length c)) ? )
10209 collect (cons (concat c spaces annot) c)))
10211 (defun anything-c-get-first-line-documentation (sym)
10212 "Return first line documentation of symbol SYM.
10213 If SYM is not documented, return \"Not documented\"."
10214 (let ((doc (cond ((fboundp sym)
10215 (documentation sym t))
10216 ((boundp sym)
10217 (documentation-property sym 'variable-documentation t))
10218 ((facep sym)
10219 (face-documentation sym))
10220 (t nil))))
10221 (if (and doc (not (string= doc ""))
10222 ;; `documentation' return "\n\n(args...)"
10223 ;; for CL-style functions.
10224 (not (string-match-p "^\n\n" doc)))
10225 (car (split-string doc "\n"))
10226 "Not documented")))
10228 ;;; File completion.
10230 ;; Complete file name at point.
10231 (defun anything-c-thing-before-point ()
10232 "Get symbol name before point.
10233 Borrowed from anything-complete.el, inlined here for compatibility."
10234 (save-excursion
10235 (let ((beg (point)))
10236 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10237 (when (re-search-backward
10238 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10239 (buffer-substring-no-properties beg (match-end 0))))))
10241 ;;;###autoload
10242 (defun anything-c-complete-file-name-at-point ()
10243 "Complete file name at point."
10244 (interactive)
10245 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10246 (end (point))
10247 (beg (- (point) (length init)))
10248 (anything-quit-if-no-candidate t)
10249 (anything-execute-action-at-once-if-one t)
10250 completion)
10251 (with-anything-show-completion beg end
10252 (setq completion (anything-c-read-file-name "FileName: "
10253 :initial-input init
10254 :must-match t)))
10255 (anything-c-insert-file-name-completion-at-point completion)))
10257 ;; Internal
10258 (defvar anything-lisp-completion-counter 0)
10259 ;;;###autoload
10260 (defun anything-lisp-completion-at-point-or-indent (arg)
10261 "First call indent and second call complete lisp symbol.
10262 The second call should happen before `anything-lisp-completion-or-indent-delay',
10263 after this delay, next call will indent again.
10264 After completion, next call is always indent.
10265 See that like click and double mouse click.
10266 One hit indent, two quick hits maybe indent and complete."
10267 (interactive "P")
10268 ;; Be sure `indent-for-tab-command' will not try
10269 ;; to use `completion-at-point'.
10270 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10271 t tab-always-indent)))
10272 (incf anything-lisp-completion-counter)
10273 (unwind-protect
10274 (if (> anything-lisp-completion-counter 1)
10275 (anything-lisp-completion-or-file-name-at-point)
10276 (indent-for-tab-command arg))
10277 ;; After `anything-lisp-completion-or-indent-delay' seconds
10278 ;; reset to 0.
10279 (run-with-timer anything-lisp-completion-or-indent-delay nil
10280 #'(lambda ()
10281 (setq anything-lisp-completion-counter 0)))
10282 ;; Always reset to 0 at second hit.
10283 (when (eq anything-lisp-completion-counter 2)
10284 (setq anything-lisp-completion-counter 0)))))
10286 ;;;###autoload
10287 (defun anything-lisp-completion-or-file-name-at-point ()
10288 "Complete lisp symbol or filename at point.
10289 Filename completion happen if filename is started in
10290 or between double quotes."
10291 (interactive)
10292 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10293 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10294 (save-excursion (search-backward "\"" (point-at-bol) t)))
10295 (anything-c-complete-file-name-at-point)
10296 (anything-lisp-completion-at-point))))
10300 ;;; Run Externals commands within Emacs with anything completion
10303 (defvar anything-external-command-history nil)
10305 (defun anything-c-external-commands-list-1 (&optional sort)
10306 "Returns a list of all external commands the user can execute.
10307 If `anything-c-external-commands-list' is non-nil it will
10308 return its contents. Else it calculates all external commands
10309 and sets `anything-c-external-commands-list'."
10310 (if anything-c-external-commands-list
10311 anything-c-external-commands-list
10312 (setq anything-c-external-commands-list
10313 (loop
10314 with paths = (split-string (getenv "PATH") path-separator)
10315 with completions = ()
10316 for dir in paths
10317 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10318 for lsdir = (loop for i in (directory-files dir t)
10319 for bn = (file-name-nondirectory i)
10320 when (and (not (member bn completions))
10321 (not (file-directory-p i))
10322 (file-executable-p i))
10323 collect bn)
10324 append lsdir into completions
10325 finally return (if sort (sort completions 'string-lessp) completions)))))
10327 (defun anything-run-or-raise (exe &optional file)
10328 "Generic command that run asynchronously EXE.
10329 If EXE is already running just jump to his window if `anything-raise-command'
10330 is non--nil.
10331 When FILE argument is provided run EXE with FILE.
10332 In this case EXE must be provided as \"EXE %s\"."
10333 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10334 "'%s'" "" exe))))
10335 (proc (if file (concat real-com " " file) real-com)))
10336 (if (get-process proc)
10337 (if anything-raise-command
10338 (shell-command (format anything-raise-command real-com))
10339 (error "Error: %s is already running" real-com))
10340 (when (loop for i in anything-c-external-commands-list thereis real-com)
10341 (message "Starting %s..." real-com)
10342 (if file
10343 (start-process-shell-command proc nil (format exe file))
10344 (start-process-shell-command proc nil real-com))
10345 (set-process-sentinel
10346 (get-process proc)
10347 #'(lambda (process event)
10348 (when (and (string= event "finished\n")
10349 anything-raise-command
10350 (not (anything-c-get-pid-from-process-name real-com)))
10351 (shell-command (format anything-raise-command "emacs")))
10352 (message "%s process...Finished." process))))
10353 (setq anything-c-external-commands-list
10354 (cons real-com
10355 (delete real-com anything-c-external-commands-list))))))
10359 ;;; Generic action functions
10362 (defun anything-c-file-buffers (filename)
10363 "Returns a list of buffer names corresponding to FILENAME."
10364 (let ((name (expand-file-name filename))
10365 (buf-list ()))
10366 (dolist (buf (buffer-list) buf-list)
10367 (let ((bfn (buffer-file-name buf)))
10368 (when (and bfn (string= name bfn))
10369 (push (buffer-name buf) buf-list))))))
10371 (defun anything-revert-buffer (candidate)
10372 (with-current-buffer candidate
10373 (when (or (buffer-modified-p)
10374 (not (verify-visited-file-modtime
10375 (get-buffer candidate))))
10376 (revert-buffer t t))))
10378 (defun anything-revert-marked-buffers (ignore)
10379 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10381 (defun anything-kill-marked-buffers (ignore)
10382 (mapc 'kill-buffer (anything-marked-candidates)))
10384 (defun anything-c-delete-file (file)
10385 "Delete the given file after querying the user.
10386 Ask to kill buffers associated with that file, too."
10387 (let ((buffers (anything-c-file-buffers file)))
10388 (if (< emacs-major-version 24)
10389 ;; `dired-delete-file' in Emacs versions < 24
10390 ;; doesn't support delete-by-moving-to-trash
10391 ;; so use `delete-directory' and `delete-file'
10392 ;; that handle it.
10393 (cond ((and (not (file-symlink-p file))
10394 (file-directory-p file)
10395 (directory-files file t dired-re-no-dot))
10396 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10397 (delete-directory file 'recursive)))
10398 ((and (not (file-symlink-p file))
10399 (file-directory-p file))
10400 (delete-directory file))
10401 (t (delete-file file)))
10402 (dired-delete-file
10403 file 'dired-recursive-deletes delete-by-moving-to-trash))
10404 (when buffers
10405 (dolist (buf buffers)
10406 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10407 (kill-buffer buf))))))
10409 (defun anything-get-mailcap-for-file (filename)
10410 "Get the command to use for FILENAME from mailcap files.
10411 The command is like <command %s> and is meant to use with `format'."
10412 (mailcap-parse-mailcaps)
10413 (let* ((ext (file-name-extension filename))
10414 (mime (when ext (mailcap-extension-to-mime ext)))
10415 (result (when mime (mailcap-mime-info mime))))
10416 ;; If elisp file have no associations in .mailcap
10417 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10418 (when (stringp result) result)))
10420 (defun anything-get-default-program-for-file (filename)
10421 "Try to find a default program to open FILENAME.
10422 Try first in `anything-c-external-programs-associations' and then in mailcap file
10423 if nothing found return nil."
10424 (let* ((ext (file-name-extension filename))
10425 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10426 (cond ((and def-prog (not (string= def-prog "")))
10427 (concat def-prog " %s"))
10428 ((and anything-c-default-external-file-browser
10429 (file-directory-p filename))
10430 (concat anything-c-default-external-file-browser " %s"))
10431 (t (anything-get-mailcap-for-file filename)))))
10433 (defun anything-c-open-file-externally (file)
10434 "Open FILE with an external program.
10435 Try to guess which program to use with `anything-get-default-program-for-file'.
10436 If not found or a prefix arg is given query the user which tool to use."
10437 (let* ((fname (expand-file-name file))
10438 (collection (anything-c-external-commands-list-1 'sort))
10439 (def-prog (anything-get-default-program-for-file fname))
10440 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10441 ;; Prefix arg or no default program.
10442 (prog1
10443 (anything-comp-read
10444 "Program: " collection
10445 :must-match t
10446 :name "Open file Externally"
10447 :history anything-external-command-history)
10448 ;; Always prompt to set this program as default.
10449 (setq def-prog nil))
10450 ;; No prefix arg or default program exists.
10451 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10452 (program (concat real-prog-name " '%s'")))
10453 (unless (or def-prog ; Association exists, no need to record it.
10454 ;; Don't try to record non--filenames associations (e.g urls).
10455 (not (file-exists-p fname)))
10456 (when
10457 (y-or-n-p
10458 (format
10459 "Do you want to make `%s' the default program for this kind of files? "
10460 real-prog-name))
10461 (anything-aif (assoc (file-name-extension fname)
10462 anything-c-external-programs-associations)
10463 (setq anything-c-external-programs-associations
10464 (delete it anything-c-external-programs-associations)))
10465 (push (cons (file-name-extension fname)
10466 (read-string
10467 "Program (Add args maybe and confirm): " real-prog-name))
10468 anything-c-external-programs-associations)
10469 (customize-save-variable 'anything-c-external-programs-associations
10470 anything-c-external-programs-associations)))
10471 (anything-run-or-raise program file)
10472 (setq anything-external-command-history
10473 (cons real-prog-name
10474 (delete real-prog-name
10475 (loop for i in anything-external-command-history
10476 when (executable-find i) collect i))))))
10479 (defun anything-c-find-file-or-marked (candidate)
10480 "Open file CANDIDATE or open anything marked files in background."
10481 (let ((marked (anything-marked-candidates))
10482 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10483 (find-file-wildcards nil))
10484 (if (> (length marked) 1)
10485 ;; Open all marked files in background and display
10486 ;; the first one.
10487 (progn (mapc 'find-file-noselect (cdr marked))
10488 (find-file (car marked)))
10489 (if (and (not (file-exists-p candidate))
10490 (and ffap-url-regexp
10491 (not (string-match ffap-url-regexp candidate)))
10492 (string-match "/$" candidate))
10493 ;; A a non--existing filename ending with /
10494 ;; Create a directory and jump to it.
10495 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10496 (let ((dirfname (directory-file-name candidate)))
10497 (if (file-exists-p dirfname)
10498 (error "Mkdir: Unable to create directory `%s': file exists."
10499 (anything-c-basename dirfname))
10500 (make-directory candidate 'parent)))
10501 (anything-find-files-1 candidate))
10502 ;; A non--existing filename NOT ending with / or
10503 ;; an existing filename, create or jump to it.
10504 (find-file-at-point (car marked))))))
10506 (defun anything-delete-marked-files (ignore)
10507 (let* ((files (anything-marked-candidates))
10508 (len (length files)))
10509 (if (not (y-or-n-p
10510 (format "Delete *%s File(s):\n%s"
10512 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10513 (message "(No deletions performed)")
10514 (dolist (i files)
10515 (set-text-properties 0 (length i) nil i)
10516 (anything-c-delete-file i))
10517 (message "%s File(s) deleted" len))))
10519 (defun anything-ediff-marked-buffers (candidate &optional merge)
10520 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10521 With optional arg MERGE call `ediff-merge-buffers'."
10522 (let ((lg-lst (length (anything-marked-candidates)))
10523 buf1 buf2)
10524 (case lg-lst
10526 (error "Error:You have to mark at least 1 buffer"))
10528 (setq buf1 anything-current-buffer
10529 buf2 (first (anything-marked-candidates))))
10531 (setq buf1 (first (anything-marked-candidates))
10532 buf2 (second (anything-marked-candidates))))
10534 (error "Error:To much buffers marked!")))
10535 (if merge
10536 (ediff-merge-buffers buf1 buf2)
10537 (ediff-buffers buf1 buf2))))
10539 (defun anything-ediff-marked-buffers-merge (candidate)
10540 "Ediff merge `anything-current-buffer' with CANDIDATE.
10541 See `anything-ediff-marked-buffers'."
10542 (anything-ediff-marked-buffers candidate t))
10544 (defun anything-bookmark-get-bookmark-from-name (bmk)
10545 "Return bookmark name even if it is a bookmark with annotation.
10546 e.g prepended with *.
10547 Return nil if bmk is not a valid bookmark."
10548 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10549 (if (assoc bookmark bookmark-alist)
10550 bookmark
10551 (when (assoc bmk bookmark-alist)
10552 bmk))))
10554 (defun anything-delete-marked-bookmarks (ignore)
10555 "Delete this bookmark or all marked bookmarks."
10556 (dolist (i (anything-marked-candidates))
10557 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10558 'batch)))
10560 (defun anything-require-or-error (feature function)
10561 (or (require feature nil t)
10562 (error "Need %s to use `%s'." feature function)))
10564 (defun anything-find-buffer-on-elscreen (candidate)
10565 "Open buffer in new screen, if marked buffers open all in elscreens."
10566 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10567 (anything-aif (anything-marked-candidates)
10568 (dolist (i it)
10569 (let ((target-screen (elscreen-find-screen-by-buffer
10570 (get-buffer i) 'create)))
10571 (elscreen-goto target-screen)))
10572 (let ((target-screen (elscreen-find-screen-by-buffer
10573 (get-buffer candidate) 'create)))
10574 (elscreen-goto target-screen))))
10576 (defun anything-elscreen-find-file (file)
10577 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10578 (elscreen-find-file file))
10580 ;;;###autoload
10581 (defun w32-shell-execute-open-file (file)
10582 (interactive "fOpen file:")
10583 (with-no-warnings
10584 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10585 "/" "\\"
10586 (replace-regexp-in-string ; strip cygdrive paths
10587 "/cygdrive/\\(.\\)" "\\1:"
10588 file nil nil) nil t))))
10590 (defun anything-c-open-file-with-default-tool (file)
10591 "Open FILE with the default tool on this platform."
10592 (if (eq system-type 'windows-nt)
10593 (w32-shell-execute-open-file file)
10594 (start-process "anything-c-open-file-with-default-tool"
10596 (cond ((eq system-type 'gnu/linux)
10597 "xdg-open")
10598 ((or (eq system-type 'darwin) ;; Mac OS X
10599 (eq system-type 'macos)) ;; Mac OS 9
10600 "open"))
10601 file)))
10603 (defun anything-c-open-dired (file)
10604 "Opens a dired buffer in FILE's directory. If FILE is a
10605 directory, open this directory."
10606 (if (file-directory-p file)
10607 (dired file)
10608 (dired (file-name-directory file))
10609 (dired-goto-file file)))
10611 (defun anything-c-display-to-real-line (candidate)
10612 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10613 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10614 (error "Line number not found")))
10616 (defun anything-c-action-line-goto (lineno-and-content)
10617 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10618 (append lineno-and-content
10619 (list (if (and (anything-attr-defined 'target-file)
10620 (not anything-in-persistent-action))
10621 'find-file-other-window
10622 'find-file)))))
10624 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10625 (apply #'anything-goto-file-line
10626 (if (stringp file-line-content)
10627 ;; Case: filtered-candidate-transformer is skipped
10628 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10629 file-line-content)))
10631 (require 'compile)
10632 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10633 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10635 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10636 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10637 (let ((filename (match-string 1 candidate))
10638 (lineno (match-string 2 candidate))
10639 (content (match-string 3 candidate)))
10640 (cons (format "%s:%s\n %s"
10641 (propertize filename 'face compilation-info-face)
10642 (propertize lineno 'face compilation-line-face)
10643 content)
10644 (list (expand-file-name
10645 filename
10646 (or (anything-interpret-value (anything-attr 'default-directory))
10647 (and (anything-candidate-buffer)
10648 (buffer-local-value
10649 'default-directory (anything-candidate-buffer)))))
10650 (string-to-number lineno) content)))))
10652 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10653 (anything-aif (anything-attr 'before-jump-hook)
10654 (funcall it))
10655 (when file (funcall find-file-function file))
10656 (if (anything-attr-defined 'adjust)
10657 (anything-c-goto-line-with-adjustment lineno content)
10658 (anything-goto-line lineno))
10659 (unless (anything-attr-defined 'recenter)
10660 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10661 (anything-aif (anything-attr 'after-jump-hook)
10662 (funcall it))
10663 (when anything-in-persistent-action
10664 (anything-match-line-color-current-line)))
10666 (defun anything-find-file-as-root (candidate)
10667 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10669 (defun anything-find-many-files (ignore)
10670 (mapc 'find-file (anything-marked-candidates)))
10672 ;; borrowed from etags.el
10673 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10674 (defun anything-c-goto-line-with-adjustment (line line-content)
10675 (let ((startpos)
10676 offset found pat)
10677 ;; This constant is 1/2 the initial search window.
10678 ;; There is no sense in making it too small,
10679 ;; since just going around the loop once probably
10680 ;; costs about as much as searching 2000 chars.
10681 (setq offset 1000
10682 found nil
10683 pat (concat (if (eq selective-display t)
10684 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10685 (regexp-quote line-content)))
10686 ;; If no char pos was given, try the given line number.
10687 (setq startpos (progn (anything-goto-line line) (point)))
10688 (or startpos (setq startpos (point-min)))
10689 ;; First see if the tag is right at the specified location.
10690 (goto-char startpos)
10691 (setq found (looking-at pat))
10692 (while (and (not found)
10693 (progn
10694 (goto-char (- startpos offset))
10695 (not (bobp))))
10696 (setq found
10697 (re-search-forward pat (+ startpos offset) t)
10698 offset (* 3 offset))) ; expand search window
10699 (or found
10700 (re-search-forward pat nil t)
10701 (error "not found")))
10702 ;; Position point at the right place
10703 ;; if the search string matched an extra Ctrl-m at the beginning.
10704 (and (eq selective-display t)
10705 (looking-at "\^m")
10706 (forward-char 1))
10707 (beginning-of-line))
10709 (anything-document-attribute 'default-directory "type . file-line"
10710 "`default-directory' to interpret file.")
10711 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10712 "Function to call before jumping to the target location.")
10713 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10714 "Function to call after jumping to the target location.")
10715 (anything-document-attribute 'adjust "type . file-line"
10716 "Search around line matching line contents.")
10717 (anything-document-attribute 'recenter "type . file-line / line"
10718 "`recenter' after jumping.")
10719 (anything-document-attribute 'target-file "type . line"
10720 "Goto line of target-file.")
10722 ;;;###autoload
10723 (defun anything-c-call-interactively (cmd-or-name)
10724 "Execute CMD-OR-NAME as Emacs command.
10725 It is added to `extended-command-history'.
10726 `anything-current-prefix-arg' is used as the command's prefix argument."
10727 (setq extended-command-history
10728 (cons (anything-c-stringify cmd-or-name)
10729 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10730 (let ((current-prefix-arg anything-current-prefix-arg)
10731 (cmd (anything-c-symbolify cmd-or-name)))
10732 (if (stringp (symbol-function cmd))
10733 (execute-kbd-macro (symbol-function cmd))
10734 (setq this-command cmd)
10735 (call-interactively cmd))))
10737 ;;;###autoload
10738 (defun anything-c-set-variable (var)
10739 "Set value to VAR interactively."
10740 (interactive)
10741 (let ((sym (anything-c-symbolify var)))
10742 (set sym (eval-minibuffer (format "Set %s: " var)
10743 (prin1-to-string (symbol-value sym))))))
10744 ;; (setq hh 12)
10745 ;; (anything-c-set-variable 'hh)
10749 ;;; Persistent Action Helpers
10752 (defvar anything-match-line-overlay-face nil)
10753 (defvar anything-match-line-overlay nil)
10755 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10756 "Highlight and underline current position"
10757 (let ((args (list (or start (line-beginning-position))
10758 (or end (1+ (line-end-position)))
10759 buf)))
10760 (if (not anything-match-line-overlay)
10761 (setq anything-match-line-overlay (apply 'make-overlay args))
10762 (apply 'move-overlay anything-match-line-overlay args)))
10763 (overlay-put anything-match-line-overlay
10764 'face (or face anything-match-line-overlay-face))
10765 (when rec
10766 (goto-char start)
10767 (recenter)))
10769 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10772 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10774 (defun anything-match-line-cleanup ()
10775 (when anything-match-line-overlay
10776 (delete-overlay anything-match-line-overlay)
10777 (setq anything-match-line-overlay nil)))
10779 (defun anything-match-line-update ()
10780 (when anything-match-line-overlay
10781 (delete-overlay anything-match-line-overlay)
10782 (anything-match-line-color-current-line)))
10784 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10785 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10788 ;;; Actions Transformers
10791 ;;; Files
10792 (defun anything-c-transform-file-load-el (actions candidate)
10793 "Add action to load the file CANDIDATE if it is an emacs lisp
10794 file. Else return ACTIONS unmodified."
10795 (if (member (file-name-extension candidate) '("el" "elc"))
10796 (append actions '(("Load Emacs Lisp File" . load-file)))
10797 actions))
10799 (defun anything-c-transform-file-browse-url (actions candidate)
10800 "Add an action to browse the file CANDIDATE if it in a html
10801 file or URL. Else return ACTIONS unmodified."
10802 (let ((browse-action '("Browse with Browser" . browse-url)))
10803 (cond ((string-match "^http\\|^ftp" candidate)
10804 (cons browse-action actions))
10805 ((string-match "\\.html?$" candidate)
10806 (append actions (list browse-action)))
10807 (t actions))))
10809 ;;; Function
10810 (defun anything-c-transform-function-call-interactively (actions candidate)
10811 "Add an action to call the function CANDIDATE interactively if
10812 it is a command. Else return ACTIONS unmodified."
10813 (if (commandp (intern-soft candidate))
10814 (append actions '(("Call Interactively"
10816 anything-c-call-interactively)))
10817 actions))
10819 ;;;; S-Expressions
10820 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10821 "If CANDIDATE's `car' is a command, then add an action to
10822 evaluate it and put it onto the `command-history'."
10823 (if (commandp (car (read candidate)))
10824 ;; Make it first entry
10825 (cons '("Eval and put onto command-history" .
10826 (lambda (sexp)
10827 (let ((sym (read sexp)))
10828 (eval sym)
10829 (setq command-history
10830 (cons sym command-history)))))
10831 actions)
10832 actions))
10835 ;;; Candidate Transformers
10838 ;;; Buffers
10839 (defun anything-c-skip-boring-buffers (buffers)
10840 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10842 (defun anything-c-skip-current-buffer (buffers)
10843 (if anything-allow-skipping-current-buffer
10844 (remove (buffer-name anything-current-buffer) buffers)
10845 buffers))
10847 (defun anything-c-shadow-boring-buffers (buffers)
10848 "Buffers matching `anything-c-boring-buffer-regexp' will be
10849 displayed with the `file-name-shadow' face if available."
10850 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10852 (defvar anything-c-buffer-display-string-functions
10853 '(anything-c-buffer-display-string--compilation
10854 anything-c-buffer-display-string--shell
10855 anything-c-buffer-display-string--eshell)
10856 "Functions to setup display string for buffer.
10858 Function has one argument, buffer name.
10859 If it returns string, use it.
10860 If it returns nil, display buffer name.
10861 See `anything-c-buffer-display-string--compilation' for example.")
10863 (defun anything-c-transform-buffer-display-string (buffers)
10864 "Setup display string for buffer candidates
10865 using `anything-c-buffer-display-string-functions'."
10866 (loop for buf in buffers
10867 if (consp buf)
10868 collect buf
10869 else
10870 for disp = (progn (set-buffer buf)
10871 (run-hook-with-args-until-success
10872 'anything-c-buffer-display-string-functions buf))
10873 collect (if disp (cons disp buf) buf)))
10875 (defun anything-c-buffer-display-string--compilation (buf)
10876 (anything-aif (car compilation-arguments)
10877 (format "%s: %s [%s]" buf it default-directory)))
10879 (defun anything-c-buffer-display-string--eshell (buf)
10880 (declare (special eshell-history-ring))
10881 (when (eq major-mode 'eshell-mode)
10882 (format "%s: %s [%s]" buf
10883 (ignore-errors (ring-ref eshell-history-ring 0))
10884 default-directory)))
10886 (defun anything-c-buffer-display-string--shell (buf)
10887 (when (eq major-mode 'shell-mode)
10888 (format "%s: %s [%s]" buf
10889 (ignore-errors (ring-ref comint-input-ring 0))
10890 default-directory)))
10892 ;;; Files
10893 (defun anything-c-shadow-boring-files (files)
10894 "Files matching `anything-c-boring-file-regexp' will be
10895 displayed with the `file-name-shadow' face if available."
10896 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10898 (defun anything-c-skip-boring-files (files)
10899 "Files matching `anything-c-boring-file-regexp' will be skipped."
10900 (anything-c-skip-entries files anything-c-boring-file-regexp))
10901 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10903 (defun anything-c-skip-current-file (files)
10904 "Current file will be skipped."
10905 (remove (buffer-file-name anything-current-buffer) files))
10907 (defun anything-c-w32-pathname-transformer (args)
10908 "Change undesirable features of windows pathnames to ones more acceptable to
10909 other candidate transformers."
10910 (if (eq system-type 'windows-nt)
10911 (mapcar (lambda (x)
10912 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10913 (mapcar (lambda (y)
10914 (replace-regexp-in-string "\\\\" "/" y)) args))
10915 args))
10917 (defun anything-c-shorten-home-path (files)
10918 "Replaces /home/user with ~."
10919 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10920 (getenv "HOME"))))
10921 (mapcar (lambda (file)
10922 (if (and (stringp file) (string-match home file))
10923 (cons (replace-match "~" nil nil file) file)
10924 file))
10925 files)))
10927 ;;; Functions
10928 (defun anything-c-mark-interactive-functions (functions)
10929 "Mark interactive functions (commands) with (i) after the function name."
10930 (let (list)
10931 (loop for function in functions
10932 do (push (cons (concat function
10933 (when (commandp (intern-soft function)) " (i)"))
10934 function)
10935 list)
10936 finally (return (nreverse list)))))
10939 ;;; Adaptive Sorting of Candidates
10942 ;; Internal
10943 (defvar anything-c-adaptive-done nil
10944 "nil if history information is not yet stored for the current
10945 selection.")
10947 (defvar anything-c-adaptive-history nil
10948 "Contains the stored history information.
10949 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10951 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10952 "Reset `anything-c-adaptive-done' when anything is started."
10953 (when anything-c-use-adaptative-sorting
10954 (setq anything-c-adaptive-done nil)))
10956 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10957 "Store history information when action is executed on selected candidate."
10958 (when anything-c-use-adaptative-sorting
10959 (anything-c-adaptive-store-selection)))
10961 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10962 "Store history information when the user goes to the action buffer."
10963 (when anything-c-use-adaptative-sorting
10964 (anything-c-adaptive-store-selection)))
10966 (defun anything-c-source-use-adaptative-p (&optional source-name)
10967 "Return current source only if it use adaptative history, nil otherwise."
10968 (when anything-c-use-adaptative-sorting
10969 (let* ((source (or source-name (anything-get-current-source)))
10970 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10971 (assoc (assoc-default 'type source)
10972 anything-type-attributes))
10973 (assoc-default 'candidate-transformer
10974 (assoc (assoc-default 'type source)
10975 anything-type-attributes))
10976 (assoc-default 'filtered-candidate-transformer source)
10977 (assoc-default 'candidate-transformer source))))
10978 (if (listp adapt-source)
10979 (when (member 'anything-c-adaptive-sort adapt-source) source)
10980 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10982 (defun anything-c-adaptive-store-selection ()
10983 "Store history information for the selected candidate."
10984 (unless anything-c-adaptive-done
10985 (setq anything-c-adaptive-done t)
10986 (let ((source (anything-c-source-use-adaptative-p)))
10987 (when source
10988 (let* ((source-name (or (assoc-default 'type source)
10989 (assoc-default 'name source)))
10990 (source-info (or (assoc source-name anything-c-adaptive-history)
10991 (progn
10992 (push (list source-name) anything-c-adaptive-history)
10993 (car anything-c-adaptive-history))))
10994 (selection (anything-get-selection))
10995 (selection-info (progn
10996 (setcdr source-info
10997 (cons
10998 (let ((found (assoc selection (cdr source-info))))
10999 (if (not found)
11000 ;; new entry
11001 (list selection)
11003 ;; move entry to the beginning of the
11004 ;; list, so that it doesn't get
11005 ;; trimmed when the history is
11006 ;; truncated
11007 (setcdr source-info
11008 (delete found (cdr source-info)))
11009 found))
11010 (cdr source-info)))
11011 (cadr source-info)))
11012 (pattern-info (progn
11013 (setcdr selection-info
11014 (cons
11015 (let ((found (assoc anything-pattern (cdr selection-info))))
11016 (if (not found)
11017 ;; new entry
11018 (cons anything-pattern 0)
11020 ;; move entry to the beginning of the
11021 ;; list, so if two patterns used the
11022 ;; same number of times then the one
11023 ;; used last appears first in the list
11024 (setcdr selection-info
11025 (delete found (cdr selection-info)))
11026 found))
11027 (cdr selection-info)))
11028 (cadr selection-info))))
11030 ;; increase usage count
11031 (setcdr pattern-info (1+ (cdr pattern-info)))
11033 ;; truncate history if needed
11034 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
11035 (setcdr selection-info
11036 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
11038 (defun anything-c-adaptative-maybe-load-history ()
11039 (when (and anything-c-use-adaptative-sorting
11040 (file-readable-p anything-c-adaptive-history-file))
11041 (load-file anything-c-adaptive-history-file)))
11043 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
11044 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
11046 (defun anything-c-adaptive-save-history (&optional arg)
11047 "Save history information to file given by `anything-c-adaptive-history-file'."
11048 (interactive "p")
11049 (when anything-c-use-adaptative-sorting
11050 (with-temp-buffer
11051 (insert
11052 ";; -*- mode: emacs-lisp -*-\n"
11053 ";; History entries used for anything adaptive display.\n")
11054 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
11055 (current-buffer))
11056 (insert ?\n)
11057 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11058 (unless arg 'quiet)))))
11060 (defun anything-c-adaptive-sort (candidates source)
11061 "Sort the CANDIDATES for SOURCE by usage frequency.
11062 This is a filtered candidate transformer you can use for the
11063 attribute `filtered-candidate-transformer' of a source in
11064 `anything-sources' or a type in `anything-type-attributes'."
11065 (let* ((source-name (or (assoc-default 'type source)
11066 (assoc-default 'name source)))
11067 (source-info (assoc source-name anything-c-adaptive-history)))
11068 (if source-info
11069 (let ((usage
11070 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11071 ;; pairs
11072 (mapcar (lambda (candidate-info)
11073 (let ((count 0))
11074 (dolist (pattern-info (cdr candidate-info))
11075 (if (not (equal (car pattern-info)
11076 anything-pattern))
11077 (incf count (cdr pattern-info))
11079 ;; if current pattern is equal to the previously
11080 ;; used one then this candidate has priority
11081 ;; (that's why its count is boosted by 10000) and
11082 ;; it only has to compete with other candidates
11083 ;; which were also selected with the same pattern
11084 (setq count (+ 10000 (cdr pattern-info)))
11085 (return)))
11086 (cons (car candidate-info) count)))
11087 (cdr source-info)))
11088 sorted)
11089 (if (and usage (consp usage))
11090 ;; sort the list in descending order, so candidates with highest
11091 ;; priorty come first
11092 (progn
11093 (setq usage (sort usage (lambda (first second)
11094 (> (cdr first) (cdr second)))))
11096 ;; put those candidates first which have the highest usage count
11097 (dolist (info usage)
11098 (when (member* (car info) candidates
11099 :test 'anything-c-adaptive-compare)
11100 (push (car info) sorted)
11101 (setq candidates (remove* (car info) candidates
11102 :test 'anything-c-adaptive-compare))))
11104 ;; and append the rest
11105 (append (reverse sorted) candidates nil))
11106 (message "Your `%s' is maybe corrupted or too old, \
11107 you should reinitialize it with `anything-c-reset-adaptative-history'"
11108 anything-c-adaptive-history-file)
11109 (sit-for 1)
11110 candidates))
11111 ;; if there is no information stored for this source then do nothing
11112 candidates)))
11114 ;;;###autoload
11115 (defun anything-c-reset-adaptative-history ()
11116 "Delete all `anything-c-adaptive-history' and his file.
11117 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11118 (interactive)
11119 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11120 (setq anything-c-adaptive-history nil)
11121 (delete-file anything-c-adaptive-history-file)))
11123 (defun anything-c-adaptive-compare (x y)
11124 "Compare candidates X and Y taking into account that the
11125 candidate can be in (DISPLAY . REAL) format."
11126 (equal (if (listp x)
11127 (cdr x)
11129 (if (listp y)
11130 (cdr y)
11131 y)))
11135 ;;; Outliner
11138 (defvar anything-outline-goto-near-line-flag t)
11139 (defvar anything-outline-using nil)
11140 (defun anything-after-update-hook--outline ()
11141 (if (and (eq anything-outline-using t)
11142 (eq anything-outline-goto-near-line-flag t))
11143 (anything-outline-goto-near-line)))
11144 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11146 (defun anything-outline-goto-near-line ()
11147 (with-anything-window
11148 ;; TODO need consideration whether to update position by every input.
11149 (when t ; (equal anything-pattern "")
11150 (anything-goto-line 2)
11151 (let ((lineno (with-anything-current-buffer
11152 (line-number-at-pos (car anything-current-position)))))
11153 (block exit
11154 (while (<= (progn (skip-chars-forward " ")
11155 (or (number-at-point) lineno))
11156 lineno)
11157 (forward-line 1)
11158 (when (eobp)
11159 (forward-line -1)
11160 (return-from exit))))
11161 (forward-line -1)
11162 (and (bobp) (forward-line 1))
11163 (and (anything-pos-header-line-p) (forward-line -2))
11164 (anything-mark-current-line)))))
11168 ;;; Plug-in
11171 ;; Plug-in: info-index
11172 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11173 (let (result)
11174 (unless (anything-candidate-buffer)
11175 (save-window-excursion
11176 (info file)
11177 (let (Info-history
11178 (tobuf (anything-candidate-buffer 'global))
11179 (infobuf (current-buffer))
11180 s e)
11181 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11182 (Info-goto-node node)
11183 (goto-char (point-min))
11184 (while (search-forward "\n* " nil t)
11185 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11186 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11187 (setq s (point-at-bol)
11188 e (point-at-eol))
11189 (with-current-buffer tobuf
11190 (insert-buffer-substring infobuf s e)
11191 (insert "\n"))))))))))
11193 (defun anything-c-info-goto (node-line)
11194 (Info-goto-node (car node-line))
11195 (anything-goto-line (cdr node-line)))
11197 (defun anything-c-info-display-to-real (line)
11198 (and (string-match
11199 ;; This regexp is stolen from Info-apropos-matches
11200 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11201 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11202 (string-to-number (or (match-string 3 line) "1")))))
11204 (defun anything-c-make-info-source (source file)
11205 `(,@source
11206 (name . ,(concat "Info Index: " file))
11207 (info-file . ,file)
11208 (init . anything-c-info-init)
11209 (display-to-real . anything-c-info-display-to-real)
11210 (get-line . buffer-substring)
11211 (candidates-in-buffer)
11212 (action ("Goto node" . anything-c-info-goto))))
11214 (defun anything-compile-source--info-index (source)
11215 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11216 (anything-c-make-info-source source it)
11217 source))
11218 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11220 (anything-document-attribute 'info-index "info-index plugin"
11221 "Create a source of info index very easily.
11223 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11225 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11226 "Index nodes of info file.
11228 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11229 Some info files are missing index specification.
11231 ex. See `anything-c-source-info-screen'.")
11233 ;; Plug-in: candidates-file
11234 (defun anything-compile-source--candidates-file (source)
11235 (if (assoc-default 'candidates-file source)
11236 `((init anything-p-candidats-file-init
11237 ,@(let ((orig-init (assoc-default 'init source)))
11238 (cond ((null orig-init) nil)
11239 ((functionp orig-init) (list orig-init))
11240 (t orig-init))))
11241 (candidates-in-buffer)
11242 ,@source)
11243 source))
11244 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11246 (defun anything-p-candidats-file-init ()
11247 (destructuring-bind (file &optional updating)
11248 (anything-mklist (anything-attr 'candidates-file))
11249 (setq file (anything-interpret-value file))
11250 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11251 (when updating
11252 (buffer-disable-undo)
11253 (font-lock-mode -1)
11254 (auto-revert-mode 1)))))
11256 (anything-document-attribute 'candidates-file "candidates-file plugin"
11257 "Use a file as the candidates buffer.
11259 1st argument is a filename, string or function name or variable name.
11260 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11262 ;; Plug-in: headline
11263 (defun anything-compile-source--anything-headline (source)
11264 (if (assoc-default 'headline source)
11265 (append '((init . anything-headline-init)
11266 (get-line . buffer-substring)
11267 (type . line))
11268 source
11269 '((candidates-in-buffer)
11270 (persistent-help . "Show this line")))
11271 source))
11272 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11274 (defun anything-headline-init ()
11275 (when (and (anything-current-buffer-is-modified)
11276 (with-anything-current-buffer
11277 (eval (or (anything-attr 'condition) t))))
11278 (anything-headline-make-candidate-buffer
11279 (anything-interpret-value (anything-attr 'headline))
11280 (anything-interpret-value (anything-attr 'subexp)))))
11282 (anything-document-attribute 'headline "Headline plug-in"
11283 "Regexp string for anything-headline to scan.")
11284 (anything-document-attribute 'condition "Headline plug-in"
11285 "A sexp representing the condition to use anything-headline.")
11286 (anything-document-attribute 'subexp "Headline plug-in"
11287 "Display (match-string-no-properties subexp).")
11290 (defun anything-headline-get-candidates (regexp subexp)
11291 (with-anything-current-buffer
11292 (save-excursion
11293 (goto-char (point-min))
11294 (if (functionp regexp) (setq regexp (funcall regexp)))
11295 (let (hierarchy curhead)
11296 (flet ((matched ()
11297 (if (numberp subexp)
11298 (cons (match-string-no-properties subexp) (match-beginning subexp))
11299 (cons (buffer-substring (point-at-bol) (point-at-eol))
11300 (point-at-bol))))
11301 (hierarchies (headlines)
11302 (1+ (loop for (_ . hierarchy) in headlines
11303 maximize hierarchy)))
11304 (vector-0-n (v n)
11305 (loop for i from 0 to hierarchy
11306 collecting (aref curhead i)))
11307 (arrange (headlines)
11308 (unless (null headlines) ; FIX headlines empty bug!
11309 (loop with curhead = (make-vector (hierarchies headlines) "")
11310 for ((str . pt) . hierarchy) in headlines
11311 do (aset curhead hierarchy str)
11312 collecting
11313 (cons
11314 (format "H%d:%s" (1+ hierarchy)
11315 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11316 pt)))))
11317 (if (listp regexp)
11318 (arrange
11319 (sort
11320 (loop for re in regexp
11321 for hierarchy from 0
11322 do (goto-char (point-min))
11323 appending
11324 (loop
11325 while (re-search-forward re nil t)
11326 collect (cons (matched) hierarchy)))
11327 (lambda (a b) (> (cdar b) (cdar a)))))
11328 (loop while (re-search-forward regexp nil t)
11329 collect (matched))))))))
11332 (defun anything-headline-make-candidate-buffer (regexp subexp)
11333 (with-current-buffer (anything-candidate-buffer 'local)
11334 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11335 do (insert
11336 (format "%5d:%s\n"
11337 (with-anything-current-buffer
11338 (line-number-at-pos pos))
11339 content)))))
11341 (defun anything-headline-goto-position (pos recenter)
11342 (goto-char pos)
11343 (unless recenter
11344 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11347 ;; Plug-in: persistent-help
11348 (defun anything-compile-source--persistent-help (source)
11349 (append source '((header-line . anything-persistent-help-string))))
11350 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11352 (defun anything-persistent-help-string ()
11353 (substitute-command-keys
11354 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11355 (or (anything-interpret-value (anything-attr 'persistent-help))
11356 (anything-aif (or (assoc-default 'persistent-action
11357 (anything-get-current-source))
11358 (assoc-default 'action
11359 (anything-get-current-source)))
11360 (cond ((symbolp it) (symbol-name it))
11361 ((listp it) (or (ignore-errors (caar it)) ""))))
11363 " (keeping session)")))
11365 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11366 "A string to explain persistent-action of this source.
11367 It also accepts a function or a variable name.")
11369 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11371 ;; Plug-in: Type customize
11372 (defun anything-c-uniq-list (lst)
11373 "Like `remove-duplicates' in CL.
11374 But cut deeper duplicates and test by `equal'. "
11375 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11376 (defvar anything-additional-type-attributes nil)
11377 (defun anything-c-arrange-type-attribute (type spec)
11378 "Override type attributes by `define-anything-type-attribute'.
11380 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11382 Example: Set `play-sound-file' as default action
11383 (anything-c-arrange-type-attribute 'file
11384 '((action (\"Play sound\" . play-sound-file)
11385 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11388 (add-to-list 'anything-additional-type-attributes
11389 (cons type
11390 (loop with typeattr = (assoc-default type anything-type-attributes)
11391 for (attr . value) in spec
11392 if (listp value)
11393 collect (cons attr
11394 (anything-c-uniq-list
11395 (loop for v in value
11396 if (eq v 'REST)
11397 append (assoc-default attr typeattr)
11398 else
11399 collect v)))
11400 else
11401 collect (cons attr value)))))
11402 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11404 (defun anything-compile-source--type-customize (source)
11405 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11406 (append it source)
11407 source))
11408 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11410 ;; Plug-in: default-action
11411 (defun anything-compile-source--default-action (source)
11412 (anything-aif (assoc-default 'default-action source)
11413 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11414 source)
11415 source))
11416 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11417 (anything-document-attribute 'default-action "default-action plug-in"
11418 "Default action.")
11421 ;;; Toggle anything-match-plugin
11424 (defvar anything-mp-initial-highlight-delay nil)
11426 ;;;###autoload
11427 (defun anything-c-toggle-match-plugin ()
11428 "Toggle anything-match-plugin."
11429 (interactive)
11430 (let ((anything-match-plugin-enabled
11431 (member 'anything-compile-source--match-plugin
11432 anything-compile-source-functions)))
11433 (flet ((disable-match-plugin ()
11434 (setq anything-compile-source-functions
11435 (delq 'anything-compile-source--match-plugin
11436 anything-compile-source-functions))
11437 (setq anything-mp-initial-highlight-delay
11438 anything-mp-highlight-delay)
11439 (setq anything-mp-highlight-delay nil))
11440 (enable-match-plugin ()
11441 (require 'anything-match-plugin)
11442 (unless anything-mp-initial-highlight-delay
11443 (setq anything-mp-initial-highlight-delay
11444 anything-mp-highlight-delay))
11445 (setq anything-compile-source-functions
11446 (cons 'anything-compile-source--match-plugin
11447 anything-compile-source-functions))
11448 (unless anything-mp-highlight-delay
11449 (setq anything-mp-highlight-delay
11450 anything-mp-initial-highlight-delay))))
11451 (if anything-match-plugin-enabled
11452 (when (y-or-n-p "Really disable match-plugin? ")
11453 (disable-match-plugin)
11454 (message "Anything-match-plugin disabled"))
11455 (when (y-or-n-p "Really enable match-plugin? ")
11456 (enable-match-plugin)
11457 (message "Anything-match-plugin enabled"))))))
11461 ;;; Type Attributes
11464 (define-anything-type-attribute 'buffer
11465 `((action
11466 ("Switch to buffer" . anything-c-switch-to-buffer)
11467 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11468 ("Switch to buffer other window" . switch-to-buffer-other-window)
11469 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11470 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11471 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11472 ("Query replace" . anything-c-buffer-query-replace)
11473 ("View buffer" . view-buffer)
11474 ("Display buffer" . display-buffer)
11475 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11476 ("Revert buffer(s)" . anything-revert-marked-buffers)
11477 ("Insert buffer" . insert-buffer)
11478 ("Kill buffer(s)" . anything-kill-marked-buffers)
11479 ("Diff with file" . diff-buffer-with-file)
11480 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11481 ("Ediff Merge marked buffers" . (lambda (candidate)
11482 (anything-ediff-marked-buffers candidate t))))
11483 (persistent-help . "Show this buffer")
11484 (candidate-transformer anything-c-skip-current-buffer
11485 anything-c-skip-boring-buffers
11486 anything-c-transform-buffer-display-string))
11487 "Buffer or buffer name.")
11489 (define-anything-type-attribute 'file
11490 `((action
11491 ("Find file" . anything-find-many-files)
11492 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11493 ("Find file as root" . anything-find-file-as-root)
11494 ("Find file other window" . find-file-other-window)
11495 ("Find file other frame" . find-file-other-frame)
11496 ("Open dired in file's directory" . anything-c-open-dired)
11497 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11498 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11499 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11500 ("Checksum File" . anything-ff-checksum)
11501 ("View file" . view-file)
11502 ("Insert file" . insert-file)
11503 ("Delete file(s)" . anything-delete-marked-files)
11504 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11505 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11506 ("Find file in hex dump" . hexl-find-file))
11507 (persistent-help . "Show this file")
11508 (action-transformer anything-c-transform-file-load-el
11509 anything-c-transform-file-browse-url)
11510 (candidate-transformer anything-c-w32-pathname-transformer
11511 anything-c-skip-current-file
11512 anything-c-skip-boring-files
11513 anything-c-shorten-home-path))
11514 "File name.")
11516 (let ((actions '(("Describe command" . describe-function)
11517 ("Add command to kill ring" . anything-c-kill-new)
11518 ("Go to command's definition" . find-function)
11519 ("Debug on entry" . debug-on-entry)
11520 ("Cancel debug on entry" . cancel-debug-on-entry)
11521 ("Trace function" . trace-function)
11522 ("Trace function (background)" . trace-function-background)
11523 ("Untrace function" . untrace-function))))
11524 (define-anything-type-attribute 'command
11525 `((action ("Call interactively" . anything-c-call-interactively)
11526 ,@actions)
11527 ;; Sort commands according to their usage count.
11528 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11529 (coerce . anything-c-symbolify)
11530 (persistent-action . describe-function))
11531 "Command. (string or symbol)")
11533 (define-anything-type-attribute 'function
11534 `((action . ,actions)
11535 (action-transformer anything-c-transform-function-call-interactively)
11536 (candidate-transformer anything-c-mark-interactive-functions)
11537 (coerce . anything-c-symbolify))
11538 "Function. (string or symbol)"))
11540 (define-anything-type-attribute 'variable
11541 '((action ("Describe variable" . describe-variable)
11542 ("Add variable to kill ring" . anything-c-kill-new)
11543 ("Go to variable's definition" . find-variable)
11544 ("Set variable" . anything-c-set-variable))
11545 (coerce . anything-c-symbolify))
11546 "Variable.")
11548 (define-anything-type-attribute 'sexp
11549 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11550 ("Add s-expression to kill ring" . kill-new))
11551 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11552 "String representing S-Expressions.")
11554 (define-anything-type-attribute 'bookmark
11555 `((coerce . anything-bookmark-get-bookmark-from-name)
11556 (action
11557 ("Jump to bookmark" . (lambda (bookmark)
11558 (let ((current-prefix-arg anything-current-prefix-arg))
11559 (bookmark-jump bookmark))
11560 (anything-update)))
11561 ("Jump to BM other window" . (lambda (bookmark)
11562 (bookmark-jump-other-window bookmark)
11563 (anything-update)))
11564 ("Bookmark edit annotation" . bookmark-edit-annotation)
11565 ("Bookmark show annotation" . bookmark-show-annotation)
11566 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11567 ,@(and (locate-library "bookmark-extensions")
11568 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11569 ("Rename bookmark" . bookmark-rename)
11570 ("Relocate bookmark" . bookmark-relocate)))
11571 "Bookmark name.")
11573 (define-anything-type-attribute 'line
11574 '((display-to-real . anything-c-display-to-real-line)
11575 (action ("Go to Line" . anything-c-action-line-goto)))
11576 "LINENO:CONTENT string, eg. \" 16:foo\".
11578 Optional `target-file' attribute is a name of target file.
11580 Optional `before-jump-hook' attribute is a function with no
11581 arguments which is called before jumping to position.
11583 Optional `after-jump-hook' attribute is a function with no
11584 arguments which is called after jumping to position.
11586 If `adjust' attribute is specified, searches the line whose
11587 content is CONTENT near the LINENO.
11589 If `recenter' attribute is specified, the line is displayed at
11590 the center of window, otherwise at the top of window.
11593 (define-anything-type-attribute 'file-line
11594 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11595 (multiline)
11596 (action ("Go to" . anything-c-action-file-line-goto)))
11597 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11599 Optional `default-directory' attribute is a default-directory
11600 FILENAME is interpreted.
11602 Optional `before-jump-hook' attribute is a function with no
11603 arguments which is called before jumping to position.
11605 Optional `after-jump-hook' attribute is a function with no
11606 arguments which is called after jumping to position.
11608 If `adjust' attribute is specified, searches the line whose
11609 content is CONTENT near the LINENO.
11611 If `recenter' attribute is specified, the line is displayed at
11612 the center of window, otherwise at the top of window.
11615 (define-anything-type-attribute 'timer
11616 '((real-to-display . anything-c-timer-real-to-display)
11617 (action ("Cancel Timer" . cancel-timer)
11618 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11619 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11620 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11621 (persistent-help . "Describe Function"))
11622 "Timer.")
11624 ;;;; Default `anything-sources'
11625 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11626 ;; tend to invoke M-x anything directly. So I offer default setting.
11627 (setq anything-sources
11628 '(anything-c-source-buffers-list
11629 anything-c-source-recentf
11630 anything-c-source-files-in-current-dir+))
11632 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
11634 (provide 'anything-config)
11636 ;;; Local Variables:
11637 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
11638 ;;; End:
11640 ;; How to save (DO NOT REMOVE!!)
11641 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
11642 ;;; anything-config.el ends here
11644 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
11645 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
11646 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
11647 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
11648 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
11649 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
11650 ;;; LocalWords: dotimes Thierry online vname
11651 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
11652 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
11653 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
11654 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
11655 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
11656 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
11657 ;;; LocalWords: startpos noselect dont desc