* anything-config.el (anything-esh-get-candidates): Don't try to expand on remote...
[anything-config.git] / anything-config.el
blob2ce077b4f90f7c9112a1aad89e9ebca0c33248bd
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-c-buffer-help'
85 ;; Help command for anything buffers.
86 ;; `anything-ff-help'
87 ;; Help command for `anything-find-files'.
88 ;; `anything-read-file-name-help'
89 ;; Not documented.
90 ;; `anything-generic-file-help'
91 ;; Not documented.
92 ;; `anything-grep-help'
93 ;; Not documented.
94 ;; `anything-pdfgrep-help'
95 ;; Not documented.
96 ;; `anything-etags-help'
97 ;; The help function for etags.
98 ;; `anything-c-ucs-help'
99 ;; Help command for `anything-ucs'.
100 ;; `anything-mini'
101 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
102 ;; `anything-for-files'
103 ;; Preconfigured `anything' for opening files.
104 ;; `anything-recentf'
105 ;; Preconfigured `anything' for `recentf'.
106 ;; `anything-info-at-point'
107 ;; Preconfigured `anything' for searching info at point.
108 ;; `anything-info-emacs'
109 ;; Preconfigured anything for Emacs manual index.
110 ;; `anything-show-kill-ring'
111 ;; Preconfigured `anything' for `kill-ring'.
112 ;; `anything-minibuffer-history'
113 ;; Preconfigured `anything' for `minibuffer-history'.
114 ;; `anything-gentoo'
115 ;; Preconfigured `anything' for gentoo linux.
116 ;; `anything-imenu'
117 ;; Preconfigured `anything' for `imenu'.
118 ;; `anything-google-suggest'
119 ;; Preconfigured `anything' for google search with google suggest.
120 ;; `anything-yahoo-suggest'
121 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
122 ;; `anything-for-buffers'
123 ;; Preconfigured `anything' for buffer.
124 ;; `anything-buffers-list'
125 ;; Enhanced preconfigured `anything' for buffer.
126 ;; `anything-bbdb'
127 ;; Preconfigured `anything' for BBDB.
128 ;; `anything-locate'
129 ;; Preconfigured `anything' for Locate.
130 ;; `anything-w3m-bookmarks'
131 ;; Preconfigured `anything' for w3m bookmark.
132 ;; `anything-firefox-bookmarks'
133 ;; Preconfigured `anything' for firefox bookmark.
134 ;; `anything-colors'
135 ;; Preconfigured `anything' for color.
136 ;; `anything-bookmarks'
137 ;; Preconfigured `anything' for bookmarks.
138 ;; `anything-c-pp-bookmarks'
139 ;; Preconfigured `anything' for bookmarks (pretty-printed).
140 ;; `anything-c-insert-latex-math'
141 ;; Preconfigured anything for latex math symbols completion.
142 ;; `anything-register'
143 ;; Preconfigured `anything' for Emacs registers.
144 ;; `anything-man-woman'
145 ;; Preconfigured `anything' for Man and Woman pages.
146 ;; `anything-org-keywords'
147 ;; Preconfigured `anything' for org keywords.
148 ;; `anything-emms'
149 ;; Preconfigured `anything' for emms sources.
150 ;; `anything-eev-anchors'
151 ;; Preconfigured `anything' for eev anchors.
152 ;; `anything-bm-list'
153 ;; Preconfigured `anything' for visible bookmarks.
154 ;; `anything-timers'
155 ;; Preconfigured `anything' for timers.
156 ;; `anything-list-emacs-process'
157 ;; Preconfigured `anything' for emacs process.
158 ;; `anything-occur'
159 ;; Preconfigured Anything for Occur source.
160 ;; `anything-browse-code'
161 ;; Preconfigured anything to browse code.
162 ;; `anything-org-headlines'
163 ;; Preconfigured anything to show org headlines.
164 ;; `anything-info-gnus'
165 ;; Preconfigured anything to browse Gnus Manual.
166 ;; `anything-regexp'
167 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
168 ;; `anything-c-copy-files-async'
169 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
170 ;; `anything-find-files'
171 ;; Preconfigured `anything' for anything implementation of `find-file'.
172 ;; `anything-write-file'
173 ;; Preconfigured `anything' providing completion for `write-file'.
174 ;; `anything-insert-file'
175 ;; Preconfigured `anything' providing completion for `insert-file'.
176 ;; `anything-dired-rename-file'
177 ;; Preconfigured `anything' to rename files from dired.
178 ;; `anything-dired-copy-file'
179 ;; Preconfigured `anything' to copy files from dired.
180 ;; `anything-dired-symlink-file'
181 ;; Preconfigured `anything' to symlink files from dired.
182 ;; `anything-dired-hardlink-file'
183 ;; Preconfigured `anything' to hardlink files from dired.
184 ;; `anything-do-grep'
185 ;; Preconfigured anything for grep.
186 ;; `anything-c-etags-select'
187 ;; Preconfigured anything for etags.
188 ;; `anything-filelist'
189 ;; Preconfigured `anything' to open files instantly.
190 ;; `anything-filelist+'
191 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
192 ;; `anything-M-x'
193 ;; Preconfigured `anything' for Emacs commands.
194 ;; `anything-manage-advice'
195 ;; Preconfigured `anything' to disable/enable function advices.
196 ;; `anything-bookmark-ext'
197 ;; Preconfigured `anything' for bookmark-extensions sources.
198 ;; `anything-simple-call-tree'
199 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
200 ;; `anything-mark-ring'
201 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
202 ;; `anything-global-mark-ring'
203 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
204 ;; `anything-all-mark-rings'
205 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
206 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
207 ;; Preconfigured `anything' to edit or view EmacsWiki page.
208 ;; `anything-yaoddmuse-emacswiki-post-library'
209 ;; Preconfigured `anything' to post library to EmacsWiki.
210 ;; `anything-eval-expression'
211 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
212 ;; `anything-eval-expression-with-eldoc'
213 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
214 ;; `anything-calcul-expression'
215 ;; Preconfigured anything for `anything-c-source-calculation-result'.
216 ;; `anything-surfraw'
217 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
218 ;; `anything-call-source'
219 ;; Preconfigured `anything' to call anything source.
220 ;; `anything-execute-anything-command'
221 ;; Preconfigured `anything' to execute preconfigured `anything'.
222 ;; `anything-create'
223 ;; Preconfigured `anything' to do many create actions from STRING.
224 ;; `anything-top'
225 ;; Preconfigured `anything' for top command.
226 ;; `anything-select-xfont'
227 ;; Preconfigured `anything' to select Xfont.
228 ;; `anything-world-time'
229 ;; Preconfigured `anything' to show world time.
230 ;; `anything-apt'
231 ;; Preconfigured `anything' : frontend of APT package manager.
232 ;; `anything-esh-pcomplete'
233 ;; Preconfigured anything to provide anything completion in eshell.
234 ;; `anything-eshell-history'
235 ;; Preconfigured anything for eshell history.
236 ;; `anything-c-run-external-command'
237 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
238 ;; `anything-ratpoison-commands'
239 ;; Preconfigured `anything' to execute ratpoison commands.
240 ;; `anything-ucs'
241 ;; Preconfigured anything for `ucs-names' math symbols.
242 ;; `anything-show-this-source-only'
243 ;; Show all candidates of this source.
244 ;; `anything-test-sources'
245 ;; List all anything sources for test.
246 ;; `anything-select-source'
247 ;; [OBSOLETE] Select source.
248 ;; `anything-mark-all'
249 ;; Mark all visible unmarked candidates in current source.
250 ;; `anything-unmark-all'
251 ;; Unmark all candidates in all sources of current anything session.
252 ;; `anything-toggle-all-marks'
253 ;; Toggle all marks.
254 ;; `anything-buffer-diff-persistent'
255 ;; Toggle diff buffer without quitting anything.
256 ;; `anything-buffer-revert-persistent'
257 ;; Revert buffer without quitting anything.
258 ;; `anything-buffer-save-persistent'
259 ;; Save buffer without quitting anything.
260 ;; `anything-buffer-run-kill-buffers'
261 ;; Run kill buffer action from `anything-c-source-buffers-list'.
262 ;; `anything-buffer-run-grep'
263 ;; Run Grep action from `anything-c-source-buffers-list'.
264 ;; `anything-buffer-run-zgrep'
265 ;; Run Grep action from `anything-c-source-buffers-list'.
266 ;; `anything-buffer-run-query-replace-regexp'
267 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
268 ;; `anything-buffer-run-query-replace'
269 ;; Run Query replace action from `anything-c-source-buffers-list'.
270 ;; `anything-buffer-switch-other-window'
271 ;; Run switch to other window action from `anything-c-source-buffers-list'.
272 ;; `anything-buffer-switch-other-frame'
273 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
274 ;; `anything-buffer-switch-to-elscreen'
275 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
276 ;; `anything-buffer-run-ediff'
277 ;; Run ediff action from `anything-c-source-buffers-list'.
278 ;; `anything-buffer-run-ediff-merge'
279 ;; Run ediff action from `anything-c-source-buffers-list'.
280 ;; `anything-ff-run-toggle-auto-update'
281 ;; Not documented.
282 ;; `anything-ff-run-switch-to-history'
283 ;; Run Switch to history action from `anything-c-source-find-files'.
284 ;; `anything-ff-run-grep'
285 ;; Run Grep action from `anything-c-source-find-files'.
286 ;; `anything-ff-run-pdfgrep'
287 ;; Run Pdfgrep action from `anything-c-source-find-files'.
288 ;; `anything-ff-run-zgrep'
289 ;; Run Grep action from `anything-c-source-find-files'.
290 ;; `anything-ff-run-copy-file'
291 ;; Run Copy file action from `anything-c-source-find-files'.
292 ;; `anything-ff-run-rename-file'
293 ;; Run Rename file action from `anything-c-source-find-files'.
294 ;; `anything-ff-run-byte-compile-file'
295 ;; Run Byte compile file action from `anything-c-source-find-files'.
296 ;; `anything-ff-run-load-file'
297 ;; Run Load file action from `anything-c-source-find-files'.
298 ;; `anything-ff-run-eshell-command-on-file'
299 ;; Run eshell command on file action from `anything-c-source-find-files'.
300 ;; `anything-ff-run-ediff-file'
301 ;; Run Ediff file action from `anything-c-source-find-files'.
302 ;; `anything-ff-run-ediff-merge-file'
303 ;; Run Ediff merge file action from `anything-c-source-find-files'.
304 ;; `anything-ff-run-symlink-file'
305 ;; Run Symlink file action from `anything-c-source-find-files'.
306 ;; `anything-ff-run-delete-file'
307 ;; Run Delete file action from `anything-c-source-find-files'.
308 ;; `anything-ff-run-complete-fn-at-point'
309 ;; Run complete file name action from `anything-c-source-find-files'.
310 ;; `anything-ff-run-switch-to-eshell'
311 ;; Run switch to eshell action from `anything-c-source-find-files'.
312 ;; `anything-ff-run-switch-other-window'
313 ;; Run switch to other window action from `anything-c-source-find-files'.
314 ;; `anything-ff-run-switch-other-frame'
315 ;; Run switch to other frame action from `anything-c-source-find-files'.
316 ;; `anything-ff-run-open-file-externally'
317 ;; Run open file externally command action from `anything-c-source-find-files'.
318 ;; `anything-ff-run-locate'
319 ;; Run locate action from `anything-c-source-find-files'.
320 ;; `anything-ff-run-gnus-attach-files'
321 ;; Run gnus attach files command action from `anything-c-source-find-files'.
322 ;; `anything-ff-run-etags'
323 ;; Run Etags command action from `anything-c-source-find-files'.
324 ;; `anything-ff-run-print-file'
325 ;; Run Print file action from `anything-c-source-find-files'.
326 ;; `anything-ff-run-toggle-basename'
327 ;; Not documented.
328 ;; `anything-find-files-down-one-level'
329 ;; Go down one level like unix command `cd ..'.
330 ;; `anything-ff-properties-persistent'
331 ;; Show properties without quitting anything.
332 ;; `anything-ff-run-kill-buffer-persistent'
333 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
334 ;; `anything-ff-rotate-left-persistent'
335 ;; Rotate image left without quitting anything.
336 ;; `anything-ff-rotate-right-persistent'
337 ;; Rotate image right without quitting anything.
338 ;; `anything-c-goto-precedent-file'
339 ;; Go to precedent file in anything grep/etags buffers.
340 ;; `anything-c-goto-next-file'
341 ;; Go to precedent file in anything grep/etags buffers.
342 ;; `anything-c-grep-run-persistent-action'
343 ;; Run grep persistent action from `anything-do-grep-1'.
344 ;; `anything-c-grep-run-default-action'
345 ;; Run grep default action from `anything-do-grep-1'.
346 ;; `anything-c-grep-run-other-window-action'
347 ;; Run grep goto other window action from `anything-do-grep-1'.
348 ;; `anything-c-grep-run-save-buffer'
349 ;; Run grep save results action from `anything-do-grep-1'.
350 ;; `anything-do-pdfgrep'
351 ;; Not documented.
352 ;; `anything-yank-text-at-point'
353 ;; Yank text at point in minibuffer.
354 ;; `anything-c-describe-attributes'
355 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
356 ;; `anything-yaoddmuse-cache-pages'
357 ;; Fetch the list of files on emacswiki and create cache file.
358 ;; `anything-eval-new-line-and-indent'
359 ;; Not documented.
360 ;; `anything-call-source-from-anything'
361 ;; Call anything source within `anything' session.
362 ;; `anything-create-from-anything'
363 ;; Run `anything-create' from `anything' as a fallback.
364 ;; `anything-c-ucs-persistent-insert'
365 ;; Not documented.
366 ;; `anything-c-ucs-persistent-forward'
367 ;; Not documented.
368 ;; `anything-c-ucs-persistent-backward'
369 ;; Not documented.
370 ;; `anything-c-ucs-persistent-delete'
371 ;; Not documented.
372 ;; `anything-lisp-completion-at-point'
373 ;; Anything lisp symbol completion at point.
374 ;; `anything-c-complete-file-name-at-point'
375 ;; Complete file name at point.
376 ;; `anything-lisp-completion-at-point-or-indent'
377 ;; First call indent and second call complete lisp symbol.
378 ;; `anything-lisp-completion-or-file-name-at-point'
379 ;; Complete lisp symbol or filename at point.
380 ;; `anything-c-set-variable'
381 ;; Set value to VAR interactively.
382 ;; `anything-c-adaptive-save-history'
383 ;; Save history information to file given by `anything-c-adaptive-history-file'.
384 ;; `anything-c-reset-adaptative-history'
385 ;; Delete all `anything-c-adaptive-history' and his file.
386 ;; `anything-c-toggle-match-plugin'
387 ;; Toggle anything-match-plugin.
389 ;; * User variables defined here:
390 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
391 ;; `anything-c-adaptive-history-file'
392 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
393 ;; `anything-c-adaptive-history-length'
394 ;; Default Value: 50
395 ;; `anything-c-google-suggest-url'
396 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
397 ;; `anything-c-google-suggest-search-url'
398 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
399 ;; `anything-google-suggest-use-curl-p'
400 ;; Default Value: nil
401 ;; `anything-c-yahoo-suggest-url'
402 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
403 ;; `anything-c-yahoo-suggest-search-url'
404 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
405 ;; `anything-c-boring-buffer-regexp'
406 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
407 ;; `anything-c-boring-file-regexp'
408 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
409 ;; `anything-kill-ring-threshold'
410 ;; Default Value: 10
411 ;; `anything-c-kill-ring-max-lines-number'
412 ;; Default Value: nil
413 ;; `anything-su-or-sudo'
414 ;; Default Value: "su"
415 ;; `anything-for-files-prefered-list'
416 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
417 ;; `anything-create--actions-private'
418 ;; Default Value: nil
419 ;; `anything-allow-skipping-current-buffer'
420 ;; Default Value: t
421 ;; `anything-c-enable-eval-defun-hack'
422 ;; Default Value: t
423 ;; `anything-tramp-verbose'
424 ;; Default Value: 0
425 ;; `anything-raise-command'
426 ;; Default Value: nil
427 ;; `anything-command-map-prefix-key'
428 ;; Default Value: "<f5> a"
429 ;; `anything-c-browse-code-regexp-lisp'
430 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
431 ;; `anything-c-browse-code-regexp-python'
432 ;; Default Value: "\\<def\\>\\|\\<class\\>"
433 ;; `anything-c-browse-code-regexp-alist'
434 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
435 ;; `anything-c-external-programs-associations'
436 ;; Default Value: nil
437 ;; `anything-ff-auto-update-initial-value'
438 ;; Default Value: t
439 ;; `anything-c-copy-async-prefered-emacs'
440 ;; Default Value: "emacs"
441 ;; `anything-ff-lynx-style-map'
442 ;; Default Value: t
443 ;; `anything-ff-history-max-length'
444 ;; Default Value: 100
445 ;; `anything-ff-smart-completion'
446 ;; Default Value: t
447 ;; `anything-ff-default-kbsize'
448 ;; Default Value: 1024.0
449 ;; `anything-ff-tramp-not-fancy'
450 ;; Default Value: t
451 ;; `anything-ff-exif-data-program'
452 ;; Default Value: "exiftran"
453 ;; `anything-ff-exif-data-program-args'
454 ;; Default Value: "-d"
455 ;; `anything-c-grep-use-ioccur-style-keys'
456 ;; Default Value: t
457 ;; `anything-c-pdfgrep-default-read-command'
458 ;; Default Value: "xpdf '%f' %p"
459 ;; `anything-c-etags-tag-file-name'
460 ;; Default Value: "TAGS"
461 ;; `anything-c-etags-tag-file-search-limit'
462 ;; Default Value: 10
463 ;; `anything-c-etags-use-regexp-search'
464 ;; Default Value: nil
465 ;; `anything-c-filelist-file-name'
466 ;; Default Value: nil
467 ;; `anything-c-eldoc-in-minibuffer-show-fn'
468 ;; Default Value: anything-c-eldoc-show-in-mode-line
469 ;; `anything-c-turn-on-show-completion'
470 ;; Default Value: t
471 ;; `anything-lisp-completion-or-indent-delay'
472 ;; Default Value: 0.6
473 ;; `anything-c-default-external-file-browser'
474 ;; Default Value: "nautilus"
475 ;; `anything-c-use-adaptative-sorting'
476 ;; Default Value: nil
477 ;; `anything-ff-newfile-prompt-p'
478 ;; Default Value: t
479 ;; `anything-ff-avfs-directory'
480 ;; Default Value: nil
481 ;; `anything-ff-file-compressed-list'
482 ;; Default Value: ("gz" "bz2" "zip" "7z")
483 ;; `anything-locate-db-file-regexp'
484 ;; Default Value: "m?locate.db$"
485 ;; `anything-c-eldoc-show-in-mode-line-delay'
486 ;; Default Value: 12
487 ;; `anything-c-copy-files-async-log-file'
488 ;; Default Value: "/tmp/dired.log"
489 ;; `anything-ff-printer-list'
490 ;; Default Value: nil
491 ;; `anything-ff-transformer-show-only-basename'
492 ;; Default Value: nil
494 ;; * Anything sources defined here:
495 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
496 ;; `anything-c-source-regexp' (Regexp Builder)
497 ;; `anything-c-source-buffers' (Buffers)
498 ;; `anything-c-source-buffer-not-found' (Create buffer)
499 ;; `anything-c-source-buffers-list' (Buffers)
500 ;; `anything-c-source-file-name-history' (File Name History)
501 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
502 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
503 ;; `anything-c-source-find-files' (Find Files)
504 ;; `anything-c-source-write-file' (Write File)
505 ;; `anything-c-source-insert-file' (Insert File)
506 ;; `anything-c-source-copy-files' (Copy Files)
507 ;; `anything-c-source-symlink-files' (Symlink Files)
508 ;; `anything-c-source-hardlink-files' (Hardlink Files)
509 ;; `anything-c-source-file-cache' (File Cache)
510 ;; `anything-c-source-locate' (Locate)
511 ;; `anything-c-source-recentf' (Recentf)
512 ;; `anything-c-source-ffap-guesser' (File at point)
513 ;; `anything-c-source-ffap-line' (File/Lineno at point)
514 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
515 ;; `anything-c-source-filelist' (FileList)
516 ;; `anything-c-source-info-pages' (Info Pages)
517 ;; `anything-c-source-info-elisp' (Info index: elisp)
518 ;; `anything-c-source-info-cl' (Info index: cl)
519 ;; `anything-c-source-info-org' (Info index: org)
520 ;; `anything-c-source-info-gnus' (Info index: Gnus)
521 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
522 ;; `anything-c-source-info-zsh' (Info index: zsh)
523 ;; `anything-c-source-info-bash' (Info index: bash)
524 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
525 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
526 ;; `anything-c-source-info-find' (Info index: find)
527 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
528 ;; `anything-c-source-info-textutils' (Info index: textutils)
529 ;; `anything-c-source-info-libc' (Info index: libc)
530 ;; `anything-c-source-info-make' (Info index: make)
531 ;; `anything-c-source-info-automake' (Info index: automake)
532 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
533 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
534 ;; `anything-c-source-info-emacs' (Info index: emacs)
535 ;; `anything-c-source-info-elib' (Info index: elib)
536 ;; `anything-c-source-info-eieio' (Info index: eieio)
537 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
538 ;; `anything-c-source-info-guile' (Info index: guile)
539 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
540 ;; `anything-c-source-info-goops' (Info index: goops)
541 ;; `anything-c-source-info-screen' (Info index: screen)
542 ;; `anything-c-source-info-latex' (Info index: latex)
543 ;; `anything-c-source-info-gawk' (Info index: gawk)
544 ;; `anything-c-source-info-sed' (Info index: sed)
545 ;; `anything-c-source-info-m4' (Info index: m4)
546 ;; `anything-c-source-info-wget' (Info index: wget)
547 ;; `anything-c-source-info-binutils' (Info index: binutils)
548 ;; `anything-c-source-info-as' (Info index: as)
549 ;; `anything-c-source-info-bfd' (Info index: bfd)
550 ;; `anything-c-source-info-gprof' (Info index: gprof)
551 ;; `anything-c-source-info-ld' (Info index: ld)
552 ;; `anything-c-source-info-diff' (Info index: diff)
553 ;; `anything-c-source-info-flex' (Info index: flex)
554 ;; `anything-c-source-info-grep' (Info index: grep)
555 ;; `anything-c-source-info-gzip' (Info index: gzip)
556 ;; `anything-c-source-info-libtool' (Info index: libtool)
557 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
558 ;; `anything-c-source-info-info' (Info index: info)
559 ;; `anything-c-source-info-gdb' (Info index: gdb)
560 ;; `anything-c-source-info-stabs' (Info index: stabs)
561 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
562 ;; `anything-c-source-info-cvs' (Info index: cvs)
563 ;; `anything-c-source-info-bison' (Info index: bison)
564 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
565 ;; `anything-c-source-info-global' (Info index: global)
566 ;; `anything-c-source-man-pages' (Manual Pages)
567 ;; `anything-c-source-complex-command-history' (Complex Command History)
568 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
569 ;; `anything-c-source-emacs-commands' (Emacs Commands)
570 ;; `anything-c-source-lacarte' (Lacarte)
571 ;; `anything-c-source-emacs-functions' (Emacs Functions)
572 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
573 ;; `anything-c-source-advice' (Function Advice)
574 ;; `anything-c-source-emacs-variables' (Emacs Variables)
575 ;; `anything-c-source-bookmarks' (Bookmarks)
576 ;; `anything-c-source-bookmark-set' (Set Bookmark)
577 ;; `anything-c-source-bm' (Visible Bookmarks)
578 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
579 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
580 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
581 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
582 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
583 ;; `anything-c-source-bookmark-images' (Bookmark Images)
584 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
585 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
586 ;; `anything-c-source-bookmark-info' (Bookmark Info)
587 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
588 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
589 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
590 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
591 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
592 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
593 ;; `anything-c-source-imenu' (Imenu)
594 ;; `anything-c-source-ctags' (Exuberant ctags)
595 ;; `anything-c-source-etags-select' (Etags)
596 ;; `anything-c-source-semantic' (Semantic Tags)
597 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
598 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
599 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
600 ;; `anything-c-source-customize-face' (Customize Face)
601 ;; `anything-c-source-colors' (Colors)
602 ;; `anything-c-source-tracker-search' (Tracker Search)
603 ;; `anything-c-source-mac-spotlight' (mdfind)
604 ;; `anything-c-source-picklist' (Picklist)
605 ;; `anything-c-source-kill-ring' (Kill Ring)
606 ;; `anything-c-source-mark-ring' (mark-ring)
607 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
608 ;; `anything-c-source-register' (Registers)
609 ;; `anything-c-source-latex-math' (Latex Math Menu)
610 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
611 ;; `anything-c-source-rd-headline' (RD HeadLine)
612 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
613 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
614 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
615 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
616 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
617 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
618 ;; `anything-c-source-eev-anchor' (Anchors)
619 ;; `anything-c-source-org-headline' (Org HeadLine)
620 ;; `anything-c-source-org-keywords' (Org Keywords)
621 ;; `anything-c-source-bbdb' (BBDB)
622 ;; `anything-c-source-evaluation-result' (Evaluation Result)
623 ;; `anything-c-source-calculation-result' (Calculation Result)
624 ;; `anything-c-source-google-suggest' (Google Suggest)
625 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
626 ;; `anything-c-source-emms-streams' (Emms Streams)
627 ;; `anything-c-source-emms-dired' (Music Directory)
628 ;; `anything-c-source-emms-files' (Emms files)
629 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
630 ;; `anything-c-source-call-source' (Call anything source)
631 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
632 ;; `anything-c-source-occur' (Occur)
633 ;; `anything-c-source-browse-code' (Browse code)
634 ;; `anything-c-source-create' (Create)
635 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
636 ;; `anything-c-source-elscreen' (Elscreen)
637 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
638 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
639 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
640 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
641 ;; `anything-c-source-xfonts' (X Fonts)
642 ;; `anything-c-source-ucs' (Ucs names)
643 ;; `anything-c-source-emacs-process' (Emacs Process)
644 ;; `anything-c-source-time-world' (Time World List)
645 ;; `anything-c-source-apt' (APT)
646 ;; `anything-c-source-gentoo' (Portage sources)
647 ;; `anything-c-source-use-flags' (Use Flags)
648 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
649 ;; `anything-c-source-esh' (Eshell completions)
650 ;; `anything-c-source-eshell-history' (Eshell history)
652 ;; *** END auto-documentation
655 ;;; Change log:
657 ;; Change log of this file is found at
658 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
660 ;; Change log of this project is found at
661 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
663 ;;; Contributors:
665 ;; Tamas Patrovics
666 ;; Tassilo Horn <tassilo@member.fsf.org>
667 ;; Vagn Johansen <gonz808@hotmail.com>
668 ;; Mathias Dahl <mathias.dahl@gmail.com>
669 ;; Bill Clementson <billclem@gmail.com>
670 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
671 ;; Drew Adams <drew.adams@oracle.com>
672 ;; Jason McBrayer <jmcbray@carcosa.net>
673 ;; Andy Stewart <lazycat.manatee@gmail.com>
674 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
675 ;; rubikitch <rubikitch@ruby-lang.org>
676 ;; Scott Vokes <vokes.s@gmail.com>
677 ;; Kenichirou Oyama <k1lowxb@gmail.com>
679 ;;; For Maintainers:
681 ;; Evaluate (autodoc-update-all) before commit. This function
682 ;; generates anything-c-source-* / functions / options list.
684 ;; Install also developer-tools/autodoc.el
685 ;; And eval it or run interactively.
687 ;; [EVAL IT] (autodoc-update-all)
689 ;; Please write details documentation about function, then others will
690 ;; read code more easier. -- Andy Stewart
694 ;;; TODO
696 ;; - Fix documentation, now many functions haven't documentations.
699 ;;; Code:
702 ;;; Require
705 (require 'anything)
706 (require 'thingatpt)
707 (require 'ffap)
708 (require 'cl)
709 (require 'dired-aux)
710 (require 'dired-x)
711 (require 'tramp)
712 (require 'grep)
713 (require 'url)
714 (require 'xml)
715 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
716 (eval-when-compile (require 'semantic nil t))
717 (require 'anything-match-plugin)
721 ;;; Declare external functions
724 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
725 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
726 (declare-function image-dired-update-property "image-dired.el" (prop value))
727 (declare-function woman-file-name-all-completions "woman.el" (topic))
728 (declare-function Man-getpage-in-background "man.el" (topic))
729 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
730 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
731 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
732 (declare-function org-get-current-options "ext:org-exp.el")
733 (declare-function emms-streams "ext:emms-streams")
734 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
735 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
736 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
737 (declare-function emms-stream-quit "ext:emms-streams")
738 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
739 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
740 (declare-function emms-playlist-first "ext:emms")
741 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
742 (declare-function term-line-mode "term")
743 (declare-function term-char-mode "term")
744 (declare-function term-send-input "term")
745 (declare-function term-send-eof "term")
746 (declare-function Info-index-nodes "info" (&optional file))
747 (declare-function Info-goto-node "info" (&optional fork))
748 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
749 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
750 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
751 (declare-function elscreen-goto "ext:elscreen.el" (screen))
752 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
753 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
754 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
755 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
756 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
757 (declare-function bbdb "ext:bbdb-com")
758 (declare-function bbdb-current-record "ext:bbdb-com")
759 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
760 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
761 (declare-function bbdb-current-record "ext:bbdb-com")
762 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
763 (declare-function bbdb-records "ext:bbdb-com"
764 (&optional dont-check-disk already-in-db-buffer))
765 (declare-function eshell-read-aliases-list "em-alias")
766 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
767 (declare-function eshell-bol "esh-mode")
768 (declare-function eldoc-current-symbol "eldoc")
769 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
770 (declare-function eldoc-get-var-docstring "eldoc" (sym))
771 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
772 (declare-function find-library-name "find-func.el" (library))
773 (declare-function adoc-construct "ext:auto-document.el" (buf))
774 (declare-function adoc-first-line "ext:auto-document.el" (str))
775 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
776 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
780 ;;; compatibility
783 (unless (fboundp 'window-system)
784 (defun window-system (&optional arg)
785 window-system))
789 ;;; Customize
792 (defgroup anything-config nil
793 "Predefined configurations for `anything.el'."
794 :group 'anything)
796 (defcustom anything-c-adaptive-history-file
797 "~/.emacs.d/anything-c-adaptive-history"
798 "Path of file where history information is stored."
799 :type 'string
800 :group 'anything-config)
802 (defcustom anything-c-adaptive-history-length 50
803 "Maximum number of candidates stored for a source."
804 :type 'number
805 :group 'anything-config)
807 (defcustom anything-c-google-suggest-url
808 "http://google.com/complete/search?output=toolbar&q="
809 "URL used for looking up Google suggestions."
810 :type 'string
811 :group 'anything-config)
813 (defcustom anything-c-google-suggest-search-url
814 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
815 "URL used for Google searching."
816 :type 'string
817 :group 'anything-config)
819 (defcustom anything-google-suggest-use-curl-p nil
820 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
821 Otherwise `url-retrieve-synchronously' is used."
822 :type 'boolean
823 :group 'anything-config)
825 (defcustom anything-c-yahoo-suggest-url
826 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
827 "Url used for looking up Yahoo suggestions."
828 :type 'string
829 :group 'anything-config)
831 (defcustom anything-c-yahoo-suggest-search-url
832 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
833 "Url used for Yahoo searching."
834 :type 'string
835 :group 'anything-config)
837 (defcustom anything-c-boring-buffer-regexp
838 (rx (or
839 (group bos " ")
840 ;; anything-buffer
841 "*anything"
842 ;; echo area
843 " *Echo Area" " *Minibuf"))
844 "The regexp that match boring buffers.
845 Buffer candidates matching this regular expression will be
846 filtered from the list of candidates if the
847 `anything-c-skip-boring-buffers' candidate transformer is used, or
848 they will be displayed with face `file-name-shadow' if
849 `anything-c-shadow-boring-buffers' is used."
850 :type 'string
851 :group 'anything-config)
852 ;; (string-match anything-c-boring-buffer-regexp "buf")
853 ;; (string-match anything-c-boring-buffer-regexp " hidden")
854 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
856 (defcustom anything-c-boring-file-regexp
857 (rx (or
858 ;; Boring directories
859 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
860 ;; Boring files
861 (and line-start ".#")
862 (and (or ".class" ".la" ".o" "~") eol)))
863 "The regexp that match boring files.
864 File candidates matching this regular expression will be
865 filtered from the list of candidates if the
866 `anything-c-skip-boring-files' candidate transformer is used, or
867 they will be displayed with face `file-name-shadow' if
868 `anything-c-shadow-boring-files' is used."
869 :type 'string
870 :group 'anything-config)
872 (defcustom anything-kill-ring-threshold 10
873 "*Minimum length to be listed by `anything-c-source-kill-ring'."
874 :type 'integer
875 :group 'anything-config)
877 (defcustom anything-c-kill-ring-max-lines-number nil
878 "Max number of lines displayed per candidate in kill-ring browser.
879 If nil or zero, don't truncate candidate, show all."
880 :type 'integer
881 :group 'anything-config)
883 (defcustom anything-su-or-sudo "su"
884 "What command to use for root access."
885 :type 'string
886 :group 'anything-config)
888 (defcustom anything-for-files-prefered-list
889 '(anything-c-source-ffap-line
890 anything-c-source-ffap-guesser
891 anything-c-source-buffers-list
892 anything-c-source-recentf
893 anything-c-source-bookmarks
894 anything-c-source-file-cache
895 anything-c-source-files-in-current-dir+
896 anything-c-source-locate)
897 "Your prefered sources to find files."
898 :type 'list
899 :group 'anything-config)
901 (defcustom anything-create--actions-private nil
902 "User defined actions for `anything-create' / `anything-c-source-create'.
903 It is a list of (DISPLAY . FUNCTION) pairs like `action'
904 attribute of `anything-sources'.
906 It is prepended to predefined pairs."
907 :type 'list
908 :group 'anything-config)
910 (defcustom anything-allow-skipping-current-buffer t
911 "Show current buffer or not in anything buffer"
912 :type 'boolean
913 :group 'anything-config)
915 (defcustom anything-c-enable-eval-defun-hack t
916 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
917 This hack is invoked when pressing C-M-x in the form \
918 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
919 :type 'boolean
920 :group 'anything-config)
922 (defcustom anything-tramp-verbose 0
923 "*Just like `tramp-verbose' but specific to anything.
924 When set to 0 don't show tramp messages in anything.
925 If you want to have the default tramp messages set it to 3."
926 :type 'integer
927 :group 'anything-config)
929 (defcustom anything-raise-command nil
930 "*A shell command to jump to a window running specific program.
931 Need external program wmctrl.
932 This will be use with `format', so use something like \"wmctrl -xa %s\"."
933 :type 'string
934 :group 'anything-config)
936 (defun anything-set-anything-command-map-prefix-key (var key)
937 (declare (special anything-command-map-prefix-key))
938 (when (boundp 'anything-command-map-prefix-key)
939 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
940 (setq anything-command-map-prefix-key key)
941 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
942 'anything-command-map))
944 (defcustom anything-command-map-prefix-key "<f5> a"
945 "*The prefix key for all `anything-command-map' commands.
947 !!WARNING!!
948 This default value is very likely to be changed,
949 because it is under discussion."
950 :type 'string
951 :set 'anything-set-anything-command-map-prefix-key
952 :group 'anything-config)
954 (defcustom anything-c-browse-code-regexp-lisp
955 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
956 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
957 "*Regexp used to parse lisp buffer when browsing code."
958 :type 'string
959 :group 'anything-config)
961 (defcustom anything-c-browse-code-regexp-python
962 "\\<def\\>\\|\\<class\\>"
963 "*Regexp used to parse python buffer when browsing code."
964 :type 'string
965 :group 'anything-config)
967 (defcustom anything-c-browse-code-regexp-alist
968 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
969 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
970 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
971 (python-mode . ,anything-c-browse-code-regexp-python))
972 "*Alist to store regexps for browsing code corresponding \
973 to a specific `major-mode'."
974 :type 'list
975 :group 'anything-config)
977 (defcustom anything-c-external-programs-associations nil
978 "*Alist to store externals programs associated with file extension.
979 This variable overhide setting in .mailcap file.
980 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
981 :type 'list
982 :group 'anything-config)
984 (defcustom anything-ff-auto-update-initial-value t
985 "Auto update when only one candidate directory is matched.
986 This is the default value when starting `anything-find-files'."
987 :group 'anything-config
988 :type 'boolean)
990 (defcustom anything-c-copy-async-prefered-emacs "emacs"
991 "Path to the emacs you want to use for copying async.
992 Emacs versions < 24 fail to copy directory due to a bug not fixed
993 in `copy-directory'."
994 :group 'anything-config
995 :type 'string)
997 (defcustom anything-ff-lynx-style-map t
998 "Use arrow keys to navigate with `anything-find-files'.
999 You will have to restart Emacs or reeval `anything-find-files-map'
1000 and `anything-c-read-file-map' for this take effect."
1001 :group 'anything-config
1002 :type 'boolean)
1004 (defcustom anything-ff-history-max-length 100
1005 "*Number of elements shown in `anything-find-files' history."
1006 :group 'anything-config
1007 :type 'integer)
1009 (defcustom anything-ff-smart-completion t
1010 "Try to complete filenames smarter when non--nil.
1011 See `anything-ff-transform-fname-for-completion' for more info."
1012 :group 'anything-config
1013 :type 'boolean)
1015 (defcustom anything-ff-default-kbsize 1024.0
1016 "Default Kbsize to use for showing files size.
1017 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1018 :group 'anything-config
1019 :type 'float)
1021 (defcustom anything-ff-tramp-not-fancy t
1022 "No colors when listing remote files when set to non--nil.
1023 This make listing much faster, specially on slow machines."
1024 :group 'anything-config
1025 :type 'boolean)
1027 (defcustom anything-ff-exif-data-program "exiftran"
1028 "*Program used to extract exif data of an image file."
1029 :group 'anything-config
1030 :type 'string)
1032 (defcustom anything-ff-exif-data-program-args "-d"
1033 "*Arguments used for `anything-ff-exif-data-program'."
1034 :group 'anything-config
1035 :type 'string)
1037 (defcustom anything-c-grep-use-ioccur-style-keys t
1038 "Use Arrow keys to jump to occurences."
1039 :group 'anything-config
1040 :type 'boolean)
1042 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1043 "Default command to read pdf files from pdfgrep.
1044 Where '%f' format spec is filename and '%p' is page number"
1045 :group 'anything-config
1046 :type 'string)
1048 (defcustom anything-c-etags-tag-file-name "TAGS"
1049 "Etags tag file name."
1050 :type 'string
1051 :group 'anything-config)
1053 (defcustom anything-c-etags-tag-file-search-limit 10
1054 "The limit level of directory to search tag file.
1055 Don't search tag file deeply if outside this value."
1056 :type 'number
1057 :group 'anything-config)
1059 (defcustom anything-c-etags-use-regexp-search nil
1060 "When non--nil search etags candidates by regexp.
1061 This disable anything-match-plugin when enabled.
1062 When nil search is performed literally and *match-plugin is used
1063 if available."
1064 :group 'anything-config
1065 :type 'boolean)
1067 (defcustom anything-c-filelist-file-name nil
1068 "Filename of file list.
1069 Accept a list of string for multiple files.
1071 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1072 File list is created by make-filelist.rb script.
1074 Usage:
1075 ruby make-filelist.rb > /tmp/all.filelist
1077 Then
1078 ;; Assume that /tmp is ramdisk or tmpfs
1079 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1080 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1082 :type 'string
1083 :group 'anything-config)
1085 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1086 'anything-c-eldoc-show-in-mode-line
1087 "A function to display eldoc info.
1088 Should take one arg: the string to display."
1089 :group 'anything-config
1090 :type 'symbol)
1092 (defcustom anything-c-turn-on-show-completion t
1093 "Display candidate in buffer while moving selection when non--nil."
1094 :group 'anything-config
1095 :type 'boolean)
1097 (defcustom anything-lisp-completion-or-indent-delay 0.6
1098 "After this delay `anything-lisp-completion-counter' is reset to 0.
1099 This allow to indent again without completing lisp symbol after this delay.
1100 Default is 0.6 seconds."
1101 :group 'anything-config
1102 :type 'number)
1104 (defcustom anything-c-default-external-file-browser "nautilus"
1105 "Default external file browser for your system.
1106 Directories will be opened externally with it.
1107 Set to nil if you do not have external file browser
1108 or do not want to use it."
1109 :group 'anything-config
1110 :type 'string)
1112 (defcustom anything-c-use-adaptative-sorting nil
1113 "*Wheter to use or not adaptative sorting.
1114 Even if a source use it, it will have no effect when set to nil."
1115 :type 'boolean
1116 :group 'anything-config)
1118 (defcustom anything-ff-newfile-prompt-p t
1119 "Whether Prompt or not when creating new file.
1120 This set `ffap-newfile-prompt'."
1121 :type 'boolean
1122 :group 'anything-config)
1125 (defcustom anything-ff-avfs-directory nil
1126 "*The default avfs directory, usually '.avfs'.
1127 When this is set you will be able to expand archive filenames with `C-z'
1128 inside an avfs directory mounted with mountavfs.
1129 See <http://sourceforge.net/projects/avf/>."
1130 :type 'boolean
1131 :group 'anything-config)
1133 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1134 "*Minimal list of compressed files extension."
1135 :type 'list
1136 :group 'anything-config)
1138 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1139 "Default regexp to match locate database.
1140 If nil Search in all files."
1141 :type 'string
1142 :group 'anything-config)
1144 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1145 "Eldoc will show info in mode-line during this delay if user is idle."
1146 :type 'integer
1147 :group 'anything-config)
1149 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1150 "The file used to communicate with two emacs when copying files async."
1151 :type 'string
1152 :group 'anything-config)
1154 (defcustom anything-ff-printer-list nil
1155 "A list of available printers on your system.
1156 When non--nil let you choose a printer to print file.
1157 Otherwise when nil the variable `printer-name' will be used.
1158 On Unix based systems you can use `anything-ff-find-printers' to
1159 find a list of available printers."
1160 :type 'list
1161 :group 'anything-config)
1163 (defcustom anything-ff-transformer-show-only-basename nil
1164 "Show only basename of candidates in `anything-find-files'.
1165 This can be toggled at anytime from `anything-find-files' with \
1166 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1167 :type 'boolean
1168 :group 'anything-config)
1170 (defcustom anything-completing-read-handlers-alist
1171 '((describe-function . anything-completing-read-symbols)
1172 (describe-variable . anything-completing-read-symbols)
1173 (debug-on-entry . anything-completing-read-symbols)
1174 (ffap-alternate-file . nil))
1175 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1176 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1177 where key and value are symbols.
1179 Each key is an Emacs command that use originaly `completing-read'.
1181 Each value maybe an anything function that take same arguments as
1182 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1183 anything source and BUFFER the name of the buffer we will use.
1184 This function prefix name must start by \"anything\".
1186 See `anything-completing-read-symbols' for example.
1188 If the value of an entry is nil completion will fall back to
1189 emacs vanilla behavior.
1190 e.g If you want to disable anything completion for `describe-function':
1191 \(describe-function . nil\).
1193 Ido is also supported, you can use `ido-completing-read' and
1194 `ido-read-file-name' as value of an entry or just 'ido.
1195 e.g ido completion for `find-file':
1196 \(find-file . ido\)
1197 same as
1198 \(find-file . ido-read-file-name\)
1199 Note that you don't need to enable `ido-mode' for this to work."
1200 :group 'anything-config
1201 :type '(alist :key-type symbol :value-type symbol))
1205 ;;; General internal variables
1207 ;; Some internals variable that need to be loaded
1208 ;; here to avoid compiler warnings.
1209 (defvar anything-c-external-commands-list nil
1210 "A list of all external commands the user can execute. If this
1211 variable is not set by the user, it will be calculated
1212 automatically.")
1214 (defvar anything-c-show-completion-overlay nil)
1216 (defvar anything-c-locate-command
1217 (case system-type
1218 ('gnu/linux "locate -i -r %s")
1219 ('berkeley-unix "locate -i %s")
1220 ('windows-nt "es -i -r %s")
1221 (t "locate %s"))
1222 "A list of arguments for locate program.
1223 The \"-r\" option must be the last option.")
1226 ;;; Faces
1229 (defface anything-buffer-saved-out
1230 '((t (:foreground "red")))
1231 "*Face used for buffer files modified outside of emacs."
1232 :group 'anything-config)
1234 (defface anything-buffer-not-saved
1235 '((t (:foreground "Indianred2")))
1236 "*Face used for buffer files not already saved on disk."
1237 :group 'anything-config)
1239 (defface anything-ff-prefix
1240 '((t (:background "yellow" :foreground "black")))
1241 "*Face used to prefix new file or url paths in `anything-find-files'."
1242 :group 'anything-config)
1244 (defface anything-ff-executable
1245 '((t (:foreground "green")))
1246 "*Face used for executable files in `anything-find-files'."
1247 :group 'anything-config)
1249 (defface anything-ff-directory
1250 '((t (:foreground "DarkRed" :background "LightGray")))
1251 "*Face used for directories in `anything-find-files'."
1252 :group 'anything-config)
1254 (defface anything-ff-symlink
1255 '((t (:foreground "DarkOrange")))
1256 "*Face used for symlinks in `anything-find-files'."
1257 :group 'anything-config)
1259 (defface anything-ff-invalid-symlink
1260 '((t (:foreground "black" :background "red")))
1261 "*Face used for invalid symlinks in `anything-find-files'."
1262 :group 'anything-config)
1264 (defface anything-ff-file
1265 '((t (:foreground "CadetBlue" :underline t)))
1266 "*Face used for file names in `anything-find-files'."
1267 :group 'anything-config)
1269 (defface anything-grep-match
1270 '((t (:inherit match)))
1271 "Face used to highlight grep matches."
1272 :group 'anything-config)
1274 (defface anything-grep-file
1275 '((t (:foreground "BlueViolet" :underline t)))
1276 "Face used to highlight grep results filenames."
1277 :group 'anything-config)
1279 (defface anything-grep-lineno
1280 '((t (:foreground "Darkorange1")))
1281 "Face used to highlight grep number lines."
1282 :group 'anything-config)
1284 (defface anything-grep-running
1285 '((t (:foreground "Red")))
1286 "Face used in mode line when grep is running."
1287 :group 'anything-config)
1289 (defface anything-grep-finish
1290 '((t (:foreground "Green")))
1291 "Face used in mode line when grep is finish."
1292 :group 'anything-config)
1294 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1295 "*Face used in anything-M-x to show keybinding."
1296 :group 'anything)
1298 (defface anything-bmkext-info
1299 '((t (:foreground "green")))
1300 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1301 :group 'anything)
1303 (defface anything-bmkext-w3m
1304 '((t (:foreground "yellow")))
1305 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1306 :group 'anything)
1308 (defface anything-bmkext-gnus
1309 '((t (:foreground "magenta")))
1310 "*Face used for Gnus bookmarks."
1311 :group 'anything)
1313 (defface anything-bmkext-man
1314 '((t (:foreground "Orange4")))
1315 "*Face used for Woman/man bookmarks."
1316 :group 'anything)
1318 (defface anything-bmkext-no--file
1319 '((t (:foreground "grey")))
1320 "*Face used for non--file bookmarks."
1321 :group 'anything)
1323 (defface anything-bmkext-file
1324 '((t (:foreground "Deepskyblue2")))
1325 "*Face used for non--file bookmarks."
1326 :group 'anything)
1328 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1329 "Face for su/sudo bookmarks."
1330 :group 'anything)
1332 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1333 "Face for w3m bookmarks" :group 'anything)
1335 (defface anything-emms-playlist
1336 '((t (:foreground "Springgreen4" :underline t)))
1337 "*Face used for tracks in current emms playlist."
1338 :group 'anything)
1340 (defface anything-apt-installed
1341 '((t (:foreground "green")))
1342 "*Face used for apt installed candidates."
1343 :group 'anything)
1345 (defface anything-gentoo-match-face '((t (:foreground "red")))
1346 "Face for anything-gentoo installed packages."
1347 :group 'traverse-faces)
1349 (defface anything-lisp-show-completion
1350 '((t (:background "DarkSlateGray")))
1351 "*Face used for showing candidates in `anything-lisp-completion'."
1352 :group 'anything-config)
1354 (defface anything-lisp-completion-info
1355 '((t (:foreground "red")))
1356 "*Face used for showing info in `anything-lisp-completion'."
1357 :group 'anything-config)
1359 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1360 "Face for source header in the anything buffer." :group 'anything)
1362 ;;;###autoload
1363 (defun anything-configuration ()
1364 "Customize `anything'."
1365 (interactive)
1366 (customize-group "anything-config"))
1370 ;;; Anything-command-map
1373 ;;;###autoload
1374 (defvar anything-command-map)
1375 (define-prefix-command 'anything-command-map)
1378 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1379 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1380 (define-key anything-command-map (kbd "l") 'anything-locate)
1381 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1382 (define-key anything-command-map (kbd "r") 'anything-regexp)
1383 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1384 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1385 (define-key anything-command-map (kbd "#") 'anything-emms)
1386 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1387 (define-key anything-command-map (kbd "t") 'anything-top)
1388 (define-key anything-command-map (kbd "i") 'anything-imenu)
1389 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1390 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1391 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1392 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1393 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1394 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1395 (define-key anything-command-map (kbd "f") 'anything-for-files)
1396 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1397 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1398 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1399 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1400 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1401 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1402 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1403 (define-key anything-command-map (kbd "c") 'anything-colors)
1404 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1405 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1406 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1407 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1408 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1409 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1410 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1411 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1412 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1413 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1415 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1416 ;; minibuffer-local-filename-must-match-map.
1417 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1418 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1419 (dolist (map (list minibuffer-local-filename-completion-map
1420 minibuffer-local-completion-map
1421 minibuffer-local-must-match-filename-map
1422 minibuffer-local-filename-must-match-map
1423 minibuffer-local-map
1424 minibuffer-local-isearch-map
1425 minibuffer-local-must-match-map
1426 minibuffer-local-ns-map))
1427 (define-key map "\C-r" 'anything-minibuffer-history))
1431 ;;; Menu
1434 (easy-menu-define nil global-map
1435 "`anything' menu"
1436 '("Anything"
1437 ["All anything commands" anything-execute-anything-command t]
1438 ["Find any Files/Buffers" anything-for-files t]
1439 "----"
1440 ("Files:"
1441 ["Find files" anything-find-files t]
1442 ["Recent Files" anything-recentf t]
1443 ["Locate" anything-locate t]
1444 ["Bookmarks" anything-c-pp-bookmarks t])
1445 ("Buffers:"
1446 ["Find buffers" anything-buffers-list t])
1447 ("Commands:"
1448 ["Emacs Commands" anything-M-x t]
1449 ["Externals Commands" anything-c-run-external-command t])
1450 ("Info:"
1451 ["Info at point" anything-info-at-point t]
1452 ["Emacs Manual index" anything-info-emacs t]
1453 ["Gnus Manual index" anything-info-gnus t])
1454 ("Org:"
1455 ["Org keywords" anything-org-keywords t]
1456 ["Org headlines" anything-org-headlines t])
1457 ("Tools:"
1458 ["Occur" anything-occur t]
1459 ["Grep" anything-do-grep t]
1460 ["Etags" anything-c-etags-select t]
1461 ["Lisp complete at point" anything-lisp-completion-at-point t]
1462 ["Browse Kill ring" anything-show-kill-ring t]
1463 ["Browse register" anything-register t]
1464 ["Browse code" anything-browse-code t]
1465 ["Mark Ring" anything-all-mark-rings t]
1466 ["Regexp handler" anything-regexp t]
1467 ["Colors & Faces" anything-colors t]
1468 ["Show xfonts" anything-select-xfont t]
1469 ["Ucs Symbols" anything-ucs t]
1470 ["Imenu" anything-imenu t]
1471 ["Google Suggest" anything-google-suggest t]
1472 ["Eval expression" anything-eval-expression-with-eldoc t]
1473 ["Calcul expression" anything-calcul-expression t]
1474 ["Man pages" anything-man-woman t]
1475 ["Top externals process" anything-top t]
1476 ["Emacs internals process" anything-list-emacs-process t])
1477 "----"
1478 ["Prefered Options" anything-configuration t]))
1482 ;;; Specialized keymaps
1485 (defvar anything-c-buffer-map
1486 (let ((map (copy-keymap anything-map)))
1487 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1488 ;; No need to have separate command for grep and zgrep
1489 ;; as we don't use recursivity for buffers.
1490 ;; So use zgrep for both as it is capable to handle non--compressed files.
1491 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1492 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1493 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1494 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1495 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1496 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1497 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1498 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1499 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1500 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1501 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1502 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1503 (define-key map (kbd "M-a") 'anything-mark-all)
1504 (when (locate-library "elscreen")
1505 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1506 (delq nil map))
1507 "Keymap for buffer sources in anything.")
1509 (defvar anything-find-files-map
1510 (let ((map (copy-keymap anything-map)))
1511 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1512 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1513 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1514 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1515 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1516 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1517 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1518 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1519 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1520 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1521 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1522 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1523 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1524 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1525 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1526 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1527 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1528 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1529 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1530 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1531 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1532 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1533 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1534 (define-key map (kbd "C-c ?") 'anything-ff-help)
1535 (define-key map (kbd "C-}") 'anything-narrow-window)
1536 (define-key map (kbd "C-{") 'anything-enlarge-window)
1537 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1538 (define-key map (kbd "M-a") 'anything-mark-all)
1539 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1540 (define-key map (kbd "M-u") 'anything-unmark-all)
1541 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1542 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1543 ;; Next 2 have no effect if candidate is not an image file.
1544 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1545 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1546 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1547 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1548 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1549 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1550 (when anything-ff-lynx-style-map
1551 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1552 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1553 (delq nil map))
1554 "Keymap for `anything-find-files'.")
1556 (defvar anything-c-read-file-map
1557 (let ((map (copy-keymap anything-map)))
1558 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1559 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1560 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1561 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1562 (when anything-ff-lynx-style-map
1563 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1565 (define-key map (kbd "<M-left>") 'anything-previous-source)
1566 (define-key map (kbd "<M-right>") 'anything-next-source))
1567 (delq nil map))
1568 "Keymap for `anything-c-read-file-name'.")
1570 (defvar anything-generic-files-map
1571 (let ((map (copy-keymap anything-map)))
1572 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1573 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1574 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1575 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1576 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1577 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1578 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1579 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1580 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1581 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1582 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1583 map)
1584 "Generic Keymap for files.")
1586 (defvar anything-c-grep-map
1587 (let ((map (copy-keymap anything-map)))
1588 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1589 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1590 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1591 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1592 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1593 (when anything-c-grep-use-ioccur-style-keys
1594 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1595 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1596 (define-key map (kbd "C-c ?") 'anything-grep-help)
1597 (delq nil map))
1598 "Keymap used in Grep sources.")
1600 (defvar anything-c-pdfgrep-map
1601 (let ((map (copy-keymap anything-map)))
1602 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1603 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1604 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1605 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1606 map)
1607 "Keymap used in pdfgrep.")
1609 (defvar anything-c-etags-map
1610 (let ((map (copy-keymap anything-map)))
1611 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1612 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1613 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1614 (define-key map (kbd "C-c ?") 'anything-etags-help)
1615 map)
1616 "Keymap used in Etags.")
1618 (defvar anything-eval-expression-map
1619 (let ((map (copy-keymap anything-map)))
1620 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1621 (define-key map (kbd "<tab>") 'lisp-indent-line)
1622 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1623 (define-key map (kbd "C-p") 'previous-line)
1624 (define-key map (kbd "C-n") 'next-line)
1625 (define-key map (kbd "<up>") 'previous-line)
1626 (define-key map (kbd "<down>") 'next-line)
1627 (define-key map (kbd "<right>") 'forward-char)
1628 (define-key map (kbd "<left>") 'backward-char)
1629 map))
1631 (defvar anything-c-ucs-map
1632 (let ((map (copy-keymap anything-map)))
1633 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1634 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1635 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1636 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1637 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1638 map)
1639 "Keymap for `anything-ucs'.")
1643 ;;; Embeded documentation.
1646 (defun anything-c-list-preconfigured-anything ()
1647 "Collect preconfigured anything functions in this file."
1648 (loop with doc
1649 with sym
1650 for entry in (cdr (assoc
1651 (file-truename (locate-library "anything-config"))
1652 load-history))
1653 if (and (consp entry)
1654 (eq (car entry) 'defun)
1655 (string-match "^Preconfigured.+$"
1656 (setq doc (or (documentation (setq sym (cdr entry)))
1657 ""))))
1658 collect (cons sym (match-string 0 doc))))
1660 (defun anything-c-format-preconfigured-anything ()
1661 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1662 (anything-c-list-preconfigured-anything)))
1664 ;;; Global help message - Used by `anything-help'
1667 (setq anything-help-message
1668 (lambda ()
1669 (concat
1670 "\\<anything-map>"
1671 "`anything' is QuickSilver-like candidate-selection framework.
1673 Narrow the list by typing some pattern,
1674 Multiple patterns are allowed by splitting by space.
1675 Select with natural Emacs operations, choose with RET.
1677 If you have any problems, press C-c C-x C-b!!
1678 Feel free to send bug reports. I'll fix them.
1679 The steps are described in the beginning of anything.el file.
1681 == Basic Operations ==
1682 C-p, Up: Previous Line
1683 C-n, Down : Next Line
1684 M-v, PageUp : Previous Page
1685 C-v, PageDown : Next Page
1686 Enter : Execute first (default) action / Select
1687 M-< : First Line
1688 M-> : Last Line
1689 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1690 M-PageDown, C-M-v : Next Page (other-window)
1692 Tab, C-i : Show action list
1693 Left : Previous Source
1694 Right, C-o : Next Source
1695 C-k : Delete pattern
1696 C-z : Persistent Action (Execute action with anything session kept)
1697 C-c C-x C-b: Send a bug report
1699 == Shortcuts For 2nd/3rd Action ==
1700 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1701 \\[anything-select-3rd-action] : Execute 3rd Action
1703 == Visible Marks ==
1704 Visible marks store candidate. Some actions uses marked candidates.
1706 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1707 \\[anything-prev-visible-mark] : Previous Mark
1708 \\[anything-next-visible-mark] : Next Mark
1710 == Miscellaneous Commands ==
1711 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1712 \\[anything-quit-and-find-file] : Drop into `find-file'
1713 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1714 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1715 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1716 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1717 \\[anything-force-update] : Recalculate And Redisplay Candidates
1719 == Global Commands ==
1720 \\<global-map>\\[anything-resume] revives last `anything' session.
1721 It is very useful, so you should bind any key.
1723 Single source is executed by \\[anything-call-source].
1725 == Preconfigured `anything' ==
1726 Preconfigured `anything' is commands that uses `anything' interface.
1727 You can use them without configuration.
1730 (apply 'concat (anything-c-format-preconfigured-anything))
1732 Enjoy!")))
1734 ;;; `anything-buffer-list' help
1737 ;;;###autoload
1738 (defun anything-c-buffer-help ()
1739 "Help command for anything buffers."
1740 (interactive)
1741 (let ((anything-help-message "== Anything Buffer ==
1742 \nTips:
1743 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1744 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1745 \nSpecific commands for `anything-buffers-list':
1746 \\<anything-c-buffer-map>
1747 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1748 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1749 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1750 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1751 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1752 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1753 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1754 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1755 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1756 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1757 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1758 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1759 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1760 \\[anything-mark-all]\t\t->Mark all.
1761 \\[anything-c-buffer-help]\t\t->Display this help.
1762 \n== Anything Map ==
1763 \\{anything-map}
1765 (anything-help)))
1768 ;;; Find files help (`anything-find-files')
1771 ;;;###autoload
1772 (defun anything-ff-help ()
1773 "Help command for `anything-find-files'."
1774 (interactive)
1775 (let ((anything-help-message "== Anything Find Files ==
1776 \nTips:
1777 \n- Enter \"~/\" at anytime to reach home directory.
1778 - Enter \"/\" at anytime to reach root of your file system.
1779 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1780 - Use `C-u C-z' to watch an image.
1781 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1782 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1784 \nSpecific commands for `anything-find-files':
1785 \\<anything-find-files-map>
1786 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1787 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1788 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1789 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1790 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1791 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1792 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1793 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1794 \\[anything-ff-run-load-file]\t\t->Load File.
1795 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1796 \\[anything-ff-run-delete-file]\t\t->Delete File.
1797 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1798 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1799 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1800 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1801 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1802 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1803 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1804 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1805 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1806 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1807 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1808 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1809 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1810 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1811 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1812 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1813 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1814 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1815 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1816 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1817 \\[anything-narrow-window]\t\t->Narrow anything window.
1818 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1819 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1820 \\[anything-ff-help]\t\t->Display this help info.
1821 \n== Anything Map ==
1822 \\{anything-map}
1824 (anything-help)))
1826 ;;; Help for `anything-c-read-file-name'
1829 ;;;###autoload
1830 (defun anything-read-file-name-help ()
1831 (interactive)
1832 (let ((anything-help-message "== Anything read file name Map ==\
1833 \nSpecific commands for anything-c-read-file-name:
1834 \\<anything-c-read-file-map>
1835 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1836 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1837 \\[anything-next-source]\t\t->Goto next source.
1838 \\[anything-previous-source]\t->Goto previous source.
1839 \\[anything-read-file-name-help]\t\t->Display this help info.
1840 \n== Anything Map ==
1841 \\{anything-map}
1843 (anything-help)))
1845 ;;; Generic file help - Used by locate.
1848 ;;;###autoload
1849 (defun anything-generic-file-help ()
1850 (interactive)
1851 (let ((anything-help-message "== Anything Generic files Map ==\
1852 \nSpecific commands for anything locate and others files sources:
1853 \\<anything-generic-files-map>
1854 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1855 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1856 \\[anything-ff-run-delete-file]\t\t->Delete file.
1857 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1858 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1859 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1860 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1861 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1862 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1863 \nLocate tips:
1864 You can add after writing search pattern any of the locate command line options.
1865 e.g -b, -e, -n <number>...etc.
1866 See Man locate for more infos.
1867 \n== Anything Map ==
1868 \\{anything-map}"))
1869 (anything-help)))
1872 ;;; Grep help
1875 ;;;###autoload
1876 (defun anything-grep-help ()
1877 (interactive)
1878 (let ((anything-help-message "== Anything Grep Map ==\
1879 \nSpecific commands for Grep and Etags:
1880 \\<anything-c-grep-map>
1881 \\[anything-c-goto-next-file]\t->Next File.
1882 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1883 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1884 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1885 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1886 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1887 \\[anything-grep-help]\t\t->Show this help.
1888 \n== Anything Map ==
1889 \\{anything-map}"))
1890 (anything-help)))
1892 ;;; Pdf grep help
1895 ;;;###autoload
1896 (defun anything-pdfgrep-help ()
1897 (interactive)
1898 (let ((anything-help-message "== Anything PdfGrep Map ==\
1899 \nSpecific commands for Pdf Grep:
1900 \\<anything-c-pdfgrep-map>
1901 \\[anything-c-goto-next-file]\t->Next File.
1902 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1903 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1904 \\[anything-pdfgrep-help]\t\t->Show this help.
1905 \n== Anything Map ==
1906 \\{anything-map}"))
1907 (anything-help)))
1909 ;;; Etags help
1912 ;;;###autoload
1913 (defun anything-etags-help ()
1914 "The help function for etags."
1915 (interactive)
1916 (let ((anything-help-message "== Anything Etags Map ==\
1917 \nSpecific commands for Etags:
1918 \\<anything-c-etags-map>
1919 \\[anything-c-goto-next-file]\t->Next File.
1920 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1921 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1922 \\[anything-etags-help]\t\t->Show this help.
1923 \n== Anything Map ==
1924 \\{anything-map}"))
1925 (anything-help)))
1927 ;;; Ucs help
1930 (defun anything-c-ucs-help ()
1931 "Help command for `anything-ucs'."
1932 (interactive)
1933 (let ((anything-help-message "== Anything Ucs ==
1934 \nSpecific commands for `anything-ucs':
1935 \\<anything-c-ucs-map>
1936 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1937 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1938 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1939 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1940 \\[anything-c-ucs-help]\t\t->Show this help.
1942 \n== Anything Map ==
1943 \\{anything-map}
1945 (anything-help)))
1949 ;;; Mode line strings
1952 (defvar anything-buffer-mode-line-string
1953 '("Buffer(s)"
1954 "\\<anything-c-buffer-map>\
1955 \\[anything-c-buffer-help]:Help, \
1956 \\<anything-map>\
1957 \\[anything-select-action]:Acts,\
1958 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1959 \\[anything-select-3rd-action]:NthAct,\
1960 \\[anything-send-bug-report-from-anything]:BugReport."
1961 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1963 (defvar anything-ff-mode-line-string
1964 "\\<anything-find-files-map>\
1965 \\[anything-ff-help]:Help, \
1966 \\[anything-send-bug-report-from-anything]:BugReport, \
1967 \\<anything-map>\
1968 \\[anything-select-action]:Acts, \
1969 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1970 \\[anything-select-3rd-action]:NthAct"
1971 "String displayed in mode-line in `anything-c-source-find-files'")
1973 (defvar anything-read-file-name-mode-line-string
1974 "\\<anything-c-read-file-map>\
1975 \\[anything-read-file-name-help]:Help, \
1976 \\<anything-map>\
1977 \\[anything-select-action]:Acts,\
1978 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1979 \\[anything-select-3rd-action]:NthAct"
1980 "String displayed in mode-line in `anything-c-source-find-files'")
1982 (defvar anything-generic-file-mode-line-string
1983 "\\<anything-generic-files-map>\
1984 \\[anything-generic-file-help]:Help, \
1985 \\<anything-map>\
1986 \\[anything-select-action]:Acts,\
1987 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1988 \\[anything-select-3rd-action]:NthAct,\
1989 \\[anything-send-bug-report-from-anything]:BugReport."
1990 "String displayed in mode-line in Locate.")
1992 (defvar anything-grep-mode-line-string
1993 "\\<anything-c-grep-map>\
1994 \\[anything-grep-help]:Help,\
1995 \\<anything-map>\
1996 \\[anything-select-action]:Acts,\
1997 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1998 \\[anything-select-3rd-action]:NthAct,\
1999 \\[anything-send-bug-report-from-anything]:BugReport."
2000 "String displayed in mode-line in `anything-do-grep'.")
2002 (defvar anything-pdfgrep-mode-line-string
2003 "\\<anything-c-pdfgrep-map>\
2004 \\[anything-pdfgrep-help]:Help,\
2005 \\<anything-map>\
2006 \\[anything-select-action]:Acts,\
2007 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2008 \\[anything-select-3rd-action]:NthAct,\
2009 \\[anything-send-bug-report-from-anything]:BugReport."
2010 "String displayed in mode-line in `anything-do-pdfgrep'.")
2012 (defvar anything-etags-mode-line-string
2013 "\\<anything-c-etags-map>\
2014 \\[anything-etags-help]:Help,\
2015 \\<anything-map>\
2016 \\[anything-select-action]:Acts,\
2017 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2018 \\[anything-select-3rd-action]:NthAct,\
2019 \\[anything-send-bug-report-from-anything]:BugReport."
2020 "String displayed in mode-line in `anything-c-etags-select'.")
2023 (defvar anything-c-ucs-mode-line-string
2024 "\\<anything-c-ucs-map>\
2025 \\[anything-c-ucs-help]:Help, \
2026 \\<anything-map>\
2027 \\[anything-select-action]:Acts,\
2028 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2029 \\[anything-select-3rd-action]:NthAct."
2030 "String displayed in mode-line in `anything-ucs'.")
2034 ;;; Utilities Functions
2037 (defun anything-ff-find-printers ()
2038 "Return a list of available printers on Unix systems."
2039 (let ((printer-list (with-temp-buffer
2040 (call-process "lpstat" nil t nil "-a")
2041 (split-string (buffer-string) "\n"))))
2042 (loop for p in printer-list
2043 for printer = (car (split-string p))
2044 when printer
2045 collect printer)))
2047 ;; Shut up byte compiler in emacs24*.
2048 (defun anything-c-switch-to-buffer (buffer-or-name)
2049 "Same as `switch-to-buffer' whithout warnings at compile time."
2050 (with-no-warnings
2051 (switch-to-buffer buffer-or-name)))
2053 (defsubst* anything-c-position (item seq &key (test 'eq))
2054 "A simple and faster replacement of CL `position'."
2055 (loop for i in seq for index from 0
2056 when (funcall test i item) return index))
2058 (defun anything-c-get-pid-from-process-name (process-name)
2059 "Get pid from running process PROCESS-NAME."
2060 (loop with process-list = (list-system-processes)
2061 for pid in process-list
2062 for process = (assoc-default 'comm (process-attributes pid))
2063 when (and process (string-match process-name process))
2064 return pid))
2066 (defun* anything-current-buffer-narrowed-p (&optional
2067 (buffer anything-current-buffer))
2068 "Check if BUFFER is narrowed.
2069 Default is `anything-current-buffer'."
2070 (with-current-buffer buffer
2071 (let ((beg (point-min))
2072 (end (point-max))
2073 (total (buffer-size)))
2074 (or (/= beg 1) (/= end (1+ total))))))
2076 (defun anything-region-active-p ()
2077 (and transient-mark-mode mark-active (/= (mark) (point))))
2079 (defun anything-goto-line (lineno)
2080 "Goto LINENO opening only outline headline if needed."
2081 (goto-char (point-min)) (forward-line (1- lineno))
2082 (when (or (eq major-mode 'org-mode)
2083 (and (boundp 'outline-minor-mode)
2084 outline-minor-mode))
2085 (require 'org) ; On some old Emacs versions org may not be loaded.
2086 (org-reveal))
2087 (anything-match-line-color-current-line) (sit-for 0.3)
2088 (anything-match-line-cleanup))
2090 (defun anything-show-this-source-only ()
2091 "Show all candidates of this source."
2092 (interactive)
2093 (setq anything-candidate-number-limit nil)
2094 (anything-set-source-filter
2095 (list (assoc-default 'name (anything-get-current-source)))))
2097 ;;;###autoload
2098 (defun anything-test-sources ()
2099 "List all anything sources for test.
2100 The output is sexps which are evaluated by \\[eval-last-sexp]."
2101 (interactive)
2102 (with-output-to-temp-buffer "*Anything Test Sources*"
2103 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2104 (apropos-internal "^anything-c-source" #'boundp))
2105 (pop-to-buffer standard-output)))
2107 (defun anything-nest (&rest same-as-anything)
2108 "Nested `anything'. If you use `anything' within `anything', use it."
2109 (with-selected-window (anything-window)
2110 (let (anything-current-position
2111 anything-current-buffer
2112 (orig-anything-buffer anything-buffer)
2113 anything-pattern
2114 anything-buffer
2115 anything-sources
2116 anything-compiled-sources
2117 anything-buffer-chars-modified-tick
2118 (anything-samewindow t)
2119 (enable-recursive-minibuffers t))
2120 (unwind-protect
2121 (apply #'anything same-as-anything)
2122 (anything-initialize-overlays orig-anything-buffer)
2123 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2125 (defun anything-displaying-source-names ()
2126 "Display sources name."
2127 (with-current-buffer anything-buffer
2128 (goto-char (point-min))
2129 (loop with pos
2130 while (setq pos (next-single-property-change (point) 'anything-header))
2131 do (goto-char pos)
2132 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2133 do (forward-line 1))))
2135 ;; [Obsolete]
2136 (defun anything-select-source ()
2137 "[OBSOLETE] Select source."
2138 (interactive)
2139 (let ((default (assoc-default 'name (anything-get-current-source)))
2140 (source-names (anything-displaying-source-names))
2141 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2142 (anything-get-sources))))
2143 (setq anything-candidate-number-limit 9999)
2144 (anything-aif
2145 (let (anything-source-filter)
2146 (anything-nest '(((name . "Anything Source")
2147 (candidates . source-names)
2148 (action . identity))
2149 ((name . "Anything Source (ALL)")
2150 (candidates . all-source-names)
2151 (action . identity)))
2152 nil "Source: " nil
2153 default "*anything select source*"))
2154 (anything-set-source-filter (list it))
2155 (anything-set-source-filter nil))))
2157 (defun anything-c-match-on-file-name (candidate)
2158 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2159 (string-match anything-pattern (file-name-nondirectory candidate)))
2161 (defun anything-c-match-on-directory-name (candidate)
2162 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2163 (anything-aif (file-name-directory candidate)
2164 (string-match anything-pattern it)))
2166 (defun anything-c-string-match (candidate)
2167 "Return non-nil if `anything-pattern' match CANDIDATE.
2168 The match is done with `string-match'."
2169 (string-match anything-pattern candidate))
2171 (defun anything-c-skip-entries (list regexp)
2172 "Remove entries which matches REGEXP from LIST."
2173 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2174 list))
2176 (defun anything-c-shadow-entries (list regexp)
2177 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2178 (mapcar (lambda (file)
2179 ;; Add shadow face property to boring files.
2180 (let ((face (if (facep 'file-name-shadow)
2181 'file-name-shadow
2182 ;; fall back to default on XEmacs
2183 'default)))
2184 (if (string-match regexp file)
2185 (setq file (propertize file 'face face))))
2186 file)
2187 list))
2189 (defsubst anything-c-stringify (str-or-sym)
2190 "Get string of STR-OR-SYM."
2191 (if (stringp str-or-sym)
2192 str-or-sym
2193 (symbol-name str-or-sym)))
2195 (defsubst anything-c-symbolify (str-or-sym)
2196 "Get symbol of STR-OR-SYM."
2197 (if (symbolp str-or-sym)
2198 str-or-sym
2199 (intern str-or-sym)))
2201 (defun anything-c-describe-function (func)
2202 "FUNC is symbol or string."
2203 (describe-function (anything-c-symbolify func)))
2205 (defun anything-c-describe-variable (var)
2206 "VAR is symbol or string."
2207 (describe-variable (anything-c-symbolify var)))
2209 (defun anything-c-find-function (func)
2210 "FUNC is symbol or string."
2211 (find-function (anything-c-symbolify func)))
2213 (defun anything-c-find-variable (var)
2214 "VAR is symbol or string."
2215 (find-variable (anything-c-symbolify var)))
2217 (defun anything-c-kill-new (candidate &optional replace)
2218 "CANDIDATE is symbol or string.
2219 See `kill-new' for argument REPLACE."
2220 (kill-new (anything-c-stringify candidate) replace))
2222 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2223 "Remove duplicates elements in list SEQ.
2224 This is same as `remove-duplicates' but with memoisation.
2225 It is much faster, especially in large lists.
2226 A test function can be provided with TEST argument key.
2227 Default is `eq'."
2228 (let ((cont (make-hash-table :test test)))
2229 (loop for elm in seq
2230 unless (gethash elm cont)
2231 do (puthash elm elm cont)
2232 finally return
2233 (loop for i being the hash-values in cont collect i))))
2235 (defadvice eval-defun (after anything-source-hack activate)
2236 "Allow immediate execution of anything source when evaling it.
2237 See `anything-c-enable-eval-defun-hack'."
2238 (when anything-c-enable-eval-defun-hack
2239 (let ((varsym (save-excursion
2240 (beginning-of-defun)
2241 (forward-char 1)
2242 (when (memq (read (current-buffer)) '(defvar setq))
2243 (read (current-buffer))))))
2244 (when (string-match "^anything-c-source-" (symbol-name varsym))
2245 (anything varsym)))))
2246 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2248 (defadvice anything-quit-and-find-file (around use-anything-find-files activate)
2249 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
2250 (interactive)
2251 (anything-run-after-quit
2252 (lambda (f)
2253 (if (file-exists-p f)
2254 (anything-find-files-1 (file-name-directory f)
2255 (if anything-ff-transformer-show-only-basename
2256 (anything-c-basename f) f))
2257 (anything-find-files-1 f)))
2258 (anything-aif (get-buffer (anything-get-selection))
2259 (or (buffer-file-name it)
2260 (car (rassoc it dired-buffers))
2261 (and (with-current-buffer it
2262 (eq major-mode 'org-agenda-mode))
2263 org-directory
2264 (expand-file-name org-directory))
2265 default-directory)
2266 (let ((sel (anything-get-selection)))
2267 (if (file-exists-p sel)
2268 (expand-file-name sel)
2269 default-directory)))))
2271 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2272 "Walk through DIRECTORY tree.
2273 PATH can be one of basename, relative, or full.
2274 DIRECTORIES when non--nil (default) return also directories names, otherwise
2275 skip directories names.
2276 MATCH match only filenames matching regexp MATCH."
2277 `(let (result
2278 (fn (case ,path
2279 (basename 'file-name-nondirectory)
2280 (relative 'file-relative-name)
2281 (full 'identity)
2282 (t 'file-name-nondirectory))))
2283 (labels ((ls-R (dir)
2284 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2285 for f in ls
2286 if (file-directory-p f)
2287 do (progn (when ,directories
2288 (push (funcall fn f) result))
2289 ;; Don't recurse in directory symlink.
2290 (unless (file-symlink-p f)
2291 (ls-R f)))
2292 else do
2293 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2294 (push (funcall fn f) result)))))
2295 (ls-R ,directory)
2296 (nreverse result))))
2298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2300 ;;; Anything regexp.
2303 (defun anything-c-query-replace-regexp (candidate)
2304 "Query replace regexp from `anything-regexp'.
2305 With a prefix arg replace only matches surrounded by word boundaries,
2306 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2307 (let ((regexp (funcall (anything-attr 'regexp))))
2308 (apply 'query-replace-regexp
2309 (anything-c-query-replace-args regexp))))
2311 (defun anything-c-kill-regexp-as-sexp (candidate)
2312 "Kill regexp in a format usable in lisp code."
2313 (anything-c-regexp-kill-new
2314 (prin1-to-string (funcall (anything-attr 'regexp)))))
2316 (defun anything-c-kill-regexp (candidate)
2317 "Kill regexp as it is in `anything-pattern'."
2318 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2320 (defun anything-c-query-replace-args (regexp)
2321 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2322 (let ((region-only (anything-region-active-p)))
2323 (list
2324 regexp
2325 (query-replace-read-to regexp
2326 (format "Query replace %sregexp %s"
2327 (if anything-current-prefix-arg "word " "")
2328 (if region-only "in region " ""))
2330 anything-current-prefix-arg
2331 (when region-only (region-beginning))
2332 (when region-only (region-end)))))
2334 (defvar anything-c-source-regexp
2335 '((name . "Regexp Builder")
2336 (init . (lambda ()
2337 (anything-candidate-buffer anything-current-buffer)))
2338 (candidates-in-buffer)
2339 (get-line . anything-c-regexp-get-line)
2340 (persistent-action . anything-c-regexp-persistent-action)
2341 (persistent-help . "Show this line")
2342 (multiline)
2343 (delayed)
2344 (requires-pattern . 2)
2345 (mode-line . "Press TAB to select action.")
2346 (regexp . (lambda () anything-input))
2347 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2348 ("Query Replace Regexp (C-u Not inside word.)"
2349 . anything-c-query-replace-regexp)
2350 ("Kill Regexp" . anything-c-kill-regexp)))))
2352 (defun anything-c-regexp-get-line (s e)
2353 (propertize
2354 (apply 'concat
2355 ;; Line contents
2356 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2357 ;; subexps
2358 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2359 collect (format "\n %s'%s'"
2360 (if (zerop i) "Group 0: " (format "Group %d: " i))
2361 (match-string i))))
2362 ;; match beginning
2363 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2364 ;; It is implementation problem of candidates-in-buffer.
2365 'anything-realvalue
2366 (1- s)))
2368 (defun anything-c-regexp-persistent-action (pt)
2369 (goto-char pt)
2370 (anything-persistent-highlight-point))
2372 (defun anything-c-regexp-kill-new (input)
2373 (kill-new input)
2374 (message "Killed: %s" input))
2378 ;;; Toggle all marks.
2381 ;;;###autoload
2382 (defun anything-mark-all ()
2383 "Mark all visible unmarked candidates in current source."
2384 (interactive)
2385 (with-anything-window
2386 (save-excursion
2387 (goto-char (anything-get-previous-header-pos))
2388 (anything-next-line)
2389 (let* ((next-head (anything-get-next-header-pos))
2390 (end (and next-head
2391 (save-excursion
2392 (goto-char next-head)
2393 (forward-line -1)
2394 (point))))
2395 (maxpoint (or end (point-max))))
2396 (while (< (point) maxpoint)
2397 (anything-mark-current-line)
2398 (let ((prefix (get-text-property (point-at-bol) 'display))
2399 (bn (anything-c-basename (anything-get-selection)))
2400 (src (assoc-default 'name (anything-get-current-source))))
2401 (when (and (not (anything-this-visible-mark))
2402 (not (or (string= prefix "[?]")
2403 (string= prefix "[@]"))))
2404 ;; Don't mark possibles directories ending with . or ..
2405 ;; and also autosave files/links.
2406 (unless
2407 (and (or (anything-file-completion-source-p)
2408 (equal src "Files from Current Directory"))
2409 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2410 (anything-make-visible-mark))))
2411 (forward-line 1) (end-of-line))))
2412 (anything-mark-current-line)
2413 (message "%s candidates marked" (length anything-marked-candidates))))
2415 ;;;###autoload
2416 (defun anything-unmark-all ()
2417 "Unmark all candidates in all sources of current anything session."
2418 (interactive)
2419 (with-anything-window
2420 (let ((len (length anything-marked-candidates)))
2421 (save-excursion
2422 (anything-clear-visible-mark))
2423 (setq anything-marked-candidates nil)
2424 (anything-mark-current-line)
2425 (message "%s candidates unmarked" len))))
2427 ;;;###autoload
2428 (defun anything-toggle-all-marks ()
2429 "Toggle all marks.
2430 Mark all visible candidates of current source or unmark all candidates
2431 visible or invisible in all sources of current anything session"
2432 (interactive)
2433 (let ((marked (anything-marked-candidates)))
2434 (if (and (>= (length marked) 1)
2435 (with-anything-window anything-visible-mark-overlays))
2436 (anything-unmark-all)
2437 (anything-mark-all))))
2439 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
2443 ;;; Buffers
2446 (defun anything-c-buffer-list ()
2447 "Return the list of names of buffers with boring buffers filtered out.
2448 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2449 The first buffer in the list will be the last recently used
2450 buffer that is not the current buffer."
2451 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2452 (append (cdr buffers) (list (car buffers)))))
2454 (defvar anything-c-source-buffers
2455 '((name . "Buffers")
2456 (candidates . anything-c-buffer-list)
2457 (type . buffer)))
2458 ;; (anything 'anything-c-source-buffers)
2460 (defvar anything-c-source-buffer-not-found
2461 '((name . "Create buffer")
2462 (dummy)
2463 (filtered-candidate-transformer (lambda (cands source)
2464 (list anything-pattern)))
2465 (action . (lambda (candidate)
2466 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2467 ;; (anything 'anything-c-source-buffer-not-found)
2469 ;;; Buffers-list (was buffers+)
2472 (eval-when-compile (require 'dired))
2474 (defun anything-c-highlight-buffers (buffers)
2475 (loop for i in buffers
2476 for buf = (get-buffer i)
2477 for bfname = (buffer-file-name buf)
2478 collect
2479 (cond (;; A dired buffer.
2480 (rassoc buf dired-buffers)
2481 (propertize i 'face 'anything-ff-directory
2482 'help-echo (car (rassoc buf dired-buffers))))
2483 ;; A buffer file modified somewhere outside of emacs.
2484 ((and bfname (not (file-remote-p bfname))
2485 (file-exists-p bfname)
2486 (not (verify-visited-file-modtime buf)))
2487 (propertize i 'face 'anything-buffer-saved-out
2488 'help-echo bfname))
2489 ;; A new buffer file not already saved on disk.
2490 ((and bfname (not (file-remote-p bfname))
2491 (not (verify-visited-file-modtime buf)))
2492 (propertize i 'face 'anything-buffer-not-saved
2493 'help-echo bfname))
2494 ;; A Remote buffer file modified and not saved on disk.
2495 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2496 (let ((prefix (propertize
2497 " " 'display
2498 (propertize "@ " 'face 'anything-ff-prefix))))
2499 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2500 'help-echo bfname)) i)))
2501 ;; A buffer file modified and not saved on disk.
2502 ((and bfname (buffer-modified-p buf))
2503 (propertize i 'face 'anything-ff-symlink
2504 'help-echo bfname))
2505 ;; A remote buffer file not modified and saved on disk.
2506 ((and bfname (file-remote-p bfname))
2507 (let ((prefix (propertize
2508 " " 'display
2509 (propertize "@ " 'face 'anything-ff-prefix))))
2510 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2511 'help-echo bfname)) i)))
2512 ;; A buffer file not modified and saved on disk.
2513 (bfname
2514 (propertize i 'face 'font-lock-type-face
2515 'help-echo bfname))
2516 ;; Any non--file buffer.
2517 (t (propertize i 'face 'italic)))))
2520 (defvar anything-c-source-buffers-list
2521 '((name . "Buffers")
2522 (candidates . anything-c-buffer-list)
2523 (type . buffer)
2524 (match anything-c-buffer-match-major-mode)
2525 (diff-action . anything-buffer-toggle-diff)
2526 (revert-action . anything-buffer-revert-and-update)
2527 (save-action . anything-buffer-save-and-update)
2528 (candidate-transformer anything-c-skip-current-buffer
2529 anything-c-skip-boring-buffers
2530 anything-c-highlight-buffers)
2531 (persistent-action . anything-c-buffers-list-persistent-action)
2532 (volatile)
2533 (mode-line . anything-buffer-mode-line-string)
2534 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2535 ;; (anything 'anything-c-source-buffers-list)
2537 (defun anything-c-buffer-match-major-mode (candidate)
2538 "Match maybe buffer by major-mode.
2539 If you give a major-mode or partial major-mode,
2540 it will list all buffers of this major-mode and/or buffers with name
2541 matching this major-mode.
2542 If you add a space after major-mode and then a space,
2543 it will match all buffers of the major-mode
2544 before space matching pattern after space.
2545 If you give a pattern which doesn't match a major-mode, it will search buffer
2546 with name matching pattern."
2547 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2548 (buf (get-buffer cand)))
2549 (when buf
2550 (with-current-buffer buf
2551 (let ((mjm (symbol-name major-mode))
2552 (split (split-string anything-pattern)))
2553 (cond ((string-match "\\s-$" anything-pattern)
2554 (string-match (car split) mjm))
2555 ((string-match "\\s-" anything-pattern)
2556 (and (string-match (car split) mjm)
2557 (string-match (cadr split) cand)))
2558 (t (or (string-match anything-pattern mjm)
2559 (string-match anything-pattern cand)))))))))
2561 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2562 "Query replace in marked buffers.
2563 If REGEXP-FLAG is given use `query-replace-regexp'."
2564 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2565 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2566 (bufs (anything-marked-candidates)))
2567 (loop
2568 with replace = (query-replace-read-from prompt regexp-flag)
2569 with tostring = (unless (consp replace)
2570 (query-replace-read-to
2571 replace prompt regexp-flag))
2572 for buf in bufs
2574 (save-window-excursion
2575 (anything-c-switch-to-buffer buf)
2576 (save-excursion
2577 (let ((case-fold-search t))
2578 (goto-char (point-min))
2579 (if (consp replace)
2580 (apply fn (list (car replace) (cdr replace)))
2581 (apply fn (list replace tostring)))))))))
2583 (defun anything-c-buffer-query-replace-regexp (candidate)
2584 (anything-c-buffer-query-replace-1 'regexp))
2586 (defun anything-c-buffer-query-replace (candidate)
2587 (anything-c-buffer-query-replace-1))
2589 (defun anything-buffer-toggle-diff (candidate)
2590 "Toggle diff buffer CANDIDATE with it's file."
2591 (if (get-buffer-window "*Diff*")
2592 (kill-buffer "*Diff*")
2593 (diff-buffer-with-file (get-buffer candidate))))
2595 ;;;###autoload
2596 (defun anything-buffer-diff-persistent ()
2597 "Toggle diff buffer without quitting anything."
2598 (interactive)
2599 (anything-execute-persistent-action 'diff-action))
2601 (defun anything-buffer-revert-and-update (candidate)
2602 (let ((marked (anything-marked-candidates)))
2603 (loop for buf in marked do (anything-revert-buffer buf))
2604 (anything-force-update)
2605 (anything-c-recenter-window)))
2607 ;;;###autoload
2608 (defun anything-buffer-revert-persistent ()
2609 "Revert buffer without quitting anything."
2610 (interactive)
2611 (anything-execute-persistent-action 'revert-action 'onewindow))
2613 (defun anything-buffer-save-and-update (candidate)
2614 (let ((marked (anything-marked-candidates))
2615 (enable-recursive-minibuffers t))
2616 (loop for buf in marked do
2617 (with-current-buffer (get-buffer buf)
2618 (save-buffer)))
2619 (anything-force-update)
2620 (anything-c-recenter-window)))
2622 ;;;###autoload
2623 (defun anything-buffer-save-persistent ()
2624 "Save buffer without quitting anything."
2625 (interactive)
2626 (anything-execute-persistent-action 'save-action 'onewindow))
2628 ;;;###autoload
2629 (defun anything-buffer-run-kill-buffers ()
2630 "Run kill buffer action from `anything-c-source-buffers-list'."
2631 (interactive)
2632 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2634 ;;;###autoload
2635 (defun anything-buffer-run-grep ()
2636 "Run Grep action from `anything-c-source-buffers-list'."
2637 (interactive)
2638 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2640 ;;;###autoload
2641 (defun anything-buffer-run-zgrep ()
2642 "Run Grep action from `anything-c-source-buffers-list'."
2643 (interactive)
2644 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2646 ;;;###autoload
2647 (defun anything-buffer-run-query-replace-regexp ()
2648 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2649 (interactive)
2650 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2652 ;;;###autoload
2653 (defun anything-buffer-run-query-replace ()
2654 "Run Query replace action from `anything-c-source-buffers-list'."
2655 (interactive)
2656 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2658 ;;;###autoload
2659 (defun anything-buffer-switch-other-window ()
2660 "Run switch to other window action from `anything-c-source-buffers-list'."
2661 (interactive)
2662 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2664 ;;;###autoload
2665 (defun anything-buffer-switch-other-frame ()
2666 "Run switch to other frame action from `anything-c-source-buffers-list'."
2667 (interactive)
2668 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2670 ;;;###autoload
2671 (defun anything-buffer-switch-to-elscreen ()
2672 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2673 (interactive)
2674 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2676 ;;;###autoload
2677 (defun anything-buffer-run-ediff ()
2678 "Run ediff action from `anything-c-source-buffers-list'."
2679 (interactive)
2680 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2682 (defun anything-buffer-run-ediff-merge ()
2683 "Run ediff action from `anything-c-source-buffers-list'."
2684 (interactive)
2685 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2687 (defun anything-c-buffers-persistent-kill (buffer)
2688 "Persistent action to kill buffer."
2689 (with-current-buffer (get-buffer buffer)
2690 (if (and (buffer-modified-p)
2691 (buffer-file-name (current-buffer)))
2692 (progn
2693 (save-buffer)
2694 (kill-buffer buffer))
2695 (kill-buffer buffer)))
2696 (anything-delete-current-selection))
2698 (defun anything-c-recenter-window ()
2699 "Make visible current selection by recentering anything window."
2700 (with-anything-window (recenter)))
2702 (defun anything-c-buffers-list-persistent-action (candidate)
2703 (if current-prefix-arg
2704 (anything-c-buffers-persistent-kill candidate)
2705 (anything-c-switch-to-buffer candidate)))
2708 ;;;; <File>
2711 ;;; File name history
2712 (defvar anything-c-source-file-name-history
2713 '((name . "File Name History")
2714 (candidates . file-name-history)
2715 (match anything-c-match-on-file-name
2716 anything-c-match-on-directory-name)
2717 (type . file)))
2718 ;; (anything 'anything-c-source-file-name-history)
2720 ;;; Files in current dir
2723 (defvar anything-c-source-files-in-current-dir
2724 '((name . "Files from Current Directory")
2725 (candidates . (lambda ()
2726 (with-anything-current-buffer
2727 (directory-files (anything-c-current-directory)))))
2728 ;; volatile is not needed, I think.
2729 (type . file)))
2730 ;; (anything 'anything-c-source-files-in-current-dir)
2732 (defun anything-c-highlight-files (files)
2733 (loop for i in files
2734 if (file-directory-p i)
2735 collect (propertize (file-name-nondirectory i)
2736 'face 'anything-ff-directory
2737 'help-echo (expand-file-name i))
2738 else
2739 collect (propertize (file-name-nondirectory i)
2740 'face 'anything-ff-file
2741 'help-echo (expand-file-name i))))
2743 (defvar anything-c-source-files-in-current-dir+
2744 '((name . "Files from Current Directory")
2745 (candidates . (lambda ()
2746 (with-anything-current-buffer
2747 (directory-files (anything-c-current-directory) t))))
2748 (candidate-transformer anything-c-highlight-files)
2749 ;; volatile is not needed, I think.
2750 (type . file)))
2751 ;; (anything 'anything-c-source-files-in-current-dir+)
2755 ;;; Anything-find-files - The anything files browser.
2758 ;; Internal.
2759 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2760 "*The doc that is inserted in the Name header of a find-files or dired source.")
2761 (defvar anything-ff-auto-update-flag nil
2762 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2763 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2764 (defvar anything-ff-last-expanded nil
2765 "Store last expanded directory or file.")
2766 (defvar anything-ff-default-directory nil)
2767 (defvar anything-ff-history nil)
2768 (defvar anything-ff-cand-to-mark nil)
2771 (defvar anything-c-source-find-files
2772 `((name . "Find Files")
2773 (header-name . (lambda (name)
2774 (concat name anything-c-find-files-doc-header)))
2775 ;; It is needed for filenames with capital letters
2776 (disable-shortcuts)
2777 (init . (lambda ()
2778 (setq anything-ff-auto-update-flag
2779 anything-ff-auto-update-initial-value)))
2780 (candidates . anything-find-files-get-candidates)
2781 (filtered-candidate-transformer anything-c-find-files-transformer)
2782 (image-action1 . anything-ff-rotate-image-left)
2783 (image-action2 . anything-ff-rotate-image-right)
2784 (toggle-basename . anything-ff-toggle-basename)
2785 (properties-action . anything-ff-properties)
2786 (toggle-auto-update . anything-ff-toggle-auto-update)
2787 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2788 (persistent-action . anything-find-files-persistent-action)
2789 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2790 (mode-line . anything-ff-mode-line-string)
2791 (volatile)
2792 (candidate-number-limit . 9999)
2793 (action-transformer . anything-find-files-action-transformer)
2794 (action
2795 . ,(delq
2797 `(("Find File" . anything-c-find-file-or-marked)
2798 ("Find file in Dired" . anything-c-point-file-in-dired)
2799 ,(and (locate-library "elscreen")
2800 '("Find file in Elscreen" . anything-elscreen-find-file))
2801 ,(and (locate-library "popwin")
2802 '("Find file in popup window" . popwin:find-file))
2803 ("Checksum File" . anything-ff-checksum)
2804 ("Complete at point `M-tab'"
2805 . anything-c-insert-file-name-completion-at-point)
2806 ("Open file externally `C-c C-x, C-u to choose'"
2807 . anything-c-open-file-externally)
2808 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2809 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2810 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2811 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2812 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2813 . anything-find-files-eshell-command-on-file)
2814 ("Find file as root" . anything-find-file-as-root)
2815 ("Find file in hex dump" . hexl-find-file)
2816 ("Ediff File `C-='" . anything-find-files-ediff-files)
2817 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2818 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2819 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2820 ("Copy file(s) Async" . anything-ff-copy-async)
2821 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2822 ("Serial rename files" . anything-ff-serial-rename)
2823 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2824 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2825 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2826 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2827 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2828 ("Find file other window `C-o'" . find-file-other-window)
2829 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2830 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2831 ("Print File `C-c p'" . anything-ff-print)
2832 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2833 ;; (anything 'anything-c-source-find-files)
2835 (defun anything-find-files-set-prompt-for-action (prompt files)
2836 "Set prompt for action in `anything-find-files'."
2837 (let ((len (length files)))
2838 (if (> len 1)
2839 (format "%s * %d Files to: " prompt len)
2840 (format "%s %s to: " prompt (car files)))))
2842 (defun anything-dwim-target-directory ()
2843 "Return value of `default-directory' of buffer in other window.
2844 If there is only one window return the value ot `default-directory'
2845 for current buffer."
2846 (with-anything-current-buffer
2847 (let ((num-windows (length (window-list))))
2848 (if (> num-windows 1)
2849 (save-window-excursion
2850 (other-window 1)
2851 default-directory)
2852 (car anything-ff-history)))))
2854 (defun anything-find-files-do-action (action)
2855 "Generic function for creating action from `anything-c-source-find-files'.
2856 ACTION must be an action supported by `anything-dired-action'."
2857 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2858 (anything-marked-candidates)))
2859 (cand (anything-get-selection)) ; Target
2860 (prompt (anything-find-files-set-prompt-for-action
2861 (capitalize (symbol-name action)) ifiles))
2862 (parg anything-current-prefix-arg)
2863 (dest (anything-c-read-file-name
2864 prompt
2865 :preselect (if anything-ff-transformer-show-only-basename
2866 (anything-c-basename cand) cand)
2867 :initial-input (anything-dwim-target-directory)
2868 :history (anything-find-files-history :comp-read nil)))
2869 (win-conf (current-window-configuration)))
2870 (unwind-protect
2871 (let ((default-directory anything-ff-default-directory))
2872 (anything-dired-action
2873 dest :files ifiles :action action :follow parg))
2874 ;; Don't reset win-conf when following.
2875 (unless parg (set-window-configuration win-conf)))))
2877 (defun anything-find-files-copy (candidate)
2878 "Copy files from `anything-find-files'."
2879 (anything-find-files-do-action 'copy))
2881 (defun anything-find-files-rename (candidate)
2882 "Rename files from `anything-find-files'."
2883 (anything-find-files-do-action 'rename))
2885 (defun anything-find-files-symlink (candidate)
2886 "Symlink files from `anything-find-files'."
2887 (anything-find-files-do-action 'symlink))
2889 (defun anything-find-files-relsymlink (candidate)
2890 "Relsymlink files from `anything-find-files'."
2891 (anything-find-files-do-action 'relsymlink))
2893 (defun anything-find-files-hardlink (candidate)
2894 "Hardlink files from `anything-find-files'."
2895 (anything-find-files-do-action 'hardlink))
2897 (defun anything-find-files-byte-compile (candidate)
2898 "Byte compile elisp files from `anything-find-files'."
2899 (let ((files (anything-marked-candidates))
2900 (parg anything-current-prefix-arg))
2901 (loop for fname in files
2902 do (byte-compile-file fname parg))))
2904 (defun anything-find-files-load-files (candidate)
2905 "Load elisp files from `anything-find-files'."
2906 (let ((files (anything-marked-candidates)))
2907 (loop for fname in files
2908 do (load fname))))
2910 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2911 "Generic function to ediff/merge files in `anything-find-files'."
2912 (let ((bname (anything-c-basename candidate))
2913 (prompt (if merge "Ediff Merge `%s' With File: "
2914 "Ediff `%s' With File: "))
2915 (fun (if merge 'ediff-merge-files 'ediff-files)))
2916 (funcall fun
2917 candidate
2918 (condition-case quit
2919 (anything-c-read-file-name
2920 (format prompt bname))
2921 (quit ;; Hit C-g ask user to fallback to locate.
2922 (if (y-or-n-p "Search file for ediff with locate? ")
2923 (anything-c-locate-read-file-name
2924 (format prompt bname)
2925 ;; Check if -b option is available.
2926 (if (and (eq system-type 'windows-nt)
2927 (string-match "^es" anything-c-locate-command))
2928 bname
2929 (concat bname " -b")))
2930 (error "Error: Ediff Operation aborted")))))))
2932 (defun anything-find-files-ediff-files (candidate)
2933 (anything-find-files-ediff-files-1 candidate))
2935 (defun anything-find-files-ediff-merge-files (candidate)
2936 (anything-find-files-ediff-files-1 candidate 'merge))
2938 (defun anything-find-files-grep (candidate)
2939 "Default action to grep files from `anything-find-files'."
2940 (anything-do-grep-1 (anything-marked-candidates)
2941 anything-current-prefix-arg))
2943 (defun anything-ff-zgrep (candidate)
2944 "Default action to zgrep files from `anything-find-files'."
2945 (let ((prefarg anything-current-prefix-arg)
2946 (ls (anything-marked-candidates)))
2947 (anything-ff-zgrep-1 ls prefarg)))
2949 (defun anything-ff-pdfgrep (candidate)
2950 "Default action to pdfgrep files from `anything-find-files'."
2951 (let ((cands (loop for file in (anything-marked-candidates)
2952 if (or (string= (file-name-extension file) "pdf")
2953 (string= (file-name-extension file) "PDF"))
2954 collect file))
2955 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2956 (when cands
2957 (anything-do-pdfgrep-1 cands))))
2959 (defun anything-ff-etags-select (candidate)
2960 "Default action to jump to etags from `anything-find-files'."
2961 (when (get-buffer anything-action-buffer)
2962 (kill-buffer anything-action-buffer))
2963 (let ((default-directory anything-ff-default-directory))
2964 (anything-c-etags-select anything-current-prefix-arg)))
2966 (defun anything-find-files-switch-to-hist (candidate)
2967 "Switch to anything-find-files history."
2968 (anything-find-files t))
2970 ;;; Asynchronous copy of files.
2973 (defun anything-c-copy-files-async-1 (flist dest)
2974 "Copy a list of Files FLIST to DEST asynchronously.
2975 It use another emacs process to do the job.
2976 Communication with background emacs is done with temp file
2977 `anything-c-copy-files-async-log-file'."
2978 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2979 "-Q" "--batch" "--eval"
2980 (format "(progn
2981 (require 'dired) (require 'cl)
2982 (let ((dired-recursive-copies 'always)
2983 failures success
2984 (ovw-count 0)
2985 (cpf-count 0))
2986 (dolist (f '%S)
2987 (condition-case err
2988 (let ((file-exists (file-exists-p
2989 (expand-file-name
2990 (file-name-nondirectory (directory-file-name f))
2991 (file-name-directory
2992 (file-name-as-directory \"%s\"))))))
2993 (dired-copy-file f \"%s\" t)
2994 (if file-exists
2995 (progn (push (cons \"Overwriting\" f) success)
2996 (incf ovw-count))
2997 (push (cons \"Copying\" f) success)
2998 (incf cpf-count)))
2999 (file-error
3000 (push (dired-make-relative
3001 (expand-file-name
3002 (file-name-nondirectory (directory-file-name f))
3003 (file-name-directory \"%s\")))
3004 failures))))
3005 (with-current-buffer (find-file-noselect \"%s\")
3006 (erase-buffer)
3007 (when failures
3008 (dolist (fail (reverse failures))
3009 (insert (concat \"Failed to copy \" fail \"\n\"))))
3010 (when success
3011 (loop for (a . s) in (reverse success) do
3012 (insert (concat a \" \" s \" to %s done\n\"))))
3013 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3014 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3015 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3016 (save-buffer))))"
3017 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3019 (defun anything-c-copy-async-with-log (flist dest)
3020 "Copy file list FLIST to DEST showing log.
3021 Log is send to `anything-c-copy-files-async-log-file'.
3022 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3023 (declare (special auto-revert-interval))
3024 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3025 (set (make-local-variable 'auto-revert-interval) 1)
3026 (erase-buffer)
3027 (insert "Wait copying files...\n")
3028 (sit-for 0.5) (save-buffer)
3029 (goto-char (point-max))
3030 (auto-revert-mode 1)
3031 (anything-c-copy-files-async-1 flist dest))
3033 (defun anything-ff-copy-async (candidate)
3034 "Anything find files action to copy files async.
3035 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3036 (let ((flist (anything-marked-candidates))
3037 (dest (anything-c-read-file-name
3038 "Copy File(s) async To: "
3039 :preselect candidate
3040 :initial-input (car anything-ff-history)
3041 :history (anything-find-files-history :comp-read nil))))
3042 (anything-c-copy-async-with-log flist dest)))
3044 (defvar eshell-command-aliases-list nil)
3045 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3046 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3048 Basename of CANDIDATE can be a wild-card.
3049 If MAP is given run `eshell-command' on all marked files at once,
3050 Otherwise, run `eshell-command' on each marked files.
3052 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3053 `eshell-command-aliases-list' will not be loaded first time you use this."
3054 (when (or eshell-command-aliases-list
3055 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3056 (and eshell-command-aliases-list (eshell-read-aliases-list))
3057 (let* ((cand-list (anything-marked-candidates))
3058 (default-directory (or anything-ff-default-directory
3059 ;; If candidate is an url *-ff-default-directory is nil
3060 ;; so keep value of default-directory.
3061 default-directory))
3062 (command (anything-comp-read
3063 "Command: "
3064 (loop for (a . c) in eshell-command-aliases-list
3065 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3066 collect (propertize a 'help-echo (car c)) into ls
3067 finally return (sort ls 'string<))))
3068 (com-value (car (assoc-default command eshell-command-aliases-list))))
3069 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3070 (> (length cand-list) 1))
3071 ;; Run eshell-command with ALL marked files as arguments.
3072 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3073 (eshell-command (format "%s %s" command mapfiles)))
3074 ;; Run eshell-command on EACH marked files.
3075 (loop
3076 for i in cand-list
3077 for bn = (anything-c-basename i)
3078 for files = (if (and bn (string-match "^\*" bn))
3079 ;; Assume if fname is a wildcard
3080 ;; cand-list have a length of 1.
3081 (mapconcat
3082 'shell-quote-argument
3083 (file-expand-wildcards i t) " ")
3084 (format "'%s'" i))
3085 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3086 ;; This allow to enter other args AFTER filename
3087 ;; i.e <command %s some_more_args>
3088 (format command files)
3089 (format "%s %s" command files))
3090 do (eshell-command com))))))
3092 (defun anything-find-files-eshell-command-on-file (candidate)
3093 "Run `eshell-command' on CANDIDATE or marked candidates.
3094 See `anything-find-files-eshell-command-on-file-1' for more info."
3095 (anything-find-files-eshell-command-on-file-1
3096 candidate anything-current-prefix-arg))
3098 (defun anything-ff-switch-to-eshell (candidate)
3099 "Switch to eshell and cd to `anything-ff-default-directory'."
3100 (flet ((cd-eshell ()
3101 (goto-char (point-max))
3102 (insert
3103 (format "cd '%s'" anything-ff-default-directory))
3104 (eshell-send-input)))
3105 (if (get-buffer "*eshell*")
3106 (progn
3107 (anything-c-switch-to-buffer "*eshell*")
3108 (cd-eshell))
3109 (call-interactively 'eshell)
3110 (cd-eshell))))
3112 (defun anything-ff-serial-rename-action (method)
3113 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3114 See `anything-ff-serial-rename-1'."
3115 (let* ((cands (anything-marked-candidates))
3116 (name (read-string "NewName: "))
3117 (start (read-number "StartAtNumber: "))
3118 (extension (read-string "Extension: " (file-name-extension (car cands))))
3119 (dir (expand-file-name
3120 (anything-c-read-file-name
3121 "Serial Rename to directory: " :initial-input
3122 (expand-file-name anything-ff-default-directory)))))
3123 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3124 (length cands) dir name))
3125 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3126 (anything-find-files-1 dir))))
3128 (defun anything-ff-member-directory-p (file directory)
3129 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3130 (cur-dir (expand-file-name (file-name-as-directory directory))))
3131 (string= dir-file cur-dir)))
3133 (defun* anything-ff-serial-rename-1
3134 (directory collection new-name start-at-num extension &key (method 'rename))
3135 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3136 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3137 EXTENSION is the file extension to use, in empty prompt,
3138 reuse the original extension of file.
3139 METHOD can be one of rename, copy or symlink.
3140 Files will be renamed if they are files of current directory, otherwise they
3141 will be treated with METHOD.
3142 Default METHOD is rename."
3143 ;; Maybe remove directories selected by error in collection.
3144 (setq collection (remove-if 'file-directory-p collection))
3145 (flet ((symlink-file (file dest)
3146 (let ((flist (list file)))
3147 (anything-dired-action
3148 dest :action 'symlink :files flist))))
3150 (let* ((tmp-dir (file-name-as-directory
3151 (concat (file-name-as-directory directory)
3152 (symbol-name (gensym "tmp")))))
3153 (fn (case method
3154 (copy 'copy-file)
3155 (symlink 'symlink-file)
3156 (rename 'rename-file)
3157 (t (error "Error: Unknow method %s" method)))))
3158 (make-directory tmp-dir)
3159 (loop for i in collection
3160 for count from start-at-num
3161 for fnum = (if (< count 10) "0%s" "%s")
3162 for nname = (concat tmp-dir new-name (format fnum count)
3163 (if (not (string= extension ""))
3164 (format ".%s" (replace-regexp-in-string
3165 "[.]" "" extension))
3166 (file-name-extension i 'dot)))
3167 do (if (anything-ff-member-directory-p i directory)
3168 (rename-file i nname)
3169 (funcall fn i nname)))
3170 (loop with dirlist = (directory-files
3171 tmp-dir t directory-files-no-dot-files-regexp)
3172 for f in dirlist do
3173 (if (file-symlink-p f)
3174 (symlink-file (file-truename f)
3175 (concat (file-name-as-directory directory)
3176 (anything-c-basename f)))
3177 (rename-file f directory)))
3178 (delete-directory tmp-dir t))))
3180 (defun anything-ff-serial-rename (candidate)
3181 "Serial rename all marked files to `anything-ff-default-directory'.
3182 Rename only file of current directory, and symlink files coming from
3183 other directories.
3184 See `anything-ff-serial-rename-1'."
3185 (anything-ff-serial-rename-action 'rename))
3187 (defun anything-ff-serial-rename-by-symlink (candidate)
3188 "Serial rename all marked files to `anything-ff-default-directory'.
3189 Rename only file of current directory, and symlink files coming from
3190 other directories.
3191 See `anything-ff-serial-rename-1'."
3192 (anything-ff-serial-rename-action 'symlink))
3194 (defun anything-ff-serial-rename-by-copying (candidate)
3195 "Serial rename all marked files to `anything-ff-default-directory'.
3196 Rename only file of current directory, and copy files coming from
3197 other directories.
3198 See `anything-ff-serial-rename-1'."
3199 (anything-ff-serial-rename-action 'copy))
3201 (defun anything-c-quit-and-execute-action (action)
3202 "Quit current anything session and execute ACTION."
3203 (setq anything-saved-action action)
3204 (anything-exit-minibuffer))
3206 (defun anything-ff-toggle-auto-update (candidate)
3207 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3208 (message "[Auto expansion %s]"
3209 (if anything-ff-auto-update-flag "enabled" "disabled")))
3211 ;;;###autoload
3212 (defun anything-ff-run-toggle-auto-update ()
3213 (interactive)
3214 (anything-execute-persistent-action 'toggle-auto-update))
3216 ;;;###autoload
3217 (defun anything-ff-run-switch-to-history ()
3218 "Run Switch to history action from `anything-c-source-find-files'."
3219 (interactive)
3220 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3222 ;;;###autoload
3223 (defun anything-ff-run-grep ()
3224 "Run Grep action from `anything-c-source-find-files'."
3225 (interactive)
3226 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3228 ;;;###autoload
3229 (defun anything-ff-run-pdfgrep ()
3230 "Run Pdfgrep action from `anything-c-source-find-files'."
3231 (interactive)
3232 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3234 ;;;###autoload
3235 (defun anything-ff-run-zgrep ()
3236 "Run Grep action from `anything-c-source-find-files'."
3237 (interactive)
3238 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3240 ;;;###autoload
3241 (defun anything-ff-run-copy-file ()
3242 "Run Copy file action from `anything-c-source-find-files'."
3243 (interactive)
3244 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3246 ;;;###autoload
3247 (defun anything-ff-run-rename-file ()
3248 "Run Rename file action from `anything-c-source-find-files'."
3249 (interactive)
3250 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3252 ;;;###autoload
3253 (defun anything-ff-run-byte-compile-file ()
3254 "Run Byte compile file action from `anything-c-source-find-files'."
3255 (interactive)
3256 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3258 ;;;###autoload
3259 (defun anything-ff-run-load-file ()
3260 "Run Load file action from `anything-c-source-find-files'."
3261 (interactive)
3262 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3264 ;;;###autoload
3265 (defun anything-ff-run-eshell-command-on-file ()
3266 "Run eshell command on file action from `anything-c-source-find-files'."
3267 (interactive)
3268 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3270 ;;;###autoload
3271 (defun anything-ff-run-ediff-file ()
3272 "Run Ediff file action from `anything-c-source-find-files'."
3273 (interactive)
3274 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3276 ;;;###autoload
3277 (defun anything-ff-run-ediff-merge-file ()
3278 "Run Ediff merge file action from `anything-c-source-find-files'."
3279 (interactive)
3280 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3282 ;;;###autoload
3283 (defun anything-ff-run-symlink-file ()
3284 "Run Symlink file action from `anything-c-source-find-files'."
3285 (interactive)
3286 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3288 ;;;###autoload
3289 (defun anything-ff-run-delete-file ()
3290 "Run Delete file action from `anything-c-source-find-files'."
3291 (interactive)
3292 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3294 ;;;###autoload
3295 (defun anything-ff-run-complete-fn-at-point ()
3296 "Run complete file name action from `anything-c-source-find-files'."
3297 (interactive)
3298 (anything-c-quit-and-execute-action
3299 'anything-c-insert-file-name-completion-at-point))
3301 ;;;###autoload
3302 (defun anything-ff-run-switch-to-eshell ()
3303 "Run switch to eshell action from `anything-c-source-find-files'."
3304 (interactive)
3305 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3307 ;;;###autoload
3308 (defun anything-ff-run-switch-other-window ()
3309 "Run switch to other window action from `anything-c-source-find-files'."
3310 (interactive)
3311 (anything-c-quit-and-execute-action 'find-file-other-window))
3313 ;;;###autoload
3314 (defun anything-ff-run-switch-other-frame ()
3315 "Run switch to other frame action from `anything-c-source-find-files'."
3316 (interactive)
3317 (anything-c-quit-and-execute-action 'find-file-other-frame))
3319 ;;;###autoload
3320 (defun anything-ff-run-open-file-externally ()
3321 "Run open file externally command action from `anything-c-source-find-files'."
3322 (interactive)
3323 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3325 (defun anything-ff-locate (candidate)
3326 "Locate action function for `anything-find-files'."
3327 (let ((input (concat (anything-c-basename
3328 (expand-file-name
3329 candidate
3330 anything-ff-default-directory))
3331 ;; The locate '-b' option doesn't exists
3332 ;; in everything.
3333 (unless (and (eq system-type 'windows-nt)
3334 (string-match "^es" anything-c-locate-command))
3335 " -b")))
3336 (anything-mp-highlight-delay 0.7))
3337 (anything-locate-1 anything-current-prefix-arg input)))
3339 ;;;###autoload
3340 (defun anything-ff-run-locate ()
3341 "Run locate action from `anything-c-source-find-files'."
3342 (interactive)
3343 (anything-c-quit-and-execute-action 'anything-ff-locate))
3345 ;;;###autoload
3346 (defun anything-ff-run-gnus-attach-files ()
3347 "Run gnus attach files command action from `anything-c-source-find-files'."
3348 (interactive)
3349 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3351 ;;;###autoload
3352 (defun anything-ff-run-etags ()
3353 "Run Etags command action from `anything-c-source-find-files'."
3354 (interactive)
3355 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3358 (defun anything-ff-print (candidate)
3359 "Print marked files.
3360 You have to set in order
3361 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3363 e.g:
3364 \(setq lpr-command \"gtklp\"\)
3365 \(setq lpr-switches '(\"-P\")\)
3366 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3368 Same as `dired-do-print' but for anything."
3369 (let* ((file-list (anything-marked-candidates))
3370 (len (length file-list))
3371 (printer-name (if anything-ff-printer-list
3372 (anything-comp-read
3373 "Printer: " anything-ff-printer-list)
3374 printer-name))
3375 (command (read-string
3376 (format "Print *%s File(s):\n%s with: "
3378 (mapconcat
3379 (lambda (f) (format "- %s\n" f))
3380 file-list ""))
3381 (when (and lpr-command
3382 (or lpr-switches
3383 printer-name))
3384 (mapconcat 'identity
3385 (cons lpr-command
3386 (append (if (stringp lpr-switches)
3387 (list lpr-switches)
3388 lpr-switches)
3389 (list printer-name)))
3390 " "))))
3391 (file-args (mapconcat #'(lambda (x)
3392 (format "'%s'" x))
3393 file-list " "))
3394 (cmd-line (concat command " " file-args)))
3395 (if command
3396 (start-process-shell-command "anything-print" nil cmd-line)
3397 (error "Error: Please verify your printer settings in Emacs."))))
3399 ;;;###autoload
3400 (defun anything-ff-run-print-file ()
3401 "Run Print file action from `anything-c-source-find-files'."
3402 (interactive)
3403 (anything-c-quit-and-execute-action 'anything-ff-print))
3405 (defun anything-ff-checksum (file)
3406 "Calculate the checksum of FILE.
3407 Provide completion on different algorithms to use on Emacs24.
3408 On Emacs23 only 'sha1' is available.
3409 The checksum is copied to kill-ring."
3410 (let ((algo-list (and (fboundp 'secure-hash)
3411 '(md5 sha1 sha224 sha256 sha384 sha512))))
3412 (kill-new
3413 (if algo-list
3414 (secure-hash (intern
3415 (anything-comp-read
3416 "Algorithm: " algo-list))
3417 file)
3418 (sha1 (with-temp-buffer
3419 (insert-file-contents file)
3420 (buffer-string)))))
3421 (message "Checksum copied to kill-ring.")))
3423 (defun anything-ff-toggle-basename (candidate)
3424 (setq anything-ff-transformer-show-only-basename
3425 (not anything-ff-transformer-show-only-basename))
3426 (save-excursion
3427 (anything-force-update)))
3429 (defun anything-ff-run-toggle-basename ()
3430 (interactive)
3431 (anything-execute-persistent-action 'toggle-basename))
3433 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3434 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3435 If LEVEL is positive reduce from end else from beginning.
3436 If UNIX-CLOSE is non--nil close filename with /.
3437 If EXPAND is non--nil expand-file-name."
3438 (let* ((exp-fname (expand-file-name fname))
3439 (fname-list (split-string (if (or (string= fname "~/") expand)
3440 exp-fname fname) "/" t))
3441 (len (length fname-list))
3442 (pop-list (if (< level 0)
3443 (subseq fname-list (* level -1))
3444 (subseq fname-list 0 (- len level))))
3445 (result (mapconcat 'identity pop-list "/"))
3446 (empty (string= result "")))
3447 (when unix-close (setq result (concat result "/")))
3448 (if (string-match "^~" result)
3449 (if (string= result "~/") "~/" result)
3450 (if (< level 0)
3451 (if empty "../" (concat "../" result))
3452 (cond ((eq system-type 'windows-nt)
3453 (if empty "c:/" result))
3454 (empty "/")
3456 (concat "/" result)))))))
3458 ;; Internal
3459 (defvar anything-file-completion-sources
3460 '("Find Files" "find-file" "Copy Files"
3461 "dired-do-copy" "dired-do-rename"
3462 "dired-do-symlink" "dired-do-hardlink"
3463 "write-file" "insert-file" "dired"
3464 "find-alternate-file" "list-directory"
3465 "find-file-read-only"
3466 "Read File Name History"
3467 "Rename Files" "Symlink Files"
3468 "Hardlink Files" "Write File"
3469 "Insert File" "Read File Name")
3470 "Sources that use the *find-files mechanism can be added here.
3471 You should not modify this yourself and know what you do if you do so.")
3473 (defun anything-file-completion-source-p ()
3474 "Test if current source is a dired or find-files source."
3475 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3476 (loop for i in anything-file-completion-sources
3477 thereis (string= cur-source i))))
3479 (defun anything-find-files-down-one-level (arg)
3480 "Go down one level like unix command `cd ..'.
3481 If prefix numeric arg is given go ARG level down."
3482 (interactive "p")
3483 (with-anything-window
3484 (setq anything-follow-mode nil))
3485 ;; When going to precedent level we want to be at the line
3486 ;; corresponding to actual directory, so store this info
3487 ;; in `anything-ff-last-expanded'.
3488 (if (and (not (file-directory-p anything-pattern))
3489 (file-exists-p anything-pattern))
3490 (setq anything-ff-last-expanded anything-pattern)
3491 (setq anything-ff-last-expanded anything-ff-default-directory))
3492 (when (anything-file-completion-source-p)
3493 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3494 :unix-close t :expand t)))
3495 (anything-set-pattern new-pattern))))
3497 (defun anything-ff-retrieve-last-expanded ()
3498 "Move overlay to last visited directory `anything-ff-last-expanded'.
3499 This happen after using `anything-find-files-down-one-level',
3500 or hitting C-z on \"..\"."
3501 (when (and anything-ff-last-expanded
3502 (anything-file-completion-source-p))
3503 (let ((dirname (if anything-ff-transformer-show-only-basename
3504 (anything-c-basename
3505 (directory-file-name anything-ff-last-expanded))
3506 (directory-file-name anything-ff-last-expanded))))
3507 (with-anything-window
3508 (when (or (re-search-forward (concat dirname "$") nil t)
3509 (re-search-forward
3510 (concat anything-ff-last-expanded "$") nil t))
3511 (forward-line 0)
3512 (anything-mark-current-line)))
3513 (setq anything-ff-last-expanded nil))))
3514 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3516 ;; Auto-update - anything-find-files auto expansion of directories.
3518 (defun anything-ff-update-when-only-one-matched ()
3519 "Expand to directory when sole completion.
3520 When only one candidate is remaining and it is a directory,
3521 expand to this directory."
3522 (when (and anything-ff-auto-update-flag
3523 (anything-file-completion-source-p))
3524 (let* ((history-p (string= (assoc-default
3525 'name (anything-get-current-source))
3526 "Read File Name History"))
3527 (pat (if (string-match tramp-file-name-regexp
3528 anything-pattern)
3529 (anything-create-tramp-name anything-pattern)
3530 anything-pattern))
3531 (completed-p (string= (file-name-as-directory pat)
3532 anything-ff-default-directory)))
3533 (when (and (or
3534 ;; Only one candidate remaining
3535 ;; and at least 2 char in basename.
3536 (and (<= (anything-approximate-candidate-number) 2)
3537 (>= (length (anything-c-basename anything-pattern)) 2))
3538 ;; Already completed.
3539 completed-p)
3540 (not history-p)) ; Don't try to auto complete in history.
3541 (with-anything-window
3542 (let ((cur-cand (prog2
3543 (unless completed-p
3544 ;; Only one non--existing candidate
3545 ;; and one directory candidate, move to it.
3546 (anything-next-line))
3547 (anything-get-selection))))
3548 (when (file-directory-p cur-cand)
3549 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3550 ;; Maybe we are here because completed-p is true
3551 ;; but check this again to be sure. (Windows fix)
3552 (<= (anything-approximate-candidate-number) 2)) ; [2]
3553 ;; If after going to next line the candidate
3554 ;; is not one of "." or ".." [1]
3555 ;; and only one candidate is remaining [2],
3556 ;; assume candidate is a new directory to expand, and do it.
3557 (anything-set-pattern (file-name-as-directory cur-cand))
3558 ;; The candidate is one of "." or ".."
3559 ;; that mean we have entered the last letter of the directory name
3560 ;; in prompt, so expansion is already done, just add the "/" at end
3561 ;; of name unless anything-pattern ends with "."
3562 ;; (i.e we are writing something starting with ".")
3563 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3564 (anything-set-pattern
3565 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3566 (expand-file-name (file-name-as-directory anything-pattern)))))
3567 (anything-check-minibuffer-input-1))))))))
3568 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3570 ;; Allow expanding to home directory or root
3571 ;; when entering respectively "~/" or "//" at end of pattern.
3572 ;; e.g /home/thierry/labo/anything-config-qp/~/
3573 ;; will expand to "~/"
3574 ;; and /home/thierry/labo/anything-config-qp//
3575 ;; will expand to "/"
3576 (defun anything-ff-auto-expand-to-home-or-root ()
3577 "Goto home or root directory when adding ~/ or / at end of pattern.
3578 This happen only in function using sources that are
3579 `anything-file-completion-source-p' compliant."
3580 (when (and (anything-file-completion-source-p)
3581 (string-match ".*\\(/~/\\|/\\{2\\}\\)$" anything-pattern))
3582 (let ((match (match-string 1 anything-pattern)))
3583 (cond ((string= match "//")
3584 (if (eq system-type 'windows-nt)
3585 (setq anything-pattern "c:/")
3586 (setq anything-pattern "/")))
3587 ((string= match "/~/")
3588 (if (eq system-type 'windows-nt)
3589 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3590 (setq anything-pattern "~/")))))
3591 (setq anything-ff-default-directory anything-pattern)
3592 ;; For some reasons, i must use here with-current-buffer => mini buffer
3593 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3594 (with-current-buffer (window-buffer (minibuffer-window))
3595 (delete-minibuffer-contents)
3596 (insert anything-pattern))))
3598 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3600 (defun anything-c-point-file-in-dired (file)
3601 "Put point on filename FILE in dired buffer."
3602 (dired (file-name-directory file))
3603 (dired-goto-file file))
3605 (defun anything-create-tramp-name (fname)
3606 "Build filename for `anything-pattern' like /su:: or /sudo::."
3607 (apply #'tramp-make-tramp-file-name
3608 (loop with v = (tramp-dissect-file-name fname)
3609 for i across v collect i)))
3611 (defun anything-ff-set-pattern (pattern)
3612 "Handle tramp filenames in `anything-pattern'."
3613 (let ((methods (mapcar 'car tramp-methods))
3614 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3615 cur-method tramp-name)
3616 (cond ((string= pattern "") "")
3617 ((string-match ".*\\(~//\\|//\\)$" pattern)
3618 (if (eq system-type 'windows-nt) "c:/" "/"))
3619 ((string-match "^~\\|.*/~/$" pattern)
3620 (let* ((home (getenv "HOME"))
3621 (replace (if (eq system-type 'windows-nt)
3622 (replace-regexp-in-string
3623 "\\\\" "/" home)
3624 home)))
3625 (replace-match replace nil t pattern)))
3626 ;; Match "/method:maybe_hostname:"
3627 ((and (string-match reg pattern)
3628 (setq cur-method (match-string 1 pattern))
3629 (member cur-method methods))
3630 (setq tramp-name (anything-create-tramp-name
3631 (match-string 0 pattern)))
3632 (replace-match tramp-name nil t pattern))
3633 ;; Match "/hostname:"
3634 ((and (string-match tramp-file-name-regexp pattern)
3635 (setq cur-method (match-string 1 pattern))
3636 (and cur-method (not (member cur-method methods))))
3637 (setq tramp-name (anything-create-tramp-name
3638 (match-string 0 pattern)))
3639 (replace-match tramp-name nil t pattern))
3640 ;; Match "/method:" in this case don't try to connect.
3641 ((and (not (string-match reg pattern))
3642 (string-match tramp-file-name-regexp pattern)
3643 (member (match-string 1 pattern) methods))
3644 "Invalid tramp file name") ; Write in anything-buffer.
3645 ;; PATTERN is a directory, end it with "/".
3646 ;; This will make PATTERN not ending yet with "/"
3647 ;; candidate for `anything-ff-default-directory',
3648 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3649 ;; when descending level.
3650 ((file-directory-p pattern)
3651 (file-name-as-directory pattern))
3652 ;; Return PATTERN unchanged.
3653 (t pattern))))
3656 (defun anything-find-files-get-candidates ()
3657 "Create candidate list for `anything-c-source-find-files'."
3658 (let* ((path (anything-ff-set-pattern anything-pattern))
3659 (path-name-dir (if (file-directory-p path)
3660 (file-name-as-directory path)
3661 (file-name-directory path)))
3662 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3663 (set-text-properties 0 (length path) nil path)
3664 (setq anything-pattern (anything-ff-transform-fname-for-completion path))
3665 (setq anything-ff-default-directory
3666 (if (string= anything-pattern "")
3667 (if (eq system-type 'windows-nt) "c:/" "/")
3668 (unless (string-match ffap-url-regexp path)
3669 ;; If path is an url *default-directory have to be nil.
3670 path-name-dir)))
3671 (cond ((or (string= path "Invalid tramp file name")
3672 (file-regular-p path)
3673 (and (not (file-exists-p path)) (string-match "/$" path))
3674 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3675 (list path))
3676 ((string= path "") (directory-files "/" t))
3677 ((and (file-directory-p path) (not (file-readable-p path)))
3678 (list (format "Opening directory: access denied, `%s'" path)))
3679 ((file-directory-p path) (directory-files path t))
3681 (append (list path) (directory-files path-name-dir t))))))
3683 (defun anything-ff-transform-fname-for-completion (fname)
3684 "Return FNAME with it's basename modified as a regexp.
3685 e.g foo => f.*o.*o .
3686 If basename contain one or more space or FNAME is a valid directory name
3687 return FNAME unchanged."
3688 (let ((bn (anything-c-basename fname)))
3689 (if (or (not anything-ff-smart-completion)
3690 (string-match "\\s-" bn)
3691 (string-match "/$" fname) ; Allow mkdir.
3692 (file-directory-p fname))
3693 fname ; Fall back to match-plugin.
3694 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3695 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3696 (concat (file-name-directory fname) bn))))
3698 (defun anything-ff-save-history ()
3699 "Store the last value of `anything-ff-default-directory' \
3700 in `anything-ff-history'."
3701 (when (and anything-ff-default-directory
3702 (anything-file-completion-source-p))
3703 (push anything-ff-default-directory anything-ff-history)))
3704 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3706 (defun anything-ff-valid-symlink-p (file)
3707 (file-exists-p (file-truename file)))
3709 (defun anything-ff-properties (candidate)
3710 "Show file properties of CANDIDATE in a tooltip or message."
3711 (let ((type (anything-ff-attributes candidate :type t))
3712 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3713 (if (window-system)
3714 (tooltip-show
3715 (concat
3716 (anything-c-basename candidate) ": \n"
3717 "Type: " type "\n"
3718 (when (string= type "symlink")
3719 (format "True name: '%s'\n"
3720 (cond ((string-match "^\.#" (anything-c-basename candidate))
3721 "Autosave symlink")
3722 ((anything-ff-valid-symlink-p candidate)
3723 (file-truename candidate))
3724 (t "Invalid Symlink"))))
3725 dired-line))
3726 (message dired-line) (sit-for 5))))
3728 ;;;###autoload
3729 (defun anything-ff-properties-persistent ()
3730 "Show properties without quitting anything."
3731 (interactive)
3732 (anything-execute-persistent-action 'properties-action))
3734 (defun anything-ff-kill-buffer-fname (candidate)
3735 (let* ((buf (get-file-buffer candidate))
3736 (buf-name (buffer-name buf)))
3737 (if buf
3738 (progn
3739 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3740 (message "No buffer to kill"))))
3742 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3743 "Find file CANDIDATE or kill it's buffer if it is visible.
3744 Never kill `anything-current-buffer'.
3745 Never kill buffer modified.
3746 This is called normally on third hit of \
3747 \\<anything-map>\\[anything-execute-persistent-action]
3748 in `anything-find-files-persistent-action'."
3749 (let* ((buf (get-file-buffer candidate))
3750 (buf-name (buffer-name buf)))
3751 (if (and buf (get-buffer-window buf)
3752 (not (eq buf (get-buffer anything-current-buffer)))
3753 (not (buffer-modified-p buf)))
3754 (progn
3755 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3756 (find-file candidate))))
3758 ;;;###autoload
3759 (defun anything-ff-run-kill-buffer-persistent ()
3760 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3761 (interactive)
3762 (anything-execute-persistent-action 'kill-buffer-fname))
3764 (defun anything-ff-human-size (size)
3765 "Return a string showing SIZE of a file in human readable form.
3766 SIZE can be an integer or a float depending it's value.
3767 `file-attributes' will take care of that to avoid overflow error.
3768 KBSIZE if a floating point number, default value is 1024.0."
3769 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3770 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3771 (K (cons "K" (/ size anything-ff-default-kbsize)))
3772 (B (cons "B" size)))
3773 (loop with result = B
3774 for (a . b) in
3775 (loop for (x . y) in (list M G K B)
3776 unless (< y 1) collect (cons x y))
3777 when (< b (cdr result)) do (setq result (cons a b))
3778 finally return (if (string= (car result) "B")
3779 (format "%s" size)
3780 (format "%.1f%s" (cdr result) (car result))))))
3782 (defun* anything-ff-attributes
3783 (file &key type links uid gid access-time modif-time
3784 status size mode gid-change inode device-num dired human-size)
3785 "Easy interface for `file-attributes'."
3786 (let ((all (destructuring-bind
3787 (type links uid gid access-time modif-time
3788 status size mode gid-change inode device-num)
3789 (file-attributes file 'string)
3790 (list :type type
3791 :links links
3792 :uid uid
3793 :gid gid
3794 :access-time access-time
3795 :modif-time modif-time
3796 :status status
3797 :size size
3798 :mode mode
3799 :gid-change gid-change
3800 :inode inode
3801 :device-num device-num))))
3802 (cond (type
3803 (let ((result (getf all :type)))
3804 (cond ((stringp result)
3805 "symlink")
3806 (result "directory")
3807 (t "file"))))
3808 (links (getf all :links))
3809 (uid (getf all :uid))
3810 (gid (getf all :gid))
3811 (access-time
3812 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3813 (modif-time
3814 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3815 (status
3816 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3817 (size (if human-size (anything-ff-human-size (getf all :size))
3818 (getf all :size)))
3819 (mode (getf all :mode))
3820 (gid-change (getf all :gid-change))
3821 (inode (getf all :inode))
3822 (device-num (getf all :device-num))
3823 (dired
3824 (concat
3825 (getf all :mode) " "
3826 (number-to-string (getf all :links)) " "
3827 (getf all :uid) ":"
3828 (getf all :gid) " "
3829 (if human-size (anything-ff-human-size (getf all :size))
3830 (int-to-string (getf all :size))) " "
3831 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3832 (t all))))
3834 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3835 "Return filename FNAME maybe prefixed with [?] or [@].
3836 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3837 existing filename or valid symlink and there is no need to test it.
3838 NEW-FILE when non--nil mean FNAME is a non existing file and
3839 return FNAME prefixed with [?]."
3840 (let* ((prefix-new (propertize
3841 " " 'display
3842 (propertize "[?]" 'face 'anything-ff-prefix)))
3843 (prefix-url (propertize
3844 " " 'display
3845 (propertize "[@]" 'face 'anything-ff-prefix))))
3846 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3847 ((string-match ffap-url-regexp fname)
3848 (concat prefix-url " " fname))
3849 ((or new-file (not (file-exists-p fname)))
3850 (concat prefix-new " " fname)))))
3852 (defun anything-c-find-files-transformer (files sources)
3853 "Transformer for `anything-c-source-find-files'.
3854 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3855 is non--nil."
3856 (if (and (string-match tramp-file-name-regexp anything-pattern)
3857 anything-ff-tramp-not-fancy)
3858 (if anything-ff-transformer-show-only-basename
3859 (loop for i in files collect
3860 (if (string-match "[.]\\{1,2\\}$" i)
3861 i (cons (anything-c-basename i) i)))
3862 files)
3863 (anything-ff-highlight-files files sources)))
3865 (defun anything-ff-highlight-files (files sources)
3866 "Candidate transformer for `anything-c-source-find-files' without icons."
3867 (loop for i in files
3868 for disp = (if (and anything-ff-transformer-show-only-basename
3869 (not (string-match "[.]\\{1,2\\}$" i))
3870 (not (string-match ffap-url-regexp i)))
3871 (anything-c-basename i) i)
3872 collect
3873 (cond ((and (stringp (car (file-attributes i)))
3874 (not (anything-ff-valid-symlink-p i))
3875 (not (string-match "^\.#" (anything-c-basename i))))
3876 (cons (anything-ff-prefix-filename
3877 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3879 ((stringp (car (file-attributes i)))
3880 (cons (anything-ff-prefix-filename
3881 (propertize disp 'face 'anything-ff-symlink) t)
3883 ((eq t (car (file-attributes i)))
3884 (cons (anything-ff-prefix-filename
3885 (propertize disp 'face 'anything-ff-directory) t)
3887 ((file-executable-p i)
3888 (cons (anything-ff-prefix-filename
3889 (propertize disp 'face 'anything-ff-executable) t)
3891 ((file-exists-p i)
3892 (cons (anything-ff-prefix-filename
3893 (propertize disp 'face 'anything-ff-file) t)
3896 (cons (anything-ff-prefix-filename
3897 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3898 i)))))
3900 (defun anything-find-files-action-transformer (actions candidate)
3901 "Action transformer for `anything-c-source-find-files'."
3902 (cond ((with-anything-current-buffer
3903 (eq major-mode 'message-mode))
3904 (append (subseq actions 0 4)
3905 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3906 (subseq actions 4)))
3907 ((string-match (image-file-name-regexp) candidate)
3908 (append (subseq actions 0 4)
3909 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3910 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3911 (subseq actions 4)))
3912 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3913 (car it) candidate))
3914 (append (subseq actions 0 4)
3915 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3916 . anything-find-files-byte-compile)
3917 ("Load File(s) `M-L'" . anything-find-files-load-files))
3918 (subseq actions 4)))
3919 ((and (string-match "\.html?$" candidate)
3920 (file-exists-p candidate))
3921 (append (subseq actions 0 4)
3922 '(("Browse url file" . browse-url-of-file))
3923 (subseq actions 5)))
3924 ((or (string= (file-name-extension candidate) "pdf")
3925 (string= (file-name-extension candidate) "PDF"))
3926 (append (subseq actions 0 4)
3927 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3928 (subseq actions 5)))
3929 (t actions)))
3931 (defun anything-ff-gnus-attach-files (candidate)
3932 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3933 (let ((flist (anything-marked-candidates)))
3934 (gnus-dired-attach flist)))
3936 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
3937 "Rotate current image at NUM-ARG degrees.
3938 This is a destructive operation on FILE made by external tool mogrify."
3939 (declare (special image-dired-display-image-buffer))
3940 (setq file (file-truename file)) ; For symlinked images.
3941 ;; When FILE is not an image-file, do nothing.
3942 (when (string-match (image-file-name-regexp) file)
3943 (if (executable-find "mogrify")
3944 (progn
3945 (shell-command (format "mogrify -rotate %s %s"
3946 (or num-arg 90)
3947 (shell-quote-argument file)))
3948 (when (buffer-live-p image-dired-display-image-buffer)
3949 (kill-buffer image-dired-display-image-buffer))
3950 (image-dired-display-image file)
3951 (message nil)
3952 (display-buffer (get-buffer image-dired-display-image-buffer)))
3953 (error "mogrify not found"))))
3955 (defun anything-ff-rotate-image-left (candidate)
3956 "Rotate image file CANDIDATE left.
3957 This affect directly file CANDIDATE."
3958 (anything-ff-rotate-current-image-1 candidate -90))
3960 (defun anything-ff-rotate-image-right (candidate)
3961 "Rotate image file CANDIDATE right.
3962 This affect directly file CANDIDATE."
3963 (anything-ff-rotate-current-image-1 candidate))
3965 (defun anything-ff-rotate-left-persistent ()
3966 "Rotate image left without quitting anything."
3967 (interactive)
3968 (anything-execute-persistent-action 'image-action1))
3970 (defun anything-ff-rotate-right-persistent ()
3971 "Rotate image right without quitting anything."
3972 (interactive)
3973 (anything-execute-persistent-action 'image-action2))
3975 (defun anything-ff-exif-data (candidate)
3976 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
3977 (if (and anything-ff-exif-data-program
3978 (executable-find anything-ff-exif-data-program))
3979 (shell-command-to-string (format "%s %s %s"
3980 anything-ff-exif-data-program
3981 anything-ff-exif-data-program-args
3982 candidate))
3983 (format "No program %s found to extract exif"
3984 anything-ff-exif-data-program)))
3986 (defun anything-find-files-persistent-action (candidate)
3987 "Open subtree CANDIDATE without quitting anything.
3988 If CANDIDATE is not a directory expand CANDIDATE filename.
3989 If CANDIDATE is alone, open file CANDIDATE filename.
3990 That's mean:
3991 First hit on C-z expand CANDIDATE second hit open file.
3992 If a prefix arg is given or `anything-follow-mode' is on open file."
3993 (let ((follow (buffer-local-value
3994 'anything-follow-mode
3995 (get-buffer-create anything-buffer)))
3996 (new-pattern (anything-get-selection))
3997 (num-lines-buf (with-current-buffer anything-buffer
3998 (count-lines (point-min) (point-max)))))
3999 (flet ((insert-in-minibuffer (fname)
4000 (with-selected-window (minibuffer-window)
4001 (unless follow
4002 (delete-minibuffer-contents)
4003 (set-text-properties 0 (length fname) nil fname)
4004 (insert fname)))))
4005 (cond (;; A symlink directory, expand it's truename.
4006 (and (file-directory-p candidate) (file-symlink-p candidate))
4007 (insert-in-minibuffer (file-name-as-directory
4008 (file-truename
4009 (expand-file-name candidate)))))
4010 ;; A directory, open it.
4011 ((file-directory-p candidate)
4012 (when (string= (anything-c-basename candidate) "..")
4013 (setq anything-ff-last-expanded anything-ff-default-directory))
4014 (insert-in-minibuffer (file-name-as-directory
4015 (expand-file-name candidate))))
4016 ;; A symlink file, expand to it's true name. (first hit)
4017 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4018 (insert-in-minibuffer (file-truename candidate)))
4019 ;; A regular file, expand it, (first hit)
4020 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4021 (insert-in-minibuffer new-pattern))
4022 ;; An image file and it is the second hit on C-z,
4023 ;; show the file in `image-dired'.
4024 ((string-match (image-file-name-regexp) candidate)
4025 (when (buffer-live-p image-dired-display-image-buffer)
4026 (kill-buffer image-dired-display-image-buffer))
4027 (image-dired-display-image candidate)
4028 (message nil)
4029 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4030 (with-current-buffer image-dired-display-image-buffer
4031 (let ((exif-data (anything-ff-exif-data candidate)))
4032 (image-dired-update-property 'help-echo exif-data))))
4033 ;; Allow browsing archive on avfs fs.
4034 ;; Assume volume is already mounted with mountavfs.
4035 ((and anything-ff-avfs-directory
4036 (string-match
4037 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4038 (file-name-directory candidate))
4039 (anything-ff-file-compressed-p candidate))
4040 (insert-in-minibuffer (concat candidate "#")))
4041 ;; On second hit we open file.
4042 ;; On Third hit we kill it's buffer maybe.
4044 (anything-ff-kill-or-find-buffer-fname candidate))))))
4046 (defun anything-ff-file-compressed-p (candidate)
4047 "Whether CANDIDATE is a compressed file or not."
4048 (member (file-name-extension candidate)
4049 anything-ff-file-compressed-list))
4051 (defun anything-c-insert-file-name-completion-at-point (candidate)
4052 "Insert file name completion at point."
4053 (with-anything-current-buffer
4054 (if buffer-read-only
4055 (error "Error: Buffer `%s' is read-only" (buffer-name))
4056 (let* ((end (point))
4057 (guess (substring-no-properties (thing-at-point 'filename)))
4058 (beg (- (point) (length guess)))
4059 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4060 (string-match-p "^[^\~]" guess))))
4061 (set-text-properties 0 (length candidate) nil candidate)
4062 (if (and guess (not (string= guess ""))
4063 (string-match-p "^~\\|/.*" guess))
4064 (progn
4065 (delete-region beg end)
4066 (insert (if full-path-p
4067 (expand-file-name candidate)
4068 (abbreviate-file-name candidate))))
4069 (error "Aborting completion: No valid file name at point"))))))
4071 (defun* anything-find-files-history (&key (comp-read t))
4072 "The `anything-find-files' history.
4073 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4074 in an `anything-comp-read'."
4075 (let ((history (when anything-ff-history
4076 (loop with dup for i in anything-ff-history
4077 ;; Remove duplicate and not existing files.
4078 ;; Keep remote files.
4079 unless (or (member i dup)
4080 (and (not (file-remote-p i))
4081 (not (file-exists-p i))))
4082 collect i into dup
4083 finally return dup)))) ; Remove dups.
4084 (when history
4085 (setq anything-ff-history
4086 (if (>= (length history) anything-ff-history-max-length)
4087 (subseq history 0 anything-ff-history-max-length)
4088 history))
4089 (if comp-read
4090 (anything-comp-read
4091 "Switch to Directory: "
4092 anything-ff-history
4093 :name "Anything Find Files History"
4094 :must-match t)
4095 anything-ff-history))))
4097 (defun anything-find-files-1 (fname &optional preselect)
4098 "Find FNAME with `anything' completion.
4099 Like `find-file' but with `anything' support.
4100 Use it for non--interactive calls of `anything-find-files'."
4101 (when (get-buffer anything-action-buffer)
4102 (kill-buffer anything-action-buffer))
4103 (let ((anything-mp-highlight-delay nil)
4104 ;; Be sure we don't erase the precedent minibuffer if some.
4105 (anything-ff-auto-update-initial-value
4106 (not (minibuffer-window-active-p (minibuffer-window))))
4107 anything-samewindow)
4108 (anything :sources 'anything-c-source-find-files
4109 :input fname
4110 :preselect preselect
4111 :keymap anything-find-files-map
4112 :prompt "Find Files or Url: "
4113 :buffer "*Anything Find Files*")))
4116 (defun anything-find-files-initial-input (&optional input)
4117 "Return INPUT if present, otherwise try to guess it."
4118 (or (and input (expand-file-name input))
4119 (anything-find-files-input
4120 (ffap-guesser)
4121 (thing-at-point 'filename))))
4123 (defun anything-find-files-input (fap tap)
4124 "Default input of `anything-find-files'."
4125 (let* ((def-dir (anything-c-current-directory))
4126 (lib (anything-find-library-at-point))
4127 (url (anything-ff-find-url-at-point))
4128 (file-p (and fap (not (string= fap ""))
4129 (file-exists-p fap)
4130 tap (not (string= tap ""))
4131 (file-exists-p
4132 (file-name-directory (expand-file-name tap def-dir))))))
4133 (cond (lib) ; e.g we are inside a require sexp.
4134 (url) ; String at point is an hyperlink.
4135 (file-p (expand-file-name tap def-dir))
4136 (t (and (not (string= fap "")) fap)))))
4138 (defun anything-c-current-directory ()
4139 "Return current-directory name at point.
4140 Useful in dired buffers when there is inserted subdirs."
4141 (if (eq major-mode 'dired-mode)
4142 (dired-current-directory)
4143 default-directory))
4145 (defun anything-ff-find-url-at-point ()
4146 "Try to find link to an url in text-property at point."
4147 (let* ((he (get-text-property (point) 'help-echo))
4148 (ov (overlays-at (point)))
4149 (ov-he (and ov (overlay-get
4150 (car (overlays-at (point))) 'help-echo)))
4151 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4152 (nt-prop (get-text-property (point) 'nt-link)))
4153 ;; Org link.
4154 (when (and (stringp he) (string-match "^LINK: " he))
4155 (setq he (replace-match "" t t he)))
4156 (loop for i in (list he ov-he w3m-l nt-prop)
4157 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4159 (defun anything-find-library-at-point ()
4160 "Try to find library path at point.
4161 Find inside `require' and `declare-function' sexp."
4162 (require 'find-func)
4163 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4164 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4165 (sexp (and beg-sexp end-sexp
4166 (buffer-substring-no-properties
4167 (1+ beg-sexp) (1- end-sexp)))))
4168 (ignore-errors
4169 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4170 (find-library-name
4171 (replace-regexp-in-string
4172 "'\\|\)\\|\(" ""
4173 ;; If require use third arg, ignore it,
4174 ;; always use library path found in `load-path'.
4175 (second (split-string (match-string 0 sexp))))))
4176 ((and sexp (string-match-p "^declare-function" sexp))
4177 (find-library-name
4178 (replace-regexp-in-string
4179 "\"\\|ext:" ""
4180 (third (split-string sexp)))))
4181 (t nil)))))
4183 ;;; Anything completion for `write-file'.==> C-x C-w
4184 (defvar anything-c-source-write-file
4185 `((name . "Write File")
4186 (header-name . (lambda (name)
4187 (concat name anything-c-find-files-doc-header)))
4188 ;; It is needed for filenames with capital letters
4189 (disable-shortcuts)
4190 (candidates . anything-find-files-get-candidates)
4191 (filtered-candidate-transformer anything-c-find-files-transformer)
4192 (persistent-action . anything-find-files-persistent-action)
4193 (persistent-help . "Expand Candidate")
4194 (volatile)
4195 (action .
4196 (("Write File" . (lambda (candidate)
4197 (write-file candidate 'confirm)))))))
4199 ;;; Anything completion for `insert-file'.==> C-x i
4200 (defvar anything-c-source-insert-file
4201 `((name . "Insert File")
4202 (header-name . (lambda (name)
4203 (concat name anything-c-find-files-doc-header)))
4204 ;; It is needed for filenames with capital letters
4205 (disable-shortcuts)
4206 (candidates . anything-find-files-get-candidates)
4207 (filtered-candidate-transformer anything-c-find-files-transformer)
4208 (persistent-action . anything-find-files-persistent-action)
4209 (persistent-help . "Expand Candidate")
4210 (volatile)
4211 (action .
4212 (("Insert File" . (lambda (candidate)
4213 (when (y-or-n-p (format "Really insert %s in %s "
4214 candidate anything-current-buffer))
4215 (insert-file-contents candidate))))))))
4217 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4218 (defvar anything-c-source-copy-files
4219 `((name . "Copy Files")
4220 (header-name . (lambda (name)
4221 (concat name anything-c-find-files-doc-header)))
4222 ;; It is needed for filenames with capital letters
4223 (disable-shortcuts)
4224 (candidates . anything-find-files-get-candidates)
4225 (filtered-candidate-transformer anything-c-find-files-transformer)
4226 (persistent-action . anything-find-files-persistent-action)
4227 (persistent-help . "Expand Candidate")
4228 (volatile)
4229 (action .
4230 (("Copy File"
4231 . (lambda (candidate)
4232 (anything-dired-action candidate :action 'copy)))
4233 ("Copy and Follow"
4234 . (lambda (candidate)
4235 (anything-dired-action candidate :action 'copy :follow t)))))))
4238 (defvar anything-c-source-rename-files
4239 `((name . "Rename Files")
4240 (header-name . (lambda (name)
4241 (concat name anything-c-find-files-doc-header)))
4242 ;; It is needed for filenames with capital letters
4243 (disable-shortcuts)
4244 (candidates . anything-find-files-get-candidates)
4245 (filtered-candidate-transformer anything-c-find-files-transformer)
4246 (persistent-action . anything-find-files-persistent-action)
4247 (persistent-help . "Expand Candidate")
4248 (volatile)
4249 (action .
4250 (("Rename File"
4251 . (lambda (candidate)
4252 (anything-dired-action candidate :action 'rename)))
4253 ("Rename and Follow"
4254 . (lambda (candidate)
4255 (anything-dired-action candidate :action 'rename :follow t)))))))
4257 (defvar anything-c-source-symlink-files
4258 `((name . "Symlink Files")
4259 (header-name . (lambda (name)
4260 (concat name anything-c-find-files-doc-header)))
4261 ;; It is needed for filenames with capital letters
4262 (disable-shortcuts)
4263 (candidates . anything-find-files-get-candidates)
4264 (filtered-candidate-transformer anything-c-find-files-transformer)
4265 (persistent-action . anything-find-files-persistent-action)
4266 (persistent-help . "Expand Candidate")
4267 (volatile)
4268 (action
4269 . (("Symlink File"
4270 . (lambda (candidate)
4271 (anything-dired-action candidate :action 'symlink)))
4272 ("RelSymlink File"
4273 . (lambda (candidate)
4274 (anything-dired-action candidate :action 'relsymlink)))))))
4277 (defvar anything-c-source-hardlink-files
4278 `((name . "Hardlink Files")
4279 (header-name . (lambda (name)
4280 (concat name anything-c-find-files-doc-header)))
4281 ;; It is needed for filenames with capital letters
4282 (disable-shortcuts)
4283 (candidates . anything-find-files-get-candidates)
4284 (filtered-candidate-transformer anything-c-find-files-transformer)
4285 (persistent-action . anything-find-files-persistent-action)
4286 (persistent-help . "Expand Candidate")
4287 (volatile)
4288 (action
4289 . (("Hardlink File"
4290 . (lambda (candidate)
4291 (anything-dired-action candidate :action 'hardlink)))))))
4293 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4294 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4295 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4296 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4297 (let ((fn (case action
4298 ('copy 'dired-copy-file)
4299 ('rename 'dired-rename-file)
4300 ('symlink 'make-symbolic-link)
4301 ('relsymlink 'dired-make-relative-symlink)
4302 ('hardlink 'dired-hardlink)))
4303 (marker (case action
4304 ((copy rename) dired-keep-marker-copy)
4305 ('symlink dired-keep-marker-symlink)
4306 ('relsymlink dired-keep-marker-relsymlink)
4307 ('hardlink dired-keep-marker-hardlink)))
4308 (dirflag (and (= (length files) 1)
4309 (file-directory-p (car files))
4310 (not (file-directory-p candidate)))))
4311 (dired-create-files
4312 fn (symbol-name action) files
4313 ;; CANDIDATE is the destination.
4314 (if (file-directory-p candidate)
4315 ;; When CANDIDATE is a directory, build file-name in this directory.
4316 ;; Else we use CANDIDATE.
4317 #'(lambda (from)
4318 (expand-file-name (file-name-nondirectory from) candidate))
4319 #'(lambda (from) candidate))
4320 marker)
4321 (when (and follow (not (get-buffer dired-log-buffer)))
4322 (let ((target (directory-file-name candidate)))
4323 (unwind-protect
4324 (progn
4325 (setq anything-ff-cand-to-mark
4326 (anything-get-dest-fnames-from-list files candidate dirflag))
4327 (if (and dirflag (eq action 'rename))
4328 (anything-find-files-1 (file-name-directory target)
4329 (if anything-ff-transformer-show-only-basename
4330 (anything-c-basename target) target))
4331 (anything-find-files-1 (expand-file-name candidate))))
4332 (setq anything-ff-cand-to-mark nil))))))
4335 (defun anything-c-basename (fname)
4336 "Resolve basename of file or directory named FNAME."
4337 (file-name-nondirectory (directory-file-name fname)))
4339 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4340 "Transform filenames of FLIST to abs of DEST-CAND.
4341 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4342 members of FLIST."
4343 ;; At this point files have been renamed/copied at destination.
4344 ;; That's mean DEST-CAND exists.
4345 (loop
4346 with dest = (expand-file-name dest-cand)
4347 for src in flist
4348 for basename-src = (anything-c-basename src)
4349 for fname = (cond (rename-dir-flag (directory-file-name dest))
4350 ((file-directory-p dest)
4351 (concat (file-name-as-directory dest) basename-src))
4352 (t dest))
4353 when (file-exists-p fname)
4354 collect fname into tmp-list
4355 finally return (sort tmp-list 'string<)))
4357 (defun anything-ff-maybe-mark-candidates ()
4358 "Mark all candidates of list `anything-ff-cand-to-mark'."
4359 (when (and (string= (assoc-default 'name (anything-get-current-source))
4360 (assoc-default 'name anything-c-source-find-files))
4361 anything-ff-cand-to-mark)
4362 (with-anything-window
4363 (while anything-ff-cand-to-mark
4364 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4365 (progn
4366 (anything-make-visible-mark)
4367 (anything-next-line)
4368 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4369 (anything-next-line)))
4370 (unless (anything-this-visible-mark)
4371 (anything-prev-visible-mark)))))
4373 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4375 (defun* anything-dired-do-action-on-file (&key action)
4376 (let* ((files (dired-get-marked-files))
4377 (len (length files))
4378 (fname (if (> len 1)
4379 (format "* %d Files" len)
4380 (car files)))
4381 (source (case action
4382 ('copy 'anything-c-source-copy-files)
4383 ('rename 'anything-c-source-rename-files)
4384 ('symlink 'anything-c-source-symlink-files)
4385 ('hardlink 'anything-c-source-hardlink-files)))
4386 (prompt-fm (case action
4387 ('copy "Copy %s to: ")
4388 ('rename "Rename %s to: ")
4389 ('symlink "Symlink %s to: ")
4390 ('hardlink "Hardlink %s to: ")))
4391 (buffer (case action
4392 ('copy "*Anything Copy Files*")
4393 ('rename "*Anything Rename Files*")
4394 ('symlink "*Anything Symlink Files*")
4395 ('hardlink "*Anything Hardlink Files*")))
4396 (anything-mp-highlight-delay nil))
4397 (anything :sources source
4398 :input (or (dired-dwim-target-directory)
4399 (expand-file-name (anything-c-current-directory)))
4400 :preselect (dired-get-filename)
4401 :prompt (format prompt-fm fname)
4402 :keymap anything-c-read-file-map
4403 :buffer buffer)))
4405 ;;;###autoload
4406 (define-minor-mode anything-dired-mode ()
4407 "Enable anything completion in Dired functions.
4408 Bindings affected are C, R, S, H.
4409 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4410 :group 'anything-config
4411 :global t
4412 (if anything-dired-mode
4413 (progn
4414 (substitute-key-definition
4415 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4416 (substitute-key-definition
4417 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4418 (substitute-key-definition
4419 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4420 (substitute-key-definition
4421 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4422 (substitute-key-definition
4423 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4424 (substitute-key-definition
4425 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4426 (substitute-key-definition
4427 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4428 (substitute-key-definition
4429 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4431 (defalias 'anything-dired-bindings 'anything-dired-mode)
4433 (defun* anything-c-read-file-name (prompt
4434 &key
4435 (name "Read File Name")
4436 (initial-input (expand-file-name default-directory))
4437 (buffer "*Anything Completions*")
4438 test
4439 (preselect nil)
4440 (history nil)
4441 (marked-candidates nil)
4442 (alistp t)
4443 (persistent-action 'anything-find-files-persistent-action)
4444 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4445 "Anything `read-file-name' emulation.
4446 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4447 (when (get-buffer anything-action-buffer)
4448 (kill-buffer anything-action-buffer))
4449 (let ((anything-mp-highlight-delay nil)
4450 ;; Be sure we don't erase the underlying minibuffer if some.
4451 (anything-ff-auto-update-initial-value
4452 (not (minibuffer-window-active-p (minibuffer-window))))
4453 anything-same-window)
4454 (flet ((action-fn (candidate)
4455 (if marked-candidates
4456 (anything-marked-candidates)
4457 (identity candidate))))
4458 (or (anything
4459 :sources
4460 `(((name . ,(format "%s History" name))
4461 (header-name . (lambda (name)
4462 (concat name anything-c-find-files-doc-header)))
4463 (disable-shortcuts)
4464 (mode-line . anything-read-file-name-mode-line-string)
4465 (candidates . (lambda ()
4466 (anything-comp-read-get-candidates history nil nil alistp)))
4467 (persistent-action . ,persistent-action)
4468 (persistent-help . ,persistent-help)
4469 (action . ,'action-fn))
4470 ((name . ,name)
4471 (header-name . (lambda (name)
4472 (concat name anything-c-find-files-doc-header)))
4473 ;; It is needed for filenames with capital letters
4474 (disable-shortcuts)
4475 (mode-line . anything-read-file-name-mode-line-string)
4476 (candidates . (lambda ()
4477 (let ((seq (anything-find-files-get-candidates)))
4478 (if test
4479 (loop
4480 for fname in seq when (funcall test fname)
4481 collect fname into ls
4482 finally return
4483 (append (list anything-pattern) ls))
4484 seq))))
4485 (filtered-candidate-transformer anything-c-find-files-transformer)
4486 (persistent-action . ,persistent-action)
4487 (candidate-number-limit . 9999)
4488 (toggle-auto-update . anything-ff-toggle-auto-update)
4489 (persistent-help . ,persistent-help)
4490 (volatile)
4491 (action . ,'action-fn)))
4492 :input initial-input
4493 :prompt prompt
4494 :keymap anything-c-read-file-map
4495 :resume 'noresume
4496 :buffer buffer
4497 :preselect preselect)
4498 (keyboard-quit)))))
4501 ;;; File Cache
4502 (defvar anything-c-file-cache-initialized-p nil)
4504 (defvar anything-c-file-cache-files nil)
4506 (defvar anything-c-source-file-cache
4507 '((name . "File Cache")
4508 (init
4509 . (lambda ()
4510 (require 'filecache nil t)
4511 (unless anything-c-file-cache-initialized-p
4512 (setq anything-c-file-cache-files
4513 (loop for item in file-cache-alist append
4514 (destructuring-bind (base &rest dirs) item
4515 (loop for dir in dirs collect
4516 (concat dir base)))))
4517 (defadvice file-cache-add-file (after file-cache-list activate)
4518 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4519 (setq anything-c-file-cache-initialized-p t))))
4520 (candidates . anything-c-file-cache-files)
4521 (match anything-c-match-on-file-name
4522 anything-c-match-on-directory-name)
4523 (type . file)))
4524 ;; (anything 'anything-c-source-file-cache)
4527 ;;; Locate
4530 ;; NOTE for WINDOZE users:
4531 ;; You have to install Everything with his command line interface here:
4532 ;; http://www.voidtools.com/download.php
4534 (defun anything-locate-1 (&optional localdb init)
4535 "Generic function to run Locate.
4536 if LOCALDB is non--nil search and use a local locate db file.
4537 INIT is a string to use as initial input in prompt.
4538 See `anything-locate-with-db' and `anything-locate'."
4539 (anything-locate-with-db
4540 (and localdb
4541 (anything-c-read-file-name
4542 "LocateDBFiles: "
4543 :marked-candidates t
4544 :preselect anything-locate-db-file-regexp
4545 :test #'(lambda (x)
4546 (if anything-locate-db-file-regexp
4547 ;; Select only locate db files and directories
4548 ;; to allow navigation.
4549 (or (string-match
4550 anything-locate-db-file-regexp x)
4551 (file-directory-p x))
4552 x))))
4553 init))
4554 ;; (anything-locate-1 t)
4556 (defun anything-locate-with-db (&optional db initial-input)
4557 "Run locate -d DB.
4558 If DB is not given or nil use locate without -d option.
4559 Argument DB can be given as a string or list of db files.
4560 Argument INITIAL-INPUT is a string to use as initial-input.
4561 See also `anything-locate'."
4562 (when (and db (stringp db)) (setq db (list db)))
4563 (let ((anything-c-locate-command
4564 (if db
4565 (replace-regexp-in-string
4566 "locate"
4567 (format "locate -d %s"
4568 (mapconcat 'identity
4569 ;; Remove eventually
4570 ;; marked directories by error.
4571 (loop for i in db
4572 unless (file-directory-p i)
4573 collect i) ":"))
4574 anything-c-locate-command)
4575 anything-c-locate-command)))
4576 (anything :sources 'anything-c-source-locate
4577 :buffer "*anything locate*"
4578 :input initial-input
4579 :keymap anything-generic-files-map)))
4580 ;; (anything-locate-with-db "~/locate.db")
4582 (defun anything-c-locate-init ()
4583 "Initialize async locate process for `anything-c-source-locate'."
4584 (setq mode-line-format
4585 '(" " mode-line-buffer-identification " "
4586 (line-number-mode "%l") " "
4587 (:eval (propertize "(Locate Process Running) "
4588 'face '((:foreground "red"))))))
4589 (prog1
4590 (start-process-shell-command "locate-process" nil
4591 (format anything-c-locate-command
4592 anything-pattern))
4593 (set-process-sentinel (get-process "locate-process")
4594 #'(lambda (process event)
4595 (when (string= event "finished\n")
4596 (with-anything-window
4597 (force-mode-line-update nil)
4598 (anything-update-move-first-line)))))))
4600 (defvar anything-c-source-locate
4601 '((name . "Locate")
4602 (candidates . anything-c-locate-init)
4603 (type . file)
4604 (properties-action . anything-ff-properties)
4605 (requires-pattern . 3)
4606 (candidate-number-limit . 9999)
4607 (mode-line . anything-generic-file-mode-line-string)
4608 (delayed))
4609 "Find files matching the current input pattern with locate.")
4610 ;; (anything 'anything-c-source-locate)
4612 (defun anything-c-locate-read-file-name (prompt &optional init)
4613 "Search a file with locate and return it's filename.
4614 Use argument PROMPT and INIT for `anything' arguments
4615 prompt and input."
4616 (anything :sources
4617 '((name . "Locate")
4618 (candidates . anything-c-locate-init)
4619 (action . identity)
4620 (properties-action . anything-ff-properties)
4621 (requires-pattern . 3)
4622 (candidate-number-limit . 9999)
4623 (mode-line . anything-generic-file-mode-line-string)
4624 (delayed))
4625 :prompt prompt
4626 :input init
4627 :buffer "*anything locate rfn*"))
4631 ;;; Anything Incremental Grep.
4634 ;; Allow to grep incrementally with anything interface.
4635 ;; It allow also to Grep files recursively without using 'find' shell command.
4636 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4637 (defvar anything-c-grep-default-command
4638 "grep -d skip %e -niH -e %p %f"
4639 "Default grep format command for `anything-do-grep-1'.
4640 Where:
4641 '%e' format spec is for --exclude or --include grep options.
4642 '%p' format spec is for pattern.
4643 '%f' format spec is for filenames.")
4645 (defvar anything-c-grep-default-recurse-command
4646 "grep -d recurse %e -niH -e %p %f"
4647 "Default recursive grep format command for `anything-do-grep-1'.
4648 See `anything-c-grep-default-command' for format specs.")
4650 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4652 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4654 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4656 (defvar anything-c-grep-debug-command-line nil
4657 "Turn on anything grep command-line debugging when non--nil.")
4659 (defvar anything-c-zgrep-recurse-flag nil)
4661 (defvar anything-c-grep-history nil)
4663 (defvar anything-c-grep-max-length-history 100
4664 "*Max number of elements to save in `anything-c-grep-history'.")
4666 (defun anything-c-grep-prepare-candidates (candidates)
4667 "Prepare filenames and directories CANDIDATES for grep command line."
4668 ;; If one or more candidate is a directory, search in all files
4669 ;; of this candidate (e.g /home/user/directory/*).
4670 ;; If r option is enabled search also in subdidrectories.
4671 ;; We need here to expand wildcards to support crap windows filenames
4672 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4673 (if anything-c-zgrep-recurse-flag
4674 (mapconcat 'shell-quote-argument candidates " ")
4675 (loop for i in candidates append
4676 (cond ( ;; Candidate is a directory and we use recursion.
4677 (and (file-directory-p i)
4678 (anything-c-grep-recurse-p))
4679 (list (expand-file-name i)))
4680 ;; Candidate is a directory, search in all files.
4681 ((file-directory-p i)
4682 (file-expand-wildcards
4683 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4684 ;; Candidate is a file or wildcard and we use recursion, use the
4685 ;; current directory instead of candidate.
4686 ((and (or (file-exists-p i) (string-match "\*" i))
4687 (anything-c-grep-recurse-p))
4688 (list (expand-file-name
4689 (directory-file-name ; Needed for windoze.
4690 (file-name-directory (directory-file-name i))))))
4691 ;; Candidate use wildcard.
4692 ((string-match "^\*" (anything-c-basename i))
4693 (file-expand-wildcards i t))
4694 ;; Else should be one or more file.
4695 (t (list i))) into all-files
4696 finally return
4697 (mapconcat 'shell-quote-argument all-files " "))))
4699 (defun anything-c-grep-recurse-p ()
4700 "Check if `anything-do-grep-1' have switched to recursive."
4701 (let ((args (replace-regexp-in-string
4702 "grep" "" anything-c-grep-default-command)))
4703 (string-match-p "r\\|recurse" args)))
4705 (defun anything-c-grep-init (only-files &optional include zgrep)
4706 "Start an asynchronous grep process in ONLY-FILES list."
4707 (let* ((fnargs (anything-c-grep-prepare-candidates
4708 (if (file-remote-p anything-ff-default-directory)
4709 (mapcar #'(lambda (x)
4710 (file-remote-p x 'localname))
4711 only-files)
4712 only-files)))
4713 (ignored-files (mapconcat
4714 #'(lambda (x)
4715 (concat "--exclude=" (shell-quote-argument x)))
4716 grep-find-ignored-files " "))
4717 (ignored-dirs (mapconcat
4718 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4719 #'(lambda (x)
4720 (concat "--exclude-dir=" (shell-quote-argument x)))
4721 grep-find-ignored-directories " "))
4722 (exclude (if (anything-c-grep-recurse-p)
4723 (concat (or include ignored-files) " " ignored-dirs)
4724 ignored-files))
4725 (cmd-line (format-spec
4726 anything-c-grep-default-command
4727 (delq nil
4728 (list (unless zgrep (cons ?e exclude))
4729 (cons ?p (shell-quote-argument anything-pattern))
4730 (cons ?f fnargs))))))
4731 (when anything-c-grep-debug-command-line
4732 (with-current-buffer (get-buffer-create "*any grep debug*")
4733 (goto-char (point-max))
4734 (insert (concat ">>> " cmd-line "\n\n"))))
4735 (setq mode-line-format
4736 '(" " mode-line-buffer-identification " "
4737 (line-number-mode "%l") " "
4738 (:eval (when (get-process "grep-process")
4739 (propertize "[Grep Process Running] "
4740 'face 'anything-grep-running)))))
4741 (force-mode-line-update nil)
4742 (prog1
4743 (let ((default-directory anything-ff-default-directory))
4744 (start-file-process-shell-command "grep-process" nil cmd-line))
4745 (message nil)
4746 (set-process-sentinel
4747 (get-process "grep-process")
4748 #'(lambda (process event)
4749 (when (string= event "finished\n")
4750 (with-anything-window
4751 (anything-update-move-first-line)
4752 (setq mode-line-format
4753 '(" " mode-line-buffer-identification " "
4754 (line-number-mode "%l") " "
4755 (:eval (propertize
4756 (format "[Grep Process Finished - (%s results)] "
4757 (let ((nlines (1- (count-lines
4758 (point-min)
4759 (point-max)))))
4760 (if (> nlines 0) nlines 0)))
4761 'face 'anything-grep-finish))))
4762 (force-mode-line-update nil))))))))
4764 (defun anything-c-grep-action (candidate &optional where mark)
4765 "Define a default action for `anything-do-grep' on CANDIDATE.
4766 WHERE can be one of other-window, elscreen, other-frame."
4767 (let* ((split (anything-c-grep-split-line candidate))
4768 (lineno (string-to-number (nth 1 split)))
4769 (loc-fname (car split))
4770 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4771 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4772 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4773 (fname (if tramp-host
4774 (concat tramp-prefix loc-fname) loc-fname)))
4775 (case where
4776 (other-window (find-file-other-window fname))
4777 (elscreen (anything-elscreen-find-file fname))
4778 (other-frame (find-file-other-frame fname))
4779 (t (find-file fname)))
4780 (anything-goto-line lineno)
4781 (when mark
4782 (set-marker (mark-marker) (point))
4783 (push-mark (point) 'nomsg))
4784 ;; Save history
4785 (unless (or anything-in-persistent-action
4786 (string= anything-pattern ""))
4787 (setq anything-c-grep-history
4788 (cons anything-pattern
4789 (delete anything-pattern anything-c-grep-history)))
4790 (when (> (length anything-c-grep-history)
4791 anything-c-grep-max-length-history)
4792 (setq anything-c-grep-history
4793 (delete (car (last anything-c-grep-history))
4794 anything-c-grep-history))))))
4796 (defun anything-c-grep-other-window (candidate)
4797 "Jump to result in other window from anything grep."
4798 (anything-c-grep-action candidate 'other-window))
4800 (defun anything-c-grep-other-frame (candidate)
4801 "Jump to result in other frame from anything grep."
4802 (anything-c-grep-action candidate 'other-frame))
4804 (defun anything-c-grep-jump-elscreen (candidate)
4805 "Jump to result in elscreen from anything grep."
4806 (anything-c-grep-action candidate 'elscreen))
4808 (defun anything-c-grep-save-results (candidate)
4809 "Save anything grep result in a `grep-mode' buffer."
4810 (let ((buf "*grep*")
4811 new-buf)
4812 (when (get-buffer buf)
4813 (setq new-buf (read-string "GrepBufferName: " buf))
4814 (loop for b in (anything-c-buffer-list)
4815 when (and (string= new-buf b)
4816 (not (y-or-n-p
4817 (format "Buffer `%s' already exists overwrite? "
4818 new-buf))))
4819 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4820 (setq buf new-buf))
4821 (with-current-buffer (get-buffer-create buf)
4822 (let ((inhibit-read-only t))
4823 (erase-buffer)
4824 (insert "-*- mode: grep -*-\n\n"
4825 (format "Grep Results for `%s':\n\n" anything-pattern))
4826 (save-excursion
4827 (insert (with-current-buffer anything-buffer
4828 (forward-line 1)
4829 (buffer-substring (point) (point-max))))
4830 (grep-mode))))
4831 (message "Anything Grep Results saved in `%s' buffer" buf)))
4833 (defun anything-c-grep-persistent-action (candidate)
4834 "Persistent action for `anything-do-grep'.
4835 With a prefix arg record CANDIDATE in `mark-ring'."
4836 (if current-prefix-arg
4837 (anything-c-grep-action candidate nil 'mark)
4838 (anything-c-grep-action candidate))
4839 (anything-match-line-color-current-line))
4841 (defun anything-c-grep-guess-extensions (files)
4842 "Try to guess file extensions in FILES list when using grep recurse.
4843 These extensions will be added to command line with --include arg of grep."
4844 (loop
4845 with glob-list = nil
4846 with lst = (if (file-directory-p (car files))
4847 (directory-files
4848 (car files) nil
4849 directory-files-no-dot-files-regexp)
4850 files)
4851 for i in lst
4852 for ext = (file-name-extension i t)
4853 for glob = (and ext (not (string= ext ""))
4854 (concat "*" ext))
4855 unless (or (not glob)
4856 (member glob glob-list)
4857 (member glob grep-find-ignored-files))
4858 collect glob into glob-list
4859 finally return glob-list))
4861 (defun anything-do-grep-1 (only &optional recurse zgrep)
4862 "Launch grep with a list of ONLY files.
4863 When RECURSE is given use -r option of grep and prompt user
4864 to set the --include args of grep.
4865 You can give more than one arg separated by space.
4866 e.g *.el *.py *.tex.
4867 If it's empty --exclude `grep-find-ignored-files' is used instead."
4868 (let* ((anything-compile-source-functions
4869 ;; rule out anything-match-plugin because the input is one regexp.
4870 (delq 'anything-compile-source--match-plugin
4871 (copy-sequence anything-compile-source-functions)))
4872 (exts (anything-c-grep-guess-extensions only))
4873 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4874 (include-files (and recurse (not zgrep)
4875 (read-string "OnlyExt(*.[ext]): "
4876 globs)))
4877 ;; Set `minibuffer-history' AFTER includes-files
4878 ;; to avoid storing wild-cards here.
4879 (minibuffer-history anything-c-grep-history)
4880 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4881 (recurse anything-c-grep-default-recurse-command)
4882 (zgrep anything-c-default-zgrep-command)
4883 (t anything-c-grep-default-command)))
4884 ;; Disable match-plugin and use here own highlighting.
4885 (anything-mp-highlight-delay nil))
4886 (when include-files
4887 (setq include-files
4888 (and (not (string= include-files ""))
4889 (mapconcat #'(lambda (x)
4890 (concat "--include=" (shell-quote-argument x)))
4891 (split-string include-files) " "))))
4892 ;; When called as action from an other source e.g *-find-files
4893 ;; we have to kill action buffer.
4894 (when (get-buffer anything-action-buffer)
4895 (kill-buffer anything-action-buffer))
4896 ;; `anything-find-files' haven't already started,
4897 ;; give a default value to `anything-ff-default-directory'.
4898 (setq anything-ff-default-directory (or anything-ff-default-directory
4899 default-directory))
4900 (anything
4901 :sources
4902 `(((name . "Grep (C-c ? Help)")
4903 (candidates
4904 . (lambda ()
4905 (funcall anything-c-grep-default-function only include-files zgrep)))
4906 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4907 (candidate-number-limit . 9999)
4908 (mode-line . anything-grep-mode-line-string)
4909 (jump-persistent . anything-c-grep-persistent-action)
4910 (action . ,(delq
4912 `(("Find File" . anything-c-grep-action)
4913 ("Find file other frame" . anything-c-grep-other-frame)
4914 ,(and (locate-library "elscreen")
4915 '("Find file in Elscreen"
4916 . anything-c-grep-jump-elscreen))
4917 ("Save results in grep buffer" . anything-c-grep-save-results)
4918 ("Find file other window" . anything-c-grep-other-window))))
4919 (persistent-action . anything-c-grep-persistent-action)
4920 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4921 (requires-pattern . 3)
4922 (delayed)))
4923 :keymap anything-c-grep-map
4924 :buffer "*anything grep*")))
4926 (defun anything-ff-zgrep-1 (flist recursive)
4927 (unwind-protect
4928 (let* ((def-dir (or anything-ff-default-directory
4929 default-directory))
4930 (only (if recursive
4931 (or (gethash def-dir anything-c-rzgrep-cache)
4932 (puthash
4933 def-dir
4934 (anything-c-walk-directory
4935 def-dir
4936 :directories nil
4937 :path 'full
4938 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
4939 anything-c-rzgrep-cache))
4940 flist)))
4941 (when recursive (setq anything-c-zgrep-recurse-flag t))
4942 (anything-do-grep-1 only recursive 'zgrep))
4943 (setq anything-c-zgrep-recurse-flag nil)))
4945 (defun anything-c-grep-split-line (line)
4946 "Split a grep output line."
4947 (let (beg fname lineno str)
4948 ;; Don't print until grep line is valid.
4949 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
4950 (with-temp-buffer
4951 (insert line)
4952 (goto-char (point-min))
4953 (setq beg (point))
4954 (forward-char 2)
4955 (re-search-forward ":" nil t)
4956 (setq fname (buffer-substring-no-properties beg (1- (point))))
4957 (setq beg (point))
4958 (re-search-forward ":" nil t)
4959 (setq lineno (buffer-substring-no-properties beg (1- (point))))
4960 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
4961 (list fname lineno str))))
4963 (defun anything-c-grep-cand-transformer (candidates sources)
4964 "Filtered candidate transformer function for `anything-do-grep'."
4965 (loop for i in candidates
4966 for split = (and i (anything-c-grep-split-line i))
4967 for fname = (car split)
4968 for lineno = (nth 1 split)
4969 for str = (nth 2 split)
4970 when (and fname lineno str)
4971 collect
4972 (cons (concat (propertize (file-name-nondirectory fname)
4973 'face 'anything-grep-file
4974 'help-echo fname) ":"
4975 (propertize lineno 'face 'anything-grep-lineno) ":"
4976 (anything-c-grep-highlight-match str))
4977 i)))
4979 (defun anything-c-grep-highlight-match (str)
4980 "Highlight in string STR all occurences matching `anything-pattern'."
4981 (condition-case nil
4982 (with-temp-buffer
4983 (insert str)
4984 (goto-char (point-min))
4985 (while (and (re-search-forward anything-pattern nil t)
4986 (> (- (match-end 0) (match-beginning 0)) 0))
4987 (add-text-properties
4988 (match-beginning 0) (match-end 0)
4989 '(face anything-grep-match)))
4990 (buffer-string))
4991 (error nil)))
4993 ;; Go to next or precedent file (common to etags and grep).
4994 (defun anything-c-goto-next-or-prec-file (n)
4995 "Go to next or precedent candidate file in anything grep/etags buffers.
4996 If N is positive go forward otherwise go backward."
4997 (with-anything-window
4998 (let* ((current-line-list (split-string
4999 (buffer-substring
5000 (point-at-bol)
5001 (point-at-eol)) ":"))
5002 (current-fname (nth 0 current-line-list))
5003 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5004 (catch 'break
5005 (while (not (funcall fn-b-o-f))
5006 (forward-line n) ; Go forward or backward depending of n value.
5007 (unless (search-forward current-fname (point-at-eol) t)
5008 (anything-mark-current-line)
5009 (throw 'break nil))))
5010 (cond ((and (eq n 1) (eobp))
5011 (re-search-backward ".")
5012 (forward-line 0)
5013 (anything-mark-current-line))
5014 ((and (< n 1) (bobp))
5015 (forward-line 1)
5016 (anything-mark-current-line))))))
5018 ;;;###autoload
5019 (defun anything-c-goto-precedent-file ()
5020 "Go to precedent file in anything grep/etags buffers."
5021 (interactive)
5022 (anything-c-goto-next-or-prec-file -1))
5024 ;;;###autoload
5025 (defun anything-c-goto-next-file ()
5026 "Go to precedent file in anything grep/etags buffers."
5027 (interactive)
5028 (anything-c-goto-next-or-prec-file 1))
5030 ;;;###autoload
5031 (defun anything-c-grep-run-persistent-action ()
5032 "Run grep persistent action from `anything-do-grep-1'."
5033 (interactive)
5034 (anything-execute-persistent-action 'jump-persistent))
5036 ;;;###autoload
5037 (defun anything-c-grep-run-default-action ()
5038 "Run grep default action from `anything-do-grep-1'."
5039 (interactive)
5040 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5042 ;;;###autoload
5043 (defun anything-c-grep-run-other-window-action ()
5044 "Run grep goto other window action from `anything-do-grep-1'."
5045 (interactive)
5046 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5048 ;;;###autoload
5049 (defun anything-c-grep-run-save-buffer ()
5050 "Run grep save results action from `anything-do-grep-1'."
5051 (interactive)
5052 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5054 ;; Grep buffers
5055 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5056 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5057 If one of selected buffers is not a file--buffer,
5058 it is ignored and grep will run on all others file--buffers.
5059 If only one candidate is selected and it is not a file--buffer,
5060 switch to this buffer and run `anything-occur'.
5061 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5062 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5063 (cands (if prefarg
5064 (buffer-list)
5065 (anything-marked-candidates)))
5066 (win-conf (current-window-configuration))
5067 ;; Non--fname buffers are ignored.
5068 (bufs (loop for buf in cands
5069 for fname = (buffer-file-name (get-buffer buf))
5070 when fname
5071 collect (expand-file-name fname))))
5072 (if bufs
5073 (if zgrep
5074 (anything-do-grep-1 bufs nil 'zgrep)
5075 (anything-do-grep-1 bufs))
5076 ;; bufs is empty, thats mean we have only CANDIDATE
5077 ;; and it is not a buffer-filename, fallback to occur.
5078 (anything-c-switch-to-buffer candidate)
5079 (when (get-buffer anything-action-buffer)
5080 (kill-buffer anything-action-buffer))
5081 (anything-occur)
5082 (when (eq anything-exit-status 1)
5083 (set-window-configuration win-conf)))))
5085 (defun anything-c-grep-buffers (candidate)
5086 "Action to grep buffers."
5087 (anything-c-grep-buffers-1 candidate))
5089 (defun anything-c-zgrep-buffers (candidate)
5090 "Action to zgrep buffers."
5091 (anything-c-grep-buffers-1 candidate 'zgrep))
5094 ;;; Anything interface for pdfgrep
5095 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5096 ;; and a pdf-reader (e.g xpdf) are needed.
5098 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5099 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5100 (defvar anything-c-pdfgrep-debug-command-line nil)
5102 (defun anything-c-pdfgrep-init (only-files)
5103 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5104 (let* ((fnargs (anything-c-grep-prepare-candidates
5105 (if (file-remote-p anything-ff-default-directory)
5106 (mapcar #'(lambda (x)
5107 (file-remote-p x 'localname))
5108 only-files)
5109 only-files)))
5110 (cmd-line (format anything-c-pdfgrep-default-command
5111 anything-pattern
5112 fnargs)))
5113 (when anything-c-pdfgrep-debug-command-line
5114 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5115 (goto-char (point-max))
5116 (insert (concat ">>> " cmd-line "\n\n"))))
5117 (setq mode-line-format
5118 '(" " mode-line-buffer-identification " "
5119 (line-number-mode "%l") " "
5120 (:eval (propertize "(Pdfgrep Process Running) "
5121 'face '((:foreground "red"))))))
5122 (prog1
5123 (let ((default-directory anything-ff-default-directory))
5124 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5125 (message nil)
5126 (set-process-sentinel
5127 (get-process "pdfgrep-process")
5128 #'(lambda (process event)
5129 (when (string= event "finished\n")
5130 (with-anything-window
5131 (anything-update-move-first-line))
5132 (force-mode-line-update nil)))))))
5135 (defun anything-do-pdfgrep-1 (only)
5136 "Launch pdfgrep with a list of ONLY files."
5137 (unless (executable-find "pdfgrep")
5138 (error "Error: No such program `pdfgrep'."))
5139 (let* ((anything-compile-source-functions
5140 ;; rule out anything-match-plugin because the input is one regexp.
5141 (delq 'anything-compile-source--match-plugin
5142 (copy-sequence anything-compile-source-functions)))
5143 ;; Disable match-plugin and use here own highlighting.
5144 (anything-mp-highlight-delay nil))
5145 ;; When called as action from an other source e.g *-find-files
5146 ;; we have to kill action buffer.
5147 (when (get-buffer anything-action-buffer)
5148 (kill-buffer anything-action-buffer))
5149 ;; If `anything-find-files' haven't already started,
5150 ;; give a default value to `anything-ff-default-directory'.
5151 (setq anything-ff-default-directory (or anything-ff-default-directory
5152 default-directory))
5153 (anything
5154 :sources
5155 `(((name . "PdfGrep")
5156 (candidates
5157 . (lambda ()
5158 (funcall anything-c-pdfgrep-default-function only)))
5159 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5160 (candidate-number-limit . 9999)
5161 (mode-line . anything-pdfgrep-mode-line-string)
5162 (action . anything-c-pdfgrep-action)
5163 (persistent-help . "Jump to PDF Page")
5164 (requires-pattern . 3)
5165 (delayed)))
5166 :keymap anything-c-pdfgrep-map
5167 :buffer "*anything grep*")))
5170 (defun anything-c-pdfgrep-action (candidate)
5171 (let* ((split (anything-c-grep-split-line candidate))
5172 (pageno (nth 1 split))
5173 (fname (car split)))
5174 (start-file-process-shell-command
5175 "pdf-reader" nil
5176 (format-spec anything-c-pdfgrep-default-read-command
5177 (list (cons ?f fname) (cons ?p pageno))))))
5179 (defun anything-do-pdfgrep ()
5180 (interactive)
5181 (let ((only (anything-c-read-file-name
5182 "Search in file(s): "
5183 :marked-candidates t
5184 :test #'(lambda (file)
5185 (or (string= (file-name-extension file) "pdf")
5186 (string= (file-name-extension file) "PDF")
5187 (file-directory-p file)))
5188 :preselect (or (dired-get-filename nil t)
5189 (buffer-file-name (current-buffer)))))
5190 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5191 (anything-do-pdfgrep-1 only)))
5194 ;; Yank text at point.
5197 ;; Internal
5198 (defvar anything-yank-point nil)
5200 ;;;###autoload
5201 (defun anything-yank-text-at-point ()
5202 "Yank text at point in minibuffer."
5203 (interactive)
5204 (let (input)
5205 (flet ((insert-in-minibuffer (word)
5206 (with-selected-window (minibuffer-window)
5207 (let ((str anything-pattern))
5208 (delete-minibuffer-contents)
5209 (set-text-properties 0 (length word) nil word)
5210 (insert (concat str word))))))
5211 (with-anything-current-buffer
5212 ;; Start to initial point if C-w have never been hit.
5213 (unless anything-yank-point (setq anything-yank-point (point)))
5214 (and anything-yank-point (goto-char anything-yank-point))
5215 (forward-word 1)
5216 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5217 (setq anything-yank-point (point))) ; End of last forward-word
5218 (insert-in-minibuffer input))))
5220 (defun anything-reset-yank-point ()
5221 (setq anything-yank-point nil))
5223 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5224 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5225 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
5228 ;;; Recentf files
5231 (defvar anything-c-source-recentf
5232 '((name . "Recentf")
5233 (init . (lambda ()
5234 (require 'recentf)
5235 (or recentf-mode (recentf-mode 1))
5236 ;; Big value empowers anything/recentf
5237 (when (and (numberp recentf-max-saved-items)
5238 (<= recentf-max-saved-items 20))
5239 (setq recentf-max-saved-items 500))))
5240 (candidates . recentf-list)
5241 (match anything-c-match-on-file-name
5242 anything-c-match-on-directory-name)
5243 (type . file))
5244 "See (info \"(emacs)File Conveniences\").
5245 if `recentf-max-saved-items' is too small, set it to 500.")
5246 ;; (anything 'anything-c-source-recentf)
5248 ;;; ffap
5249 (eval-when-compile (require 'ffap))
5250 (defvar anything-c-source-ffap-guesser
5251 '((name . "File at point")
5252 (init . (lambda () (require 'ffap)))
5253 (candidates . (lambda ()
5254 (anything-aif
5255 (with-anything-current-buffer
5256 (ffap-guesser))
5257 (list it))))
5258 (type . file)))
5259 ;; (anything 'anything-c-source-ffap-guesser)
5261 ;;; ffap with line number
5262 (defun anything-c-ffap-file-line-at-point ()
5263 "Get (FILENAME . LINENO) at point."
5264 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5265 (save-excursion
5266 (beginning-of-line)
5267 (when (and (search-forward it nil t)
5268 (looking-at ":\\([0-9]+\\)"))
5269 (cons it (string-to-number (match-string 1)))))))
5271 (defvar anything-c-ffap-line-location nil
5272 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5273 It is cleared after jumping line.")
5275 (defun anything-c-ffap-line-candidates ()
5276 (with-anything-current-buffer
5277 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5278 (when anything-c-ffap-line-location
5279 (destructuring-bind (file . line) anything-c-ffap-line-location
5280 (list (cons (format "%s (line %d)" file line) file)))))
5282 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5283 (defun anything-c-ffap-line-goto-line ()
5284 (when (car anything-c-ffap-line-location)
5285 (unwind-protect
5286 (ignore-errors
5287 (with-selected-window
5288 (get-buffer-window
5289 (get-file-buffer (car anything-c-ffap-line-location)))
5290 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5291 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5292 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5294 (defvar anything-c-source-ffap-line
5295 '((name . "File/Lineno at point")
5296 (init . (lambda () (require 'ffap)))
5297 (candidates . anything-c-ffap-line-candidates)
5298 (type . file)))
5299 ;; (anything 'anything-c-source-ffap-line)
5301 ;;; list of files gleaned from every dired buffer
5302 (defun anything-c-files-in-all-dired-candidates ()
5303 (save-excursion
5304 (mapcan
5305 (lambda (dir)
5306 (cond ((listp dir) ;filelist
5307 dir)
5308 ((equal "" (file-name-nondirectory dir)) ;dir
5309 (directory-files dir t))
5310 (t ;wildcard
5311 (file-expand-wildcards dir t))))
5312 (delq nil
5313 (mapcar (lambda (buf)
5314 (set-buffer buf)
5315 (when (eq major-mode 'dired-mode)
5316 (if (consp dired-directory)
5317 (cdr dired-directory) ;filelist
5318 dired-directory))) ;dir or wildcard
5319 (buffer-list))))))
5320 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5322 (defvar anything-c-source-files-in-all-dired
5323 '((name . "Files in all dired buffer.")
5324 (candidates . anything-c-files-in-all-dired-candidates)
5325 (type . file)))
5326 ;; (anything 'anything-c-source-files-in-all-dired)
5328 (defvar anything-c-source-filelist
5329 '((name . "FileList")
5330 (grep-candidates . anything-c-filelist-file-name)
5331 (candidate-number-limit . 200)
5332 (requires-pattern . 4)
5333 (type . file))
5334 "Source to find files instantly.
5335 See `anything-c-filelist-file-name' docstring for usage.")
5338 ;;;; <info>
5339 ;;; Info pages
5340 (defvar anything-c-info-pages nil
5341 "All info pages on system.
5342 Will be calculated the first time you invoke anything with this
5343 source.")
5345 (defun anything-c-info-pages-init ()
5346 "Collect candidates for initial Info node Top."
5347 (if anything-c-info-pages
5348 anything-c-info-pages
5349 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5350 topics)
5351 (require 'info)
5352 (with-temp-buffer
5353 (Info-find-node "dir" "top")
5354 (goto-char (point-min))
5355 (while (re-search-forward info-topic-regexp nil t)
5356 (push (match-string-no-properties 1) topics))
5357 (kill-buffer))
5358 (setq anything-c-info-pages topics))))
5360 (defvar anything-c-source-info-pages
5361 `((name . "Info Pages")
5362 (init . anything-c-info-pages-init)
5363 (candidates . anything-c-info-pages)
5364 (action . (("Show with Info" .(lambda (node-str)
5365 (info (replace-regexp-in-string
5366 "^[^:]+: " "" node-str))))))
5367 (requires-pattern . 2)))
5368 ;; (anything 'anything-c-source-info-pages)
5371 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5372 (defun anything-c-describe-attributes (anything-attribute)
5373 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5374 Same as `anything-describe-anything-attribute' but with anything completion."
5375 (interactive (list (intern
5376 (anything-comp-read
5377 "Describe anything attribute: "
5378 (mapcar 'symbol-name anything-additional-attributes)
5379 :must-match t
5380 :persistent-action
5381 #'(lambda (candidate)
5382 (with-output-to-temp-buffer "*Help*"
5383 (princ (get (intern candidate) 'anything-attrdoc))))))))
5384 (with-output-to-temp-buffer "*Help*"
5385 (princ (get anything-attribute 'anything-attrdoc))))
5388 ;;; Use info-index plug-in.
5391 ;; Note that `name' attribute is not needed since
5392 ;; `anything-c-insert-summary' have been removed.
5393 ;; Info Elisp
5394 (defvar anything-c-source-info-elisp
5395 '((name . "Info index: elisp")
5396 (info-index . "elisp")))
5397 ;; (anything 'anything-c-source-info-elisp)
5399 ;; Info-Common-Lisp
5400 (defvar anything-c-source-info-cl
5401 '((name . "Info index: cl")
5402 (info-index . "cl")))
5403 ;; (anything 'anything-c-source-info-cl)
5405 ;; Info Index org
5406 (defvar anything-c-source-info-org
5407 '((name . "Info index: org")
5408 (info-index . "org")))
5409 ;; (anything 'anything-c-source-info-org)
5411 ;; Info Index gnus
5412 (defvar anything-c-source-info-gnus
5413 '((name . "Info index: Gnus")
5414 (info-index . "gnus")))
5416 ;; Info Index ratpoison
5417 (defvar anything-c-source-info-ratpoison
5418 '((name . "Info index: ratpoison")
5419 (info-index . "ratpoison")))
5420 ;; (anything 'anything-c-source-info-ratpoison)
5422 ;; Info Index zsh
5423 (defvar anything-c-source-info-zsh
5424 '((name . "Info index: zsh")
5425 (info-index . "zsh")))
5426 ;; (anything 'anything-c-source-info-zsh)
5428 ;; Info Index bash
5429 (defvar anything-c-source-info-bash
5430 '((name . "Info index: bash")
5431 (info-index . "bash")))
5432 ;; (anything 'anything-c-source-info-bash)
5434 ;; Info Index coreutils
5435 (defvar anything-c-source-info-coreutils
5436 '((name . "Info index: coreutils")
5437 (info-index . "coreutils")))
5438 ;; (anything 'anything-c-source-info-coreutils)
5440 ;; Info Index fileutils
5441 (defvar anything-c-source-info-fileutils
5442 '((name . "Info index: fileutils")
5443 (info-index . "fileutils")))
5444 ;; (anything 'anything-c-source-info-fileutils)
5446 ;; Info Index find
5447 (defvar anything-c-source-info-find
5448 '((name . "Info index: find")
5449 (info-index . "find")))
5450 ;; (anything 'anything-c-source-info-find)
5452 ;; Info Index sh-utils
5453 (defvar anything-c-source-info-sh-utils
5454 '((name . "Info index: sh-utils")
5455 (info-index . "sh-utils")))
5456 ;; (anything 'anything-c-source-info-sh-utils)
5458 ;; Info Index textutils
5459 (defvar anything-c-source-info-textutils
5460 '((name . "Info index: textutils")
5461 (info-index . "textutils")))
5462 ;; (anything 'anything-c-source-info-textutils)
5464 ;; Info Index libc
5465 (defvar anything-c-source-info-libc
5466 '((name . "Info index: libc")
5467 (info-index . "libc")))
5468 ;; (anything 'anything-c-source-info-libc)
5470 ;; Info Index make
5471 (defvar anything-c-source-info-make
5472 '((name . "Info index: make")
5473 (info-index . "make")))
5474 ;; (anything 'anything-c-source-info-make)
5476 ;; Info Index automake
5477 (defvar anything-c-source-info-automake
5478 '((name . "Info index: automake")
5479 (info-index . "automake")))
5480 ;; (anything 'anything-c-source-info-automake)
5482 ;; Info Index autoconf
5483 (defvar anything-c-source-info-autoconf
5484 '((name . "Info index: autoconf")
5485 (info-index . "autoconf")))
5486 ;; (anything 'anything-c-source-info-autoconf)
5488 ;; Info Index emacs-lisp-intro
5489 (defvar anything-c-source-info-emacs-lisp-intro
5490 '((name . "Info index: emacs-lisp-intro")
5491 (info-index . "emacs-lisp-intro")))
5492 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5494 ;; Info Index emacs
5495 (defvar anything-c-source-info-emacs
5496 '((name . "Info index: emacs")
5497 (info-index . "emacs")))
5498 ;; (anything 'anything-c-source-info-emacs)
5500 ;; Info Index elib
5501 (defvar anything-c-source-info-elib
5502 '((name . "Info index: elib")
5503 (info-index . "elib")))
5504 ;; (anything 'anything-c-source-info-elib)
5506 ;; Info Index eieio
5507 (defvar anything-c-source-info-eieio
5508 '((name . "Info index: eieio")
5509 (info-index . "eieio")))
5510 ;; (anything 'anything-c-source-info-eieio)
5512 ;; Info Index gauche-refe
5513 (defvar anything-c-source-info-gauche-refe
5514 '((name . "Info index: gauche")
5515 (info-index . "gauche-refe")))
5516 ;; (anything 'anything-c-source-info-gauche-refe)
5518 ;; Info Index guile
5519 (defvar anything-c-source-info-guile
5520 '((name . "Info index: guile")
5521 (info-index . "guile")))
5522 ;; (anything 'anything-c-source-info-guile)
5524 ;; Info Index guile-tut
5525 (defvar anything-c-source-info-guile-tut
5526 '((name . "Info index: guile-tut")
5527 (info-index . "guile-tut")))
5528 ;; (anything 'anything-c-source-info-guile-tut)
5530 ;; Info Index goops
5531 (defvar anything-c-source-info-goops
5532 '((name . "Info index: goops")
5533 (info-index . "goops")))
5534 ;; (anything 'anything-c-source-info-goops)
5536 ;; Info Index screen
5537 (defvar anything-c-source-info-screen
5538 '((name . "Info index: screen")
5539 (info-index . "screen")
5540 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5541 ;; (anything 'anything-c-source-info-screen)
5543 ;; Info Index latex
5544 (defvar anything-c-source-info-latex
5545 '((name . "Info index: latex")
5546 (info-index . "latex")))
5547 ;; (anything 'anything-c-source-info-latex)
5549 ;; Info Index gawk
5550 (defvar anything-c-source-info-gawk
5551 '((name . "Info index: gawk")
5552 (info-index . "gawk")))
5553 ;; (anything 'anything-c-source-info-gawk)
5555 ;; Info Index sed
5556 (defvar anything-c-source-info-sed
5557 '((name . "Info index: sed")
5558 (info-index . "sed")))
5559 ;; (anything 'anything-c-source-info-sed)
5561 ;; Info Index m4
5562 (defvar anything-c-source-info-m4
5563 '((name . "Info index: m4")
5564 (info-index . "m4")))
5565 ;; (anything 'anything-c-source-info-m4)
5567 ;; Info Index wget
5568 (defvar anything-c-source-info-wget
5569 '((name . "Info index: wget")
5570 (info-index . "wget")))
5571 ;; (anything 'anything-c-source-info-wget)
5573 ;; Info Index binutils
5574 (defvar anything-c-source-info-binutils
5575 '((name . "Info index: binutils")
5576 (info-index . "binutils")))
5577 ;; (anything 'anything-c-source-info-binutils)
5579 ;; Info Index as
5580 (defvar anything-c-source-info-as
5581 '((name . "Info index: as")
5582 (info-index . "as")))
5583 ;; (anything 'anything-c-source-info-as)
5585 ;; Info Index bfd
5586 (defvar anything-c-source-info-bfd
5587 '((name . "Info index: bfd")
5588 (info-index . "bfd")))
5589 ;; (anything 'anything-c-source-info-bfd)
5591 ;; Info Index gprof
5592 (defvar anything-c-source-info-gprof
5593 '((name . "Info index: gprof")
5594 (info-index . "gprof")))
5595 ;; (anything 'anything-c-source-info-gprof)
5597 ;; Info Index ld
5598 (defvar anything-c-source-info-ld
5599 '((name . "Info index: ld")
5600 (info-index . "ld")))
5601 ;; (anything 'anything-c-source-info-ld)
5603 ;; Info Index diff
5604 (defvar anything-c-source-info-diff
5605 '((name . "Info index: diff")
5606 (info-index . "diff")))
5607 ;; (anything 'anything-c-source-info-diff)
5609 ;; Info Index flex
5610 (defvar anything-c-source-info-flex
5611 '((name . "Info index: flex")
5612 (info-index . "flex")))
5613 ;; (anything 'anything-c-source-info-flex)
5615 ;; Info Index grep
5616 (defvar anything-c-source-info-grep
5617 '((name . "Info index: grep")
5618 (info-index . "grep")))
5619 ;; (anything 'anything-c-source-info-grep)
5621 ;; Info Index gzip
5622 (defvar anything-c-source-info-gzip
5623 '((name . "Info index: gzip")
5624 (info-index . "gzip")))
5625 ;; (anything 'anything-c-source-info-gzip)
5627 ;; Info Index libtool
5628 (defvar anything-c-source-info-libtool
5629 '((name . "Info index: libtool")
5630 (info-index . "libtool")))
5631 ;; (anything 'anything-c-source-info-libtool)
5633 ;; Info Index texinfo
5634 (defvar anything-c-source-info-texinfo
5635 '((name . "Info index: texinfo")
5636 (info-index . "texinfo")))
5637 ;; (anything 'anything-c-source-info-texinfo)
5639 ;; Info Index info
5640 (defvar anything-c-source-info-info
5641 '((name . "Info index: info")
5642 (info-index . "info")))
5643 ;; (anything 'anything-c-source-info-info)
5645 ;; Info Index gdb
5646 (defvar anything-c-source-info-gdb
5647 '((name . "Info index: gdb")
5648 (info-index . "gdb")))
5649 ;; (anything 'anything-c-source-info-gdb)
5651 ;; Info Index stabs
5652 (defvar anything-c-source-info-stabs
5653 '((name . "Info index: stabs")
5654 (info-index . "stabs")))
5655 ;; (anything 'anything-c-source-info-stabs)
5657 ;; Info Index cvsbook
5658 (defvar anything-c-source-info-cvsbook
5659 '((name . "Info index: cvsbook")
5660 (info-index . "cvsbook")))
5661 ;; (anything 'anything-c-source-info-cvsbook)
5663 ;; Info Index cvs
5664 (defvar anything-c-source-info-cvs
5665 '((name . "Info index: cvs")
5666 (info-index . "cvs")))
5667 ;; (anything 'anything-c-source-info-cvs)
5669 ;; Info Index bison
5670 (defvar anything-c-source-info-bison
5671 '((name . "Info index: bison")
5672 (info-index . "bison")))
5673 ;; (anything 'anything-c-source-info-bison)
5675 ;; Info Index id-utils
5676 (defvar anything-c-source-info-id-utils
5677 '((name . "Info index: id-utils")
5678 (info-index . "id-utils")))
5679 ;; (anything 'anything-c-source-info-id-utils)
5681 ;; Info Index global
5682 (defvar anything-c-source-info-global
5683 '((name . "Info index: global")
5684 (info-index . "global")))
5685 ;; (anything 'anything-c-source-info-global)
5688 ;;;; <Help>
5689 ;;; Man and woman UI
5692 (defvar anything-c-man-pages nil
5693 "All man pages on system.
5694 Will be calculated the first time you invoke anything with this
5695 source.")
5697 (defun anything-c-man-default-action (candidate)
5698 "Default action for jumping to a woman or man page from anything."
5699 (let ((wfiles (woman-file-name-all-completions candidate)))
5700 (condition-case err
5701 (if (> (length wfiles) 1)
5702 (woman-find-file
5703 (anything-comp-read
5704 "ManFile: " wfiles :must-match t))
5705 (woman candidate))
5706 ;; If woman is unable to format correctly
5707 ;; use man instead.
5708 (error (kill-buffer) ; Kill woman buffer.
5709 (let ((Man-notify-method 'meek))
5710 (Man-getpage-in-background candidate))))))
5712 (defvar anything-c-source-man-pages
5713 `((name . "Manual Pages")
5714 (candidates . (lambda ()
5715 (if anything-c-man-pages
5716 anything-c-man-pages
5717 ;; XEmacs doesn't have a woman :)
5718 (setq anything-c-man-pages
5719 (ignore-errors
5720 (require 'woman)
5721 (woman-file-name "")
5722 (sort (mapcar 'car woman-topic-all-completions)
5723 'string-lessp))))))
5724 (action ("Show with Woman" . anything-c-man-default-action))
5725 ;; Woman does not work OS X
5726 ;; http://xahlee.org/emacs/modernization_man_page.html
5727 (action-transformer . (lambda (actions candidate)
5728 (if (eq system-type 'darwin)
5729 '(("Show with Man" . man))
5730 actions)))
5731 (requires-pattern . 2)))
5732 ;; (anything 'anything-c-source-man-pages)
5735 ;;;; <Command>
5736 ;;; Complex command history
5739 (defvar anything-c-source-complex-command-history
5740 '((name . "Complex Command History")
5741 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5742 (type . sexp)))
5743 ;; (anything 'anything-c-source-complex-command-history)
5745 ;;; M-x history (not related to `anything-M-x')
5748 (defvar anything-c-source-extended-command-history
5749 '((name . "Emacs Commands History")
5750 (candidates . extended-command-history)
5751 (type . command)))
5752 ;; (anything 'anything-c-source-extended-command-history)
5754 ;;; Emacs commands (Basic source for emacs commands)
5757 (defvar anything-c-source-emacs-commands
5758 '((name . "Emacs Commands")
5759 (candidates . (lambda ()
5760 (let (commands)
5761 (mapatoms (lambda (a)
5762 (if (commandp a)
5763 (push (symbol-name a)
5764 commands))))
5765 (sort commands 'string-lessp))))
5766 (type . command)
5767 (requires-pattern . 2))
5768 "Source for completing and invoking Emacs commands.
5769 A command is a function with interactive spec that can
5770 be invoked with `M-x'.
5772 To get non-interactive functions listed, use
5773 `anything-c-source-emacs-functions'.")
5774 ;; (anything 'anything-c-source-emacs-commands)
5777 ;;; Anything M-x - Enhanced M-x UI
5780 ;; Another replacement of `M-x' that act exactly like the
5781 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5782 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5783 ;; anything invocation.
5784 ;; Documentation of commands available without quitting,
5785 ;; Show keybindings of commands.
5786 ;; Show history.
5787 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5788 "Return alist of MODE-MAP."
5789 (loop for key being the key-seqs of mode-map using (key-bindings com)
5790 for str-key = (key-description key)
5791 for ismenu = (string-match "<menu-bar>" str-key)
5792 unless ismenu collect (cons str-key com)))
5794 (defun anything-get-mode-map-from-mode (mode)
5795 "Guess the mode-map name according to MODE.
5796 Some modes don't use conventional mode-map name
5797 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5798 Return nil if no mode-map found."
5799 (loop
5800 ;; Start with a conventional mode-map name.
5801 with mode-map = (intern-soft (format "%s-map" mode))
5802 with mode-string = (symbol-name mode)
5803 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5804 while (not mode-map)
5805 for count downfrom (length mode-name)
5806 ;; Return when no result after parsing entire string.
5807 when (eq count 0) return nil
5808 for sub-name = (substring mode-name 0 count)
5809 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5810 finally return mode-map))
5812 (defun anything-M-x-current-mode-map-alist ()
5813 "Return mode-map alist of current `major-mode'."
5814 (let ((map (anything-get-mode-map-from-mode major-mode)))
5815 (when (and map (boundp map))
5816 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5819 (defun anything-M-x-transformer (candidates sources)
5820 "filtered-candidate-transformer to show bindings in emacs commands.
5821 Show global bindings and local bindings according to current `major-mode'."
5822 (with-anything-current-buffer
5823 (loop
5824 with local-map = (anything-M-x-current-mode-map-alist)
5825 for cand in candidates
5826 for local-key = (car (rassq cand local-map))
5827 for key = (substitute-command-keys (format "\\[%s]" cand))
5828 collect
5829 (cons (cond ((and (string-match "^M-x" key) local-key)
5830 (format "%s (%s)"
5831 cand (propertize
5832 local-key
5833 'face 'anything-M-x-key-face)))
5834 ((string-match "^M-x" key) cand)
5835 (t (format "%s (%s)"
5836 cand (propertize
5838 'face 'anything-M-x-key-face))))
5839 cand) into ls
5840 finally return
5841 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5844 ;;; LaCarte
5845 (defvar anything-c-source-lacarte
5846 '((name . "Lacarte")
5847 (init . (lambda () (require 'lacarte )))
5848 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
5849 (candidate-number-limit . 9999)
5850 (action . anything-c-call-interactively))
5851 "Needs lacarte.el.
5853 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
5854 ;; (anything 'anything-c-source-lacarte)
5857 ;;;; <Function>
5858 ;;; Emacs functions
5861 (defvar anything-c-source-emacs-functions
5862 '((name . "Emacs Functions")
5863 (candidates . (lambda ()
5864 (let (commands)
5865 (mapatoms (lambda (a)
5866 (if (functionp a)
5867 (push (symbol-name a) commands))))
5868 (sort commands 'string-lessp))))
5869 (type . function)
5870 (requires-pattern . 2))
5871 "Source for completing Emacs functions.")
5872 ;; (anything 'anything-c-source-emacs-functions)
5874 ;;; With abbrev expansion
5875 ;;; Similar to my exec-abbrev-cmd.el
5876 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5877 (defvar anything-c-function-abbrev-regexp nil
5878 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5879 Regexp built from the current `anything-pattern' interpreting it
5880 as abbreviation.
5881 Only for internal use.")
5883 (defun anything-c-match-function-by-abbrev (candidate)
5884 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5886 Abbreviations are made by taking the first character from each
5887 word in the function's name, e.g. \"bb\" is an abbrev for
5888 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5889 (string-match anything-c-function-abbrev-regexp candidate))
5891 (defvar anything-c-source-emacs-functions-with-abbrevs
5892 (append anything-c-source-emacs-functions
5893 '((match anything-c-match-function-by-abbrev
5894 anything-c-string-match))
5895 '((init
5896 . (lambda ()
5897 (defadvice anything-update
5898 (before anything-c-update-function-abbrev-regexp activate)
5899 (let ((char-list (append anything-pattern nil))
5900 (str "^"))
5901 (dolist (c char-list)
5902 (setq str (concat str (list c) "[^-]*-")))
5903 (setq str (concat (substring str 0 (1- (length str))) "$"))
5904 (setq anything-c-function-abbrev-regexp str))))))))
5905 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5907 (defvar anything-c-source-advice
5908 '((name . "Function Advice")
5909 (candidates . anything-c-advice-candidates)
5910 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5911 ;; (real-to-display . anything-c-advice-real-to-display)
5912 (persistent-action . anything-c-advice-persistent-action)
5913 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5914 ;; (anything 'anything-c-source-advice)
5915 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5916 ;; (testadvice)
5918 (defun anything-c-advice-candidates ()
5919 (require 'advice)
5920 (loop for (fname) in ad-advised-functions
5921 for function = (intern fname)
5922 append
5923 (loop for class in ad-advice-classes append
5924 (loop for advice in (ad-get-advice-info-field function class)
5925 for enabled = (ad-advice-enabled advice)
5926 collect
5927 (cons (format
5928 "%s %s %s"
5929 (if enabled "Enabled " "Disabled")
5930 (propertize fname 'face 'font-lock-function-name-face)
5931 (ad-make-single-advice-docstring advice class nil))
5932 (list function class advice))))))
5934 (defun anything-c-advice-persistent-action (func-class-advice)
5935 (if current-prefix-arg
5936 (anything-c-advice-toggle func-class-advice)
5937 (describe-function (car func-class-advice))))
5939 (defun anything-c-advice-toggle (func-class-advice)
5940 (destructuring-bind (function class advice) func-class-advice
5941 (cond ((ad-advice-enabled advice)
5942 (ad-advice-set-enabled advice nil)
5943 (message "Disabled"))
5944 (t ;disabled
5945 (ad-advice-set-enabled advice t)
5946 (message "Enabled")))
5947 (ad-activate function)
5948 (and anything-in-persistent-action
5949 (anything-c-advice-update-current-display-string))))
5951 (defun anything-c-advice-update-current-display-string ()
5952 (anything-edit-current-selection
5953 (let ((newword (cond ((looking-at "Disabled") "Enabled")
5954 ((looking-at "Enabled") "Disabled")))
5955 realvalue)
5956 (when newword
5957 (delete-region (point) (progn (forward-word 1) (point)))
5958 (insert newword)))))
5961 ;;;; <Variable>
5962 ;;; Emacs variables
5965 (defvar anything-c-source-emacs-variables
5966 '((name . "Emacs Variables")
5967 (candidates . (lambda ()
5968 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
5969 (type . variable)
5970 (requires-pattern . 2))
5971 "Source for completing Emacs variables.")
5972 ;; (anything 'anything-c-source-emacs-variables)
5975 ;;; Bookmarks
5978 ;; Bind some faces for bookmarks.
5979 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
5980 (defvar anything-c-bookmarks-face2 'anything-ff-file)
5981 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
5983 (eval-when-compile (require 'bookmark))
5984 (defvar anything-c-source-bookmarks
5985 '((name . "Bookmarks")
5986 (init . (lambda ()
5987 (require 'bookmark)))
5988 (candidates . bookmark-all-names)
5989 (type . bookmark))
5990 "See (info \"(emacs)Bookmarks\").")
5991 ;; (anything 'anything-c-source-bookmarks)
5993 ;;; bookmark-set
5994 (defvar anything-c-source-bookmark-set
5995 '((name . "Set Bookmark")
5996 (dummy)
5997 (action . bookmark-set))
5998 "See (info \"(emacs)Bookmarks\").")
5999 ;; (anything 'anything-c-source-bookmark-set)
6001 ;;; Visible Bookmarks
6002 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6005 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6006 (defvar anything-c-source-bm
6007 '((name . "Visible Bookmarks")
6008 (init . anything-c-bm-init)
6009 (candidates-in-buffer)
6010 (type . line))
6011 "Needs bm.el.
6013 http://www.nongnu.org/bm/")
6015 (defun anything-c-bm-init ()
6016 "Init function for `anything-c-source-bm'."
6017 (when (require 'bm nil t)
6018 (with-no-warnings
6019 (let ((bookmarks (bm-lists))
6020 (buf (anything-candidate-buffer 'global)))
6021 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6022 '< :key 'overlay-start))
6023 (let ((start (overlay-start bm))
6024 (end (overlay-end bm))
6025 (annotation (or (overlay-get bm 'annotation) "")))
6026 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6027 (let ((str (format "%5d: [%s]: %s\n"
6028 (line-number-at-pos start)
6029 annotation
6030 (buffer-substring start (1- end)))))
6031 (with-current-buffer buf (insert str))))))))))
6033 ;;; Special bookmarks
6034 (defvar anything-c-source-bookmarks-ssh
6035 '((name . "Bookmarks-ssh")
6036 (init . (lambda ()
6037 (require 'bookmark)))
6038 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6039 (type . bookmark))
6040 "See (info \"(emacs)Bookmarks\").")
6041 ;; (anything 'anything-c-source-bookmarks-ssh)
6043 (defvar anything-c-source-bookmarks-su
6044 '((name . "Bookmarks-root")
6045 (init . (lambda ()
6046 (require 'bookmark)))
6047 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6048 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6050 (type . bookmark))
6051 "See (info \"(emacs)Bookmarks\").")
6052 ;; (anything 'anything-c-source-bookmarks-su)
6054 (defvar anything-c-source-bookmarks-local
6055 '((name . "Bookmarks-Local")
6056 (init . (lambda ()
6057 (require 'bookmark)))
6058 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6059 (filtered-candidate-transformer
6060 anything-c-adaptive-sort
6061 anything-c-highlight-bookmark)
6062 (type . bookmark))
6063 "See (info \"(emacs)Bookmarks\").")
6064 ;; (anything 'anything-c-source-bookmarks-local)
6066 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6067 (let* ((lis-all (bookmark-all-names))
6068 (lis-loc (cond (local (loop for i in lis-all
6069 unless (string-match "^(ssh)\\|^(su)" i)
6070 collect i))
6071 (su (loop for i in lis-all
6072 when (string-match "^(su)" i)
6073 collect i))
6074 (sudo (loop for i in lis-all
6075 when (string-match "^(sudo)" i)
6076 collect i))
6077 (ssh (loop for i in lis-all
6078 when (string-match "^(ssh)" i)
6079 collect i)))))
6080 (sort lis-loc 'string-lessp)))
6082 (defun anything-c-bookmark-root-logged-p ()
6083 (catch 'break
6084 (dolist (i (mapcar #'buffer-name (buffer-list)))
6085 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6086 (throw 'break t)))))
6088 (defun anything-c-highlight-bookmark-su (files source)
6089 (if (anything-c-bookmark-root-logged-p)
6090 (anything-c-highlight-bookmark files source)
6091 (anything-c-highlight-not-logged files source)))
6093 (defun anything-c-highlight-not-logged (files source)
6094 (loop for i in files
6095 collect (propertize i 'face anything-c-bookmarks-face3)))
6097 (defun anything-c-highlight-bookmark (bookmarks source)
6098 "Used as `candidate-transformer' to colorize bookmarks.
6099 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6100 (loop for i in bookmarks
6101 for isfile = (bookmark-get-filename i)
6102 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6103 (bmkext-get-buffer-name i))
6104 for handlerp = (and (fboundp 'bookmark-get-handler)
6105 (bookmark-get-handler i))
6106 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6107 (bmkext-w3m-bookmark-p i))
6108 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6109 (bmkext-gnus-bookmark-p i))
6110 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6111 (bmkext-man-bookmark-p i))
6112 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6113 (bmkext-woman-bookmark-p i))
6114 for handlerp = (bookmark-get-handler i)
6115 for isannotation = (bookmark-get-annotation i)
6116 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6117 for isinfo = (eq handlerp 'Info-bookmark-jump)
6118 ;; Add a * if bookmark have annotation
6119 if (and isannotation (not (string-equal isannotation "")))
6120 do (setq i (concat "*" i))
6121 collect (cond (;; info buffers
6122 isinfo
6123 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6124 (;; w3m buffers
6125 isw3m
6126 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6127 (;; gnus buffers
6128 isgnus
6129 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6130 (;; Man Woman
6131 (or iswoman isman)
6132 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6133 (;; Addressbook
6134 isabook
6135 (propertize i 'face '((:foreground "Tomato"))))
6136 (;; directories
6137 (and isfile (file-directory-p isfile))
6138 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6139 (;; regular files
6141 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6145 ;;; Sources to filter bookmark-extensions bookmarks.
6148 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6149 ;; If you want to enable google-maps in addressbook you will need
6150 ;; Julien Danjou google-maps-el package available here:
6151 ;; http://julien.danjou.info/google-maps-el.html
6153 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6154 "Return a filtered `bookmark-alist' sorted alphabetically."
6155 (loop
6156 with alist = (if args
6157 (apply #'(lambda (x) (funcall fn x)) args)
6158 (funcall fn))
6159 for i in alist
6160 for b = (car i)
6161 collect b into sa
6162 finally return (sort sa 'string-lessp)))
6164 ;;; Addressbook.
6167 (defvar anything-c-source-bmkext-addressbook
6168 '((name . "Bookmark Addressbook")
6169 (init . (lambda ()
6170 (require 'bookmark-extensions)
6171 (bookmark-maybe-load-default-file)))
6172 (candidates . anything-c-bmkext-addressbook-setup-alist)
6173 (persistent-action
6174 . (lambda (candidate)
6175 (let ((bmk (anything-bookmark-get-bookmark-from-name
6176 candidate)))
6177 (bookmark--jump-via bmk 'pop-to-buffer))))
6178 (persistent-help . "Show contact - Prefix with C-u to append")
6179 (filtered-candidate-transformer
6180 anything-c-adaptive-sort
6181 anything-c-highlight-bookmark)
6182 (action . (("Show Contact(s)"
6183 . (lambda (candidate)
6184 (let* ((contacts (anything-marked-candidates))
6185 (current-prefix-arg (or anything-current-prefix-arg
6186 (> (length contacts) 1))))
6187 (bookmark-jump
6188 (anything-bookmark-get-bookmark-from-name (car contacts)))
6189 (anything-aif (cdr contacts)
6190 (loop for bmk in it do
6191 (bookmark-jump
6192 (anything-bookmark-get-bookmark-from-name bmk)))))))
6193 ("Send Mail"
6194 . (lambda (candidate)
6195 (let* ((contacts (anything-marked-candidates))
6196 (bmk (anything-bookmark-get-bookmark-from-name
6197 (car contacts)))
6198 (append (message-buffers)))
6199 (if append
6200 (addressbook-set-mail-buffer1 bmk 'append)
6201 (addressbook-set-mail-buffer1 bmk))
6202 (setq contacts (cdr contacts))
6203 (when contacts
6204 (loop for bmk in contacts do
6205 (addressbook-set-mail-buffer1 bmk 'append))))))
6206 ("Edit Bookmark"
6207 . (lambda (candidate)
6208 (let ((bmk (anything-bookmark-get-bookmark-from-name
6209 candidate)))
6210 (addressbook-bookmark-edit
6211 (assoc bmk bookmark-alist)))))
6212 ("Insert Email at point"
6213 . (lambda (candidate)
6214 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6215 candidate))
6216 (mlist (split-string
6217 (assoc-default
6218 'email (assoc bmk bookmark-alist))
6219 ", ")))
6220 (insert
6221 (if (> (length mlist) 1)
6222 (anything-comp-read
6223 "Insert Mail Address: " mlist :must-match t)
6224 (car mlist))))))
6225 ("Show annotation"
6226 . (lambda (candidate)
6227 (let ((bmk (anything-bookmark-get-bookmark-from-name
6228 candidate)))
6229 (bookmark-show-annotation bmk))))
6230 ("Edit annotation"
6231 . (lambda (candidate)
6232 (let ((bmk (anything-bookmark-get-bookmark-from-name
6233 candidate)))
6234 (bookmark-edit-annotation bmk))))
6235 ("Show Google map"
6236 . (lambda (candidate)
6237 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6238 candidate))
6239 (full-bmk (assoc bmk bookmark-alist)))
6240 (addressbook-google-map full-bmk))))))))
6243 (defun anything-c-bmkext-addressbook-setup-alist ()
6244 "Specialized filter function for bookmarks w3m."
6245 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6247 ;; W3m bookmarks from bookmark-extensions.
6248 (defvar anything-c-source-bookmark-w3m
6249 '((name . "Bookmark W3m")
6250 (init . (lambda ()
6251 (require 'bookmark-extensions)
6252 (bookmark-maybe-load-default-file)))
6253 (candidates . anything-c-bookmark-w3m-setup-alist)
6254 (filtered-candidate-transformer
6255 anything-c-adaptive-sort
6256 anything-c-highlight-bookmark)
6257 (type . bookmark)))
6258 ;; (anything 'anything-c-source-bookmark-w3m)
6260 (defun anything-c-bookmark-w3m-setup-alist ()
6261 "Specialized filter function for bookmarks w3m."
6262 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6264 ;; Images
6265 (defvar anything-c-source-bookmark-images
6266 '((name . "Bookmark Images")
6267 (init . (lambda ()
6268 (require 'bookmark-extensions)
6269 (bookmark-maybe-load-default-file)))
6270 (candidates . anything-c-bookmark-images-setup-alist)
6271 (filtered-candidate-transformer
6272 anything-c-adaptive-sort
6273 anything-c-highlight-bookmark)
6274 (type . bookmark)))
6275 ;; (anything 'anything-c-source-bookmark-images)
6277 (defun anything-c-bookmark-images-setup-alist ()
6278 "Specialized filter function for images bookmarks."
6279 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6281 ;; Woman Man
6282 (defvar anything-c-source-bookmark-man
6283 '((name . "Bookmark Woman&Man")
6284 (init . (lambda ()
6285 (require 'bookmark-extensions)
6286 (bookmark-maybe-load-default-file)))
6287 (candidates . anything-c-bookmark-man-setup-alist)
6288 (filtered-candidate-transformer
6289 anything-c-adaptive-sort
6290 anything-c-highlight-bookmark)
6291 (type . bookmark)))
6292 ;; (anything 'anything-c-source-bookmark-man)
6294 (defun anything-c-bookmark-man-setup-alist ()
6295 "Specialized filter function for bookmarks w3m."
6296 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6297 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6299 ;; Gnus
6300 (defvar anything-c-source-bookmark-gnus
6301 '((name . "Bookmark Gnus")
6302 (init . (lambda ()
6303 (require 'bookmark-extensions)
6304 (bookmark-maybe-load-default-file)))
6305 (candidates . anything-c-bookmark-gnus-setup-alist)
6306 (filtered-candidate-transformer
6307 anything-c-adaptive-sort
6308 anything-c-highlight-bookmark)
6309 (type . bookmark)))
6310 ;; (anything 'anything-c-source-bookmark-gnus)
6312 (defun anything-c-bookmark-gnus-setup-alist ()
6313 "Specialized filter function for bookmarks gnus."
6314 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6316 ;; Info
6317 (defvar anything-c-source-bookmark-info
6318 '((name . "Bookmark Info")
6319 (init . (lambda ()
6320 (require 'bookmark-extensions)
6321 (bookmark-maybe-load-default-file)))
6322 (candidates . anything-c-bookmark-info-setup-alist)
6323 (filtered-candidate-transformer
6324 anything-c-adaptive-sort
6325 anything-c-highlight-bookmark)
6326 (type . bookmark)))
6327 ;; (anything 'anything-c-source-bookmark-info)
6329 (defun anything-c-bookmark-info-setup-alist ()
6330 "Specialized filter function for bookmarks info."
6331 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6333 ;; Local Files&directories
6334 (defvar anything-c-source-bookmark-files&dirs
6335 '((name . "Bookmark Files&Directories")
6336 (init . (lambda ()
6337 (require 'bookmark-extensions)
6338 (bookmark-maybe-load-default-file)))
6339 (candidates . anything-c-bookmark-local-files-setup-alist)
6340 (filtered-candidate-transformer
6341 anything-c-adaptive-sort
6342 anything-c-highlight-bookmark)
6343 (type . bookmark)))
6344 ;; (anything 'anything-c-source-bookmark-files&dirs)
6346 (defun anything-c-bookmark-local-files-setup-alist ()
6347 "Specialized filter function for bookmarks locals files."
6348 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6350 ;; Su Files&directories
6351 (defvar anything-c-source-bookmark-su-files&dirs
6352 '((name . "Bookmark Root-Files&Directories")
6353 (init . (lambda ()
6354 (require 'bookmark-extensions)
6355 (bookmark-maybe-load-default-file)))
6356 (candidates . anything-c-bookmark-su-files-setup-alist)
6357 (filtered-candidate-transformer
6358 anything-c-adaptive-sort
6359 anything-c-highlight-bookmark-su)
6360 (type . bookmark)))
6361 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6363 (defun anything-c-bookmark-su-files-setup-alist ()
6364 "Specialized filter function for bookmarks su/sudo files."
6365 (declare (special bmkext-su-or-sudo-regexp))
6366 (loop
6367 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6368 for i in l
6369 for isfile = (bookmark-get-filename i)
6370 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6371 (save-match-data
6372 (string-match tramp-file-name-regexp isfile)))
6373 for issu = (and istramp
6374 (string-match bmkext-su-or-sudo-regexp isfile))
6375 if issu
6376 collect i))
6378 ;; Ssh Files&directories
6379 (defvar anything-c-source-bookmark-ssh-files&dirs
6380 '((name . "Bookmark Ssh-Files&Directories")
6381 (init . (lambda ()
6382 (require 'bookmark-extensions)
6383 (bookmark-maybe-load-default-file)))
6384 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6385 (filtered-candidate-transformer . anything-c-adaptive-sort)
6386 (type . bookmark)))
6387 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6389 (defun anything-c-bookmark-ssh-files-setup-alist ()
6390 "Specialized filter function for bookmarks ssh files."
6391 (loop
6392 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6393 for i in l
6394 for isfile = (bookmark-get-filename i)
6395 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6396 (save-match-data
6397 (string-match tramp-file-name-regexp isfile)))
6398 for isssh = (and istramp
6399 (string-match "/ssh:" isfile))
6400 if isssh
6401 collect i))
6405 ;;; Firefox bookmarks
6408 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6409 ;; (only for firefox versions >=3)
6410 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6411 ;; to true:
6412 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6413 ;; You should have now:
6414 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6416 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6417 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6419 (defun anything-get-firefox-user-init-dir ()
6420 "Guess the default Firefox user directory name."
6421 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6422 (moz-user-dir
6423 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6424 (goto-char (point-min))
6425 (prog1
6426 (when (search-forward "Path=" nil t)
6427 (buffer-substring-no-properties (point) (point-at-eol)))
6428 (kill-buffer)))))
6429 (file-name-as-directory (concat moz-dir moz-user-dir))))
6431 (defun anything-guess-firefox-bookmark-file ()
6432 "Return the path of the Firefox bookmarks file."
6433 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6435 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6436 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6437 (let (bookmarks-alist url title)
6438 (with-temp-buffer
6439 (insert-file-contents file)
6440 (goto-char (point-min))
6441 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6442 (forward-line 0)
6443 (when (re-search-forward url-regexp nil t)
6444 (setq url (match-string 0)))
6445 (when (re-search-forward bmk-regexp nil t)
6446 (setq title (match-string 1)))
6447 (push (cons title url) bookmarks-alist)
6448 (forward-line)))
6449 (nreverse bookmarks-alist)))
6451 (defvar anything-c-firefox-bookmarks-alist nil)
6452 (defvar anything-c-source-firefox-bookmarks
6453 '((name . "Firefox Bookmarks")
6454 (init . (lambda ()
6455 (setq anything-c-firefox-bookmarks-alist
6456 (anything-html-bookmarks-to-alist
6457 (anything-guess-firefox-bookmark-file)
6458 anything-firefox-bookmark-url-regexp
6459 anything-firefox-bookmarks-regexp))))
6460 (candidates . (lambda ()
6461 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6462 (filtered-candidate-transformer
6463 anything-c-adaptive-sort
6464 anything-c-highlight-firefox-bookmarks)
6465 (action . (("Browse Url Firefox"
6466 . (lambda (candidate)
6467 (browse-url-firefox
6468 (anything-c-firefox-bookmarks-get-value candidate))))
6469 ("Browse Url w3m"
6470 . (lambda (candidate)
6471 (w3m-browse-url
6472 (anything-c-firefox-bookmarks-get-value candidate))))
6473 ("Copy Url"
6474 . (lambda (elm)
6475 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6477 ;; (anything 'anything-c-source-firefox-bookmarks)
6479 (defun anything-c-firefox-bookmarks-get-value (elm)
6480 (assoc-default elm anything-c-firefox-bookmarks-alist))
6482 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6483 (loop for i in bookmarks
6484 collect (propertize
6485 i 'face '((:foreground "YellowGreen"))
6486 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6490 ;;; W3m bookmark - anything interface.
6493 ;; Some users have the emacs-w3m library in load-path
6494 ;; without having the w3m executable :-;
6495 ;; So check if w3m program is present before trying to load
6496 ;; emacs-w3m.
6497 (eval-when-compile
6498 (when (executable-find "w3m")
6499 (require 'w3m-bookmark nil t)))
6501 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6502 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6503 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6504 (defvar anything-c-w3m-bookmarks-alist nil)
6505 (defvar anything-c-source-w3m-bookmarks
6506 '((name . "W3m Bookmarks")
6507 (init . (lambda ()
6508 (setq anything-c-w3m-bookmarks-alist
6509 (anything-html-bookmarks-to-alist
6510 w3m-bookmark-file
6511 anything-w3m-bookmark-url-regexp
6512 anything-w3m-bookmarks-regexp))))
6513 (candidates . (lambda ()
6514 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6515 (filtered-candidate-transformer
6516 anything-c-adaptive-sort
6517 anything-c-highlight-w3m-bookmarks)
6518 (action . (("Browse Url"
6519 . (lambda (candidate)
6520 (anything-c-w3m-browse-bookmark candidate)))
6521 ("Copy Url"
6522 . (lambda (elm)
6523 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6524 ("Browse Url Firefox"
6525 . (lambda (candidate)
6526 (anything-c-w3m-browse-bookmark candidate t)))
6527 ("Delete Bookmark"
6528 . (lambda (candidate)
6529 (anything-c-w3m-delete-bookmark candidate)))
6530 ("Rename Bookmark"
6531 . (lambda (candidate)
6532 (anything-c-w3m-rename-bookmark candidate)))))
6533 (persistent-action . (lambda (candidate)
6534 (if current-prefix-arg
6535 (anything-c-w3m-browse-bookmark candidate t)
6536 (anything-c-w3m-browse-bookmark candidate nil t))))
6537 (persistent-help . "Open URL with emacs-w3m in new tab / \
6538 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6539 "Needs w3m and emacs-w3m.
6541 http://w3m.sourceforge.net/
6542 http://emacs-w3m.namazu.org/")
6544 ;; (anything 'anything-c-source-w3m-bookmarks)
6546 (defun anything-c-w3m-bookmarks-get-value (elm)
6547 (replace-regexp-in-string
6548 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6550 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6551 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6552 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6553 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6555 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6556 (loop for i in bookmarks
6557 collect (propertize
6558 i 'face 'anything-w3m-bookmarks-face
6559 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6562 (defun anything-c-w3m-delete-bookmark (elm)
6563 "Delete w3m bookmark from `w3m-bookmark-file'."
6564 (with-current-buffer
6565 (find-file-literally w3m-bookmark-file)
6566 (goto-char (point-min))
6567 (when (re-search-forward elm nil t)
6568 (beginning-of-line)
6569 (delete-region (point)
6570 (line-end-position))
6571 (delete-blank-lines))
6572 (save-buffer)
6573 (kill-buffer)))
6575 (defun anything-c-w3m-rename-bookmark (elm)
6576 "Rename w3m bookmark in `w3m-bookmark-file'."
6577 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6578 (new-title (read-string "NewTitle: " old-title)))
6579 (with-current-buffer
6580 (find-file-literally w3m-bookmark-file)
6581 (goto-char (point-min))
6582 (when (re-search-forward (concat elm "<") nil t)
6583 (goto-char (1- (point)))
6584 (delete-char (- (length old-title)))
6585 (insert new-title))
6586 (save-buffer)
6587 (kill-buffer))))
6590 ;;;; <Library>
6591 ;;; Elisp library scan
6594 (defvar anything-c-source-elisp-library-scan
6595 '((name . "Elisp libraries (Scan)")
6596 (init . (anything-c-elisp-library-scan-init))
6597 (candidates-in-buffer)
6598 (action ("Find library"
6599 . (lambda (candidate) (find-file (find-library-name candidate))))
6600 ("Find library other window"
6601 . (lambda (candidate)
6602 (find-file-other-window (find-library-name candidate))))
6603 ("Load library"
6604 . (lambda (candidate) (load-library candidate))))))
6605 ;; (anything 'anything-c-source-elisp-library-scan)
6607 (defun anything-c-elisp-library-scan-init ()
6608 "Init anything buffer status."
6609 (let ((anything-buffer (anything-candidate-buffer 'global))
6610 (library-list (anything-c-elisp-library-scan-list)))
6611 (with-current-buffer anything-buffer
6612 (dolist (library library-list)
6613 (insert (format "%s\n" library))))))
6615 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6616 "Do completion for file names passed to `locate-file'.
6617 DIRS is directory to search path.
6618 STRING is string to match."
6619 ;; Use `load-path' as path when ignore `dirs'.
6620 (or dirs (setq dirs load-path))
6621 ;; Init with blank when ignore `string'.
6622 (or string (setq string ""))
6623 ;; Get library list.
6624 (let ((string-dir (file-name-directory string))
6625 ;; File regexp that suffix match `load-file-rep-suffixes'.
6626 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6627 name
6628 names)
6629 (dolist (dir dirs)
6630 (unless dir
6631 (setq dir default-directory))
6632 (if string-dir
6633 (setq dir (expand-file-name string-dir dir)))
6634 (when (file-directory-p dir)
6635 (dolist (file (file-name-all-completions
6636 (file-name-nondirectory string) dir))
6637 ;; Suffixes match `load-file-rep-suffixes'.
6638 (setq name (if string-dir (concat string-dir file) file))
6639 (if (string-match match-regexp name)
6640 (add-to-list 'names name)))))
6641 names))
6644 ;;;; <Programming>
6648 ;;; Imenu
6651 (defvar anything-c-imenu-delimiter " / ")
6653 (defvar anything-c-imenu-index-filter nil)
6654 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6656 (defvar anything-c-cached-imenu-alist nil)
6657 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6659 (defvar anything-c-cached-imenu-candidates nil)
6660 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6662 (defvar anything-c-cached-imenu-tick nil)
6663 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6665 (eval-when-compile (require 'imenu))
6666 (setq imenu-auto-rescan t)
6668 (defun anything-imenu-create-candidates (entry)
6669 "Create candidates with ENTRY."
6670 (if (listp (cdr entry))
6671 (mapcan
6672 (lambda (sub)
6673 (if (consp (cdr sub))
6674 (mapcar
6675 (lambda (subentry)
6676 (concat (car entry) anything-c-imenu-delimiter subentry))
6677 (anything-imenu-create-candidates sub))
6678 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6679 (cdr entry))
6680 (list entry)))
6682 (defvar anything-c-source-imenu
6683 '((name . "Imenu")
6684 (init . (lambda () (require 'imenu)))
6685 (candidates . anything-c-imenu-candidates)
6686 (persistent-action . (lambda (elm)
6687 (anything-c-imenu-default-action elm)
6688 (unless (fboundp 'semantic-imenu-tag-overlay)
6689 (anything-match-line-color-current-line))))
6690 (persistent-help . "Show this entry")
6691 (action . anything-c-imenu-default-action))
6692 "See (info \"(emacs)Imenu\")")
6694 ;; (anything 'anything-c-source-imenu)
6696 (defun anything-c-imenu-candidates ()
6697 (with-anything-current-buffer
6698 (let ((tick (buffer-modified-tick)))
6699 (if (eq anything-c-cached-imenu-tick tick)
6700 anything-c-cached-imenu-candidates
6701 (setq imenu--index-alist nil)
6702 (setq anything-c-cached-imenu-tick tick
6703 anything-c-cached-imenu-candidates
6704 (ignore-errors
6705 (mapcan
6706 'anything-imenu-create-candidates
6707 (setq anything-c-cached-imenu-alist
6708 (let ((index (imenu--make-index-alist)))
6709 (if anything-c-imenu-index-filter
6710 (funcall anything-c-imenu-index-filter index)
6711 index))))))
6712 (setq anything-c-cached-imenu-candidates
6713 (mapcar #'(lambda (x)
6714 (if (stringp x)
6716 (car x)))
6717 anything-c-cached-imenu-candidates))))))
6719 (setq imenu-default-goto-function 'imenu-default-goto-function)
6720 (defun anything-c-imenu-default-action (elm)
6721 "The default action for `anything-c-source-imenu'."
6722 (let ((path (split-string elm anything-c-imenu-delimiter))
6723 (alist anything-c-cached-imenu-alist))
6724 (dolist (elm path)
6725 (setq alist (assoc elm alist)))
6726 (imenu alist)))
6730 ;;; Ctags
6733 (defvar anything-c-ctags-modes
6734 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6735 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6736 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6738 (defun anything-c-source-ctags-init ()
6739 (when (and buffer-file-name
6740 (memq major-mode anything-c-ctags-modes)
6741 (anything-current-buffer-is-modified))
6742 (with-current-buffer (anything-candidate-buffer 'local)
6743 (call-process-shell-command
6744 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6745 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6746 anything-buffer-file-name)
6747 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6748 nil (current-buffer))
6749 (goto-char (point-min))
6750 (forward-line 2)
6751 (delete-region (point-min) (point))
6752 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6753 for lineno-start = (point)
6754 for lineno = (buffer-substring
6755 lineno-start
6756 (1- (search-forward "," (point-at-eol) t)))
6758 (beginning-of-line)
6759 (insert (format "%5s:" lineno))
6760 (search-forward "\177" (point-at-eol) t)
6761 (delete-region (1- (point)) (point-at-eol))
6762 (forward-line 1)))))
6764 (defvar anything-c-source-ctags
6765 '((name . "Exuberant ctags")
6766 (init . anything-c-source-ctags-init)
6767 (candidates-in-buffer)
6768 (adjust)
6769 (type . line))
6770 "Needs Exuberant Ctags.
6772 http://ctags.sourceforge.net/")
6773 ;; (anything 'anything-c-source-ctags)
6776 ;;; Etags
6779 ;; anything-etags.el is deprecated, if this file is found,
6780 ;; warn user at compile time.
6781 (eval-when-compile
6782 (when (locate-library "anything-etags.el")
6783 (display-warning
6784 '(anything-config)
6785 "You are using obsolete library `anything-etags.el' and should remove it."
6786 :warning)))
6788 (defvar anything-c-etags-tag-file-dir nil
6789 "Etags file directory.")
6790 (defvar anything-c-etags-mtime-alist nil
6791 "Store the last modification time of etags files here.")
6792 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6793 "Cache content of etags files used here for faster access.")
6795 (defun anything-c-etags-get-tag-file (&optional directory)
6796 "Return the path of etags file if found."
6797 ;; Get tag file from `default-directory' or upper directory.
6798 (let ((current-dir (anything-c-etags-find-tag-file-directory
6799 (or directory default-directory))))
6800 ;; Return nil if not find tag file.
6801 (when current-dir
6802 ;; Set tag file directory.
6803 (setq anything-c-etags-tag-file-dir current-dir)
6804 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6806 (defun anything-c-etags-find-tag-file-directory (current-dir)
6807 "Try to find the directory containing tag file.
6808 If not found in CURRENT-DIR search in upper directory."
6809 (flet ((file-exists? (dir)
6810 (let ((tag-path (expand-file-name
6811 anything-c-etags-tag-file-name dir)))
6812 (and (stringp tag-path)
6813 (file-exists-p tag-path)
6814 (file-readable-p tag-path)))))
6815 (loop with count = 0
6816 until (file-exists? current-dir)
6817 ;; Return nil if outside the value of
6818 ;; `anything-c-etags-tag-file-search-limit'.
6819 if (= count anything-c-etags-tag-file-search-limit)
6820 do (return nil)
6821 ;; Or search upper directories.
6822 else
6823 do (incf count)
6824 (setq current-dir (expand-file-name (concat current-dir "../")))
6825 finally return current-dir)))
6827 (defun anything-c-source-etags-header-name (x)
6828 "Create header name for this anything etags session."
6829 (concat "Etags in "
6830 (with-anything-current-buffer
6831 (anything-c-etags-get-tag-file))))
6833 (defmacro anything-c-etags-create-buffer (file)
6834 "Create the `anything-buffer' based on contents of etags tag FILE."
6835 `(let* ((tag-fname ,file)
6837 (split (with-current-buffer (find-file-noselect tag-fname)
6838 (prog1
6839 (split-string (buffer-string) "\n" 'omit-nulls)
6840 (setq max (line-number-at-pos (point-max)))
6841 (kill-buffer))))
6842 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6843 (loop
6844 with fname
6845 with cand
6846 for i in split for count from 0
6847 for elm = (unless (string-match "^\x0c" i)
6848 (anything-aif (string-match "\177" i)
6849 (substring i 0 it)
6851 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6852 (setq fname (match-string 1 elm)))
6853 (elm (setq cand (concat fname ": " elm)))
6854 (t (setq cand nil)))
6855 when cand do (progn
6856 (insert (concat cand "\n"))
6857 (progress-reporter-update progress-reporter count)))))
6859 (defun anything-c-etags-init ()
6860 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6861 If no entry in cache, create one."
6862 (let ((tagfile (anything-c-etags-get-tag-file)))
6863 (when tagfile
6864 (with-current-buffer (anything-candidate-buffer 'global)
6865 (anything-aif (gethash tagfile anything-c-etags-cache)
6866 ;; An entry is present in cache, insert it.
6867 (insert it)
6868 ;; No entry, create a new buffer using content of tag file (slower).
6869 (anything-c-etags-create-buffer tagfile)
6870 ;; Store content of buffer in cache.
6871 (puthash tagfile (buffer-string) anything-c-etags-cache)
6872 ;; Store or set the last modification of tag file.
6873 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6874 ;; If an entry exists modify it.
6875 (setcdr it (anything-c-etags-mtime tagfile))
6876 ;; No entry create a new one.
6877 (add-to-list 'anything-c-etags-mtime-alist
6878 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6880 (defvar anything-c-source-etags-select
6881 '((name . "Etags")
6882 (header-name . anything-c-source-etags-header-name)
6883 (init . anything-c-etags-init)
6884 (candidates-in-buffer)
6885 (search . (anything-c-etags-search-fn))
6886 (mode-line . anything-etags-mode-line-string)
6887 (action . anything-c-etags-default-action)
6888 (persistent-action . (lambda (candidate)
6889 (anything-c-etags-default-action candidate)
6890 (anything-match-line-color-current-line))))
6891 "Anything source for Etags.")
6893 (defun anything-c-etags-search-fn (pattern bound noerror)
6894 "Search function for `anything-c-source-etags-select'."
6895 (re-search-forward
6896 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6897 bound noerror))
6899 (defun anything-c-etags-default-action (candidate)
6900 "Anything default action to jump to an etags entry."
6901 (let* ((split (split-string candidate ": "))
6902 (fname (expand-file-name
6903 (car split) anything-c-etags-tag-file-dir))
6904 (elm (cadr split)))
6905 (find-file fname)
6906 (goto-char (point-min))
6907 (search-forward elm nil t)
6908 (goto-char (match-beginning 0))))
6910 (defun anything-c-etags-mtime (file)
6911 "Last modification time of etags tag FILE."
6912 (cadr (nth 5 (file-attributes file))))
6914 (defun anything-c-etags-file-modified-p (file)
6915 "Check if tag FILE have been modified in this session.
6916 If FILE is nil return nil."
6917 (let ((last-modif (and file
6918 (assoc-default file anything-c-etags-mtime-alist))))
6919 (and last-modif
6920 (/= last-modif (anything-c-etags-mtime file)))))
6924 ;;; Semantic
6927 (defvar anything-semantic-candidates nil)
6929 (defun anything-semantic-construct-candidates (tags depth)
6930 (when (require 'semantic nil t)
6931 (apply
6932 'append
6933 (mapcar
6934 (lambda (tag)
6935 (if (listp tag)
6936 (let ((type (semantic-tag-type tag))
6937 (class (semantic-tag-class tag)))
6938 (if (or (and (stringp type)
6939 (or (string= type "class")
6940 (string= type "namespace")))
6941 (eq class 'function)
6942 (eq class 'variable))
6943 (cons (cons (concat (make-string (* depth 2) ?\s)
6944 (semantic-format-tag-summarize tag nil t))
6945 tag)
6946 (anything-semantic-construct-candidates
6947 (semantic-tag-components tag) (1+ depth)))))))
6948 tags))))
6950 (defun anything-semantic-default-action (candidate)
6951 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
6952 (semantic-go-to-tag tag)))
6954 (defvar anything-c-source-semantic
6955 '((name . "Semantic Tags")
6956 (init . (lambda ()
6957 (setq anything-semantic-candidates
6958 (ignore-errors (anything-semantic-construct-candidates
6959 (semantic-fetch-tags) 0)))))
6960 (candidates . (lambda ()
6961 (if anything-semantic-candidates
6962 (mapcar 'car anything-semantic-candidates))))
6963 (persistent-action . (lambda (elm)
6964 (anything-semantic-default-action elm)
6965 (anything-match-line-color-current-line)))
6966 (persistent-help . "Show this entry")
6967 (action . anything-semantic-default-action)
6968 "Needs semantic in CEDET.
6970 http://cedet.sourceforge.net/semantic.shtml
6971 http://cedet.sourceforge.net/"))
6973 ;; (anything 'anything-c-source-semantic)
6976 ;;; Anything interface of `simple-call-tree.el'.
6978 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
6980 ;; Function is called by
6981 (defvar anything-c-source-simple-call-tree-functions-callers
6982 '((name . "Function is called by")
6983 (init . anything-c-simple-call-tree-functions-callers-init)
6984 (multiline)
6985 (candidates . anything-c-simple-call-tree-candidates)
6986 (persistent-action . anything-c-simple-call-tree-persistent-action)
6987 (persistent-help . "Show function definitions by rotation")
6988 (action ("Find definition selected by persistent-action" .
6989 anything-c-simple-call-tree-find-definition)))
6990 "Needs simple-call-tree.el.
6991 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
6993 (defvar anything-c-simple-call-tree-tick nil)
6994 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
6995 (defun anything-c-simple-call-tree-analyze-maybe ()
6996 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
6997 (simple-call-tree-analyze)
6998 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7000 (defun anything-c-simple-call-tree-init-base (function message)
7001 (require 'simple-call-tree)
7002 (with-no-warnings
7003 (when (anything-current-buffer-is-modified)
7004 (anything-c-simple-call-tree-analyze-maybe)
7005 (let ((list (funcall function simple-call-tree-alist)))
7006 (with-current-buffer (anything-candidate-buffer 'local)
7007 (dolist (entry list)
7008 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7009 (insert (car entry) message
7010 (if (string= funcs " ")
7011 " no functions."
7012 funcs)
7013 "\n\n"))))))))
7015 (defun anything-c-simple-call-tree-functions-callers-init ()
7016 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7017 " is called by\n"))
7019 (defun anything-c-simple-call-tree-candidates ()
7020 (with-current-buffer (anything-candidate-buffer)
7021 (split-string (buffer-string) "\n\n")))
7023 (defvar anything-c-simple-call-tree-related-functions nil)
7024 (defvar anything-c-simple-call-tree-function-index 0)
7025 (defun anything-c-simple-call-tree-persistent-action (candidate)
7026 (unless (eq last-command 'anything-execute-persistent-action)
7027 (setq anything-c-simple-call-tree-related-functions
7028 (delete "no functions."
7029 (split-string
7030 (replace-regexp-in-string " \\| is called by\\| calls "
7031 "" candidate)
7032 "\n")))
7033 (setq anything-c-simple-call-tree-function-index -1))
7034 (incf anything-c-simple-call-tree-function-index)
7035 (anything-c-simple-call-tree-find-definition candidate))
7037 (defun anything-c-simple-call-tree-find-definition (candidate)
7038 (find-function
7039 (intern
7040 (nth (mod anything-c-simple-call-tree-function-index
7041 (length anything-c-simple-call-tree-related-functions))
7042 anything-c-simple-call-tree-related-functions))))
7044 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7046 ;;; Function calls
7047 (defvar anything-c-source-simple-call-tree-callers-functions
7048 '((name . "Function calls")
7049 (init . anything-c-simple-call-tree-callers-functions-init)
7050 (multiline)
7051 (candidates . anything-c-simple-call-tree-candidates)
7052 (persistent-action . anything-c-simple-call-tree-persistent-action)
7053 (persistent-help . "Show function definitions by rotation")
7054 (action ("Find definition selected by persistent-action" .
7055 anything-c-simple-call-tree-find-definition)))
7056 "Needs simple-call-tree.el.
7057 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7059 (defun anything-c-simple-call-tree-callers-functions-init ()
7060 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7062 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7066 ;;; Anything UI of auto-document.el
7068 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7070 ;; Commands/Options with doc
7071 (defvar anything-c-auto-document-data nil)
7072 (make-variable-buffer-local 'anything-c-auto-document-data)
7073 (defvar anything-c-source-commands-and-options-in-file
7074 '((name . "Commands/Options in file")
7075 (header-name
7076 . (lambda (x) (format "Commands/Options in %s"
7077 (buffer-local-value 'buffer-file-name
7078 anything-current-buffer))))
7079 (candidates . anything-command-and-options-candidates)
7080 (multiline)
7081 (action . imenu))
7082 "List Commands and Options with doc. It needs auto-document.el .
7084 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7086 (eval-when-compile (require 'auto-document nil t))
7087 (defun anything-command-and-options-candidates ()
7088 (with-anything-current-buffer
7089 (when (and (require 'auto-document nil t)
7090 (eq major-mode 'emacs-lisp-mode)
7091 (or (anything-current-buffer-is-modified)
7092 (not anything-c-auto-document-data)))
7093 (or imenu--index-alist (imenu--make-index-alist t))
7094 (setq anything-c-auto-document-data
7095 (destructuring-bind (commands options)
7096 (adoc-construct anything-current-buffer)
7097 (append
7098 (loop for (command . doc) in commands
7099 for cmdname = (symbol-name command)
7100 collect
7101 (cons
7102 (format "Command: %s\n %s"
7103 (propertize cmdname 'face font-lock-function-name-face)
7104 (adoc-first-line doc))
7105 (assoc cmdname imenu--index-alist)))
7106 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7107 for (option doc default) in options
7108 for optname = (symbol-name option)
7109 collect
7110 (cons
7111 (format "Option: %s\n %s\n default = %s"
7112 (propertize optname 'face font-lock-variable-name-face)
7113 (adoc-first-line doc)
7114 (adoc-prin1-to-string default))
7115 (assoc optname
7116 var-alist)))))))
7117 anything-c-auto-document-data))
7119 ;; (anything 'anything-c-source-commands-and-options-in-file)
7122 ;;;; <Color and Face>
7125 ;;; Customize Face
7128 (defvar anything-c-source-customize-face
7129 '((name . "Customize Face")
7130 (init . (lambda ()
7131 (unless (anything-candidate-buffer)
7132 (save-window-excursion (list-faces-display))
7133 (anything-candidate-buffer (get-buffer "*Faces*")))))
7134 (candidates-in-buffer)
7135 (get-line . buffer-substring)
7136 (action . (lambda (line)
7137 (customize-face (intern (car (split-string line))))))
7138 (requires-pattern . 3))
7139 "See (info \"(emacs)Faces\")")
7140 ;; (anything 'anything-c-source-customize-face)
7142 ;;; Colors browser
7145 (defvar anything-c-source-colors
7146 '((name . "Colors")
7147 (init . (lambda () (unless (anything-candidate-buffer)
7148 (save-window-excursion (list-colors-display))
7149 (anything-candidate-buffer (get-buffer "*Colors*")))))
7150 (candidates-in-buffer)
7151 (get-line . buffer-substring)
7152 (action
7153 ("Copy Name" . (lambda (candidate)
7154 (kill-new (anything-c-colors-get-name candidate))))
7155 ("Copy RGB" . (lambda (candidate)
7156 (kill-new (anything-c-colors-get-rgb candidate))))
7157 ("Insert Name" . (lambda (candidate)
7158 (with-anything-current-buffer
7159 (insert (anything-c-colors-get-name candidate)))))
7160 ("Insert RGB" . (lambda (candidate)
7161 (with-anything-current-buffer
7162 (insert (anything-c-colors-get-rgb candidate))))))))
7163 ;; (anything 'anything-c-source-colors)
7165 (defun anything-c-colors-get-name (candidate)
7166 "Get color name."
7167 (replace-regexp-in-string
7168 " " ""
7169 (with-temp-buffer
7170 (insert (capitalize candidate))
7171 (goto-char (point-min))
7172 (search-forward-regexp "\\s-\\{2,\\}")
7173 (delete-region (point) (point-max))
7174 (buffer-string))))
7176 (defun anything-c-colors-get-rgb (candidate)
7177 "Get color RGB."
7178 (replace-regexp-in-string
7179 " " ""
7180 (with-temp-buffer
7181 (insert (capitalize candidate))
7182 (goto-char (point-max))
7183 (search-backward-regexp "\\s-\\{2,\\}")
7184 (delete-region (point) (point-min))
7185 (buffer-string))))
7188 ;;;; <Search Engine>
7189 ;;; Tracker desktop search
7190 (defvar anything-c-source-tracker-search
7191 '((name . "Tracker Search")
7192 (candidates . (lambda ()
7193 (start-process "tracker-search-process" nil
7194 "tracker-search"
7195 anything-pattern)))
7196 (type . file)
7197 (requires-pattern . 3)
7198 (delayed))
7199 "Source for retrieving files matching the current input pattern
7200 with the tracker desktop search.")
7201 ;; (anything 'anything-c-source-tracker-search)
7203 ;;; Spotlight (MacOS X desktop search)
7204 (defvar anything-c-source-mac-spotlight
7205 '((name . "mdfind")
7206 (candidates
7207 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7208 (type . file)
7209 (requires-pattern . 3)
7210 (delayed))
7211 "Source for retrieving files via Spotlight's command line
7212 utility mdfind.")
7213 ;; (anything 'anything-c-source-mac-spotlight)
7215 ;;; Picklist
7216 (defvar anything-c-source-picklist
7217 '((name . "Picklist")
7218 (candidates . (lambda () (mapcar 'car picklist-list)))
7219 (type . file)))
7220 ;; (anything 'anything-c-source-picklist)
7224 ;;; Kill ring
7227 (defvar anything-c-source-kill-ring
7228 '((name . "Kill Ring")
7229 (init . (lambda () (anything-attrset 'last-command last-command)))
7230 (candidates . anything-c-kill-ring-candidates)
7231 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7232 (action . anything-c-kill-ring-action)
7233 (last-command)
7234 (migemo)
7235 (multiline))
7236 "Source for browse and insert contents of kill-ring.")
7238 (defun anything-c-kill-ring-candidates ()
7239 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7240 unless (or (< (length kill) anything-kill-ring-threshold)
7241 (string-match "^[\\s\\t]+$" kill))
7242 collect kill))
7244 (defun anything-c-kill-ring-transformer (candidates source)
7245 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7246 (loop for i in candidates
7247 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7248 if (and anything-c-kill-ring-max-lines-number
7249 (> nlines anything-c-kill-ring-max-lines-number))
7250 collect (cons
7251 (with-temp-buffer
7252 (insert i)
7253 (goto-char (point-min))
7254 (concat
7255 (buffer-substring
7256 (point-min)
7257 (save-excursion
7258 (forward-line anything-c-kill-ring-max-lines-number)
7259 (point)))
7260 "[...]")) i)
7261 else collect i))
7263 (defun anything-c-kill-ring-action (str)
7264 "Insert STR in `kill-ring' and set STR to the head.
7265 If this action is executed just after `yank',
7266 replace with STR as yanked string."
7267 (setq kill-ring (delete str kill-ring))
7268 (if (not (eq (anything-attr 'last-command) 'yank))
7269 (insert-for-yank str)
7270 ;; from `yank-pop'
7271 (let ((inhibit-read-only t)
7272 (before (< (point) (mark t))))
7273 (if before
7274 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7275 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7276 (setq yank-undo-function nil)
7277 (set-marker (mark-marker) (point) (current-buffer))
7278 (insert-for-yank str)
7279 ;; Set the window start back where it was in the yank command,
7280 ;; if possible.
7281 (set-window-start (selected-window) yank-window-start t)
7282 (if before
7283 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7284 ;; It is cleaner to avoid activation, even though the command
7285 ;; loop would deactivate the mark because we inserted text.
7286 (goto-char (prog1 (mark t)
7287 (set-marker (mark-marker) (point) (current-buffer)))))))
7288 (kill-new str))
7290 ;; (anything 'anything-c-source-kill-ring)
7293 ;;;; <Mark ring>
7294 ;; DO NOT include these sources in `anything-sources' use
7295 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7296 ;; `anything-all-mark-rings' instead.
7298 (defun anything-c-source-mark-ring-candidates ()
7299 (flet ((get-marks (pos)
7300 (save-excursion
7301 (goto-char pos)
7302 (beginning-of-line)
7303 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7304 (when (string= "" line)
7305 (setq line "<EMPTY LINE>"))
7306 (format "%7d: %s" (line-number-at-pos) line)))))
7307 (with-anything-current-buffer
7308 (loop
7309 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7310 with recip = nil
7311 for i in marks
7312 for m = (get-marks i)
7313 unless (member m recip)
7314 collect m into recip
7315 finally return recip))))
7317 (defvar anything-mark-ring-cache nil)
7318 (defvar anything-c-source-mark-ring
7319 '((name . "mark-ring")
7320 (init . (lambda ()
7321 (setq anything-mark-ring-cache
7322 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7323 (candidates . (lambda ()
7324 (anything-aif anything-mark-ring-cache
7325 it)))
7326 (action . (("Goto line"
7327 . (lambda (candidate)
7328 (anything-goto-line (string-to-number candidate))))))
7329 (persistent-action . (lambda (candidate)
7330 (anything-goto-line (string-to-number candidate))
7331 (anything-match-line-color-current-line)))
7332 (persistent-help . "Show this line")))
7334 ;; (anything 'anything-c-source-mark-ring)
7336 ;;; Global-mark-ring
7337 (defvar anything-c-source-global-mark-ring
7338 '((name . "global-mark-ring")
7339 (candidates . anything-c-source-global-mark-ring-candidates)
7340 (action . (("Goto line"
7341 . (lambda (candidate)
7342 (let ((items (split-string candidate ":")))
7343 (anything-c-switch-to-buffer (second items))
7344 (anything-goto-line (string-to-number (car items))))))))
7345 (persistent-action . (lambda (candidate)
7346 (let ((items (split-string candidate ":")))
7347 (anything-c-switch-to-buffer (second items))
7348 (anything-goto-line (string-to-number (car items)))
7349 (anything-match-line-color-current-line))))
7350 (persistent-help . "Show this line")))
7352 (defun anything-c-source-global-mark-ring-candidates ()
7353 (flet ((buf-fn (m)
7354 (with-current-buffer (marker-buffer m)
7355 (goto-char m)
7356 (beginning-of-line)
7357 (let (line)
7358 (if (string= "" line)
7359 (setq line "<EMPTY LINE>")
7360 (setq line (car (split-string (thing-at-point 'line)
7361 "[\n\r]"))))
7362 (format "%7d:%s: %s"
7363 (line-number-at-pos) (marker-buffer m) line)))))
7364 (loop
7365 with marks = global-mark-ring
7366 with recip = nil
7367 for i in marks
7368 for gm = (unless (or (string-match
7369 "^ " (format "%s" (marker-buffer i)))
7370 (null (marker-buffer i)))
7371 (buf-fn i))
7372 when (and gm (not (member gm recip)))
7373 collect gm into recip
7374 finally return recip)))
7376 ;; (anything 'anything-c-source-global-mark-ring)
7379 ;;;; <Register>
7380 ;;; Insert from register
7381 (defvar anything-c-source-register
7382 '((name . "Registers")
7383 (candidates . anything-c-register-candidates)
7384 (action-transformer . anything-c-register-action-transformer)
7385 (multiline)
7386 (action))
7387 "See (info \"(emacs)Registers\")")
7389 (defun anything-c-register-candidates ()
7390 "Collecting register contents and appropriate commands."
7391 (loop for (char . val) in register-alist
7392 for key = (single-key-description char)
7393 for string-actions =
7394 (cond
7395 ((numberp val)
7396 (list (int-to-string val)
7397 'insert-register
7398 'increment-register))
7399 ((markerp val)
7400 (let ((buf (marker-buffer val)))
7401 (if (null buf)
7402 (list "a marker in no buffer")
7403 (list (concat
7404 "a buffer position:"
7405 (buffer-name buf)
7406 ", position "
7407 (int-to-string (marker-position val)))
7408 'jump-to-register
7409 'insert-register))))
7410 ((and (consp val) (window-configuration-p (car val)))
7411 (list "window configuration."
7412 'jump-to-register))
7413 ((and (consp val) (frame-configuration-p (car val)))
7414 (list "frame configuration."
7415 'jump-to-register))
7416 ((and (consp val) (eq (car val) 'file))
7417 (list (concat "file:"
7418 (prin1-to-string (cdr val))
7419 ".")
7420 'jump-to-register))
7421 ((and (consp val) (eq (car val) 'file-query))
7422 (list (concat "file:a file-query reference: file "
7423 (car (cdr val))
7424 ", position "
7425 (int-to-string (car (cdr (cdr val))))
7426 ".")
7427 'jump-to-register))
7428 ((consp val)
7429 (let ((lines (format "%4d" (length val))))
7430 (list (format "%s: %s\n" lines
7431 (truncate-string-to-width
7432 (mapconcat 'identity (list (car val))
7433 ;; (mapconcat (lambda (y) y) val
7434 "^J") (- (window-width) 15)))
7435 'insert-register)))
7436 ((stringp val)
7437 (list ;; without properties
7438 (substring-no-properties val)
7439 'insert-register
7440 'append-to-register
7441 'prepend-to-register))
7443 "GARBAGE!"))
7444 collect (cons (format "register %3s: %s" key (car string-actions))
7445 (cons char (cdr string-actions)))))
7447 (defun anything-c-register-action-transformer (actions register-and-functions)
7448 "Decide actions by the contents of register."
7449 (loop with func-actions =
7450 '((insert-register
7451 "Insert Register" .
7452 (lambda (c) (insert-register (car c))))
7453 (jump-to-register
7454 "Jump to Register" .
7455 (lambda (c) (jump-to-register (car c))))
7456 (append-to-register
7457 "Append Region to Register" .
7458 (lambda (c) (append-to-register
7459 (car c) (region-beginning) (region-end))))
7460 (prepend-to-register
7461 "Prepend Region to Register" .
7462 (lambda (c) (prepend-to-register
7463 (car c) (region-beginning) (region-end))))
7464 (increment-register
7465 "Increment Prefix Arg to Register" .
7466 (lambda (c) (increment-register
7467 anything-current-prefix-arg (car c)))))
7468 for func in (cdr register-and-functions)
7469 for cell = (assq func func-actions)
7470 when cell
7471 collect (cdr cell)))
7473 ;; (anything 'anything-c-source-register)
7476 ;;; Latex completion
7477 (defun anything-c-latex-math-candidates ()
7478 "Collect candidates for latex math completion."
7479 (declare (special LaTeX-math-menu))
7480 (loop for i in (cddr LaTeX-math-menu)
7481 for elm = (loop for s in i when (vectorp s)
7482 collect (cons (aref s 0) (aref s 1)))
7483 append elm))
7485 (defvar anything-c-source-latex-math
7486 '((name . "Latex Math Menu")
7487 (init . (lambda ()
7488 (with-anything-current-buffer
7489 (LaTeX-math-mode 1))))
7490 (candidate-number-limit . 9999)
7491 (candidates . anything-c-latex-math-candidates)
7492 (action . (lambda (candidate)
7493 (call-interactively candidate)))))
7496 ;;;; <Headline Extraction>
7497 (defvar anything-c-source-fixme
7498 '((name . "TODO/FIXME/DRY comments")
7499 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7500 (adjust)
7501 (recenter))
7502 "Show TODO/FIXME/DRY comments in current file.")
7503 ;; (anything 'anything-c-source-fixme)
7505 (defvar anything-c-source-rd-headline
7506 '((name . "RD HeadLine")
7507 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7508 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7509 (migemo)
7510 (subexp . 1))
7511 "Show RD headlines.
7513 RD is Ruby's POD.
7514 http://en.wikipedia.org/wiki/Ruby_Document_format")
7515 ;; (anything 'anything-c-source-rd-headline)
7517 (defvar anything-c-source-oddmuse-headline
7518 '((name . "Oddmuse HeadLine")
7519 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7520 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7521 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7522 (migemo)
7523 (subexp . 1))
7524 "Show Oddmuse headlines, such as EmacsWiki.")
7525 ;; (anything 'anything-c-source-oddmuse-headline)
7527 (defvar anything-c-source-emacs-source-defun
7528 '((name . "Emacs Source DEFUN")
7529 (headline . "DEFUN\\|DEFVAR")
7530 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7531 (or buffer-file-name ""))))
7532 "Show DEFUN/DEFVAR in Emacs C source file.")
7533 ;; (anything 'anything-c-source-emacs-source-defun)
7535 (defvar anything-c-source-emacs-lisp-expectations
7536 '((name . "Emacs Lisp Expectations")
7537 (headline . "(desc[ ]\\|(expectations")
7538 (condition . (eq major-mode 'emacs-lisp-mode)))
7539 "Show descriptions (desc) in Emacs Lisp Expectations.
7541 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7542 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7544 (defvar anything-c-source-emacs-lisp-toplevels
7545 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7546 (headline . "^(\\|(@\\*\\|^;;;;")
7547 (get-line . buffer-substring)
7548 (condition . (eq major-mode 'emacs-lisp-mode))
7549 (adjust))
7550 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7551 linkd.el is optional because linkd stars are extracted by regexp.
7552 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7553 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7556 ;;; Anything yaoddmuse
7558 ;; Be sure to have yaoddmuse.el installed
7559 ;; install-elisp may be required if you want to install elisp file from here.
7560 (defvar anything-yaoddmuse-use-cache-file nil)
7561 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7562 (defvar anything-c-yaoddmuse-ew-cache nil)
7564 (defun anything-yaoddmuse-get-candidates ()
7565 (declare (special yaoddmuse-pages-hash))
7566 (if anything-yaoddmuse-use-cache-file
7567 (ignore-errors
7568 (unless anything-c-yaoddmuse-ew-cache
7569 (load anything-c-yaoddmuse-cache-file)
7570 (setq anything-c-yaoddmuse-ew-cache
7571 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7572 anything-c-yaoddmuse-ew-cache)
7573 (yaoddmuse-update-pagename t)
7574 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7576 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7577 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7578 (candidates . anything-yaoddmuse-get-candidates)
7579 (action . (("Edit page" . (lambda (candidate)
7580 (yaoddmuse-edit "EmacsWiki" candidate)))
7581 ("Browse page"
7582 . (lambda (candidate)
7583 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7584 ("Browse page other window"
7585 . (lambda (candidate)
7586 (if (one-window-p)
7587 (split-window-vertically))
7588 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7589 ("Browse diff"
7590 . (lambda (candidate)
7591 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7592 ("Copy URL"
7593 . (lambda (candidate)
7594 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7595 (message "Have copy page %s's URL to yank." candidate)))
7596 ("Create page"
7597 . (lambda (candidate)
7598 (yaoddmuse-edit "EmacsWiki" anything-input)))
7599 ("Update cache"
7600 . (lambda (candidate)
7601 (if anything-yaoddmuse-use-cache-file
7602 (progn
7603 (anything-yaoddmuse-cache-pages t)
7604 (setq anything-c-yaoddmuse-ew-cache
7605 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7606 (yaoddmuse-update-pagename))))))
7607 (action-transformer anything-c-yaoddmuse-action-transformer))
7608 "Needs yaoddmuse.el.
7610 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7612 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7614 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7615 '((name . "Yaoddmuse Post library (EmacsWiki)")
7616 (init . (anything-yaoddmuse-init))
7617 (candidates-in-buffer)
7618 (action . (("Post library and Browse"
7619 . (lambda (candidate)
7620 (yaoddmuse-post-file
7621 (find-library-name candidate)
7622 "EmacsWiki"
7623 (file-name-nondirectory (find-library-name candidate))
7624 nil t)))
7625 ("Post library"
7626 . (lambda (candidate)
7627 (yaoddmuse-post-file
7628 (find-library-name candidate)
7629 "EmacsWiki"
7630 (file-name-nondirectory
7631 (find-library-name candidate))))))))
7632 "Needs yaoddmuse.el.
7634 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7636 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7638 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7639 "Allow the use of `install-elisp' only on elisp files."
7640 (if (string-match "\.el$" candidate)
7641 (append actions '(("Install Elisp"
7642 . (lambda (elm)
7643 (install-elisp-from-emacswiki elm)))))
7644 actions))
7646 ;;;###autoload
7647 (defun anything-yaoddmuse-cache-pages (&optional load)
7648 "Fetch the list of files on emacswiki and create cache file.
7649 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7650 (interactive)
7651 (declare (special yaoddmuse-pages-hash))
7652 (yaoddmuse-update-pagename)
7653 (save-excursion
7654 (find-file anything-c-yaoddmuse-cache-file)
7655 (erase-buffer)
7656 (insert "(puthash \"EmacsWiki\" '(")
7657 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7659 (insert (concat "(\"" (car i) "\") ")))
7660 (insert ") yaoddmuse-pages-hash)\n")
7661 (save-buffer)
7662 (kill-buffer (current-buffer))
7663 (when (or current-prefix-arg
7664 load)
7665 (load anything-c-yaoddmuse-cache-file))))
7667 (defun anything-yaoddmuse-init ()
7668 "Init anything buffer status."
7669 (let ((anything-buffer (anything-candidate-buffer 'global))
7670 (library-list (yaoddmuse-get-library-list)))
7671 (with-current-buffer anything-buffer
7672 ;; Insert library name.
7673 (dolist (library library-list)
7674 (insert (format "%s\n" library)))
7675 ;; Sort lines.
7676 (sort-lines nil (point-min) (point-max)))))
7679 ;;; Eev anchors
7680 (defvar anything-c-source-eev-anchor
7681 '((name . "Anchors")
7682 (candidates
7683 . (lambda ()
7684 (ignore-errors
7685 (with-anything-current-buffer
7686 (loop initially (goto-char (point-min))
7687 while (re-search-forward
7688 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7689 for anchor = (match-string-no-properties 1)
7690 collect (cons (format "%5d:%s"
7691 (line-number-at-pos (match-beginning 0))
7692 (format ee-anchor-format anchor))
7693 anchor))))))
7694 (persistent-action . (lambda (item)
7695 (ee-to item)
7696 (anything-match-line-color-current-line)))
7697 (persistent-help . "Show this entry")
7698 (action . (("Goto link" . ee-to)))))
7699 ;; (anything 'anything-c-source-eev-anchor)
7702 ;;; Org headlines
7705 (defvar anything-c-source-org-headline
7706 `((name . "Org HeadLine")
7707 (headline
7708 ,@(mapcar
7709 (lambda (num)
7710 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7711 num))
7712 (number-sequence 1 8)))
7713 (condition . (eq major-mode 'org-mode))
7714 (migemo)
7715 (subexp . 1)
7716 (persistent-action . (lambda (elm)
7717 (anything-c-action-line-goto elm)
7718 (org-cycle)))
7719 (action-transformer
7720 . (lambda (actions candidate)
7721 '(("Go to Line" . anything-c-action-line-goto)
7722 ("Refile to this Headline" . anything-c-org-headline-refile)
7723 ("Insert Link to This Headline"
7724 . anything-c-org-headline-insert-link-to-headline)))))
7725 "Show Org headlines.
7726 org-mode is very very much extended text-mode/outline-mode.
7728 See (find-library \"org.el\")
7729 See http://orgmode.org for the latest version.")
7730 ;; (anything 'anything-c-source-org-headline)
7732 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7733 (insert
7734 (save-excursion
7735 (anything-goto-line (car lineno-and-content))
7736 (and (looking-at org-complex-heading-regexp)
7737 (org-make-link-string (concat "*" (match-string 4)))))))
7739 (defun anything-c-org-headline-refile (lineno-and-content)
7740 "Refile current org entry to LINENO-AND-CONTENT."
7741 (with-anything-current-buffer
7742 (org-cut-subtree)
7743 (anything-goto-line (car lineno-and-content))
7744 (org-end-of-subtree t t)
7745 (let ((org-yank-adjusted-subtrees t))
7746 (org-yank))))
7749 ;;; Org keywords
7752 (defvar anything-c-source-org-keywords
7753 '((name . "Org Keywords")
7754 (init . anything-c-org-keywords-init)
7755 (candidates . anything-c-org-keywords-candidates)
7756 (action . anything-c-org-keywords-insert)
7757 (persistent-action . anything-c-org-keywords-show-help)
7758 (persistent-help . "Show an example and info page to describe this keyword.")
7759 (keywords-examples)
7760 (keywords)))
7761 ;; (anything 'anything-c-source-org-keywords)
7763 (defvar anything-c-org-keywords-info-location
7764 '(("#+TITLE:" . "(org)Export options")
7765 ("#+AUTHOR:" . "(org)Export options")
7766 ("#+DATE:" . "(org)Export options")
7767 ("#+EMAIL:" . "(org)Export options")
7768 ("#+DESCRIPTION:" . "(org)Export options")
7769 ("#+KEYWORDS:" . "(org)Export options")
7770 ("#+LANGUAGE:" . "(org)Export options")
7771 ("#+TEXT:" . "(org)Export options")
7772 ("#+TEXT:" . "(org)Export options")
7773 ("#+OPTIONS:" . "(org)Export options")
7774 ("#+BIND:" . "(org)Export options")
7775 ("#+LINK_UP:" . "(org)Export options")
7776 ("#+LINK_HOME:" . "(org)Export options")
7777 ("#+LATEX_HEADER:" . "(org)Export options")
7778 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7779 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7780 ("#+INFOJS_OPT" . "(org)Javascript support")
7781 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7782 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7783 ("#+ORGTBL" . "(org)Radio tables")
7784 ("#+HTML:" . "(org)Quoting HTML tags")
7785 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7786 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7787 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7788 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7789 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7790 ("#+BEGIN_SRC" . "(org)Literal examples")
7791 ("#+CAPTION" . "(org)Tables in HTML export")
7792 ("#+LABEL" . "(org)Tables in LaTeX export")
7793 ("#+ATTR_HTML" . "(org)Links")
7794 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7796 (defun anything-c-org-keywords-init ()
7797 (unless (anything-attr 'keywords-examples)
7798 (require 'org)
7799 (anything-attrset 'keywords-examples
7800 (append
7801 (mapcar
7802 (lambda (x)
7803 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7804 (cons (match-string 2 x) (match-string 1 x)))
7805 (org-split-string (org-get-current-options) "\n"))
7806 (mapcar 'list org-additional-option-like-keywords)))
7807 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7809 (defun anything-c-org-keywords-candidates ()
7810 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7811 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7812 (anything-attr 'keywords)))
7814 (defun anything-c-org-keywords-insert (keyword)
7815 (cond ((and (string-match "BEGIN" keyword)
7816 (anything-region-active-p))
7817 (let ((beg (region-beginning))
7818 (end (region-end)))
7819 (goto-char end)
7820 (insert "\n#+" (replace-regexp-in-string
7821 "BEGIN" "END" keyword) "\n")
7822 (goto-char beg)
7823 (insert "#+" keyword " ")
7824 (save-excursion (insert "\n"))))
7825 ((string-match "BEGIN" keyword)
7826 (insert "#+" keyword " ")
7827 (save-excursion
7828 (insert "\n#+" (replace-regexp-in-string
7829 "BEGIN" "END" keyword) "\n")))
7830 (t (insert "#+" keyword " "))))
7832 (defun anything-c-org-keywords-show-help (keyword)
7833 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7834 "(org)In-buffer settings"))
7835 (search-forward (concat "#+" keyword) nil t)
7836 (anything-persistent-highlight-point)
7837 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7841 ;;; bbdb
7844 (defvar bbdb-records)
7845 (defvar bbdb-buffer-name)
7847 (defun anything-c-bbdb-candidates ()
7848 "Return a list of all names in the bbdb database. The format
7849 is \"Firstname Lastname\"."
7850 (mapcar (lambda (bbdb-record)
7851 (replace-regexp-in-string
7852 "\\s-+$" ""
7853 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7854 (bbdb-records)))
7856 (defun anything-c-bbdb-create-contact (actions candidate)
7857 "Action transformer that returns only an entry to add the
7858 current `anything-pattern' as new contact. All other actions are
7859 removed."
7860 (if (string= candidate "*Add to contacts*")
7861 '(("Add to contacts" . (lambda (actions)
7862 (bbdb-create-internal
7863 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7864 (read-from-minibuffer "Company: ")
7865 (read-from-minibuffer "Email: ")
7868 (read-from-minibuffer "Note: ")))))
7869 actions))
7871 (defun anything-c-bbdb-get-record (candidate)
7872 "Return record that match CANDIDATE."
7873 (bbdb candidate nil)
7874 (set-buffer "*BBDB*")
7875 (bbdb-current-record))
7877 (defvar anything-c-bbdb-name nil
7878 "Only for internal use.")
7880 (defvar anything-c-source-bbdb
7881 '((name . "BBDB")
7882 (candidates . anything-c-bbdb-candidates)
7883 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7884 ("View person's data" . anything-c-bbdb-view-person-action))
7885 (filtered-candidate-transformer . (lambda (candidates source)
7886 (setq anything-c-bbdb-name anything-pattern)
7887 (if (not candidates)
7888 (list "*Add to contacts*")
7889 candidates)))
7890 (action-transformer . (lambda (actions candidate)
7891 (anything-c-bbdb-create-contact actions candidate))))
7892 "Needs BBDB.
7894 http://bbdb.sourceforge.net/")
7895 ;; (anything 'anything-c-source-bbdb)
7897 (defun anything-c-bbdb-view-person-action (candidate)
7898 "View BBDB data of single CANDIDATE or marked candidates."
7899 (anything-aif (anything-marked-candidates)
7900 (let ((bbdb-append-records (length it)))
7901 (dolist (i it)
7902 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7903 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7905 (defun anything-c-bbdb-collect-mail-addresses ()
7906 "Return a list of all mail addresses of records in bbdb buffer."
7907 (with-current-buffer bbdb-buffer-name
7908 (loop for i in bbdb-records
7909 if (bbdb-record-net (car i))
7910 collect (bbdb-dwim-net-address (car i)))))
7912 (defun anything-c-bbdb-compose-mail (candidate)
7913 "Compose a mail with all records of bbdb buffer."
7914 (anything-c-bbdb-view-person-action candidate)
7915 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7916 (address-str (mapconcat 'identity address-list ",\n ")))
7917 (compose-mail address-str)))
7920 ;;; Evaluation Result
7923 ;; Internal
7924 (defvar anything-eldoc-active-minibuffers-list nil)
7926 (defvar anything-c-source-evaluation-result
7927 '((name . "Evaluation Result")
7928 (disable-shortcuts)
7929 (dummy)
7930 (multiline)
7931 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7932 (filtered-candidate-transformer . (lambda (candidates source)
7933 (list
7934 (condition-case nil
7935 (with-anything-current-buffer
7936 (pp-to-string
7937 (eval (read anything-pattern))))
7938 (error "Error")))))
7939 (action . (("Copy result to kill-ring" . (lambda (candidate)
7940 (with-current-buffer anything-buffer
7941 (let ((end (save-excursion
7942 (goto-char (point-max))
7943 (search-backward "\n")
7944 (point))))
7945 (kill-region (point) end)))))
7946 ("copy sexp to kill-ring" . (lambda (candidate)
7947 (kill-new anything-input)))))))
7948 ;; (anything 'anything-c-source-evaluation-result)
7950 (defun anything-eval-new-line-and-indent ()
7951 (interactive)
7952 (newline) (lisp-indent-line))
7954 (defun anything-eldoc-store-minibuffer ()
7955 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
7956 (with-selected-window (minibuffer-window)
7957 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
7959 (defun anything-eldoc-show-in-eval ()
7960 "Return eldoc in mode-line for current minibuffer input."
7961 (let ((buf (with-selected-window (minibuffer-window)
7962 (buffer-name))))
7963 (when (member buf anything-eldoc-active-minibuffers-list)
7964 (let* ((str-all (with-current-buffer buf
7965 (minibuffer-completion-contents)))
7966 (sym (when str-all
7967 (with-temp-buffer
7968 (insert str-all)
7969 (goto-char (point-max))
7970 (unless (looking-back ")\\|\"") (forward-char -1))
7971 (eldoc-current-symbol))))
7972 (info-fn (eldoc-fnsym-in-current-sexp))
7973 (doc (or (eldoc-get-var-docstring sym)
7974 (eldoc-get-fnsym-args-string
7975 (car info-fn) (cadr info-fn)))))
7976 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
7978 (defun anything-c-eldoc-show-in-mode-line (str)
7979 "Show string STR in mode-line."
7980 (save-window-excursion
7981 (with-current-buffer anything-buffer
7982 (let ((mode-line-format (concat " " str)))
7983 (force-mode-line-update)
7984 (sit-for anything-c-eldoc-show-in-mode-line-delay))
7985 (force-mode-line-update))))
7987 ;;; Calculation Result
7990 (defvar anything-c-source-calculation-result
7991 '((name . "Calculation Result")
7992 (dummy)
7993 (filtered-candidate-transformer . (lambda (candidates source)
7994 (list
7995 (condition-case nil
7996 (calc-eval anything-pattern)
7997 (error "error")))))
7998 (action ("Copy result to kill-ring" . kill-new))))
7999 ;; (anything 'anything-c-source-calculation-result)
8002 ;;; Google Suggestions
8005 ;; Internal
8006 (defvar anything-ggs-max-length-real-flag 0)
8007 (defvar anything-ggs-max-length-num-flag 0)
8009 (defun anything-c-google-suggest-fetch (input)
8010 "Fetch suggestions for INPUT from XML buffer.
8011 Return an alist with elements like (data . number_results)."
8012 (setq anything-ggs-max-length-real-flag 0
8013 anything-ggs-max-length-num-flag 0)
8014 (let ((request (concat anything-c-google-suggest-url
8015 (url-hexify-string input))))
8016 (flet ((fetch ()
8017 (loop
8018 with result-alist = (xml-get-children
8019 (car (xml-parse-region
8020 (point-min) (point-max)))
8021 'CompleteSuggestion)
8022 for i in result-alist
8023 for data = (cdr (caadr (assoc 'suggestion i)))
8024 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8025 for lqueries = (length (anything-c-ggs-set-number-result
8026 nqueries))
8027 for ldata = (length data)
8029 (progn
8030 (when (> ldata anything-ggs-max-length-real-flag)
8031 (setq anything-ggs-max-length-real-flag ldata))
8032 (when (> lqueries anything-ggs-max-length-num-flag)
8033 (setq anything-ggs-max-length-num-flag lqueries)))
8034 collect (cons data nqueries) into cont
8035 finally return cont)))
8036 (if anything-google-suggest-use-curl-p
8037 (with-temp-buffer
8038 (call-process "curl" nil t nil request)
8039 (fetch))
8040 (with-current-buffer
8041 (url-retrieve-synchronously request)
8042 (fetch))))))
8044 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8045 "Set candidates with result and number of google results found."
8046 (let ((suggestions
8047 (loop with suggested-results = (anything-c-google-suggest-fetch
8048 (or (and request-prefix
8049 (concat request-prefix " " anything-pattern))
8050 anything-pattern))
8051 for (real . numresult) in suggested-results
8052 ;; Prepare number of results with ","
8053 for fnumresult = (anything-c-ggs-set-number-result numresult)
8054 ;; Calculate number of spaces to add before fnumresult
8055 ;; if it is smaller than longest result
8056 ;; `anything-ggs-max-length-num-flag'.
8057 ;; e.g 1,234,567
8058 ;; 345,678
8059 ;; To be sure it is aligned properly.
8060 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8061 (- anything-ggs-max-length-num-flag (length fnumresult))
8063 ;; Add now the spaces before fnumresult.
8064 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8065 for interval = (- anything-ggs-max-length-real-flag (length real))
8066 for spaces = (make-string (+ 2 interval) ? )
8067 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8068 collect (cons display real))))
8069 (if (loop for (disp . dat) in suggestions
8070 thereis (equal dat anything-pattern))
8071 suggestions
8072 ;; if there is no suggestion exactly matching the input then
8073 ;; prepend a Search on Google item to the list
8074 (append
8075 suggestions
8076 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8077 anything-input))))))
8079 (defun anything-c-ggs-set-number-result (num)
8080 (if num
8081 (progn
8082 (and (numberp num) (setq num (number-to-string num)))
8083 (loop for i in (reverse (split-string num "" t))
8084 for count from 1
8085 append (list i) into C
8086 when (= count 3)
8087 append (list ",") into C
8088 and do (setq count 0)
8089 finally return
8090 (replace-regexp-in-string
8091 "^," "" (mapconcat 'identity (reverse C) ""))))
8092 "?"))
8094 (defvar anything-c-google-suggest-default-browser-function nil
8095 "*The browse url function you prefer to use with google suggest.
8096 When nil, use the first browser function available
8097 See `anything-browse-url-default-browser-alist'.")
8099 (defun anything-c-google-suggest-action (candidate)
8100 "Default action to jump to a google suggested candidate."
8101 (let ((arg (concat anything-c-google-suggest-search-url
8102 (url-hexify-string candidate))))
8103 (anything-aif anything-c-google-suggest-default-browser-function
8104 (funcall it arg)
8105 (anything-c-browse-url arg))))
8107 (defvar anything-c-google-suggest-default-function
8108 'anything-c-google-suggest-set-candidates
8109 "Default function to use in anything google suggest.")
8111 (defvar anything-c-source-google-suggest
8112 '((name . "Google Suggest")
8113 (candidates . (lambda ()
8114 (funcall anything-c-google-suggest-default-function)))
8115 (action . (("Google Search" . anything-c-google-suggest-action)))
8116 (volatile)
8117 (requires-pattern . 3)
8118 (delayed)))
8120 (defun anything-c-google-suggest-emacs-lisp ()
8121 "Try to emacs lisp complete with google suggestions."
8122 (anything-c-google-suggest-set-candidates "emacs lisp"))
8124 ;; (anything 'anything-c-source-google-suggest)
8126 ;;; Yahoo suggestions
8129 (defun anything-c-yahoo-suggest-fetch (input)
8130 "Fetch Yahoo suggestions for INPUT from XML buffer.
8131 Return an alist with elements like (data . number_results)."
8132 (let ((request (concat anything-c-yahoo-suggest-url
8133 (url-hexify-string input))))
8134 (flet ((fetch ()
8135 (loop
8136 with result-alist = (xml-get-children
8137 (car (xml-parse-region (point-min) (point-max)))
8138 'Result)
8139 for i in result-alist
8140 collect (caddr i))))
8141 (with-current-buffer
8142 (url-retrieve-synchronously request)
8143 (fetch)))))
8145 (defun anything-c-yahoo-suggest-set-candidates ()
8146 "Set candidates with Yahoo results found."
8147 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8148 (or suggestions
8149 (append
8150 suggestions
8151 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8152 anything-input))))))
8154 (defun anything-c-yahoo-suggest-action (candidate)
8155 "Default action to jump to a Yahoo suggested candidate."
8156 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8157 (url-hexify-string candidate))))
8159 (defvar anything-c-source-yahoo-suggest
8160 '((name . "Yahoo Suggest")
8161 (candidates . anything-c-yahoo-suggest-set-candidates)
8162 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8163 (volatile)
8164 (requires-pattern . 3)
8165 (delayed)))
8167 ;; (anything 'anything-c-source-yahoo-suggest)
8170 ;;; Web browser functions.
8173 (require 'browse-url)
8174 ;; If default setting of `w3m-command' is not
8175 ;; what you want you and you modify it, you will have to reeval
8176 ;; also `anything-browse-url-default-browser-alist'.
8177 (defvar w3m-command "/usr/bin/w3m")
8178 (defvar anything-c-home-url "http://www.google.fr"
8179 "*Default url to use as home url.")
8181 (defvar ac-browse-url-chromium-program "chromium-browser")
8182 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8183 (defvar anything-browse-url-default-browser-alist
8184 `((,w3m-command . w3m-browse-url)
8185 (,browse-url-firefox-program . browse-url-firefox)
8186 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8187 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8188 (,browse-url-kde-program . browse-url-kde)
8189 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8190 (,browse-url-mozilla-program . browse-url-mozilla)
8191 (,browse-url-galeon-program . browse-url-galeon)
8192 (,browse-url-netscape-program . browse-url-netscape)
8193 (,browse-url-mosaic-program . browse-url-mosaic)
8194 (,browse-url-xterm-program . browse-url-text-xterm))
8195 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8197 (defun* anything-c-generic-browser (url name &rest args)
8198 "Browse URL with NAME browser."
8199 (let ((proc (concat name " " url)))
8200 (message "Starting %s..." name)
8201 (apply 'start-process proc nil name
8202 (append args (list url)))
8203 (set-process-sentinel
8204 (get-process proc)
8205 #'(lambda (process event)
8206 (when (string= event "finished\n")
8207 (message "%s process %s" process event))))))
8209 (defun ac-browse-url-chromium (url)
8210 "Browse URL with google chrome browser."
8211 (interactive "sURL: ")
8212 (anything-c-generic-browser
8213 url ac-browse-url-chromium-program))
8215 (defun ac-browse-url-uzbl (url &optional ignore)
8216 "Browse URL with uzbl browser."
8217 (interactive "sURL: ")
8218 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8220 (defun anything-browse-url-default-browser (url &rest args)
8221 "Find the first available browser and ask it to load URL."
8222 (let ((default-browser-fn
8223 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8224 thereis (and exe (executable-find exe) fn))))
8225 (if default-browser-fn
8226 (apply default-browser-fn url args)
8227 (error "No usable browser found"))))
8229 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8230 "Default command to browse URL."
8231 (if browse-url-browser-function
8232 (browse-url url)
8233 (anything-browse-url-default-browser url)))
8236 ;;; Surfraw
8238 ;; Need external program surfraw.
8239 ;; <http://surfraw.alioth.debian.org/>
8241 (defvar anything-surfraw-default-browser-function nil
8242 "*The browse url function you prefer to use with surfraw.
8243 When nil, fallback to `browse-url-browser-function'.")
8245 ;; Internal
8246 (defvar anything-surfraw-engines-history nil)
8248 (defun anything-c-build-elvi-list ()
8249 "Return list of all engines and descriptions handled by surfraw."
8250 (cdr
8251 (with-temp-buffer
8252 (call-process "surfraw" nil t nil
8253 "-elvi")
8254 (split-string (buffer-string) "\n"))))
8257 ;;; Emms
8260 (defun anything-emms-stream-edit-bookmark (elm)
8261 "Change the information of current emms-stream bookmark from anything."
8262 (declare (special emms-stream-list))
8263 (let* ((cur-buf anything-current-buffer)
8264 (bookmark (assoc elm emms-stream-list))
8265 (name (read-from-minibuffer "Description: "
8266 (nth 0 bookmark)))
8267 (url (read-from-minibuffer "URL: "
8268 (nth 1 bookmark)))
8269 (fd (read-from-minibuffer "Feed Descriptor: "
8270 (int-to-string (nth 2 bookmark))))
8271 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8272 (format "%s" (car (last bookmark))))))
8273 (save-excursion
8274 (emms-streams)
8275 (when (re-search-forward (concat "^" name) nil t)
8276 (beginning-of-line)
8277 (emms-stream-delete-bookmark)
8278 (emms-stream-add-bookmark name url (string-to-number fd) type)
8279 (emms-stream-save-bookmarks-file)
8280 (emms-stream-quit)
8281 (anything-c-switch-to-buffer cur-buf)))))
8283 (defun anything-emms-stream-delete-bookmark (elm)
8284 "Delete an emms-stream bookmark from anything."
8285 (let* ((cur-buf anything-current-buffer)
8286 (bookmark (assoc elm emms-stream-list))
8287 (name (nth 0 bookmark)))
8288 (save-excursion
8289 (emms-streams)
8290 (when (re-search-forward (concat "^" name) nil t)
8291 (beginning-of-line)
8292 (emms-stream-delete-bookmark)
8293 (emms-stream-save-bookmarks-file)
8294 (emms-stream-quit)
8295 (anything-c-switch-to-buffer cur-buf)))))
8297 (defvar anything-c-source-emms-streams
8298 '((name . "Emms Streams")
8299 (init . (lambda ()
8300 (emms-stream-init)))
8301 (candidates . (lambda ()
8302 (declare (special emms-stream-list))
8303 (mapcar 'car emms-stream-list)))
8304 (action . (("Play" . (lambda (elm)
8305 (declare (special emms-stream-list))
8306 (let* ((stream (assoc elm emms-stream-list))
8307 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8308 (url (second stream)))
8309 (funcall fn url))))
8310 ("Delete" . anything-emms-stream-delete-bookmark)
8311 ("Edit" . anything-emms-stream-edit-bookmark)))
8312 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8313 ;; (anything 'anything-c-source-emms-streams)
8315 ;; Don't forget to set `emms-source-file-default-directory'
8316 (defvar anything-c-source-emms-dired
8317 '((name . "Music Directory")
8318 (candidates . (lambda ()
8319 (cddr (directory-files emms-source-file-default-directory))))
8320 (action .
8321 (("Play Directory" . (lambda (item)
8322 (emms-play-directory
8323 (expand-file-name
8324 item
8325 emms-source-file-default-directory))))
8326 ("Open dired in file's directory" . (lambda (item)
8327 (anything-c-open-dired
8328 (expand-file-name
8329 item
8330 emms-source-file-default-directory))))))
8331 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8332 ;; (anything 'anything-c-source-emms-dired)
8335 (defun anything-c-emms-files-modifier (candidates source)
8336 (let ((current-playlist (with-current-emms-playlist
8337 (loop
8338 with cur-list = (emms-playlist-tracks-in-region
8339 (point-min) (point-max))
8340 for i in cur-list
8341 collect (assoc-default 'name i)))))
8342 (loop for i in candidates
8343 if (member (cdr i) current-playlist)
8344 collect (cons (propertize (car i)
8345 'face 'anything-emms-playlist)
8346 (cdr i)) into lis
8347 else collect i into lis
8348 finally return lis)))
8350 (defun anything-c-emms-play-current-playlist ()
8351 "Play current playlist."
8352 (with-current-emms-playlist
8353 (emms-playlist-first)
8354 (emms-playlist-mode-play-smart)))
8356 (defvar anything-c-source-emms-files
8357 '((name . "Emms files")
8358 (candidates . (lambda ()
8359 (loop for v being the hash-values in emms-cache-db
8360 for name = (assoc-default 'name v)
8361 for artist = (or (assoc-default 'info-artist v) "unknown")
8362 for genre = (or (assoc-default 'info-genre v) "unknown")
8363 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8364 for song = (or (assoc-default 'info-title v) "unknown")
8365 for info = (concat artist " - " genre " - " tracknum ": " song)
8366 unless (string-match "^http:" name) collect (cons info name))))
8367 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8368 (action . (("Play file" . emms-play-file)
8369 ("Add to Playlist and play (C-u clear current)"
8370 . (lambda (candidate)
8371 (when anything-current-prefix-arg
8372 (emms-playlist-current-clear))
8373 (emms-playlist-new)
8374 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8375 (unless emms-player-playing-p
8376 (anything-c-emms-play-current-playlist))))))))
8378 ;; (anything 'anything-c-source-emms-files)
8381 ;;; Jabber Contacts (jabber.el)
8382 (defun anything-c-jabber-online-contacts ()
8383 "List online Jabber contacts."
8384 (with-no-warnings
8385 (let (jids)
8386 (dolist (item (jabber-concat-rosters) jids)
8387 (when (get item 'connected)
8388 (push (if (get item 'name)
8389 (cons (get item 'name) item)
8390 (cons (symbol-name item) item)) jids))))))
8392 (defvar anything-c-source-jabber-contacts
8393 '((name . "Jabber Contacts")
8394 (init . (lambda () (require 'jabber)))
8395 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8396 (action . (lambda (x)
8397 (jabber-chat-with
8398 (jabber-read-account)
8399 (symbol-name
8400 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8401 ;; (anything 'anything-c-source-jabber-contacts)
8405 ;;; Call source.
8406 (defvar anything-source-select-buffer "*anything source select*")
8407 (defvar anything-c-source-call-source
8408 `((name . "Call anything source")
8409 (candidate-number-limit)
8410 (candidates
8411 . (lambda ()
8412 (loop for vname in (all-completions "anything-c-source-" obarray)
8413 for var = (intern vname)
8414 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8415 if name collect
8416 (cons (format "%s `%s'"
8417 name (propertize vname 'face 'font-lock-variable-name-face))
8418 var))))
8419 (action
8420 . (("Invoke anything with selected source"
8422 (lambda (candidate)
8423 (setq anything-candidate-number-limit 9999)
8424 (anything candidate nil nil nil nil
8425 anything-source-select-buffer)))
8426 ("Describe variable" . describe-variable)
8427 ("Find variable" . find-variable)))
8428 (persistent-action . describe-variable)
8429 (persistent-help . "Show description of this source")))
8430 ;; (anything 'anything-c-source-call-source)
8432 (defun anything-call-source-from-anything ()
8433 "Call anything source within `anything' session."
8434 (interactive)
8435 (setq anything-input-idle-delay 0)
8436 (anything-set-sources '(anything-c-source-call-source)))
8438 ;;; Execute Preconfigured anything.
8439 (defvar anything-c-source-anything-commands
8440 '((name . "Preconfigured Anything")
8441 (candidates . anything-c-anything-commands-candidates)
8442 (type . command)
8443 (candidate-number-limit)))
8444 ;; (anything 'anything-c-source-anything-commands)
8446 (defun anything-c-anything-commands-candidates ()
8447 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8448 collect (cons (if (where-is-internal cmd nil t)
8449 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8450 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8451 cmd)))
8454 ;;; Occur
8457 (defun anything-c-occur-init ()
8458 "Create the initial anything occur buffer.
8459 If region is active use region as buffer contents
8460 instead of whole buffer."
8461 (with-current-buffer (anything-candidate-buffer 'global)
8462 (erase-buffer)
8463 (let ((buf-contents
8464 (with-anything-current-buffer
8465 (if (anything-region-active-p)
8466 (buffer-substring (region-beginning) (region-end))
8467 (buffer-substring (point-min) (point-max))))))
8468 (insert buf-contents))))
8470 (defun anything-c-occur-get-line (s e)
8471 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8473 (defun anything-c-occur-query-replace-regexp (candidate)
8474 "Query replace regexp starting from CANDIDATE.
8475 If region is active ignore CANDIDATE and replace only in region.
8476 With a prefix arg replace only matches surrounded by word boundaries,
8477 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8478 (let ((regexp anything-input))
8479 (unless (anything-region-active-p)
8480 (anything-c-action-line-goto candidate))
8481 (apply 'query-replace-regexp
8482 (anything-c-query-replace-args regexp))))
8484 (defvar anything-c-source-occur
8485 '((name . "Occur")
8486 (init . anything-c-occur-init)
8487 (candidates-in-buffer)
8488 (migemo)
8489 (get-line . anything-c-occur-get-line)
8490 (display-to-real . anything-c-display-to-real-line)
8491 (action . (("Go to Line" . anything-c-action-line-goto)
8492 ("Query replace regexp (C-u Not inside word.)"
8493 . anything-c-occur-query-replace-regexp)))
8494 (recenter)
8495 (requires-pattern . 1)
8496 (delayed)
8497 (volatile)))
8498 ;; (anything 'anything-c-source-occur)
8501 ;;; Anything browse code.
8502 (defun anything-c-browse-code-get-line (beg end)
8503 "Select line if it match the regexp corresponding to current `major-mode'.
8504 Line is parsed for BEG position to END position."
8505 (let ((str-line (buffer-substring beg end))
8506 (regexp (assoc-default major-mode
8507 anything-c-browse-code-regexp-alist))
8508 (num-line (if (string= anything-pattern "") beg (1- beg))))
8509 (when (and regexp (string-match regexp str-line))
8510 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8513 (defvar anything-c-source-browse-code
8514 '((name . "Browse code")
8515 (init . (lambda ()
8516 (anything-candidate-buffer anything-current-buffer)
8517 (with-anything-current-buffer
8518 (jit-lock-fontify-now))))
8519 (candidate-number-limit . 9999)
8520 (candidates-in-buffer)
8521 (get-line . anything-c-browse-code-get-line)
8522 (type . line)
8523 (recenter)))
8526 ;; Do many actions for input
8527 (defvar anything-c-source-create
8528 '((name . "Create")
8529 (dummy)
8530 (action)
8531 (action-transformer . anything-create--actions))
8532 "Do many create actions from `anything-pattern'.
8533 See also `anything-create--actions'.")
8534 ;; (anything 'anything-c-source-create)
8536 (defun anything-create-from-anything ()
8537 "Run `anything-create' from `anything' as a fallback."
8538 (interactive)
8539 (anything-run-after-quit 'anything-create nil anything-pattern))
8541 (defun anything-create--actions (&rest ignored)
8542 "Default actions for `anything-create' / `anything-c-source-create'."
8543 (remove-if-not
8544 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8545 (append anything-create--actions-private
8546 '(("find-file" . find-file)
8547 ("find-file other window" . find-file-other-window)
8548 ("New buffer" . anything-c-switch-to-buffer)
8549 ("New buffer other window" . switch-to-buffer-other-window)
8550 ("Bookmark Set" . bookmark-set)
8551 ("Set Register" .
8552 (lambda (x) (set-register (read-char "Register: ") x)))
8553 ("Insert Linkd star" . linkd-insert-star)
8554 ("Insert Linkd Tag" . linkd-insert-tag)
8555 ("Insert Linkd Link" . linkd-insert-link)
8556 ("Insert Linkd Lisp" . linkd-insert-lisp)
8557 ("Insert Linkd Wiki" . linkd-insert-wiki)
8558 ("Google Search" . google)))))
8561 ;; Minibuffer History
8564 (defvar anything-c-source-minibuffer-history
8565 '((name . "Minibuffer History")
8566 (header-name . (lambda (name)
8567 (format "%s (%s)" name minibuffer-history-variable)))
8568 (candidates
8569 . (lambda ()
8570 (let ((history (loop
8571 for i in (symbol-value minibuffer-history-variable)
8572 unless (string= "" i) collect i)))
8573 (if (consp (car history))
8574 (mapcar 'prin1-to-string history)
8575 history))))
8576 (migemo)
8577 (action . insert)))
8578 ;; (anything 'anything-c-source-minibuffer-history)
8581 ;;; Elscreen
8584 (defvar anything-c-source-elscreen
8585 '((name . "Elscreen")
8586 (candidates . (lambda ()
8587 (if (cdr (elscreen-get-screen-to-name-alist))
8588 (sort
8589 (loop for sname in (elscreen-get-screen-to-name-alist)
8590 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8591 finally (return lst))
8592 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8593 (action . (("Change Screen".
8594 (lambda (candidate)
8595 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8596 ("Kill Screen(s)".
8597 (lambda (candidate)
8598 (dolist (i (anything-marked-candidates))
8599 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8600 (elscreen-kill))))
8601 ("Only Screen".
8602 (lambda (candidate)
8603 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8604 (elscreen-kill-others)))))))
8605 ;; (anything 'anything-c-source-elscreen)
8608 ;;;; <System>
8610 ;;; Top (process)
8611 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8612 "Top command (batch mode). %s is replaced with `frame-width'.")
8613 (defvar anything-c-source-top
8614 '((name . "Top (Press C-c C-u to refresh)")
8615 (init . anything-c-top-init)
8616 (candidates-in-buffer)
8617 (display-to-real . anything-c-top-display-to-real)
8618 (update . anything-c-top-update)
8619 (persistent-action . anything-c-top-sh-persistent-action)
8620 (persistent-help . "SIGTERM")
8621 (action
8622 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8623 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8624 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8625 ;; (anything 'anything-c-source-top)
8627 (defun anything-c-top-sh (cmd)
8628 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8630 (defun anything-c-top-sh-persistent-action (pid)
8631 (delete-other-windows)
8632 (anything-c-top-sh (format "kill -TERM %s" pid))
8633 (anything-force-update))
8635 (defun anything-c-top-init ()
8636 (with-current-buffer (anything-candidate-buffer 'global)
8637 (call-process-shell-command
8638 (format anything-c-top-command
8639 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8640 nil (current-buffer))))
8642 (defun anything-c-top-display-to-real (line)
8643 (car (split-string line)))
8645 (defun anything-c-top-update ()
8646 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8647 (anything-c-top-init)))
8649 ;;; Timers
8650 (defvar anything-c-source-absolute-time-timers
8651 '((name . "Absolute Time Timers")
8652 (candidates . timer-list)
8653 (type . timer)))
8654 ;; (anything 'anything-c-source-absolute-time-timers)
8656 (defvar anything-c-source-idle-time-timers
8657 '((name . "Idle Time Timers")
8658 (candidates . timer-idle-list)
8659 (type . timer)))
8660 ;; (anything 'anything-c-source-idle-time-timers)
8662 (defun anything-c-timer-real-to-display (timer)
8663 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8664 (append timer nil) ;use `append' to convert vector->list
8665 (format "%s repeat=%5S %s(%s)"
8666 (let ((time (list t1 t2 t3)))
8667 (if idle-delay
8668 (format-time-string "idle-for=%5s" time)
8669 (format-time-string "%m/%d %T" time)))
8670 repeat-delay
8671 func
8672 (mapconcat 'prin1-to-string args " "))))
8674 ;;; X RandR resolution change
8675 ;;; FIXME I do not care multi-display.
8676 (defvar anything-c-xrandr-output "VGA")
8677 (defvar anything-c-xrandr-screen "0")
8678 (defvar anything-c-source-xrandr-change-resolution
8679 '((name . "Change Resolution")
8680 (candidates
8681 . (lambda ()
8682 (with-temp-buffer
8683 (call-process "xrandr" nil (current-buffer) nil
8684 "--screen" anything-c-xrandr-screen "-q")
8685 (goto-char 1)
8686 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8687 collect (match-string 1)))))
8688 (action
8689 ("Change Resolution" . (lambda (mode)
8690 (call-process "xrandr" nil nil nil
8691 "--screen" anything-c-xrandr-screen
8692 "--output" anything-c-xrandr-output
8693 "--mode" mode))))))
8694 ;; (anything 'anything-c-source-xrandr-change-resolution)
8696 ;;; Xfont selection
8699 (defun anything-c-persistent-xfont-action (elm)
8700 "Show current font temporarily"
8701 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8702 (default-font elm))
8703 (unwind-protect
8704 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8705 (set-frame-font current-font))))
8707 (defvar anything-c-xfonts-cache nil)
8708 (defvar anything-c-source-xfonts
8709 '((name . "X Fonts")
8710 (init . (lambda ()
8711 (unless anything-c-xfonts-cache
8712 (setq anything-c-xfonts-cache
8713 (x-list-fonts "*")))))
8714 (candidates . anything-c-xfonts-cache)
8715 (action . (("Copy to kill ring" . (lambda (elm)
8716 (kill-new elm)))
8717 ("Set Font" . (lambda (elm)
8718 (kill-new elm)
8719 (set-frame-font elm 'keep-size)
8720 (message "New font have been copied to kill ring")))))
8721 (persistent-action . anything-c-persistent-xfont-action)
8722 (persistent-help . "Switch to this font temporarily")))
8723 ;; (anything 'anything-c-source-xfonts)
8725 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8728 (defvar anything-c-ucs-max-len 0)
8729 (defun anything-c-calculate-ucs-max-len ()
8730 "Calculate the length of longest `ucs-names' candidate."
8731 (loop with count = 0
8732 for (n . v) in (ucs-names)
8733 for len = (length n)
8734 if (> len count)
8735 do (setq count len)
8736 finally return count))
8738 (defun anything-c-ucs-init ()
8739 "Initialize an anything buffer with ucs symbols.
8740 Only math* symbols are collected."
8741 (unless (> anything-c-ucs-max-len 0)
8742 (setq anything-c-ucs-max-len
8743 (anything-c-calculate-ucs-max-len)))
8744 (with-current-buffer (anything-candidate-buffer
8745 (get-buffer-create "*anything ucs*"))
8746 ;; `ucs-names' fn will not run again, data is cached in
8747 ;; var `ucs-names'.
8748 (loop for (n . v) in (ucs-names)
8749 for len = (length n)
8750 for diff = (+ (- anything-c-ucs-max-len len) 2)
8751 unless (string= "" n)
8752 do (progn (insert (concat
8753 n ":"
8754 (make-string
8755 diff ? )))
8756 (ucs-insert v)
8757 (insert "\n")))))
8759 (defun anything-c-ucs-forward-char (candidate)
8760 (with-anything-current-buffer
8761 (forward-char 1)))
8763 (defun anything-c-ucs-backward-char (candidate)
8764 (with-anything-current-buffer
8765 (forward-char -1)))
8767 (defun anything-c-ucs-delete-backward (candidate)
8768 (with-anything-current-buffer
8769 (delete-char -1)))
8771 (defun anything-c-ucs-insert-char (candidate)
8772 (with-anything-current-buffer
8773 (insert
8774 (replace-regexp-in-string
8775 " " ""
8776 (cadr (split-string candidate ":"))))))
8778 (defun anything-c-ucs-persistent-insert ()
8779 (interactive)
8780 (anything-execute-persistent-action 'action-insert))
8782 (defun anything-c-ucs-persistent-forward ()
8783 (interactive)
8784 (anything-execute-persistent-action 'action-forward))
8786 (defun anything-c-ucs-persistent-backward ()
8787 (interactive)
8788 (anything-execute-persistent-action 'action-back))
8790 (defun anything-c-ucs-persistent-delete ()
8791 (interactive)
8792 (anything-execute-persistent-action 'action-delete))
8794 (defvar anything-c-source-ucs
8795 '((name . "Ucs names")
8796 (init . anything-c-ucs-init)
8797 (candidate-number-limit . 9999)
8798 (candidates-in-buffer)
8799 (mode-line . anything-c-ucs-mode-line-string)
8800 (action-insert . anything-c-ucs-insert-char)
8801 (action-forward . anything-c-ucs-forward-char)
8802 (action-back . anything-c-ucs-backward-char)
8803 (action-delete . anything-c-ucs-delete-backward)
8804 (action . (("Insert" . anything-c-ucs-insert-char)
8805 ("Forward char" . anything-c-ucs-forward-char)
8806 ("Backward char" . anything-c-ucs-backward-char)
8807 ("Delete char backward" . anything-c-ucs-delete-backward))))
8808 "Source for collecting `ucs-names' math symbols.")
8811 ;;; Emacs process
8814 (defvar anything-c-source-emacs-process
8815 '((name . "Emacs Process")
8816 (candidates . (lambda () (mapcar #'process-name (process-list))))
8817 (persistent-action . (lambda (elm)
8818 (delete-process (get-process elm))
8819 (anything-delete-current-selection)))
8820 (persistent-help . "Kill Process")
8821 (action ("Kill Process" . (lambda (elm)
8822 (delete-process (get-process elm)))))))
8823 ;; (anything 'anything-c-source-emacs-process)
8825 ;;; World time
8828 (defvar anything-c-source-time-world
8829 '((name . "Time World List")
8830 (init . (lambda ()
8831 (let ((anything-buffer (anything-candidate-buffer 'global)))
8832 (with-current-buffer anything-buffer
8833 (display-time-world-display display-time-world-list)))))
8834 (candidates-in-buffer)))
8838 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8841 (defvar anything-c-source-apt
8842 '((name . "APT")
8843 (init . anything-c-apt-init)
8844 (candidates-in-buffer)
8845 (candidate-transformer anything-c-apt-candidate-transformer)
8846 (display-to-real . anything-c-apt-display-to-real)
8847 (requires-pattern . 2)
8848 (delayed)
8849 (action
8850 ("Show package description" . anything-c-apt-cache-show)
8851 ("Install package" . anything-c-apt-install)
8852 ("Remove package" . anything-c-apt-uninstall)
8853 ("Purge package" . anything-c-apt-purge))
8854 (persistent-action . anything-c-apt-persistent-action)
8855 (persistent-help . "Show - C-u Refresh")))
8856 ;; (anything 'anything-c-source-apt)
8858 (defvar anything-c-apt-query "emacs")
8859 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8860 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8861 (defvar anything-c-apt-installed-packages nil)
8862 (defvar anything-c-apt-all-packages nil)
8865 (defun anything-c-apt-refresh ()
8866 "Refresh installed candidates list."
8867 (setq anything-c-apt-installed-packages nil)
8868 (setq anything-c-apt-all-packages nil)
8869 (anything-force-update))
8871 (defun anything-c-apt-persistent-action (candidate)
8872 "Persistent action for APT source."
8873 (if current-prefix-arg
8874 (anything-c-apt-refresh)
8875 (anything-c-apt-cache-show candidate)))
8877 (defun anything-c-apt-candidate-transformer (candidates)
8878 "Show installed candidates in a different color."
8879 (loop
8880 with all
8881 for cand in candidates
8882 for name = (anything-c-apt-display-to-real cand)
8883 if (member name anything-c-apt-installed-packages)
8884 collect (propertize cand 'face 'anything-apt-installed) into all
8885 else collect cand into all finally return all))
8887 (defun anything-c-apt-init ()
8888 "Initialize list of debian packages."
8889 (let ((query ""))
8890 (unless (and anything-c-apt-installed-packages
8891 anything-c-apt-all-packages)
8892 (message "Loading package list...")
8893 (setq anything-c-apt-installed-packages
8894 (with-temp-buffer
8895 (call-process-shell-command "dpkg --get-selections"
8896 nil (current-buffer))
8897 (loop for i in (split-string (buffer-string) "\n" t)
8898 collect (car (split-string i)))))
8899 (setq anything-c-apt-all-packages
8900 (with-current-buffer
8901 (anything-candidate-buffer
8902 (get-buffer-create (format "*anything-apt*")))
8903 (erase-buffer)
8904 (call-process-shell-command
8905 (format anything-c-apt-search-command query)
8906 nil (current-buffer))))
8907 (message "Loading package list done")
8908 (sit-for 0.5))))
8910 (defun anything-c-apt-display-to-real (line)
8911 "Return only name of a debian package.
8912 LINE is displayed like:
8913 package name - description."
8914 (car (split-string line " - ")))
8916 (defun anything-c-shell-command-if-needed (command)
8917 "Run shell command COMMAND to describe package.
8918 If a buffer named COMMAND already exists, just switch to it."
8919 (let ((buf (get-buffer command)))
8920 (anything-c-switch-to-buffer (get-buffer-create command))
8921 (unless buf (insert (shell-command-to-string command)))))
8923 (defun anything-c-apt-cache-show (package)
8924 "Show information on apt package PACKAGE."
8925 (anything-c-shell-command-if-needed
8926 (format anything-c-apt-show-command package)))
8928 (defun anything-c-apt-install (package)
8929 "Run 'apt-get install' shell command on PACKAGE."
8930 (anything-c-apt-generic-action :action 'install))
8932 (defun anything-c-apt-uninstall (package)
8933 "Run 'apt-get remove' shell command on PACKAGE."
8934 (anything-c-apt-generic-action :action 'uninstall))
8936 (defun anything-c-apt-purge (package)
8937 "Run 'apt-get purge' shell command on PACKAGE."
8938 (anything-c-apt-generic-action :action 'purge))
8940 (defun* anything-c-apt-generic-action (&key action)
8941 "Run 'apt-get ACTION'.
8942 Support install, remove and purge actions."
8943 (ansi-term (getenv "SHELL") "anything apt")
8944 (term-line-mode)
8945 (let ((command (case action
8946 ('install "sudo apt-get install ")
8947 ('uninstall "sudo apt-get remove ")
8948 ('purge "sudo apt-get purge ")
8949 (t (error "Unknow action"))))
8950 (beg (point))
8952 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
8953 (anything-marked-candidates) " ")))
8954 (goto-char (point-max))
8955 (insert (concat command cand-list))
8956 (setq end (point))
8957 (if (y-or-n-p (format "%s package" (symbol-name action)))
8958 (progn
8959 (setq anything-c-external-commands-list nil)
8960 (setq anything-c-apt-installed-packages nil)
8961 (term-char-mode) (term-send-input))
8962 (delete-region beg end) (term-send-eof) (kill-buffer))))
8964 ;; (anything-c-apt-install "jed")
8967 ;;; Anything UI for gentoo portage.
8970 (defvar anything-c-gentoo-use-flags nil)
8971 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
8972 (defvar anything-c-cache-gentoo nil)
8973 (defvar anything-c-cache-world nil)
8974 (defvar anything-c-source-gentoo
8975 '((name . "Portage sources")
8976 (init . (lambda ()
8977 (get-buffer-create anything-c-gentoo-buffer)
8978 (unless anything-c-cache-gentoo
8979 (anything-c-gentoo-setup-cache))
8980 (unless anything-c-cache-world
8981 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
8982 (anything-c-gentoo-init-list)))
8983 (candidates-in-buffer)
8984 (match . identity)
8985 (candidate-transformer anything-c-highlight-world)
8986 (action . (("Show package" . (lambda (elm)
8987 (anything-c-gentoo-eshell-action elm "eix")))
8988 ("Show history" . (lambda (elm)
8989 (if (member elm anything-c-cache-world)
8990 (anything-c-gentoo-eshell-action elm "genlop -qe")
8991 (message "No infos on packages not yet installed"))))
8992 ("Copy in kill-ring" . kill-new)
8993 ("insert at point" . insert)
8994 ("Browse HomePage" . (lambda (elm)
8995 (let ((urls (anything-c-gentoo-get-url elm)))
8996 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
8997 ("Show extra infos" . (lambda (elm)
8998 (if (member elm anything-c-cache-world)
8999 (anything-c-gentoo-eshell-action elm "genlop -qi")
9000 (message "No infos on packages not yet installed"))))
9001 ("Show use flags" . (lambda (elm)
9002 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9003 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9004 (font-lock-mode 1)))
9005 ("Run emerge pretend" . (lambda (elm)
9006 (anything-c-gentoo-eshell-action elm "emerge -p")))
9007 ("Emerge" . (lambda (elm)
9008 (anything-gentoo-install elm :action 'install)))
9009 ("Unmerge" . (lambda (elm)
9010 (anything-gentoo-install elm :action 'uninstall)))
9011 ("Show dependencies" . (lambda (elm)
9012 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9013 ("Show related files" . (lambda (elm)
9014 (anything-c-gentoo-default-action elm "equery" "files")))
9015 ("Refresh" . (lambda (elm)
9016 (anything-c-gentoo-setup-cache)
9017 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9019 ;; (anything 'anything-c-source-gentoo)
9021 (defun* anything-gentoo-install (candidate &key action)
9022 (setq anything-c-external-commands-list nil)
9023 (ansi-term (getenv "SHELL") "Gentoo emerge")
9024 (term-line-mode)
9025 (let ((command (case action
9026 ('install "sudo emerge -av ")
9027 ('uninstall "sudo emerge -avC ")
9028 (t (error "Unknow action"))))
9029 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9030 (beg (point)) end)
9031 (goto-char (point-max))
9032 (insert (concat command elms))
9033 (setq end (point))
9034 (term-char-mode) (term-send-input)))
9036 (defun anything-c-gentoo-default-action (elm command &rest args)
9037 "Gentoo default action that use `anything-c-gentoo-buffer'."
9038 (if (member elm anything-c-cache-world)
9039 (progn
9040 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9041 (erase-buffer)
9042 (let ((com-list (append args (list elm))))
9043 (apply #'call-process command nil t nil
9044 com-list)))
9045 (message "No infos on packages not yet installed")))
9047 (defvar anything-c-source-use-flags
9048 '((name . "Use Flags")
9049 (init . (lambda ()
9050 (unless anything-c-gentoo-use-flags
9051 (anything-c-gentoo-setup-use-flags-cache))
9052 (anything-c-gentoo-get-use)))
9053 (candidates-in-buffer)
9054 (match . identity)
9055 (candidate-transformer anything-c-highlight-local-use)
9056 (action . (("Description"
9057 . (lambda (elm)
9058 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9059 (erase-buffer)
9060 (apply #'call-process "euse" nil t nil
9061 `("-i"
9062 ,elm))
9063 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9064 (font-lock-mode 1)))
9065 ("Enable"
9066 . (lambda (elm)
9067 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9068 ("Disable"
9069 . (lambda (elm)
9070 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9071 ("Remove"
9072 . (lambda (elm)
9073 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9074 ("Show which dep use this flag"
9075 . (lambda (elm)
9076 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9077 (erase-buffer)
9078 (apply #'call-process "equery" nil t nil
9079 `("-C"
9081 ,elm))))))))
9084 ;; (anything 'anything-c-source-use-flags)
9086 (defun anything-c-gentoo-init-list ()
9087 "Initialize buffer with all packages in Portage."
9088 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9089 (buf (anything-candidate-buffer 'portage-buf)))
9090 (with-current-buffer buf
9091 (dolist (i anything-c-cache-gentoo)
9092 (insert (concat i "\n"))))))
9094 (defun anything-c-gentoo-setup-cache ()
9095 "Set up `anything-c-cache-gentoo'"
9096 (setq anything-c-cache-gentoo
9097 (split-string (with-temp-buffer
9098 (call-process "eix" nil t nil
9099 "--only-names")
9100 (buffer-string)))))
9102 (defun anything-c-gentoo-eshell-action (elm command)
9103 (when (get-buffer "*EShell Command Output*")
9104 (kill-buffer "*EShell Command Output*"))
9105 (message "Wait searching...")
9106 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9107 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9108 (progn
9109 (save-window-excursion
9110 (pop-to-buffer "*scratch*")
9111 (eshell-command (format "%s %s" command elm)))
9112 (pop-to-buffer "*EShell Command Output*"))
9113 (eshell-command (format "%s %s" command elm)))))
9115 (defun anything-c-gentoo-get-use ()
9116 "Initialize buffer with all use flags."
9117 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9118 (buf (anything-candidate-buffer 'use-buf)))
9119 (with-current-buffer buf
9120 (dolist (i anything-c-gentoo-use-flags)
9121 (insert (concat i "\n"))))))
9124 (defun anything-c-gentoo-setup-use-flags-cache ()
9125 "Setup `anything-c-gentoo-use-flags'"
9126 (setq anything-c-gentoo-use-flags
9127 (split-string (with-temp-buffer
9128 (call-process "eix" nil t nil
9129 "--print-all-useflags")
9130 (buffer-string)))))
9132 (defun anything-c-gentoo-get-url (elm)
9133 "Return a list of urls from eix output."
9134 (loop
9135 with url-list = (split-string
9136 (with-temp-buffer
9137 (call-process "eix" nil t nil
9138 elm "--format" "<homepage>\n")
9139 (buffer-string)))
9140 with all
9141 for i in url-list
9142 when (and (string-match "^http://.*" i)
9143 (not (member i all)))
9144 collect i into all
9145 finally return all))
9147 (defun anything-c-gentoo-get-world ()
9148 "Return list of all installed package on your system."
9149 (split-string (with-temp-buffer
9150 (call-process "qlist" nil t nil
9151 "-I")
9152 (buffer-string))))
9154 (defun anything-c-gentoo-get-local-use ()
9155 (split-string (with-temp-buffer
9156 (call-process "portageq" nil t nil
9157 "envvar"
9158 "USE")
9159 (buffer-string))))
9162 (defun anything-c-highlight-world (eix)
9163 "Highlight all installed package."
9164 (loop for i in eix
9165 if (member i anything-c-cache-world)
9166 collect (propertize i 'face 'anything-gentoo-match-face)
9167 else
9168 collect i))
9170 (defun anything-c-highlight-local-use (use-flags)
9171 (let ((local-uses (anything-c-gentoo-get-local-use)))
9172 (loop for i in use-flags
9173 if (member i local-uses)
9174 collect (propertize i 'face 'anything-gentoo-match-face)
9175 else
9176 collect i)))
9180 ;;; Anything ratpoison UI
9183 (defvar anything-c-source-ratpoison-commands
9184 '((name . "Ratpoison Commands")
9185 (init . anything-c-ratpoison-commands-init)
9186 (candidates-in-buffer)
9187 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9188 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9189 (candidate-number-limit)))
9190 ;; (anything 'anything-c-source-ratpoison-commands)
9192 (defun anything-c-ratpoison-commands-init ()
9193 (unless (anything-candidate-buffer)
9194 (with-current-buffer (anything-candidate-buffer 'global)
9195 ;; with ratpoison prefix key
9196 (save-excursion
9197 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9198 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9199 (replace-match "<ratpoison> \\1: \\2"))
9200 (goto-char (point-max))
9201 ;; direct binding
9202 (save-excursion
9203 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9204 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9205 (replace-match "\\1: \\2")))))
9207 (defun anything-c-ratpoison-commands-display-to-real (display)
9208 (and (string-match ": " display)
9209 (substring display (match-end 0))))
9211 (defun anything-c-ratpoison-commands-execute (candidate)
9212 (call-process "ratpoison" nil nil nil "-ic" candidate))
9216 ;;; Anything `completing-read' replacement
9219 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9220 "Convert COLLECTION to list removing elements that don't match TEST.
9221 See `anything-comp-read' about supported COLLECTION arguments.
9223 SORT-FN is a predicate to sort COLLECTION.
9225 ALISTP when non--nil will not use `all-completions' to collect
9226 candidates because it doesn't handle alists correctly for anything.
9227 i.e In `all-completions' the keys \(cars of elements\)
9228 are the possible completions. In anything we want to use the cdr instead
9229 like \(display . real\).
9230 See docstring of `all-completions' for more info.
9232 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9233 (let ((cands
9234 (cond ((and (eq collection obarray) test)
9235 (all-completions "" collection test))
9236 ((and (vectorp collection) test)
9237 (loop for i across collection when (funcall test i) collect i))
9238 ((vectorp collection)
9239 (loop for i across collection collect i))
9240 ((and alistp test)
9241 (loop for i in collection when (funcall test i) collect i))
9242 (alistp collection)
9243 ((and collection test)
9244 (all-completions "" collection test))
9245 (t (all-completions "" collection)))))
9246 (if sort-fn (sort cands sort-fn) cands)))
9248 (defun anything-cr-default-transformer (candidates source)
9249 "Default filter candidate function for `anything-comp-read'.
9250 Do nothing, just return candidate list unmodified."
9251 candidates)
9253 (defun* anything-comp-read (prompt collection
9254 &key
9255 test
9256 initial-input
9257 default
9258 preselect
9259 (buffer "*Anything Completions*")
9260 must-match
9261 (requires-pattern 0)
9262 (history nil)
9263 (persistent-action nil)
9264 (persistent-help "DoNothing")
9265 (name "Anything Completions")
9266 (volatile t)
9267 sort
9268 (fc-transformer 'anything-cr-default-transformer)
9269 (marked-candidates nil)
9270 (alistp t))
9271 "Anything `completing-read' emulation.
9272 PROMPT is the prompt name to use.
9273 COLLECTION can be a list, vector, obarray or hash-table.
9274 It can be also a function that receives three arguments:
9275 the values string, predicate and t. See `all-completions' for more details.
9277 Keys description:
9279 TEST: A predicate called with one arg i.e candidate.
9280 INITIAL-INPUT: Same as initial-input arg in `anything'.
9281 PRESELECT: See preselect arg of `anything'.
9282 DEFAULT: This option is used only for compatibility with regular
9283 Emacs `completing-read'.
9284 BUFFER: Name of anything-buffer.
9285 MUST-MATCH: Candidate selected must be one of COLLECTION.
9286 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9287 HISTORY: A list containing specific history, default is nil.
9288 When it is non--nil, all elements of HISTORY are displayed in
9289 a special source before COLLECTION.
9290 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9291 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9292 NAME: The name related to this local source.
9293 VOLATILE: Use volatile attribute \(enabled by default\).
9294 SORT: A predicate to give to `sort' e.g `string-lessp'.
9295 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9296 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9297 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9299 Any prefix args passed during `anything-comp-read' invocation will be recorded
9300 in `anything-current-prefix-arg', otherwise if prefix args where given before
9301 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9302 That's mean you can pass prefix args before or after calling a command
9303 that use `anything-comp-read' See `anything-M-x' for example."
9304 (when (get-buffer anything-action-buffer)
9305 (kill-buffer anything-action-buffer))
9306 (flet ((action-fn (candidate)
9307 (if marked-candidates
9308 (anything-marked-candidates)
9309 (identity candidate))))
9310 (let ((hist `((name . ,(format "%s History" name))
9311 (candidates
9312 . (lambda ()
9313 (let ((all (anything-comp-read-get-candidates
9314 history nil nil ,alistp)))
9315 (anything-fast-remove-dups
9316 (if (and default (not (string= default "")))
9317 (delq nil (cons default (delete default all)))
9318 all)
9319 :test 'equal))))
9320 (filtered-candidate-transformer
9321 . (lambda (candidates sources)
9322 (loop for i in candidates
9323 do (set-text-properties 0 (length i) nil i)
9324 collect i)))
9325 (persistent-action . ,persistent-action)
9326 (persistent-help . ,persistent-help)
9327 (action . ,'action-fn)))
9328 (src `((name . ,name)
9329 (candidates
9330 . (lambda ()
9331 (let ((cands (anything-comp-read-get-candidates
9332 collection test sort alistp)))
9333 (unless (or must-match (string= anything-pattern ""))
9334 (setq cands (append (list anything-pattern) cands)))
9335 (if (and default (not (string= default "")))
9336 (delq nil (cons default (delete default cands)))
9337 cands))))
9338 (filtered-candidate-transformer ,fc-transformer)
9339 (requires-pattern . ,requires-pattern)
9340 (persistent-action . ,persistent-action)
9341 (persistent-help . ,persistent-help)
9342 (action . ,'action-fn))))
9343 (when volatile (setq src (append src '((volatile)))))
9344 (or (anything
9345 :sources `(,hist ,src)
9346 :input initial-input
9347 :default default
9348 :preselect preselect
9349 :prompt prompt
9350 :resume 'noresume
9351 :buffer buffer)
9352 (keyboard-quit)))))
9354 ;; Generic completing-read
9356 ;; Support also function as collection.
9357 ;; e.g M-x man is supported.
9358 ;; Support hash-table and vectors as collection.
9359 ;; NOTE:
9360 ;; Some crap emacs functions may not be supported
9361 ;; like ffap-alternate-file (bad use of completing-read)
9362 ;; and maybe others.
9363 ;; Provide a mode `anything-completion-mode' which turn on
9364 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9366 (defvar anything-completion-mode-string " AC")
9368 (defvar anything-completion-mode-quit-message
9369 "Anything completion disabled")
9371 (defvar anything-completion-mode-start-message
9372 "Anything completion enabled")
9374 ;;; Specialized handlers
9377 (defun anything-completing-read-symbols
9378 (prompt collection test require-match init
9379 hist default inherit-input-method name buffer)
9380 "Specialized function for fast symbols completion in `ac-mode'."
9382 (anything
9383 :sources `((name . ,name)
9384 (init . (lambda ()
9385 (with-current-buffer (anything-candidate-buffer 'global)
9386 (goto-char (point-min))
9387 (when (and default (stringp default)
9388 ;; Some defaults args result as
9389 ;; (symbol-name nil) == "nil".
9390 ;; e.g debug-on-entry.
9391 (not (string= default "nil")))
9392 (insert (concat default "\n")))
9393 (loop with all = (all-completions "" collection test)
9394 for sym in all
9395 unless (and default (eq sym default))
9396 do (insert (concat sym "\n"))))))
9397 (persistent-action . anything-lisp-completion-persistent-action)
9398 (persistent-help . "Show brief doc in mode-line")
9399 (candidates-in-buffer)
9400 (action . identity))
9401 :prompt prompt
9402 :buffer buffer
9403 :input init
9404 :resume 'noresume
9405 :default (or default ""))
9406 (keyboard-quit)))
9409 ;;; Generic completing read
9412 (defun anything-completing-read-default-1
9413 (prompt collection test require-match
9414 init hist default inherit-input-method
9415 name buffer)
9416 (anything-comp-read
9417 prompt collection
9418 :test test
9419 :fc-transformer #'(lambda (candidates source)
9420 ;; In regular `completing-read'
9421 ;; when a candidate is a cons cell
9422 ;; the car is used. Anything use
9423 ;; normally the cdr, so modify that
9424 ;; to fit `completing-read'.
9425 (loop for i in candidates
9426 for cand = (if (consp i) (car i) i)
9427 do (set-text-properties 0 (length cand) nil cand)
9428 collect cand))
9429 :history (eval (or (car-safe hist) hist))
9430 :must-match require-match
9431 :alistp nil
9432 :name name
9433 :buffer buffer
9434 ;; If DEF is not provided, fallback to empty string
9435 ;; to avoid `thing-at-point' to be appended on top of list
9436 :default (or default "")
9437 :initial-input init))
9439 (defun* anything-completing-read-default
9440 (prompt collection &optional
9441 predicate require-match
9442 initial-input hist def
9443 inherit-input-method)
9444 "An anything replacement of `completing-read'.
9445 This function should be used only as a `completing-read-function'.
9447 Don't use it directly, use instead `anything-comp-read' in your programs \
9448 which is more powerful.
9450 See documentation of `completing-read' and `all-completions' for details."
9451 (declare (special anything-completion-mode))
9452 (let* ((current-command this-command)
9453 (str-command (symbol-name current-command))
9454 (buf-name (format "*ac-mode-%s*" str-command))
9455 (entry (assq current-command
9456 anything-completing-read-handlers-alist))
9457 (def-com (cdr-safe entry))
9458 (str-defcom (and def-com (symbol-name def-com)))
9459 (def-args (list prompt collection predicate require-match
9460 initial-input hist def inherit-input-method))
9461 ;; Append the two extra args needed to set the buffer and source name
9462 ;; in anything specialized functions.
9463 (any-args (append def-args (list str-command buf-name)))
9464 anything-completion-mode-start-message ; Be quiet
9465 anything-completion-mode-quit-message)
9466 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9467 (unless (or (not entry) def-com)
9468 ;; An entry in *read-handlers-alist exists but have
9469 ;; a nil value, so we exit from here, disable `ac-mode'
9470 ;; and run the command again with it original behavior.
9471 ;; `ac-mode' will be restored on exit.
9472 (return-from anything-completing-read-default
9473 (unwind-protect
9474 (progn
9475 (ac-mode -1)
9476 (call-interactively current-command))
9477 (ac-mode 1))))
9478 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9479 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9480 (when (or (eq def-com 'completing-read)
9481 ;; All specialized functions are prefixed by "anything"
9482 (and (stringp str-defcom)
9483 (not (string-match "^anything" str-defcom))))
9484 (ac-mode -1))
9485 (unwind-protect
9486 (cond (;; An anything specialized function exists, run it.
9487 (and def-com anything-completion-mode)
9488 (apply def-com any-args))
9489 (;; Try to handle `ido-completing-read' everywhere.
9490 (and def-com (eq def-com 'ido-completing-read))
9491 (setcar (memq collection def-args)
9492 (all-completions "" collection predicate))
9493 (apply def-com def-args))
9494 (;; User set explicitely `completing-read' or something similar
9495 ;; in *read-handlers-alist, use this with exactly the same
9496 ;; args as in `completing-read'.
9497 ;; If we are here `anything-completion-mode' is now disabled.
9498 def-com
9499 (apply def-com def-args))
9500 (t ; Fall back to classic `anything-comp-read'.
9501 (anything-completing-read-default-1
9502 prompt collection predicate require-match
9503 initial-input hist def inherit-input-method str-command buf-name)))
9504 (ac-mode 1))))
9506 (defun* anything-generic-read-file-name
9507 (prompt &optional dir default-filename mustmatch initial predicate)
9508 "An anything replacement of `read-file-name'."
9509 (declare (special anything-completion-mode))
9510 (let* ((default (and default-filename
9511 (if (listp default-filename)
9512 (car default-filename)
9513 default-filename)))
9514 (init (or default initial dir default-directory))
9515 (ini-input (and init (expand-file-name init)))
9516 (anything-ff-auto-update-flag nil)
9517 (current-command this-command)
9518 (str-command (symbol-name current-command))
9519 (buf-name (format "*ac-mode-%s*" str-command))
9520 (entry (assq current-command
9521 anything-completing-read-handlers-alist))
9522 (def-com (cdr-safe entry))
9523 (str-defcom (symbol-name def-com))
9524 (def-args (list prompt dir default-filename mustmatch initial predicate))
9525 ;; Append the two extra args needed to set the buffer and source name
9526 ;; in anything specialized functions.
9527 (any-args (append def-args (list str-command buf-name)))
9528 (ido-state ido-mode)
9529 anything-completion-mode-start-message ; Be quiet
9530 anything-completion-mode-quit-message ; Same here
9531 fname)
9532 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9533 (unless (or (not entry) def-com)
9534 (return-from anything-completing-read-default
9535 (unwind-protect
9536 (progn
9537 (ac-mode -1)
9538 (call-interactively current-command))
9539 (ac-mode 1))))
9540 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9541 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9542 (when (or (eq def-com 'read-file-name)
9543 (eq def-com 'ido-read-file-name)
9544 (and (stringp str-defcom)
9545 (not (string-match "^anything" str-defcom))))
9546 (ac-mode -1))
9547 (unwind-protect
9548 (setq fname
9549 (cond (;; A specialized function exists, run it
9550 ;; with the two extra args specific to anything..
9551 (and def-com anything-completion-mode
9552 (not (eq def-com 'ido-read-file-name)))
9553 (apply def-com any-args))
9554 (;; Def-com value is `ido-read-file-name'
9555 ;; run it with default args.
9556 (and def-com (eq def-com 'ido-read-file-name))
9557 (ido-mode 1)
9558 (apply def-com def-args))
9559 (;; Def-com value is `read-file-name'
9560 ;; run it with default args.
9561 def-com
9562 (apply def-com def-args))
9563 (t ; Fall back to classic `anything-c-read-file-name'.
9564 (anything-c-read-file-name
9565 prompt
9566 :name str-command
9567 :buffer buf-name
9568 :initial-input (expand-file-name init dir)
9569 :alistp nil
9570 :test predicate))))
9571 (ac-mode 1)
9572 (ido-mode (if ido-state 1 -1)))
9573 (if (and mustmatch (not (file-exists-p fname)))
9574 (if (y-or-n-p "File does not exists, create buffer?")
9575 fname (error "Abort file does not exists"))
9576 fname)))
9578 ;;;###autoload
9579 (define-minor-mode anything-completion-mode
9580 "Toggle generic anything completion.
9582 All functions in Emacs that use `completing-read'
9583 or `read-file-name' and friends will use anything interface
9584 when this mode is turned on.
9585 However you can modify this behavior for functions of your choice
9586 with `anything-completing-read-handlers-alist'.
9588 Called with a positive arg, turn on inconditionnaly, with a
9589 negative arg turn off.
9590 You can turn it on with `ac-mode'.
9592 Some crap emacs functions may not be supported,
9593 e.g `ffap-alternate-file' and maybe others
9594 You can add such functions to `anything-completing-read-handlers-alist'
9595 with a nil value.
9597 Note: This mode will work only partially on Emacs23."
9598 :group 'anything
9599 :global t
9600 :lighter anything-completion-mode-string
9601 (declare (special completing-read-function))
9602 (if anything-completion-mode
9603 (progn
9604 (setq completing-read-function 'anything-completing-read-default
9605 read-file-name-function 'anything-generic-read-file-name)
9606 (message anything-completion-mode-start-message))
9607 (setq completing-read-function (and (fboundp 'completing-read-default)
9608 'completing-read-default)
9609 read-file-name-function (and (fboundp 'read-file-name-default)
9610 'read-file-name-default))
9611 (message anything-completion-mode-quit-message)))
9613 (defalias 'ac-mode 'anything-completion-mode)
9617 ;;; Eshell completion.
9619 ;; Enable like this in .emacs:
9621 ;; (add-hook 'eshell-mode-hook
9622 ;; #'(lambda ()
9623 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9625 (defvar anything-c-source-esh
9626 '((name . "Eshell completions")
9627 (init . (lambda ()
9628 (setq pcomplete-current-completions nil
9629 pcomplete-last-completion-raw nil)
9630 ;; Eshell-command add this hook in all minibuffers
9631 ;; Remove it for the anything one.
9632 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9633 (candidates . anything-esh-get-candidates)
9634 (action . anything-ec-insert))
9635 "Anything source for Eshell completion.")
9637 ;; Internal.
9638 (defvar anything-ec-target "")
9639 (defun anything-ec-insert (candidate)
9640 "Insert CANDIDATE at point.
9641 This is the same as `ac-insert', just inlined here for compatibility."
9642 (let ((pt (point)))
9643 (when (and anything-ec-target
9644 (search-backward anything-ec-target nil t)
9645 (string= (buffer-substring (point) pt) anything-ec-target))
9646 (delete-region (point) pt)))
9647 (insert candidate))
9649 (defun anything-esh-get-candidates ()
9650 "Get candidates for eshell completion using `pcomplete'."
9651 (catch 'pcompleted
9652 (let* ((pcomplete-stub)
9653 pcomplete-seen pcomplete-norm-func
9654 pcomplete-args pcomplete-last pcomplete-index
9655 (pcomplete-autolist pcomplete-autolist)
9656 (pcomplete-suffix-list pcomplete-suffix-list))
9657 (with-anything-current-buffer
9658 (loop
9659 with table = (pcomplete-completions)
9660 with entry = (condition-case nil
9661 ;; For Emacs24
9662 (funcall (pcomplete-entries) anything-pattern nil nil)
9663 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9664 (error
9666 (let ((fc (car (last (pcomplete-parse-arguments)))))
9667 ;; Check if last arg require fname completion.
9668 (and (file-name-directory fc) fc))))
9669 for i in (if (listp table) table ; Emacs23 or commands.
9670 (all-completions pcomplete-stub table)) ; Emacs24
9671 for file-cand = (and entry
9672 (if (file-remote-p i) i
9673 (expand-file-name i (file-name-directory entry))))
9674 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9675 collect file-cand into ls
9676 else collect i into ls
9677 finally return
9678 (if (and entry (not (string= entry "")) (file-exists-p entry))
9679 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9681 ;;; Eshell history.
9684 (defvar anything-c-source-eshell-history
9685 '((name . "Eshell history")
9686 (init . (lambda ()
9687 (eshell-write-history eshell-history-file-name t)
9688 (with-current-buffer (anything-candidate-buffer 'global)
9689 (insert-file-contents eshell-history-file-name))
9690 ;; Same comment as in `anything-c-source-esh'
9691 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9692 (candidates-in-buffer)
9693 (filtered-candidate-transformer . (lambda (candidates sources)
9694 (reverse candidates)))
9695 (candidate-number-limit . 9999)
9696 (action . (lambda (candidate)
9697 (eshell-kill-input)
9698 (insert candidate))))
9699 "Anything source for Eshell history.")
9702 ;;; Show completion - an alternative of anything-show-completion.el.
9704 ;; Provide show completion with macro `with-anything-show-completion'.
9707 ;; Called each time cursor move in anything-buffer.
9708 (defun anything-c-show-completion ()
9709 (with-anything-current-buffer
9710 (overlay-put anything-c-show-completion-overlay
9711 'display (anything-get-selection))))
9713 (defun anything-c-show-completion-init-overlay (beg end)
9714 (and anything-c-turn-on-show-completion
9715 (setq anything-c-show-completion-overlay (make-overlay beg end))
9716 (overlay-put anything-c-show-completion-overlay
9717 'face 'anything-lisp-show-completion)))
9719 (defmacro with-anything-show-completion (beg end &rest body)
9720 "Show anything candidate in an overlay at point.
9721 BEG and END are the beginning and end position of the current completion
9722 in `anything-current-buffer'.
9723 BODY is an anything call where we want to enable show completion.
9724 If `anything-c-turn-on-show-completion' is nil just do nothing."
9725 (declare (indent 2) (debug t))
9726 `(let ((anything-move-selection-after-hook
9727 (and anything-c-turn-on-show-completion
9728 (append (list 'anything-c-show-completion)
9729 anything-move-selection-after-hook))))
9730 (unwind-protect
9731 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9732 ,@body)
9733 (and anything-c-turn-on-show-completion
9734 (delete-overlay anything-c-show-completion-overlay)))))
9737 ;;; Lisp symbol completion.
9740 ;;;###autoload
9741 (defun anything-lisp-completion-at-point ()
9742 "Anything lisp symbol completion at point."
9743 (interactive)
9744 (let* ((data (lisp-completion-at-point))
9745 (beg (car data))
9746 (end (point)) ; 'cadr data' is wrong when no space after point.
9747 (plist (nthcdr 3 data))
9748 (pred (plist-get plist :predicate))
9749 (lgst-len 0)
9750 (target (and beg end (buffer-substring-no-properties beg end)))
9751 (candidates (all-completions target (nth 2 data) pred))
9752 (anything-quit-if-no-candidate t)
9753 (anything-execute-action-at-once-if-one t)
9754 (anything-match-plugin-enabled
9755 (member 'anything-compile-source--match-plugin
9756 anything-compile-source-functions)))
9757 (if candidates
9758 (with-anything-show-completion beg end
9759 ;; Overlay is initialized now in anything-current-buffer.
9760 (anything
9761 :sources
9762 '((name . "Lisp completion")
9763 (init . (lambda ()
9764 (with-current-buffer (anything-candidate-buffer 'global)
9765 (loop for sym in candidates
9766 for len = (length sym)
9767 when (> len lgst-len) do (setq lgst-len len)
9768 do (insert (concat sym "\n"))))))
9769 (candidates-in-buffer)
9770 (persistent-action . anything-lisp-completion-persistent-action)
9771 (persistent-help . "Show brief doc in mode-line")
9772 (filtered-candidate-transformer anything-lisp-completion-transformer)
9773 (action . (lambda (candidate)
9774 (delete-region beg end)
9775 (insert candidate))))
9776 :input (if anything-match-plugin-enabled (concat target " ") target)))
9777 (message "[No Match]"))))
9779 (defun anything-lisp-completion-persistent-action (candidate)
9780 (let ((cursor-in-echo-area t)
9781 mode-line-in-non-selected-windows)
9782 (anything-c-eldoc-show-in-mode-line
9783 (propertize
9784 (anything-c-get-first-line-documentation
9785 (intern candidate))
9786 'face 'anything-lisp-completion-info))))
9788 (defun anything-lisp-completion-transformer (candidates source)
9789 "Anything candidates transformer for lisp completion."
9790 (declare (special lgst-len))
9791 (loop for c in candidates
9792 for sym = (intern c)
9793 for annot = (cond ((commandp sym) " (Com)")
9794 ((fboundp sym) " (Fun)")
9795 ((boundp sym) " (Var)")
9796 ((facep sym) " (Face)"))
9797 for spaces = (make-string (- lgst-len (length c)) ? )
9798 collect (cons (concat c spaces annot) c)))
9800 (defun anything-c-get-first-line-documentation (sym)
9801 "Return first line documentation of symbol SYM.
9802 If SYM is not documented, return \"Not documented\"."
9803 (let ((doc (cond ((fboundp sym)
9804 (documentation sym t))
9805 ((boundp sym)
9806 (documentation-property sym 'variable-documentation t))
9807 ((facep sym)
9808 (face-documentation sym))
9809 (t nil))))
9810 (if (and doc (not (string= doc ""))
9811 ;; `documentation' return "\n\n(args...)"
9812 ;; for CL-style functions.
9813 (not (string-match-p "^\n\n" doc)))
9814 (car (split-string doc "\n"))
9815 "Not documented")))
9817 ;;; File completion.
9819 ;; Complete file name at point.
9820 (defun anything-c-thing-before-point ()
9821 "Get symbol name before point.
9822 Borrowed from anything-complete.el, inlined here for compatibility."
9823 (save-excursion
9824 (let ((beg (point)))
9825 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9826 (when (re-search-backward
9827 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9828 (buffer-substring-no-properties beg (match-end 0))))))
9830 ;;;###autoload
9831 (defun anything-c-complete-file-name-at-point ()
9832 "Complete file name at point."
9833 (interactive)
9834 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9835 (end (point))
9836 (beg (- (point) (length init)))
9837 (anything-quit-if-no-candidate t)
9838 (anything-execute-action-at-once-if-one t)
9839 completion)
9840 (with-anything-show-completion beg end
9841 (setq completion (anything-c-read-file-name "FileName: "
9842 :initial-input init)))
9843 (anything-c-insert-file-name-completion-at-point completion)))
9845 ;; Internal
9846 (defvar anything-lisp-completion-counter 0)
9847 ;;;###autoload
9848 (defun anything-lisp-completion-at-point-or-indent (arg)
9849 "First call indent and second call complete lisp symbol.
9850 The second call should happen before `anything-lisp-completion-or-indent-delay',
9851 after this delay, next call will indent again.
9852 After completion, next call is always indent.
9853 See that like click and double mouse click.
9854 One hit indent, two quick hits maybe indent and complete."
9855 (interactive "P")
9856 ;; Be sure `indent-for-tab-command' will not try
9857 ;; to use `completion-at-point'.
9858 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9859 t tab-always-indent)))
9860 (incf anything-lisp-completion-counter)
9861 (unwind-protect
9862 (if (> anything-lisp-completion-counter 1)
9863 (anything-lisp-completion-or-file-name-at-point)
9864 (indent-for-tab-command arg))
9865 ;; After `anything-lisp-completion-or-indent-delay' seconds
9866 ;; reset to 0.
9867 (run-with-timer anything-lisp-completion-or-indent-delay nil
9868 #'(lambda ()
9869 (setq anything-lisp-completion-counter 0)))
9870 ;; Always reset to 0 at second hit.
9871 (when (eq anything-lisp-completion-counter 2)
9872 (setq anything-lisp-completion-counter 0)))))
9874 ;;;###autoload
9875 (defun anything-lisp-completion-or-file-name-at-point ()
9876 "Complete lisp symbol or filename at point.
9877 Filename completion happen if filename is started in
9878 or between double quotes."
9879 (interactive)
9880 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9881 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9882 (save-excursion (search-backward "\"" (point-at-bol) t)))
9883 (anything-c-complete-file-name-at-point)
9884 (anything-lisp-completion-at-point))))
9888 ;;; Run Externals commands within Emacs with anything completion
9891 (defvar anything-external-command-history nil)
9893 (defun anything-c-external-commands-list-1 (&optional sort)
9894 "Returns a list of all external commands the user can execute.
9895 If `anything-c-external-commands-list' is non-nil it will
9896 return its contents. Else it calculates all external commands
9897 and sets `anything-c-external-commands-list'."
9898 (if anything-c-external-commands-list
9899 anything-c-external-commands-list
9900 (setq anything-c-external-commands-list
9901 (loop
9902 with paths = (split-string (getenv "PATH") path-separator)
9903 with completions = ()
9904 for dir in paths
9905 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9906 for lsdir = (loop for i in (directory-files dir t)
9907 for bn = (file-name-nondirectory i)
9908 when (and (not (member bn completions))
9909 (not (file-directory-p i))
9910 (file-executable-p i))
9911 collect bn)
9912 append lsdir into completions
9913 finally return (if sort (sort completions 'string-lessp) completions)))))
9915 (defun anything-run-or-raise (exe &optional file)
9916 "Generic command that run asynchronously EXE.
9917 If EXE is already running just jump to his window if `anything-raise-command'
9918 is non--nil.
9919 When FILE argument is provided run EXE with FILE.
9920 In this case EXE must be provided as \"EXE %s\"."
9921 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
9922 "'%s'" "" exe))))
9923 (proc (if file (concat real-com " " file) real-com)))
9924 (if (get-process proc)
9925 (if anything-raise-command
9926 (shell-command (format anything-raise-command real-com))
9927 (error "Error: %s is already running" real-com))
9928 (when (loop for i in anything-c-external-commands-list thereis real-com)
9929 (message "Starting %s..." real-com)
9930 (if file
9931 (start-process-shell-command proc nil (format exe file))
9932 (start-process-shell-command proc nil real-com))
9933 (set-process-sentinel
9934 (get-process proc)
9935 #'(lambda (process event)
9936 (when (and (string= event "finished\n")
9937 anything-raise-command
9938 (not (anything-c-get-pid-from-process-name real-com)))
9939 (shell-command (format anything-raise-command "emacs")))
9940 (message "%s process...Finished." process))))
9941 (setq anything-c-external-commands-list
9942 (cons real-com
9943 (delete real-com anything-c-external-commands-list))))))
9947 ;;; Generic action functions
9950 (defun anything-c-file-buffers (filename)
9951 "Returns a list of buffer names corresponding to FILENAME."
9952 (let ((name (expand-file-name filename))
9953 (buf-list ()))
9954 (dolist (buf (buffer-list) buf-list)
9955 (let ((bfn (buffer-file-name buf)))
9956 (when (and bfn (string= name bfn))
9957 (push (buffer-name buf) buf-list))))))
9959 (defun anything-revert-buffer (candidate)
9960 (with-current-buffer candidate
9961 (when (or (buffer-modified-p)
9962 (not (verify-visited-file-modtime
9963 (get-buffer candidate))))
9964 (revert-buffer t t))))
9966 (defun anything-revert-marked-buffers (ignore)
9967 (mapc 'anything-revert-buffer (anything-marked-candidates)))
9969 (defun anything-kill-marked-buffers (ignore)
9970 (mapc 'kill-buffer (anything-marked-candidates)))
9972 (defun anything-c-delete-file (file)
9973 "Delete the given file after querying the user.
9974 Ask to kill buffers associated with that file, too."
9975 (let ((buffers (anything-c-file-buffers file)))
9976 (if (< emacs-major-version 24)
9977 ;; `dired-delete-file' in Emacs versions < 24
9978 ;; doesn't support delete-by-moving-to-trash
9979 ;; so use `delete-directory' and `delete-file'
9980 ;; that handle it.
9981 (cond ((and (not (file-symlink-p file))
9982 (file-directory-p file)
9983 (directory-files file t dired-re-no-dot))
9984 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
9985 (delete-directory file 'recursive)))
9986 ((and (not (file-symlink-p file))
9987 (file-directory-p file))
9988 (delete-directory file))
9989 (t (delete-file file)))
9990 (dired-delete-file
9991 file 'dired-recursive-deletes delete-by-moving-to-trash))
9992 (when buffers
9993 (dolist (buf buffers)
9994 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
9995 (kill-buffer buf))))))
9997 (defun anything-get-mailcap-for-file (filename)
9998 "Get the command to use for FILENAME from mailcap files.
9999 The command is like <command %s> and is meant to use with `format'."
10000 (mailcap-parse-mailcaps)
10001 (let* ((ext (file-name-extension filename))
10002 (mime (when ext (mailcap-extension-to-mime ext)))
10003 (result (when mime (mailcap-mime-info mime))))
10004 ;; If elisp file have no associations in .mailcap
10005 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10006 (when (stringp result) result)))
10008 (defun anything-get-default-program-for-file (filename)
10009 "Try to find a default program to open FILENAME.
10010 Try first in `anything-c-external-programs-associations' and then in mailcap file
10011 if nothing found return nil."
10012 (let* ((ext (file-name-extension filename))
10013 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10014 (cond ((and def-prog (not (string= def-prog "")))
10015 (concat def-prog " %s"))
10016 ((and anything-c-default-external-file-browser
10017 (file-directory-p filename))
10018 (concat anything-c-default-external-file-browser " %s"))
10019 (t (anything-get-mailcap-for-file filename)))))
10021 (defun anything-c-open-file-externally (file)
10022 "Open FILE with an external program.
10023 Try to guess which program to use with `anything-get-default-program-for-file'.
10024 If not found or a prefix arg is given query the user which tool to use."
10025 (let* ((fname (expand-file-name file))
10026 (collection (anything-c-external-commands-list-1 'sort))
10027 (def-prog (anything-get-default-program-for-file fname))
10028 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10029 ;; Prefix arg or no default program.
10030 (prog1
10031 (anything-comp-read
10032 "Program: " collection
10033 :must-match t
10034 :name "Open file Externally"
10035 :history anything-external-command-history)
10036 ;; Always prompt to set this program as default.
10037 (setq def-prog nil))
10038 ;; No prefix arg or default program exists.
10039 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10040 (program (concat real-prog-name " '%s'")))
10041 (unless (or def-prog ; Association exists, no need to record it.
10042 ;; Don't try to record non--filenames associations (e.g urls).
10043 (not (file-exists-p fname)))
10044 (when
10045 (y-or-n-p
10046 (format
10047 "Do you want to make `%s' the default program for this kind of files? "
10048 real-prog-name))
10049 (anything-aif (assoc (file-name-extension fname)
10050 anything-c-external-programs-associations)
10051 (setq anything-c-external-programs-associations
10052 (delete it anything-c-external-programs-associations)))
10053 (push (cons (file-name-extension fname)
10054 (read-string
10055 "Program (Add args maybe and confirm): " real-prog-name))
10056 anything-c-external-programs-associations)
10057 (customize-save-variable 'anything-c-external-programs-associations
10058 anything-c-external-programs-associations)))
10059 (anything-run-or-raise program file)
10060 (setq anything-external-command-history
10061 (cons real-prog-name
10062 (delete real-prog-name
10063 (loop for i in anything-external-command-history
10064 when (executable-find i) collect i))))))
10067 (defun anything-c-find-file-or-marked (candidate)
10068 "Open file CANDIDATE or open anything marked files in background."
10069 (let ((marked (anything-marked-candidates))
10070 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10071 (find-file-wildcards nil))
10072 (if (> (length marked) 1)
10073 ;; Open all marked files in background and display
10074 ;; the first one.
10075 (progn (mapc 'find-file-noselect (cdr marked))
10076 (find-file (car marked)))
10077 (if (and (not (file-exists-p candidate))
10078 (and ffap-url-regexp
10079 (not (string-match ffap-url-regexp candidate)))
10080 (string-match "/$" candidate))
10081 ;; A a non--existing filename ending with /
10082 ;; Create a directory and jump to it.
10083 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10084 (let ((dirfname (directory-file-name candidate)))
10085 (if (file-exists-p dirfname)
10086 (error "Mkdir: Unable to create directory `%s': file exists."
10087 (anything-c-basename dirfname))
10088 (make-directory candidate 'parent)))
10089 (anything-find-files-1 candidate))
10090 ;; A non--existing filename NOT ending with / or
10091 ;; an existing filename, create or jump to it.
10092 (find-file-at-point (car marked))))))
10094 (defun anything-delete-marked-files (ignore)
10095 (let* ((files (anything-marked-candidates))
10096 (len (length files)))
10097 (if (not (y-or-n-p
10098 (format "Delete *%s File(s):\n%s"
10100 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10101 (message "(No deletions performed)")
10102 (dolist (i files)
10103 (set-text-properties 0 (length i) nil i)
10104 (anything-c-delete-file i))
10105 (message "%s File(s) deleted" len))))
10107 (defun anything-ediff-marked-buffers (candidate &optional merge)
10108 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10109 With optional arg MERGE call `ediff-merge-buffers'."
10110 (let ((lg-lst (length (anything-marked-candidates)))
10111 buf1 buf2)
10112 (case lg-lst
10114 (error "Error:You have to mark at least 1 buffer"))
10116 (setq buf1 anything-current-buffer
10117 buf2 (first (anything-marked-candidates))))
10119 (setq buf1 (first (anything-marked-candidates))
10120 buf2 (second (anything-marked-candidates))))
10122 (error "Error:To much buffers marked!")))
10123 (if merge
10124 (ediff-merge-buffers buf1 buf2)
10125 (ediff-buffers buf1 buf2))))
10127 (defun anything-ediff-marked-buffers-merge (candidate)
10128 "Ediff merge `anything-current-buffer' with CANDIDATE.
10129 See `anything-ediff-marked-buffers'."
10130 (anything-ediff-marked-buffers candidate t))
10132 (defun anything-bookmark-get-bookmark-from-name (bmk)
10133 "Return bookmark name even if it is a bookmark with annotation.
10134 e.g prepended with *.
10135 Return nil if bmk is not a valid bookmark."
10136 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10137 (if (assoc bookmark bookmark-alist)
10138 bookmark
10139 (when (assoc bmk bookmark-alist)
10140 bmk))))
10142 (defun anything-delete-marked-bookmarks (ignore)
10143 "Delete this bookmark or all marked bookmarks."
10144 (dolist (i (anything-marked-candidates))
10145 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10146 'batch)))
10148 (defun anything-require-or-error (feature function)
10149 (or (require feature nil t)
10150 (error "Need %s to use `%s'." feature function)))
10152 (defun anything-find-buffer-on-elscreen (candidate)
10153 "Open buffer in new screen, if marked buffers open all in elscreens."
10154 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10155 (anything-aif (anything-marked-candidates)
10156 (dolist (i it)
10157 (let ((target-screen (elscreen-find-screen-by-buffer
10158 (get-buffer i) 'create)))
10159 (elscreen-goto target-screen)))
10160 (let ((target-screen (elscreen-find-screen-by-buffer
10161 (get-buffer candidate) 'create)))
10162 (elscreen-goto target-screen))))
10164 (defun anything-elscreen-find-file (file)
10165 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10166 (elscreen-find-file file))
10168 ;;;###autoload
10169 (defun w32-shell-execute-open-file (file)
10170 (interactive "fOpen file:")
10171 (with-no-warnings
10172 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10173 "/" "\\"
10174 (replace-regexp-in-string ; strip cygdrive paths
10175 "/cygdrive/\\(.\\)" "\\1:"
10176 file nil nil) nil t))))
10178 (defun anything-c-open-file-with-default-tool (file)
10179 "Open FILE with the default tool on this platform."
10180 (if (eq system-type 'windows-nt)
10181 (w32-shell-execute-open-file file)
10182 (start-process "anything-c-open-file-with-default-tool"
10184 (cond ((eq system-type 'gnu/linux)
10185 "xdg-open")
10186 ((or (eq system-type 'darwin) ;; Mac OS X
10187 (eq system-type 'macos)) ;; Mac OS 9
10188 "open"))
10189 file)))
10191 (defun anything-c-open-dired (file)
10192 "Opens a dired buffer in FILE's directory. If FILE is a
10193 directory, open this directory."
10194 (if (file-directory-p file)
10195 (dired file)
10196 (dired (file-name-directory file))
10197 (dired-goto-file file)))
10199 (defun anything-c-display-to-real-line (candidate)
10200 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10201 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10202 (error "Line number not found")))
10204 (defun anything-c-action-line-goto (lineno-and-content)
10205 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10206 (append lineno-and-content
10207 (list (if (and (anything-attr-defined 'target-file)
10208 (not anything-in-persistent-action))
10209 'find-file-other-window
10210 'find-file)))))
10212 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10213 (apply #'anything-goto-file-line
10214 (if (stringp file-line-content)
10215 ;; Case: filtered-candidate-transformer is skipped
10216 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10217 file-line-content)))
10219 (require 'compile)
10220 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10221 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10223 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10224 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10225 (let ((filename (match-string 1 candidate))
10226 (lineno (match-string 2 candidate))
10227 (content (match-string 3 candidate)))
10228 (cons (format "%s:%s\n %s"
10229 (propertize filename 'face compilation-info-face)
10230 (propertize lineno 'face compilation-line-face)
10231 content)
10232 (list (expand-file-name
10233 filename
10234 (or (anything-interpret-value (anything-attr 'default-directory))
10235 (and (anything-candidate-buffer)
10236 (buffer-local-value
10237 'default-directory (anything-candidate-buffer)))))
10238 (string-to-number lineno) content)))))
10240 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10241 (anything-aif (anything-attr 'before-jump-hook)
10242 (funcall it))
10243 (when file (funcall find-file-function file))
10244 (if (anything-attr-defined 'adjust)
10245 (anything-c-goto-line-with-adjustment lineno content)
10246 (anything-goto-line lineno))
10247 (unless (anything-attr-defined 'recenter)
10248 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10249 (anything-aif (anything-attr 'after-jump-hook)
10250 (funcall it))
10251 (when anything-in-persistent-action
10252 (anything-match-line-color-current-line)))
10254 (defun anything-find-file-as-root (candidate)
10255 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10257 (defun anything-find-many-files (ignore)
10258 (mapc 'find-file (anything-marked-candidates)))
10260 ;; borrowed from etags.el
10261 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10262 (defun anything-c-goto-line-with-adjustment (line line-content)
10263 (let ((startpos)
10264 offset found pat)
10265 ;; This constant is 1/2 the initial search window.
10266 ;; There is no sense in making it too small,
10267 ;; since just going around the loop once probably
10268 ;; costs about as much as searching 2000 chars.
10269 (setq offset 1000
10270 found nil
10271 pat (concat (if (eq selective-display t)
10272 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10273 (regexp-quote line-content)))
10274 ;; If no char pos was given, try the given line number.
10275 (setq startpos (progn (anything-goto-line line) (point)))
10276 (or startpos (setq startpos (point-min)))
10277 ;; First see if the tag is right at the specified location.
10278 (goto-char startpos)
10279 (setq found (looking-at pat))
10280 (while (and (not found)
10281 (progn
10282 (goto-char (- startpos offset))
10283 (not (bobp))))
10284 (setq found
10285 (re-search-forward pat (+ startpos offset) t)
10286 offset (* 3 offset))) ; expand search window
10287 (or found
10288 (re-search-forward pat nil t)
10289 (error "not found")))
10290 ;; Position point at the right place
10291 ;; if the search string matched an extra Ctrl-m at the beginning.
10292 (and (eq selective-display t)
10293 (looking-at "\^m")
10294 (forward-char 1))
10295 (beginning-of-line))
10297 (anything-document-attribute 'default-directory "type . file-line"
10298 "`default-directory' to interpret file.")
10299 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10300 "Function to call before jumping to the target location.")
10301 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10302 "Function to call after jumping to the target location.")
10303 (anything-document-attribute 'adjust "type . file-line"
10304 "Search around line matching line contents.")
10305 (anything-document-attribute 'recenter "type . file-line / line"
10306 "`recenter' after jumping.")
10307 (anything-document-attribute 'target-file "type . line"
10308 "Goto line of target-file.")
10310 ;;;###autoload
10311 (defun anything-c-call-interactively (cmd-or-name)
10312 "Execute CMD-OR-NAME as Emacs command.
10313 It is added to `extended-command-history'.
10314 `anything-current-prefix-arg' is used as the command's prefix argument."
10315 (setq extended-command-history
10316 (cons (anything-c-stringify cmd-or-name)
10317 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10318 (let ((current-prefix-arg anything-current-prefix-arg)
10319 (cmd (anything-c-symbolify cmd-or-name)))
10320 (if (stringp (symbol-function cmd))
10321 (execute-kbd-macro (symbol-function cmd))
10322 (setq this-command cmd)
10323 (call-interactively cmd))))
10325 ;;;###autoload
10326 (defun anything-c-set-variable (var)
10327 "Set value to VAR interactively."
10328 (interactive)
10329 (let ((sym (anything-c-symbolify var)))
10330 (set sym (eval-minibuffer (format "Set %s: " var)
10331 (prin1-to-string (symbol-value sym))))))
10332 ;; (setq hh 12)
10333 ;; (anything-c-set-variable 'hh)
10337 ;;; Persistent Action Helpers
10340 (defvar anything-match-line-overlay-face nil)
10341 (defvar anything-match-line-overlay nil)
10343 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10344 "Highlight and underline current position"
10345 (let ((args (list (or start (line-beginning-position))
10346 (or end (1+ (line-end-position)))
10347 buf)))
10348 (if (not anything-match-line-overlay)
10349 (setq anything-match-line-overlay (apply 'make-overlay args))
10350 (apply 'move-overlay anything-match-line-overlay args)))
10351 (overlay-put anything-match-line-overlay
10352 'face (or face anything-match-line-overlay-face))
10353 (when rec
10354 (goto-char start)
10355 (recenter)))
10357 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10360 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10362 (defun anything-match-line-cleanup ()
10363 (when anything-match-line-overlay
10364 (delete-overlay anything-match-line-overlay)
10365 (setq anything-match-line-overlay nil)))
10367 (defun anything-match-line-update ()
10368 (when anything-match-line-overlay
10369 (delete-overlay anything-match-line-overlay)
10370 (anything-match-line-color-current-line)))
10372 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10373 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10376 ;;; Actions Transformers
10379 ;;; Files
10380 (defun anything-c-transform-file-load-el (actions candidate)
10381 "Add action to load the file CANDIDATE if it is an emacs lisp
10382 file. Else return ACTIONS unmodified."
10383 (if (member (file-name-extension candidate) '("el" "elc"))
10384 (append actions '(("Load Emacs Lisp File" . load-file)))
10385 actions))
10387 (defun anything-c-transform-file-browse-url (actions candidate)
10388 "Add an action to browse the file CANDIDATE if it in a html
10389 file or URL. Else return ACTIONS unmodified."
10390 (let ((browse-action '("Browse with Browser" . browse-url)))
10391 (cond ((string-match "^http\\|^ftp" candidate)
10392 (cons browse-action actions))
10393 ((string-match "\\.html?$" candidate)
10394 (append actions (list browse-action)))
10395 (t actions))))
10397 ;;; Function
10398 (defun anything-c-transform-function-call-interactively (actions candidate)
10399 "Add an action to call the function CANDIDATE interactively if
10400 it is a command. Else return ACTIONS unmodified."
10401 (if (commandp (intern-soft candidate))
10402 (append actions '(("Call Interactively"
10404 anything-c-call-interactively)))
10405 actions))
10407 ;;;; S-Expressions
10408 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10409 "If CANDIDATE's `car' is a command, then add an action to
10410 evaluate it and put it onto the `command-history'."
10411 (if (commandp (car (read candidate)))
10412 ;; Make it first entry
10413 (cons '("Eval and put onto command-history" .
10414 (lambda (sexp)
10415 (let ((sym (read sexp)))
10416 (eval sym)
10417 (setq command-history
10418 (cons sym command-history)))))
10419 actions)
10420 actions))
10423 ;;; Candidate Transformers
10426 ;;; Buffers
10427 (defun anything-c-skip-boring-buffers (buffers)
10428 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10430 (defun anything-c-skip-current-buffer (buffers)
10431 (if anything-allow-skipping-current-buffer
10432 (remove (buffer-name anything-current-buffer) buffers)
10433 buffers))
10435 (defun anything-c-shadow-boring-buffers (buffers)
10436 "Buffers matching `anything-c-boring-buffer-regexp' will be
10437 displayed with the `file-name-shadow' face if available."
10438 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10440 (defvar anything-c-buffer-display-string-functions
10441 '(anything-c-buffer-display-string--compilation
10442 anything-c-buffer-display-string--shell
10443 anything-c-buffer-display-string--eshell)
10444 "Functions to setup display string for buffer.
10446 Function has one argument, buffer name.
10447 If it returns string, use it.
10448 If it returns nil, display buffer name.
10449 See `anything-c-buffer-display-string--compilation' for example.")
10451 (defun anything-c-transform-buffer-display-string (buffers)
10452 "Setup display string for buffer candidates
10453 using `anything-c-buffer-display-string-functions'."
10454 (loop for buf in buffers
10455 if (consp buf)
10456 collect buf
10457 else
10458 for disp = (progn (set-buffer buf)
10459 (run-hook-with-args-until-success
10460 'anything-c-buffer-display-string-functions buf))
10461 collect (if disp (cons disp buf) buf)))
10463 (defun anything-c-buffer-display-string--compilation (buf)
10464 (anything-aif (car compilation-arguments)
10465 (format "%s: %s [%s]" buf it default-directory)))
10467 (defun anything-c-buffer-display-string--eshell (buf)
10468 (declare (special eshell-history-ring))
10469 (when (eq major-mode 'eshell-mode)
10470 (format "%s: %s [%s]" buf
10471 (ignore-errors (ring-ref eshell-history-ring 0))
10472 default-directory)))
10474 (defun anything-c-buffer-display-string--shell (buf)
10475 (when (eq major-mode 'shell-mode)
10476 (format "%s: %s [%s]" buf
10477 (ignore-errors (ring-ref comint-input-ring 0))
10478 default-directory)))
10480 ;;; Files
10481 (defun anything-c-shadow-boring-files (files)
10482 "Files matching `anything-c-boring-file-regexp' will be
10483 displayed with the `file-name-shadow' face if available."
10484 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10486 (defun anything-c-skip-boring-files (files)
10487 "Files matching `anything-c-boring-file-regexp' will be skipped."
10488 (anything-c-skip-entries files anything-c-boring-file-regexp))
10489 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10491 (defun anything-c-skip-current-file (files)
10492 "Current file will be skipped."
10493 (remove (buffer-file-name anything-current-buffer) files))
10495 (defun anything-c-w32-pathname-transformer (args)
10496 "Change undesirable features of windows pathnames to ones more acceptable to
10497 other candidate transformers."
10498 (if (eq system-type 'windows-nt)
10499 (mapcar (lambda (x)
10500 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10501 (mapcar (lambda (y)
10502 (replace-regexp-in-string "\\\\" "/" y)) args))
10503 args))
10505 (defun anything-c-shorten-home-path (files)
10506 "Replaces /home/user with ~."
10507 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10508 (getenv "HOME"))))
10509 (mapcar (lambda (file)
10510 (if (and (stringp file) (string-match home file))
10511 (cons (replace-match "~" nil nil file) file)
10512 file))
10513 files)))
10515 ;;; Functions
10516 (defun anything-c-mark-interactive-functions (functions)
10517 "Mark interactive functions (commands) with (i) after the function name."
10518 (let (list)
10519 (loop for function in functions
10520 do (push (cons (concat function
10521 (when (commandp (intern-soft function)) " (i)"))
10522 function)
10523 list)
10524 finally (return (nreverse list)))))
10527 ;;; Adaptive Sorting of Candidates
10530 ;; Internal
10531 (defvar anything-c-adaptive-done nil
10532 "nil if history information is not yet stored for the current
10533 selection.")
10535 (defvar anything-c-adaptive-history nil
10536 "Contains the stored history information.
10537 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10539 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10540 "Reset `anything-c-adaptive-done' when anything is started."
10541 (when anything-c-use-adaptative-sorting
10542 (setq anything-c-adaptive-done nil)))
10544 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10545 "Store history information when action is executed on selected candidate."
10546 (when anything-c-use-adaptative-sorting
10547 (anything-c-adaptive-store-selection)))
10549 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10550 "Store history information when the user goes to the action buffer."
10551 (when anything-c-use-adaptative-sorting
10552 (anything-c-adaptive-store-selection)))
10554 (defun anything-c-source-use-adaptative-p (&optional source-name)
10555 "Return current source only if it use adaptative history, nil otherwise."
10556 (when anything-c-use-adaptative-sorting
10557 (let* ((source (or source-name (anything-get-current-source)))
10558 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10559 (assoc (assoc-default 'type source)
10560 anything-type-attributes))
10561 (assoc-default 'candidate-transformer
10562 (assoc (assoc-default 'type source)
10563 anything-type-attributes))
10564 (assoc-default 'filtered-candidate-transformer source)
10565 (assoc-default 'candidate-transformer source))))
10566 (if (listp adapt-source)
10567 (when (member 'anything-c-adaptive-sort adapt-source) source)
10568 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10570 (defun anything-c-adaptive-store-selection ()
10571 "Store history information for the selected candidate."
10572 (unless anything-c-adaptive-done
10573 (setq anything-c-adaptive-done t)
10574 (let ((source (anything-c-source-use-adaptative-p)))
10575 (when source
10576 (let* ((source-name (or (assoc-default 'type source)
10577 (assoc-default 'name source)))
10578 (source-info (or (assoc source-name anything-c-adaptive-history)
10579 (progn
10580 (push (list source-name) anything-c-adaptive-history)
10581 (car anything-c-adaptive-history))))
10582 (selection (anything-get-selection))
10583 (selection-info (progn
10584 (setcdr source-info
10585 (cons
10586 (let ((found (assoc selection (cdr source-info))))
10587 (if (not found)
10588 ;; new entry
10589 (list selection)
10591 ;; move entry to the beginning of the
10592 ;; list, so that it doesn't get
10593 ;; trimmed when the history is
10594 ;; truncated
10595 (setcdr source-info
10596 (delete found (cdr source-info)))
10597 found))
10598 (cdr source-info)))
10599 (cadr source-info)))
10600 (pattern-info (progn
10601 (setcdr selection-info
10602 (cons
10603 (let ((found (assoc anything-pattern (cdr selection-info))))
10604 (if (not found)
10605 ;; new entry
10606 (cons anything-pattern 0)
10608 ;; move entry to the beginning of the
10609 ;; list, so if two patterns used the
10610 ;; same number of times then the one
10611 ;; used last appears first in the list
10612 (setcdr selection-info
10613 (delete found (cdr selection-info)))
10614 found))
10615 (cdr selection-info)))
10616 (cadr selection-info))))
10618 ;; increase usage count
10619 (setcdr pattern-info (1+ (cdr pattern-info)))
10621 ;; truncate history if needed
10622 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10623 (setcdr selection-info
10624 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10626 (defun anything-c-adaptative-maybe-load-history ()
10627 (when (and anything-c-use-adaptative-sorting
10628 (file-readable-p anything-c-adaptive-history-file))
10629 (load-file anything-c-adaptive-history-file)))
10631 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10632 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10634 (defun anything-c-adaptive-save-history (&optional arg)
10635 "Save history information to file given by `anything-c-adaptive-history-file'."
10636 (interactive "p")
10637 (when anything-c-use-adaptative-sorting
10638 (with-temp-buffer
10639 (insert
10640 ";; -*- mode: emacs-lisp -*-\n"
10641 ";; History entries used for anything adaptive display.\n")
10642 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10643 (current-buffer))
10644 (insert ?\n)
10645 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10646 (unless arg 'quiet)))))
10648 (defun anything-c-adaptive-sort (candidates source)
10649 "Sort the CANDIDATES for SOURCE by usage frequency.
10650 This is a filtered candidate transformer you can use for the
10651 attribute `filtered-candidate-transformer' of a source in
10652 `anything-sources' or a type in `anything-type-attributes'."
10653 (let* ((source-name (or (assoc-default 'type source)
10654 (assoc-default 'name source)))
10655 (source-info (assoc source-name anything-c-adaptive-history)))
10656 (if source-info
10657 (let ((usage
10658 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10659 ;; pairs
10660 (mapcar (lambda (candidate-info)
10661 (let ((count 0))
10662 (dolist (pattern-info (cdr candidate-info))
10663 (if (not (equal (car pattern-info)
10664 anything-pattern))
10665 (incf count (cdr pattern-info))
10667 ;; if current pattern is equal to the previously
10668 ;; used one then this candidate has priority
10669 ;; (that's why its count is boosted by 10000) and
10670 ;; it only has to compete with other candidates
10671 ;; which were also selected with the same pattern
10672 (setq count (+ 10000 (cdr pattern-info)))
10673 (return)))
10674 (cons (car candidate-info) count)))
10675 (cdr source-info)))
10676 sorted)
10677 (if (and usage (consp usage))
10678 ;; sort the list in descending order, so candidates with highest
10679 ;; priorty come first
10680 (progn
10681 (setq usage (sort usage (lambda (first second)
10682 (> (cdr first) (cdr second)))))
10684 ;; put those candidates first which have the highest usage count
10685 (dolist (info usage)
10686 (when (member* (car info) candidates
10687 :test 'anything-c-adaptive-compare)
10688 (push (car info) sorted)
10689 (setq candidates (remove* (car info) candidates
10690 :test 'anything-c-adaptive-compare))))
10692 ;; and append the rest
10693 (append (reverse sorted) candidates nil))
10694 (message "Your `%s' is maybe corrupted or too old, \
10695 you should reinitialize it with `anything-c-reset-adaptative-history'"
10696 anything-c-adaptive-history-file)
10697 (sit-for 1)
10698 candidates))
10699 ;; if there is no information stored for this source then do nothing
10700 candidates)))
10702 ;;;###autoload
10703 (defun anything-c-reset-adaptative-history ()
10704 "Delete all `anything-c-adaptive-history' and his file.
10705 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10706 (interactive)
10707 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10708 (setq anything-c-adaptive-history nil)
10709 (delete-file anything-c-adaptive-history-file)))
10711 (defun anything-c-adaptive-compare (x y)
10712 "Compare candidates X and Y taking into account that the
10713 candidate can be in (DISPLAY . REAL) format."
10714 (equal (if (listp x)
10715 (cdr x)
10717 (if (listp y)
10718 (cdr y)
10719 y)))
10723 ;;; Outliner
10726 (defvar anything-outline-goto-near-line-flag t)
10727 (defvar anything-outline-using nil)
10728 (defun anything-after-update-hook--outline ()
10729 (if (and (eq anything-outline-using t)
10730 (eq anything-outline-goto-near-line-flag t))
10731 (anything-outline-goto-near-line)))
10732 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10734 (defun anything-outline-goto-near-line ()
10735 (with-anything-window
10736 ;; TODO need consideration whether to update position by every input.
10737 (when t ; (equal anything-pattern "")
10738 (anything-goto-line 2)
10739 (let ((lineno (with-anything-current-buffer
10740 (line-number-at-pos (car anything-current-position)))))
10741 (block exit
10742 (while (<= (progn (skip-chars-forward " ")
10743 (or (number-at-point) lineno))
10744 lineno)
10745 (forward-line 1)
10746 (when (eobp)
10747 (forward-line -1)
10748 (return-from exit))))
10749 (forward-line -1)
10750 (and (bobp) (forward-line 1))
10751 (and (anything-pos-header-line-p) (forward-line -2))
10752 (anything-mark-current-line)))))
10756 ;;; Plug-in
10759 ;; Plug-in: info-index
10760 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10761 (let (result)
10762 (unless (anything-candidate-buffer)
10763 (save-window-excursion
10764 (info file)
10765 (let (Info-history
10766 (tobuf (anything-candidate-buffer 'global))
10767 (infobuf (current-buffer))
10768 s e)
10769 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10770 (Info-goto-node node)
10771 (goto-char (point-min))
10772 (while (search-forward "\n* " nil t)
10773 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10774 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10775 (setq s (point-at-bol)
10776 e (point-at-eol))
10777 (with-current-buffer tobuf
10778 (insert-buffer-substring infobuf s e)
10779 (insert "\n"))))))))))
10781 (defun anything-c-info-goto (node-line)
10782 (Info-goto-node (car node-line))
10783 (anything-goto-line (cdr node-line)))
10785 (defun anything-c-info-display-to-real (line)
10786 (and (string-match
10787 ;; This regexp is stolen from Info-apropos-matches
10788 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10789 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10790 (string-to-number (or (match-string 3 line) "1")))))
10792 (defun anything-c-make-info-source (source file)
10793 `(,@source
10794 (name . ,(concat "Info Index: " file))
10795 (info-file . ,file)
10796 (init . anything-c-info-init)
10797 (display-to-real . anything-c-info-display-to-real)
10798 (get-line . buffer-substring)
10799 (candidates-in-buffer)
10800 (action ("Goto node" . anything-c-info-goto))))
10802 (defun anything-compile-source--info-index (source)
10803 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10804 (anything-c-make-info-source source it)
10805 source))
10806 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10808 (anything-document-attribute 'info-index "info-index plugin"
10809 "Create a source of info index very easily.
10811 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10813 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10814 "Index nodes of info file.
10816 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10817 Some info files are missing index specification.
10819 ex. See `anything-c-source-info-screen'.")
10821 ;; Plug-in: candidates-file
10822 (defun anything-compile-source--candidates-file (source)
10823 (if (assoc-default 'candidates-file source)
10824 `((init anything-p-candidats-file-init
10825 ,@(let ((orig-init (assoc-default 'init source)))
10826 (cond ((null orig-init) nil)
10827 ((functionp orig-init) (list orig-init))
10828 (t orig-init))))
10829 (candidates-in-buffer)
10830 ,@source)
10831 source))
10832 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10834 (defun anything-p-candidats-file-init ()
10835 (destructuring-bind (file &optional updating)
10836 (anything-mklist (anything-attr 'candidates-file))
10837 (setq file (anything-interpret-value file))
10838 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10839 (when updating
10840 (buffer-disable-undo)
10841 (font-lock-mode -1)
10842 (auto-revert-mode 1)))))
10844 (anything-document-attribute 'candidates-file "candidates-file plugin"
10845 "Use a file as the candidates buffer.
10847 1st argument is a filename, string or function name or variable name.
10848 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10850 ;; Plug-in: headline
10851 (defun anything-compile-source--anything-headline (source)
10852 (if (assoc-default 'headline source)
10853 (append '((init . anything-headline-init)
10854 (get-line . buffer-substring)
10855 (type . line))
10856 source
10857 '((candidates-in-buffer)
10858 (persistent-help . "Show this line")))
10859 source))
10860 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10862 (defun anything-headline-init ()
10863 (when (and (anything-current-buffer-is-modified)
10864 (with-anything-current-buffer
10865 (eval (or (anything-attr 'condition) t))))
10866 (anything-headline-make-candidate-buffer
10867 (anything-interpret-value (anything-attr 'headline))
10868 (anything-interpret-value (anything-attr 'subexp)))))
10870 (anything-document-attribute 'headline "Headline plug-in"
10871 "Regexp string for anything-headline to scan.")
10872 (anything-document-attribute 'condition "Headline plug-in"
10873 "A sexp representing the condition to use anything-headline.")
10874 (anything-document-attribute 'subexp "Headline plug-in"
10875 "Display (match-string-no-properties subexp).")
10877 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10878 ;; of regexps.
10880 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10881 ;; 2. Sort this list by start-of-match.
10882 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10884 ;; It's quite brilliantly written.
10888 (defun anything-headline-get-candidates (regexp subexp)
10889 (with-anything-current-buffer
10890 (save-excursion
10891 (goto-char (point-min))
10892 (if (functionp regexp) (setq regexp (funcall regexp)))
10893 (let (hierarchy curhead)
10894 (flet ((matched ()
10895 (if (numberp subexp)
10896 (cons (match-string-no-properties subexp) (match-beginning subexp))
10897 (cons (buffer-substring (point-at-bol) (point-at-eol))
10898 (point-at-bol))))
10899 (hierarchies (headlines)
10900 (1+ (loop for (_ . hierarchy) in headlines
10901 maximize hierarchy)))
10902 (vector-0-n (v n)
10903 (loop for i from 0 to hierarchy
10904 collecting (aref curhead i)))
10905 (arrange (headlines)
10906 (unless (null headlines) ; FIX headlines empty bug!
10907 (loop with curhead = (make-vector (hierarchies headlines) "")
10908 for ((str . pt) . hierarchy) in headlines
10909 do (aset curhead hierarchy str)
10910 collecting
10911 (cons
10912 (format "H%d:%s" (1+ hierarchy)
10913 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
10914 pt)))))
10915 (if (listp regexp)
10916 (arrange
10917 (sort
10918 (loop for re in regexp
10919 for hierarchy from 0
10920 do (goto-char (point-min))
10921 appending
10922 (loop
10923 while (re-search-forward re nil t)
10924 collect (cons (matched) hierarchy)))
10925 (lambda (a b) (> (cdar b) (cdar a)))))
10926 (loop while (re-search-forward regexp nil t)
10927 collect (matched))))))))
10930 (defun anything-headline-make-candidate-buffer (regexp subexp)
10931 (with-current-buffer (anything-candidate-buffer 'local)
10932 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
10933 do (insert
10934 (format "%5d:%s\n"
10935 (with-anything-current-buffer
10936 (line-number-at-pos pos))
10937 content)))))
10939 (defun anything-headline-goto-position (pos recenter)
10940 (goto-char pos)
10941 (unless recenter
10942 (set-window-start (get-buffer-window anything-current-buffer) (point))))
10945 ;; Plug-in: persistent-help
10946 (defun anything-compile-source--persistent-help (source)
10947 (append source '((header-line . anything-persistent-help-string))))
10948 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
10950 (defun anything-persistent-help-string ()
10951 (substitute-command-keys
10952 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
10953 (or (anything-interpret-value (anything-attr 'persistent-help))
10954 (anything-aif (or (assoc-default 'persistent-action
10955 (anything-get-current-source))
10956 (assoc-default 'action
10957 (anything-get-current-source)))
10958 (cond ((symbolp it) (symbol-name it))
10959 ((listp it) (or (ignore-errors (caar it)) ""))))
10961 " (keeping session)")))
10963 (anything-document-attribute 'persistent-help "persistent-help plug-in"
10964 "A string to explain persistent-action of this source.
10965 It also accepts a function or a variable name.")
10967 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
10969 ;; Plug-in: Type customize
10970 (defun anything-c-uniq-list (lst)
10971 "Like `remove-duplicates' in CL.
10972 But cut deeper duplicates and test by `equal'. "
10973 (reverse (remove-duplicates (reverse lst) :test 'equal)))
10974 (defvar anything-additional-type-attributes nil)
10975 (defun anything-c-arrange-type-attribute (type spec)
10976 "Override type attributes by `define-anything-type-attribute'.
10978 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
10980 Example: Set `play-sound-file' as default action
10981 (anything-c-arrange-type-attribute 'file
10982 '((action (\"Play sound\" . play-sound-file)
10983 REST ;; Rest of actions (find-file, find-file-other-window, ...)
10986 (add-to-list 'anything-additional-type-attributes
10987 (cons type
10988 (loop with typeattr = (assoc-default type anything-type-attributes)
10989 for (attr . value) in spec
10990 if (listp value)
10991 collect (cons attr
10992 (anything-c-uniq-list
10993 (loop for v in value
10994 if (eq v 'REST)
10995 append (assoc-default attr typeattr)
10996 else
10997 collect v)))
10998 else
10999 collect (cons attr value)))))
11000 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11002 (defun anything-compile-source--type-customize (source)
11003 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11004 (append it source)
11005 source))
11006 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11008 ;; Plug-in: default-action
11009 (defun anything-compile-source--default-action (source)
11010 (anything-aif (assoc-default 'default-action source)
11011 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11012 source)
11013 source))
11014 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11015 (anything-document-attribute 'default-action "default-action plug-in"
11016 "Default action.")
11019 ;;; Toggle anything-match-plugin
11022 (defvar anything-mp-initial-highlight-delay nil)
11024 ;;;###autoload
11025 (defun anything-c-toggle-match-plugin ()
11026 "Toggle anything-match-plugin."
11027 (interactive)
11028 (let ((anything-match-plugin-enabled
11029 (member 'anything-compile-source--match-plugin
11030 anything-compile-source-functions)))
11031 (flet ((disable-match-plugin ()
11032 (setq anything-compile-source-functions
11033 (delq 'anything-compile-source--match-plugin
11034 anything-compile-source-functions))
11035 (setq anything-mp-initial-highlight-delay
11036 anything-mp-highlight-delay)
11037 (setq anything-mp-highlight-delay nil))
11038 (enable-match-plugin ()
11039 (require 'anything-match-plugin)
11040 (unless anything-mp-initial-highlight-delay
11041 (setq anything-mp-initial-highlight-delay
11042 anything-mp-highlight-delay))
11043 (setq anything-compile-source-functions
11044 (cons 'anything-compile-source--match-plugin
11045 anything-compile-source-functions))
11046 (unless anything-mp-highlight-delay
11047 (setq anything-mp-highlight-delay
11048 anything-mp-initial-highlight-delay))))
11049 (if anything-match-plugin-enabled
11050 (when (y-or-n-p "Really disable match-plugin? ")
11051 (disable-match-plugin)
11052 (message "Anything-match-plugin disabled"))
11053 (when (y-or-n-p "Really enable match-plugin? ")
11054 (enable-match-plugin)
11055 (message "Anything-match-plugin enabled"))))))
11059 ;;; Type Attributes
11062 (define-anything-type-attribute 'buffer
11063 `((action
11064 ("Switch to buffer" . anything-c-switch-to-buffer)
11065 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11066 ("Switch to buffer other window" . switch-to-buffer-other-window)
11067 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11068 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11069 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11070 ("Query replace" . anything-c-buffer-query-replace)
11071 ("View buffer" . view-buffer)
11072 ("Display buffer" . display-buffer)
11073 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11074 ("Revert buffer(s)" . anything-revert-marked-buffers)
11075 ("Insert buffer" . insert-buffer)
11076 ("Kill buffer(s)" . anything-kill-marked-buffers)
11077 ("Diff with file" . diff-buffer-with-file)
11078 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11079 ("Ediff Merge marked buffers" . (lambda (candidate)
11080 (anything-ediff-marked-buffers candidate t))))
11081 (persistent-help . "Show this buffer")
11082 (candidate-transformer anything-c-skip-current-buffer
11083 anything-c-skip-boring-buffers
11084 anything-c-transform-buffer-display-string))
11085 "Buffer or buffer name.")
11087 (define-anything-type-attribute 'file
11088 `((action
11089 ("Find file" . anything-find-many-files)
11090 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11091 ("Find file as root" . anything-find-file-as-root)
11092 ("Find file other window" . find-file-other-window)
11093 ("Find file other frame" . find-file-other-frame)
11094 ("Open dired in file's directory" . anything-c-open-dired)
11095 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11096 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11097 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11098 ("Checksum File" . anything-ff-checksum)
11099 ("Ediff File" . anything-find-files-ediff-files)
11100 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11101 ("View file" . view-file)
11102 ("Insert file" . insert-file)
11103 ("Delete file(s)" . anything-delete-marked-files)
11104 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11105 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11106 ("Find file in hex dump" . hexl-find-file))
11107 (persistent-help . "Show this file")
11108 (action-transformer anything-c-transform-file-load-el
11109 anything-c-transform-file-browse-url)
11110 (candidate-transformer anything-c-w32-pathname-transformer
11111 anything-c-skip-current-file
11112 anything-c-skip-boring-files
11113 anything-c-shorten-home-path))
11114 "File name.")
11116 (let ((actions '(("Describe command" . describe-function)
11117 ("Add command to kill ring" . anything-c-kill-new)
11118 ("Go to command's definition" . find-function)
11119 ("Debug on entry" . debug-on-entry)
11120 ("Cancel debug on entry" . cancel-debug-on-entry)
11121 ("Trace function" . trace-function)
11122 ("Trace function (background)" . trace-function-background)
11123 ("Untrace function" . untrace-function))))
11124 (define-anything-type-attribute 'command
11125 `((action ("Call interactively" . anything-c-call-interactively)
11126 ,@actions)
11127 ;; Sort commands according to their usage count.
11128 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11129 (coerce . anything-c-symbolify)
11130 (persistent-action . describe-function))
11131 "Command. (string or symbol)")
11133 (define-anything-type-attribute 'function
11134 `((action . ,actions)
11135 (action-transformer anything-c-transform-function-call-interactively)
11136 (candidate-transformer anything-c-mark-interactive-functions)
11137 (coerce . anything-c-symbolify))
11138 "Function. (string or symbol)"))
11140 (define-anything-type-attribute 'variable
11141 '((action ("Describe variable" . describe-variable)
11142 ("Add variable to kill ring" . anything-c-kill-new)
11143 ("Go to variable's definition" . find-variable)
11144 ("Set variable" . anything-c-set-variable))
11145 (coerce . anything-c-symbolify))
11146 "Variable.")
11148 (define-anything-type-attribute 'sexp
11149 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11150 ("Add s-expression to kill ring" . kill-new))
11151 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11152 "String representing S-Expressions.")
11154 (define-anything-type-attribute 'bookmark
11155 `((coerce . anything-bookmark-get-bookmark-from-name)
11156 (action
11157 ("Jump to bookmark" . (lambda (bookmark)
11158 (let ((current-prefix-arg anything-current-prefix-arg))
11159 (bookmark-jump bookmark))
11160 (anything-update)))
11161 ("Jump to BM other window" . (lambda (bookmark)
11162 (bookmark-jump-other-window bookmark)
11163 (anything-update)))
11164 ("Bookmark edit annotation" . bookmark-edit-annotation)
11165 ("Bookmark show annotation" . bookmark-show-annotation)
11166 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11167 ,@(and (locate-library "bookmark-extensions")
11168 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11169 ("Rename bookmark" . bookmark-rename)
11170 ("Relocate bookmark" . bookmark-relocate)))
11171 "Bookmark name.")
11173 (define-anything-type-attribute 'line
11174 '((display-to-real . anything-c-display-to-real-line)
11175 (action ("Go to Line" . anything-c-action-line-goto)))
11176 "LINENO:CONTENT string, eg. \" 16:foo\".
11178 Optional `target-file' attribute is a name of target file.
11180 Optional `before-jump-hook' attribute is a function with no
11181 arguments which is called before jumping to position.
11183 Optional `after-jump-hook' attribute is a function with no
11184 arguments which is called after jumping to position.
11186 If `adjust' attribute is specified, searches the line whose
11187 content is CONTENT near the LINENO.
11189 If `recenter' attribute is specified, the line is displayed at
11190 the center of window, otherwise at the top of window.
11193 (define-anything-type-attribute 'file-line
11194 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11195 (multiline)
11196 (action ("Go to" . anything-c-action-file-line-goto)))
11197 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11199 Optional `default-directory' attribute is a default-directory
11200 FILENAME is interpreted.
11202 Optional `before-jump-hook' attribute is a function with no
11203 arguments which is called before jumping to position.
11205 Optional `after-jump-hook' attribute is a function with no
11206 arguments which is called after jumping to position.
11208 If `adjust' attribute is specified, searches the line whose
11209 content is CONTENT near the LINENO.
11211 If `recenter' attribute is specified, the line is displayed at
11212 the center of window, otherwise at the top of window.
11215 (define-anything-type-attribute 'timer
11216 '((real-to-display . anything-c-timer-real-to-display)
11217 (action ("Cancel Timer" . cancel-timer)
11218 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11219 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11220 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11221 (persistent-help . "Describe Function"))
11222 "Timer.")
11225 ;;; Default `anything-sources'
11226 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11227 ;; tend to invoke M-x anything directly. So I offer default setting.
11228 (setq anything-sources
11229 '(anything-c-source-buffers-list
11230 anything-c-source-recentf
11231 anything-c-source-files-in-current-dir+))
11234 ;;; Preconfigured Anything
11237 ;;;###autoload
11238 (defun anything-mini ()
11239 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11240 (interactive)
11241 (anything-other-buffer '(anything-c-source-buffers-list
11242 anything-c-source-recentf
11243 anything-c-source-buffer-not-found)
11244 "*anything mini*"))
11245 ;;;###autoload
11246 (defun anything-for-files ()
11247 "Preconfigured `anything' for opening files.
11248 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11249 (interactive)
11250 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11252 ;;;###autoload
11253 (defun anything-recentf ()
11254 "Preconfigured `anything' for `recentf'."
11255 (interactive)
11256 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11258 ;;;###autoload
11259 (defun anything-info-at-point (arg)
11260 "Preconfigured `anything' for searching info at point.
11261 With a prefix-arg insert symbol at point."
11262 (interactive "P")
11263 (let ((anything-c-google-suggest-default-function
11264 'anything-c-google-suggest-emacs-lisp))
11265 (anything :sources '(anything-c-source-info-elisp
11266 anything-c-source-info-cl
11267 anything-c-source-info-pages
11268 anything-c-source-google-suggest)
11269 :input (and arg (thing-at-point 'symbol))
11270 :buffer "*anything info*")))
11272 ;;;###autoload
11273 (defun anything-info-emacs ()
11274 "Preconfigured anything for Emacs manual index."
11275 (interactive)
11276 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11278 ;;;###autoload
11279 (defun anything-show-kill-ring ()
11280 "Preconfigured `anything' for `kill-ring'.
11281 It is drop-in replacement of `yank-pop'.
11282 You may bind this command to M-y.
11283 First call open the kill-ring browser, next calls move to next line."
11284 (interactive)
11285 (let ((buf "*anything kill-ring*"))
11286 (if (get-buffer-window buf)
11287 (with-anything-window
11288 (if (eq (overlay-end anything-selection-overlay) (point-max))
11289 (anything-beginning-of-buffer)
11290 (anything-next-line)))
11291 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11293 ;;;###autoload
11294 (defun anything-minibuffer-history ()
11295 "Preconfigured `anything' for `minibuffer-history'."
11296 (interactive)
11297 (let ((enable-recursive-minibuffers t))
11298 (anything-other-buffer 'anything-c-source-minibuffer-history
11299 "*anything minibuffer-history*")))
11301 ;;;###autoload
11302 (defun anything-gentoo ()
11303 "Preconfigured `anything' for gentoo linux."
11304 (interactive)
11305 (anything-other-buffer '(anything-c-source-gentoo
11306 anything-c-source-use-flags)
11307 "*anything gentoo*"))
11309 ;;;###autoload
11310 (defun anything-imenu ()
11311 "Preconfigured `anything' for `imenu'."
11312 (interactive)
11313 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11315 ;;;###autoload
11316 (defun anything-google-suggest ()
11317 "Preconfigured `anything' for google search with google suggest."
11318 (interactive)
11319 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11321 ;;;###autoload
11322 (defun anything-yahoo-suggest ()
11323 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11324 (interactive)
11325 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11327 ;;; Converted from anything-show-*-only
11328 ;;;###autoload
11329 (defun anything-for-buffers ()
11330 "Preconfigured `anything' for buffer."
11331 (interactive)
11332 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11334 ;;;###autoload
11335 (defun anything-buffers-list ()
11336 "Enhanced preconfigured `anything' for buffer."
11337 (interactive)
11338 (anything :sources '(anything-c-source-buffers-list
11339 anything-c-source-buffer-not-found)
11340 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11342 ;;;###autoload
11343 (defun anything-bbdb ()
11344 "Preconfigured `anything' for BBDB.
11346 Needs BBDB.
11348 http://bbdb.sourceforge.net/"
11349 (interactive)
11350 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11352 ;;;###autoload
11353 (defun anything-locate (arg)
11354 "Preconfigured `anything' for Locate.
11355 Note: you can add locate options after entering pattern.
11356 See 'man locate' for valid options.
11358 You can specify a specific database with prefix argument ARG \(C-u\).
11359 Many databases can be used: navigate and mark them.
11360 See also `anything-locate-with-db'.
11362 To create a user specific db, use
11363 \"updatedb -l 0 -o db_path -U directory\".
11364 Where db_path is a filename matched by
11365 `anything-locate-db-file-regexp'."
11366 (interactive "P")
11367 (anything-locate-1 arg))
11369 ;;;###autoload
11370 (defun anything-w3m-bookmarks ()
11371 "Preconfigured `anything' for w3m bookmark.
11373 Needs w3m and emacs-w3m.
11375 http://w3m.sourceforge.net/
11376 http://emacs-w3m.namazu.org/"
11377 (interactive)
11378 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11379 "*anything w3m bookmarks*"))
11381 ;;;###autoload
11382 (defun anything-firefox-bookmarks ()
11383 "Preconfigured `anything' for firefox bookmark.
11384 You will have to enable html bookmarks in firefox:
11385 open about:config in firefox and double click on this line to enable value \
11386 to true:
11388 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11390 You should have now:
11392 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11394 After closing firefox, you will be able to browse you bookmarks.
11396 (interactive)
11397 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11398 "*Anything Firefox*"))
11400 ;;;###autoload
11401 (defun anything-colors ()
11402 "Preconfigured `anything' for color."
11403 (interactive)
11404 (anything-other-buffer
11405 '(anything-c-source-colors anything-c-source-customize-face)
11406 "*anything colors*"))
11408 ;;;###autoload
11409 (defun anything-bookmarks ()
11410 "Preconfigured `anything' for bookmarks."
11411 (interactive)
11412 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11414 ;;;###autoload
11415 (defun anything-c-pp-bookmarks ()
11416 "Preconfigured `anything' for bookmarks (pretty-printed)."
11417 (interactive)
11418 (anything-other-buffer '(anything-c-source-bookmarks-local
11419 anything-c-source-bookmarks-su
11420 anything-c-source-bookmarks-ssh)
11421 "*anything pp bookmarks*"))
11423 ;;;###autoload
11424 (defun anything-c-insert-latex-math ()
11425 "Preconfigured anything for latex math symbols completion."
11426 (interactive)
11427 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11429 ;;;###autoload
11430 (defun anything-register ()
11431 "Preconfigured `anything' for Emacs registers."
11432 (interactive)
11433 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11435 ;;;###autoload
11436 (defun anything-man-woman ()
11437 "Preconfigured `anything' for Man and Woman pages."
11438 (interactive)
11439 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11441 ;;;###autoload
11442 (defun anything-org-keywords ()
11443 "Preconfigured `anything' for org keywords."
11444 (interactive)
11445 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11447 ;;;###autoload
11448 (defun anything-emms ()
11449 "Preconfigured `anything' for emms sources."
11450 (interactive)
11451 (anything '(anything-c-source-emms-streams
11452 anything-c-source-emms-files
11453 anything-c-source-emms-dired)
11454 nil nil nil nil
11455 "*Anything Emms*"))
11457 ;;;###autoload
11458 (defun anything-eev-anchors ()
11459 "Preconfigured `anything' for eev anchors."
11460 (interactive)
11461 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11463 ;;;###autoload
11464 (defun anything-bm-list ()
11465 "Preconfigured `anything' for visible bookmarks.
11467 Needs bm.el
11469 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11470 (interactive)
11471 (let ((anything-outline-using t))
11472 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11474 ;;;###autoload
11475 (defun anything-timers ()
11476 "Preconfigured `anything' for timers."
11477 (interactive)
11478 (anything-other-buffer '(anything-c-source-absolute-time-timers
11479 anything-c-source-idle-time-timers)
11480 "*anything timers*"))
11482 ;;;###autoload
11483 (defun anything-list-emacs-process ()
11484 "Preconfigured `anything' for emacs process."
11485 (interactive)
11486 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11488 ;;;###autoload
11489 (defun anything-occur ()
11490 "Preconfigured Anything for Occur source.
11491 If region is active, search only in region,
11492 otherwise search in whole buffer."
11493 (interactive)
11494 (let ((anything-compile-source-functions
11495 ;; rule out anything-match-plugin because the input is one regexp.
11496 (delq 'anything-compile-source--match-plugin
11497 (copy-sequence anything-compile-source-functions))))
11498 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11500 ;;;###autoload
11501 (defun anything-browse-code ()
11502 "Preconfigured anything to browse code."
11503 (interactive)
11504 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11506 ;;;###autoload
11507 (defun anything-org-headlines ()
11508 "Preconfigured anything to show org headlines."
11509 (interactive)
11510 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11512 ;;;###autoload
11513 (defun anything-info-gnus ()
11514 "Preconfigured anything to browse Gnus Manual."
11515 (interactive)
11516 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11518 ;;;###autoload
11519 (defun anything-regexp ()
11520 "Preconfigured anything to build regexps and run query-replace-regexp \
11521 against."
11522 (interactive)
11523 (save-restriction
11524 (let ((anything-compile-source-functions
11525 ;; rule out anything-match-plugin because the input is one regexp.
11526 (delq 'anything-compile-source--match-plugin
11527 (copy-sequence anything-compile-source-functions))))
11528 (when (and (anything-region-active-p)
11529 ;; Don't narrow to region if buffer is already narrowed.
11530 (not (anything-current-buffer-narrowed-p)))
11531 (narrow-to-region (region-beginning) (region-end)))
11532 (anything :sources
11533 anything-c-source-regexp
11534 :buffer "*anything regexp*"
11535 :prompt "Regexp: "))))
11537 (defun anything-c-copy-files-async ()
11538 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11539 (interactive)
11540 (let* ((flist (anything-c-read-file-name
11541 "Copy File async: "
11542 :marked-candidates t))
11543 (dest (anything-c-read-file-name
11544 "Copy File async To: "
11545 :preselect (car flist)
11546 :initial-input (car anything-ff-history)
11547 :history (anything-find-files-history :comp-read nil))))
11548 (anything-c-copy-async-with-log flist dest)))
11550 ;;;###autoload
11551 (defun anything-find-files (arg)
11552 "Preconfigured `anything' for anything implementation of `find-file'.
11553 Called with a prefix arg show history if some.
11554 Don't call it from programs, use `anything-find-files-1' instead.
11555 This is the starting point for nearly all actions you can do on files."
11556 (interactive "P")
11557 (let ((any-input (if (and arg anything-ff-history)
11558 (anything-find-files-history)
11559 (anything-find-files-initial-input)))
11560 (presel (buffer-file-name (current-buffer))))
11561 (when (and (eq major-mode 'org-agenda-mode)
11562 org-directory
11563 (not any-input))
11564 (setq any-input (expand-file-name org-directory)))
11565 (set-text-properties 0 (length any-input) nil any-input)
11566 (if any-input
11567 (anything-find-files-1 any-input)
11568 (setq any-input (expand-file-name (anything-c-current-directory)))
11569 (anything-find-files-1
11570 any-input (if anything-ff-transformer-show-only-basename
11571 (and presel (anything-c-basename presel))
11572 presel)))))
11574 ;;;###autoload
11575 (defun anything-write-file ()
11576 "Preconfigured `anything' providing completion for `write-file'."
11577 (interactive)
11578 (let ((anything-mp-highlight-delay nil))
11579 (anything :sources 'anything-c-source-write-file
11580 :input (expand-file-name default-directory)
11581 :prompt "Write buffer to file: "
11582 :buffer "*Anything write file*")))
11584 ;;;###autoload
11585 (defun anything-insert-file ()
11586 "Preconfigured `anything' providing completion for `insert-file'."
11587 (interactive)
11588 (let ((anything-mp-highlight-delay nil))
11589 (anything :sources 'anything-c-source-insert-file
11590 :input (expand-file-name default-directory)
11591 :prompt "Insert file: "
11592 :buffer "*Anything insert file*")))
11594 ;;;###autoload
11595 (defun anything-dired-rename-file ()
11596 "Preconfigured `anything' to rename files from dired."
11597 (interactive)
11598 (anything-dired-do-action-on-file :action 'rename))
11600 ;;;###autoload
11601 (defun anything-dired-copy-file ()
11602 "Preconfigured `anything' to copy files from dired."
11603 (interactive)
11604 (anything-dired-do-action-on-file :action 'copy))
11606 ;;;###autoload
11607 (defun anything-dired-symlink-file ()
11608 "Preconfigured `anything' to symlink files from dired."
11609 (interactive)
11610 (anything-dired-do-action-on-file :action 'symlink))
11612 ;;;###autoload
11613 (defun anything-dired-hardlink-file ()
11614 "Preconfigured `anything' to hardlink files from dired."
11615 (interactive)
11616 (anything-dired-do-action-on-file :action 'hardlink))
11618 ;;;###autoload
11619 (defun anything-do-grep ()
11620 "Preconfigured anything for grep.
11621 Contrarily to Emacs `grep' no default directory is given, but
11622 the full path of candidates in ONLY.
11623 That allow to grep different files not only in `default-directory' but anywhere
11624 by marking them (C-<SPACE>). If one or more directory is selected
11625 grep will search in all files of these directories.
11626 You can use also wildcard in the base name of candidate.
11627 If a prefix arg is given use the -r option of grep.
11628 The prefix arg can be passed before or after start.
11629 See also `anything-do-grep-1'."
11630 (interactive)
11631 (let ((only (anything-c-read-file-name
11632 "Search in file(s): "
11633 :marked-candidates t
11634 :preselect (or (dired-get-filename nil t)
11635 (buffer-file-name (current-buffer)))))
11636 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11637 (anything-do-grep-1 only prefarg)))
11639 ;;;###autoload
11640 (defun anything-do-zgrep (candidate)
11641 "Preconfigured anything for zgrep."
11642 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11643 (ls (anything-c-read-file-name
11644 "Search in file(s): "
11645 :marked-candidates t
11646 :preselect (or (dired-get-filename nil t)
11647 (buffer-file-name (current-buffer))))))
11648 (anything-ff-zgrep-1 ls prefarg)))
11650 (defun anything-c-etags-select (arg)
11651 "Preconfigured anything for etags.
11652 Called with one prefix arg use symbol at point as initial input.
11653 Called with two prefix arg reinitialize cache.
11654 If tag file have been modified reinitialize cache."
11655 (interactive "P")
11656 (let ((tag (anything-c-etags-get-tag-file))
11657 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11658 (anything-quit-if-no-candidate t)
11659 (anything-execute-action-at-once-if-one t)
11660 (anything-compile-source-functions
11661 (if anything-c-etags-use-regexp-search
11662 ;; rule out anything-match-plugin because the input is one regexp.
11663 (delq 'anything-compile-source--match-plugin
11664 (copy-sequence anything-compile-source-functions))
11665 anything-compile-source-functions)))
11666 (when (or (equal arg '(16))
11667 (and anything-c-etags-mtime-alist
11668 (anything-c-etags-file-modified-p tag)))
11669 (remhash tag anything-c-etags-cache))
11670 (if (and tag (file-exists-p tag))
11671 (anything :sources 'anything-c-source-etags-select
11672 :keymap anything-c-etags-map
11673 :input init
11674 :buffer "*anything etags*")
11675 (message "Error: No tag file found, please create one with etags shell command."))))
11677 ;;;###autoload
11678 (defun anything-filelist ()
11679 "Preconfigured `anything' to open files instantly.
11681 See `anything-c-filelist-file-name' docstring for usage."
11682 (interactive)
11683 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11685 ;;;###autoload
11686 (defun anything-filelist+ ()
11687 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11689 This is a replacement for `anything-for-files'.
11690 See `anything-c-filelist-file-name' docstring for usage."
11691 (interactive)
11692 (anything-other-buffer
11693 '(anything-c-source-ffap-line
11694 anything-c-source-ffap-guesser
11695 anything-c-source-buffers-list
11696 anything-c-source-recentf
11697 anything-c-source-bookmarks
11698 anything-c-source-file-cache
11699 anything-c-source-filelist)
11700 "*anything file list*"))
11702 ;;;###autoload
11703 (defun anything-M-x ()
11704 "Preconfigured `anything' for Emacs commands.
11705 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11706 (interactive)
11707 (let* (in-help
11708 help-cand
11709 anything-persistent-action-use-special-display
11710 (history (loop with hist
11711 for i in extended-command-history
11712 for com = (intern i)
11713 when (fboundp com)
11714 collect i into hist finally return hist)))
11715 (flet ((pers-help (candidate)
11716 (let ((hbuf (get-buffer (help-buffer))))
11717 (if (and in-help (string= candidate help-cand))
11718 (progn
11719 ;; When M-x is started from a help buffer,
11720 ;; Don't kill it as it is anything-current-buffer.
11721 (unless (equal hbuf anything-current-buffer)
11722 (kill-buffer hbuf))
11723 (setq in-help nil))
11724 ;; Be sure anything-current-buffer
11725 ;; have not a dedicated window.
11726 (set-window-dedicated-p
11727 (get-buffer-window anything-current-buffer) nil)
11728 (describe-function (intern candidate))
11729 (message nil) ; Erase the new stupid message Type "q"[...]
11730 (setq in-help t))
11731 (setq help-cand candidate))))
11732 (let* ((command
11734 (anything
11735 :sources
11736 '(((name . "Emacs Commands history")
11737 (candidates . history)
11738 (filtered-candidate-transformer
11739 . (lambda (candidates sources)
11740 (loop for i in candidates
11741 do (set-text-properties 0 (length i) nil i)
11742 collect i)))
11743 (persistent-action . pers-help)
11744 (persistent-help . "Describe this command")
11745 (action . identity))
11746 ((name . "Emacs Commands")
11747 (init
11748 . (lambda ()
11749 (with-current-buffer (anything-candidate-buffer 'global)
11750 (goto-char (point-min))
11751 (loop
11752 for sym in (all-completions "" obarray 'commandp)
11753 do (insert (concat sym "\n"))))))
11754 (persistent-action . pers-help)
11755 (persistent-help . "Describe this command")
11756 (filtered-candidate-transformer . anything-M-x-transformer)
11757 (candidates-in-buffer)
11758 (action . identity)))
11759 :buffer "*anything M-x*")
11760 (keyboard-quit)))
11761 (sym-com (intern command)))
11762 (unless current-prefix-arg
11763 (setq current-prefix-arg anything-current-prefix-arg))
11764 ;; Avoid having `this-command' set to *exit-minibuffer.
11765 (setq this-command sym-com)
11766 (call-interactively sym-com)
11767 (setq extended-command-history
11768 (cons command (delete command history)))))))
11770 ;;;###autoload
11771 (defun anything-manage-advice ()
11772 "Preconfigured `anything' to disable/enable function advices."
11773 (interactive)
11774 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11776 ;;;###autoload
11777 (defun anything-bookmark-ext ()
11778 "Preconfigured `anything' for bookmark-extensions sources.
11779 Needs bookmark-ext.el:
11780 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11781 Contain also `anything-c-source-google-suggest'."
11782 (interactive)
11783 (anything
11784 :sources
11785 '(anything-c-source-bookmark-files&dirs
11786 anything-c-source-bookmark-w3m
11787 anything-c-source-google-suggest
11788 anything-c-source-bmkext-addressbook
11789 anything-c-source-bookmark-gnus
11790 anything-c-source-bookmark-info
11791 anything-c-source-bookmark-man
11792 anything-c-source-bookmark-images
11793 anything-c-source-bookmark-su-files&dirs
11794 anything-c-source-bookmark-ssh-files&dirs)
11795 :prompt "SearchBookmark: "
11796 :buffer "*anything bmkext*"))
11798 ;;;###autoload
11799 (defun anything-simple-call-tree ()
11800 "Preconfigured `anything' for simple-call-tree. List function relationships.
11802 Needs simple-call-tree.el.
11803 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11804 (interactive)
11805 (anything-other-buffer
11806 '(anything-c-source-simple-call-tree-functions-callers
11807 anything-c-source-simple-call-tree-callers-functions)
11808 "*anything simple-call-tree*"))
11810 ;;;###autoload
11811 (defun anything-mark-ring ()
11812 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11813 (interactive)
11814 (anything 'anything-c-source-mark-ring))
11816 ;;;###autoload
11817 (defun anything-global-mark-ring ()
11818 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11819 (interactive)
11820 (anything 'anything-c-source-global-mark-ring))
11822 ;;;###autoload
11823 (defun anything-all-mark-rings ()
11824 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11825 `anything-c-source-mark-ring'."
11826 (interactive)
11827 (anything '(anything-c-source-mark-ring
11828 anything-c-source-global-mark-ring)))
11830 ;;;###autoload
11831 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11832 "Preconfigured `anything' to edit or view EmacsWiki page.
11834 Needs yaoddmuse.el.
11836 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11837 (interactive)
11838 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11840 ;;;###autoload
11841 (defun anything-yaoddmuse-emacswiki-post-library ()
11842 "Preconfigured `anything' to post library to EmacsWiki.
11844 Needs yaoddmuse.el.
11846 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11847 (interactive)
11848 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11850 ;;;###autoload
11851 (defun anything-eval-expression (arg)
11852 "Preconfigured anything for `anything-c-source-evaluation-result'."
11853 (interactive "P")
11854 (anything :sources 'anything-c-source-evaluation-result
11855 :input (when arg (thing-at-point 'sexp))
11856 :buffer "*anything eval*"
11857 :keymap anything-eval-expression-map))
11859 ;;;###autoload
11860 (defun anything-eval-expression-with-eldoc ()
11861 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11862 (interactive)
11863 (declare (special eldoc-idle-delay))
11864 (let ((timer (run-with-idle-timer eldoc-idle-delay
11865 'repeat 'anything-eldoc-show-in-eval))
11866 (minibuffer-completing-symbol t) ; Enable lisp completion.
11867 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11868 (unwind-protect
11869 (minibuffer-with-setup-hook
11870 'anything-eldoc-store-minibuffer
11871 (call-interactively 'anything-eval-expression))
11872 (and timer (cancel-timer timer))
11873 (setq anything-eldoc-active-minibuffers-list
11874 (cdr anything-eldoc-active-minibuffers-list)))))
11876 ;;;###autoload
11877 (defun anything-calcul-expression ()
11878 "Preconfigured anything for `anything-c-source-calculation-result'."
11879 (interactive)
11880 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11882 ;;;###autoload
11883 (defun anything-surfraw (pattern engine)
11884 "Preconfigured `anything' to search PATTERN with search ENGINE."
11885 (interactive (list (read-string "SearchFor: ")
11886 (anything-comp-read
11887 "Engine: "
11888 (anything-c-build-elvi-list)
11889 :must-match t
11890 :name "Surfraw Search Engines"
11891 :history anything-surfraw-engines-history)))
11892 (let* ((engine-nodesc (car (split-string engine)))
11893 (url (with-temp-buffer
11894 (apply 'call-process "surfraw" nil t nil
11895 ;;JAVE
11896 (append (list engine-nodesc "-p") (split-string pattern)))
11897 (replace-regexp-in-string
11898 "\n" "" (buffer-string))))
11899 (browse-url-browser-function (or anything-surfraw-default-browser-function
11900 browse-url-browser-function)))
11901 (if (string= engine-nodesc "W")
11902 (anything-c-browse-url)
11903 (anything-c-browse-url url)
11904 (setq anything-surfraw-engines-history
11905 (cons engine (delete engine anything-surfraw-engines-history))))))
11907 ;;;###autoload
11908 (defun anything-call-source ()
11909 "Preconfigured `anything' to call anything source."
11910 (interactive)
11911 (anything 'anything-c-source-call-source nil nil nil nil
11912 anything-source-select-buffer))
11914 ;;;###autoload
11915 (defun anything-execute-anything-command ()
11916 "Preconfigured `anything' to execute preconfigured `anything'."
11917 (interactive)
11918 (anything-other-buffer 'anything-c-source-anything-commands
11919 "*anything commands*"))
11921 ;;;###autoload
11922 (defun anything-create (&optional string initial-input)
11923 "Preconfigured `anything' to do many create actions from STRING.
11924 See also `anything-create--actions'."
11925 (interactive)
11926 (setq string (or string (read-string "Create Anything: " initial-input)))
11927 (anything '(((name . "Anything Create")
11928 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
11929 (candidates . anything-create--actions)
11930 (candidate-number-limit)
11931 (action . (lambda (func) (funcall func string)))))))
11933 ;;;###autoload
11934 (defun anything-top ()
11935 "Preconfigured `anything' for top command."
11936 (interactive)
11937 (let ((anything-samewindow t)
11938 (anything-enable-shortcuts)
11939 (anything-display-function 'anything-default-display-buffer)
11940 (anything-candidate-number-limit 9999))
11941 (save-window-excursion
11942 (delete-other-windows)
11943 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
11945 ;;;###autoload
11946 (defun anything-select-xfont ()
11947 "Preconfigured `anything' to select Xfont."
11948 (interactive)
11949 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
11951 ;;;###autoload
11952 (defun anything-world-time ()
11953 "Preconfigured `anything' to show world time."
11954 (interactive)
11955 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
11957 ;;;###autoload
11958 (defun anything-apt (arg query)
11959 "Preconfigured `anything' : frontend of APT package manager.
11960 With a prefix arg reload cache."
11961 (interactive "P\nsSearch Package: ")
11962 (when arg
11963 (setq anything-c-apt-installed-packages nil)
11964 (setq anything-c-apt-all-packages nil))
11965 (anything :sources 'anything-c-source-apt
11966 :prompt "Search Package: " :input query))
11968 ;;;###autoload
11969 (defun anything-esh-pcomplete ()
11970 "Preconfigured anything to provide anything completion in eshell."
11971 (interactive)
11972 (let* ((anything-quit-if-no-candidate t)
11973 (anything-execute-action-at-once-if-one t)
11974 (target (thing-at-point 'symbol))
11975 (end (point))
11976 (beg (or (and target (- end (length target)))
11977 ;; Nothing at point.
11978 (progn (insert " ") (point)))))
11979 (setq anything-ec-target (or target " "))
11980 (with-anything-show-completion beg end
11981 (anything :sources 'anything-c-source-esh
11982 :input (anything-ff-set-pattern ; Handle tramp filenames.
11983 (car (last (ignore-errors ; Needed in lisp symbols completion.
11984 (pcomplete-parse-arguments)))))))))
11986 ;;;###autoload
11987 (defun anything-eshell-history ()
11988 "Preconfigured anything for eshell history."
11989 (interactive)
11990 (let* ((end (point))
11991 (beg (save-excursion (eshell-bol) (point)))
11992 flag-empty)
11993 (when (eq beg end)
11994 (insert " ")
11995 (setq flag-empty t)
11996 (setq end (point)))
11997 (unwind-protect
11998 (with-anything-show-completion beg end
11999 (anything :sources 'anything-c-source-eshell-history
12000 :buffer "*Eshell history*"))
12001 (when (and flag-empty
12002 (looking-back " "))
12003 (delete-char -1)))))
12005 ;;;###autoload
12006 (defun anything-c-run-external-command (program)
12007 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12008 If program is already running exit with error.
12009 You can set your own list of commands with
12010 `anything-c-external-commands-list'."
12011 (interactive (list
12012 (anything-comp-read
12013 "RunProgram: "
12014 (anything-c-external-commands-list-1 'sort)
12015 :must-match t
12016 :name "External Commands"
12017 :history anything-external-command-history)))
12018 (anything-run-or-raise program)
12019 (setq anything-external-command-history
12020 (cons program (delete program
12021 (loop for i in anything-external-command-history
12022 when (executable-find i) collect i)))))
12024 ;;;###autoload
12025 (defun anything-ratpoison-commands ()
12026 "Preconfigured `anything' to execute ratpoison commands."
12027 (interactive)
12028 (anything-other-buffer 'anything-c-source-ratpoison-commands
12029 "*anything ratpoison commands*"))
12031 ;;;###autoload
12032 (defun anything-ucs ()
12033 "Preconfigured anything for `ucs-names' math symbols."
12034 (interactive)
12035 (anything :sources 'anything-c-source-ucs
12036 :keymap anything-c-ucs-map))
12040 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12043 (provide 'anything-config)
12045 ;;; Local Variables:
12046 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12047 ;;; End:
12049 ;; How to save (DO NOT REMOVE!!)
12050 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12051 ;;; anything-config.el ends here
12053 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12054 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12055 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12056 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12057 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12058 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12059 ;;; LocalWords: dotimes Thierry online vname
12060 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12061 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12062 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12063 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12064 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12065 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12066 ;;; LocalWords: startpos noselect dont desc